1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-18 07:52:14 +01:00

Moving getLibImage and getThemeImage into Theme class

This commit is contained in:
Cristian Maglie 2015-12-30 14:46:59 +01:00
parent f1fc862575
commit f239f5b5ab
6 changed files with 66 additions and 61 deletions

View File

@ -36,6 +36,7 @@ import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.PreferencesData;
import processing.app.Theme;
import processing.app.helpers.FileUtils;
import processing.app.legacy.PApplet;
@ -196,7 +197,7 @@ public class Preferences extends javax.swing.JDialog {
additionalBoardsManagerField.setToolTipText(tr("Enter a comma separated list of urls"));
extendedAdditionalUrlFieldWindow.setIcon(new ImageIcon(Base.getThemeImage("newwindow.png", this)));
extendedAdditionalUrlFieldWindow.setIcon(new ImageIcon(Theme.getThemeImage("newwindow.png", this)));
extendedAdditionalUrlFieldWindow.setMargin(new java.awt.Insets(1, 1, 1, 1));
extendedAdditionalUrlFieldWindow.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {

View File

@ -1743,7 +1743,7 @@ public class Base {
*/
@SuppressWarnings("serial")
public void handleAbout() {
final Image image = getLibImage("about.png", activeEditor);
final Image image = Theme.getLibImage("about.png", activeEditor);
final Window window = new Window(activeEditor) {
public void paint(Graphics g) {
g.drawImage(image, 0, 0, null);
@ -2038,57 +2038,6 @@ public class Base {
}
/**
* Get an image associated with the current color theme.
*/
static public Image getThemeImage(String name, Component who) {
return getLibImage("theme/" + name, who);
}
/**
* Return an Image object from inside the Processing lib folder.
*/
static public Image getLibImage(String filename, Component who) {
Toolkit tk = Toolkit.getDefaultToolkit();
SplitFile name = FileUtils.splitFilename(filename);
int scale = Theme.getInteger("gui.scalePercent");
File libFolder = getContentFile("lib");
File imageFile1x = new File(libFolder, name.basename + "." + name.extension);
File imageFile2x = new File(libFolder, name.basename + "@2x." + name.extension);
File imageFile;
int sourceScale;
if ((scale > 125 && imageFile2x.exists()) || !imageFile1x.exists()) {
imageFile = imageFile2x;
sourceScale = 200;
} else {
imageFile = imageFile1x;
sourceScale = 100;
}
Image image = tk.getImage(imageFile.getAbsolutePath());
MediaTracker tracker = new MediaTracker(who);
tracker.addImage(image, 0);
try {
tracker.waitForAll();
} catch (InterruptedException e) {
}
if (scale != sourceScale) {
int width = image.getWidth(null) * scale / sourceScale;
int height = image.getHeight(null) * scale / sourceScale;
image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
tracker.addImage(image, 1);
try {
tracker.waitForAll();
} catch (InterruptedException e) {
}
}
return image;
}
// ...................................................................

View File

@ -150,7 +150,7 @@ public class EditorHeader extends JComponent {
for (int i = 0; i < STATUS.length; i++) {
for (int j = 0; j < WHERE.length; j++) {
String path = "tab-" + STATUS[i] + "-" + WHERE[j] + ".png";
pieces[i][j] = Base.getThemeImage(path, this);
pieces[i][j] = Theme.getThemeImage(path, this);
}
}
}

View File

@ -58,7 +58,7 @@ public class EditorLineStatus extends JComponent {
high = Theme.getInteger("linestatus.height") * Theme.getInteger("gui.scalePercent") / 100;
if (OSUtils.isMacOS()) {
resize = Base.getThemeImage("resize.png", this);
resize = Theme.getThemeImage("resize.png", this);
}
//linestatus.bgcolor = #000000
//linestatus.font = SansSerif,plain,10

View File

@ -139,7 +139,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
}
private void loadButtons() {
Image allButtons = Base.getThemeImage("buttons.png", this);
Image allButtons = Theme.getThemeImage("buttons.png", this);
buttonImages = new Image[BUTTON_COUNT][3];
for (int i = 0; i < BUTTON_COUNT; i++) {

View File

@ -21,6 +21,8 @@
package processing.app;
import processing.app.helpers.FileUtils;
import processing.app.helpers.FileUtils.SplitFile;
import processing.app.helpers.OSUtils;
import processing.app.helpers.PreferencesHelper;
import processing.app.helpers.PreferencesMap;
@ -55,8 +57,9 @@ public class Theme {
try {
table.load(new File(BaseNoGui.getContentFile("lib"), "theme/theme.txt"));
} catch (Exception te) {
Base.showError(null, tr("Could not read color theme settings.\n" +
"You'll need to reinstall Arduino."), te);
Base.showError(null, tr("Could not read color theme settings.\n"
+ "You'll need to reinstall Arduino."),
te);
}
// other things that have to be set explicitly for the defaults
@ -124,7 +127,8 @@ public class Theme {
}
int scale = getInteger("gui.scalePercent");
if (scale != 100) {
font = font.deriveFont((float)(font.getSize()) * (float)scale / (float)100.0);
font = font
.deriveFont((float) (font.getSize()) * (float) scale / (float) 100.0);
}
return font;
}
@ -159,7 +163,7 @@ public class Theme {
}
}
//System.out.println(font.getFamily() + ", " + font.getName());
// System.out.println(font.getFamily() + ", " + font.getName());
return font;
}
@ -173,7 +177,8 @@ public class Theme {
boolean italic = style.contains("italic");
boolean underlined = style.contains("underlined");
Font styledFont = new Font(font.getFamily(), (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize());
Font styledFont = new Font(font.getFamily(),
(bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize());
if (underlined) {
Map<TextAttribute, Object> attr = new Hashtable<TextAttribute, Object>();
attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
@ -187,4 +192,54 @@ public class Theme {
return result;
}
/**
* Return an Image object from inside the Processing lib folder.
*/
static public Image getLibImage(String filename, Component who) {
Toolkit tk = Toolkit.getDefaultToolkit();
SplitFile name = FileUtils.splitFilename(filename);
int scale = getInteger("gui.scalePercent");
File libFolder = Base.getContentFile("lib");
File imageFile1x = new File(libFolder, name.basename + "." + name.extension);
File imageFile2x = new File(libFolder, name.basename + "@2x." + name.extension);
File imageFile;
int sourceScale;
if ((scale > 125 && imageFile2x.exists()) || !imageFile1x.exists()) {
imageFile = imageFile2x;
sourceScale = 200;
} else {
imageFile = imageFile1x;
sourceScale = 100;
}
Image image = tk.getImage(imageFile.getAbsolutePath());
MediaTracker tracker = new MediaTracker(who);
tracker.addImage(image, 0);
try {
tracker.waitForAll();
} catch (InterruptedException e) {
}
if (scale != sourceScale) {
int width = image.getWidth(null) * scale / sourceScale;
int height = image.getHeight(null) * scale / sourceScale;
image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
tracker.addImage(image, 1);
try {
tracker.waitForAll();
} catch (InterruptedException e) {
}
}
return image;
}
/**
* Get an image associated with the current color theme.
*/
static public Image getThemeImage(String name, Component who) {
return getLibImage("theme/" + name, who);
}
}