diff --git a/app/src/cc/arduino/view/preferences/Preferences.java b/app/src/cc/arduino/view/preferences/Preferences.java index 53bf4dd58..4ea522e35 100644 --- a/app/src/cc/arduino/view/preferences/Preferences.java +++ b/app/src/cc/arduino/view/preferences/Preferences.java @@ -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) { diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 8b70c604e..32ab81486 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -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; - } - // ................................................................... diff --git a/app/src/processing/app/EditorHeader.java b/app/src/processing/app/EditorHeader.java index 2906ec9f7..1a54c502c 100644 --- a/app/src/processing/app/EditorHeader.java +++ b/app/src/processing/app/EditorHeader.java @@ -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); } } } diff --git a/app/src/processing/app/EditorLineStatus.java b/app/src/processing/app/EditorLineStatus.java index bb13823d2..2e559162d 100644 --- a/app/src/processing/app/EditorLineStatus.java +++ b/app/src/processing/app/EditorLineStatus.java @@ -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 diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java index 1ba6ce3cd..1f0e371d1 100644 --- a/app/src/processing/app/EditorToolbar.java +++ b/app/src/processing/app/EditorToolbar.java @@ -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++) { diff --git a/app/src/processing/app/Theme.java b/app/src/processing/app/Theme.java index 16a6f03f5..751073240 100644 --- a/app/src/processing/app/Theme.java +++ b/app/src/processing/app/Theme.java @@ -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 attr = new Hashtable(); 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); + } + }