Skip to content

Commit f239f5b

Browse files
committed
Moving getLibImage and getThemeImage into Theme class
1 parent f1fc862 commit f239f5b

File tree

6 files changed

+66
-61
lines changed

6 files changed

+66
-61
lines changed

app/src/cc/arduino/view/preferences/Preferences.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import processing.app.BaseNoGui;
3737
import processing.app.I18n;
3838
import processing.app.PreferencesData;
39+
import processing.app.Theme;
3940
import processing.app.helpers.FileUtils;
4041
import processing.app.legacy.PApplet;
4142

@@ -196,7 +197,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
196197

197198
additionalBoardsManagerField.setToolTipText(tr("Enter a comma separated list of urls"));
198199

199-
extendedAdditionalUrlFieldWindow.setIcon(new ImageIcon(Base.getThemeImage("newwindow.png", this)));
200+
extendedAdditionalUrlFieldWindow.setIcon(new ImageIcon(Theme.getThemeImage("newwindow.png", this)));
200201
extendedAdditionalUrlFieldWindow.setMargin(new java.awt.Insets(1, 1, 1, 1));
201202
extendedAdditionalUrlFieldWindow.addActionListener(new java.awt.event.ActionListener() {
202203
public void actionPerformed(java.awt.event.ActionEvent evt) {

app/src/processing/app/Base.java

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ static public String[] headerListFromIncludePath(File path) throws IOException {
17431743
*/
17441744
@SuppressWarnings("serial")
17451745
public void handleAbout() {
1746-
final Image image = getLibImage("about.png", activeEditor);
1746+
final Image image = Theme.getLibImage("about.png", activeEditor);
17471747
final Window window = new Window(activeEditor) {
17481748
public void paint(Graphics g) {
17491749
g.drawImage(image, 0, 0, null);
@@ -2038,57 +2038,6 @@ static public File getContentFile(String name) {
20382038
}
20392039

20402040

2041-
/**
2042-
* Get an image associated with the current color theme.
2043-
*/
2044-
static public Image getThemeImage(String name, Component who) {
2045-
return getLibImage("theme/" + name, who);
2046-
}
2047-
2048-
2049-
/**
2050-
* Return an Image object from inside the Processing lib folder.
2051-
*/
2052-
static public Image getLibImage(String filename, Component who) {
2053-
Toolkit tk = Toolkit.getDefaultToolkit();
2054-
2055-
SplitFile name = FileUtils.splitFilename(filename);
2056-
int scale = Theme.getInteger("gui.scalePercent");
2057-
File libFolder = getContentFile("lib");
2058-
File imageFile1x = new File(libFolder, name.basename + "." + name.extension);
2059-
File imageFile2x = new File(libFolder, name.basename + "@2x." + name.extension);
2060-
2061-
File imageFile;
2062-
int sourceScale;
2063-
if ((scale > 125 && imageFile2x.exists()) || !imageFile1x.exists()) {
2064-
imageFile = imageFile2x;
2065-
sourceScale = 200;
2066-
} else {
2067-
imageFile = imageFile1x;
2068-
sourceScale = 100;
2069-
}
2070-
2071-
Image image = tk.getImage(imageFile.getAbsolutePath());
2072-
MediaTracker tracker = new MediaTracker(who);
2073-
tracker.addImage(image, 0);
2074-
try {
2075-
tracker.waitForAll();
2076-
} catch (InterruptedException e) {
2077-
}
2078-
2079-
if (scale != sourceScale) {
2080-
int width = image.getWidth(null) * scale / sourceScale;
2081-
int height = image.getHeight(null) * scale / sourceScale;
2082-
image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
2083-
tracker.addImage(image, 1);
2084-
try {
2085-
tracker.waitForAll();
2086-
} catch (InterruptedException e) {
2087-
}
2088-
}
2089-
return image;
2090-
}
2091-
20922041
// ...................................................................
20932042

20942043

app/src/processing/app/EditorHeader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public EditorHeader(Editor eddie) {
150150
for (int i = 0; i < STATUS.length; i++) {
151151
for (int j = 0; j < WHERE.length; j++) {
152152
String path = "tab-" + STATUS[i] + "-" + WHERE[j] + ".png";
153-
pieces[i][j] = Base.getThemeImage(path, this);
153+
pieces[i][j] = Theme.getThemeImage(path, this);
154154
}
155155
}
156156
}

app/src/processing/app/EditorLineStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public EditorLineStatus() {
5858
high = Theme.getInteger("linestatus.height") * Theme.getInteger("gui.scalePercent") / 100;
5959

6060
if (OSUtils.isMacOS()) {
61-
resize = Base.getThemeImage("resize.png", this);
61+
resize = Theme.getThemeImage("resize.png", this);
6262
}
6363
//linestatus.bgcolor = #000000
6464
//linestatus.font = SansSerif,plain,10

app/src/processing/app/EditorToolbar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public EditorToolbar(Editor editor, JMenu menu) {
139139
}
140140

141141
private void loadButtons() {
142-
Image allButtons = Base.getThemeImage("buttons.png", this);
142+
Image allButtons = Theme.getThemeImage("buttons.png", this);
143143
buttonImages = new Image[BUTTON_COUNT][3];
144144

145145
for (int i = 0; i < BUTTON_COUNT; i++) {

app/src/processing/app/Theme.java

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
package processing.app;
2323

24+
import processing.app.helpers.FileUtils;
25+
import processing.app.helpers.FileUtils.SplitFile;
2426
import processing.app.helpers.OSUtils;
2527
import processing.app.helpers.PreferencesHelper;
2628
import processing.app.helpers.PreferencesMap;
@@ -55,8 +57,9 @@ static protected void init() {
5557
try {
5658
table.load(new File(BaseNoGui.getContentFile("lib"), "theme/theme.txt"));
5759
} catch (Exception te) {
58-
Base.showError(null, tr("Could not read color theme settings.\n" +
59-
"You'll need to reinstall Arduino."), te);
60+
Base.showError(null, tr("Could not read color theme settings.\n"
61+
+ "You'll need to reinstall Arduino."),
62+
te);
6063
}
6164

6265
// other things that have to be set explicitly for the defaults
@@ -124,7 +127,8 @@ static public Font getFont(String attr) {
124127
}
125128
int scale = getInteger("gui.scalePercent");
126129
if (scale != 100) {
127-
font = font.deriveFont((float)(font.getSize()) * (float)scale / (float)100.0);
130+
font = font
131+
.deriveFont((float) (font.getSize()) * (float) scale / (float) 100.0);
128132
}
129133
return font;
130134
}
@@ -159,7 +163,7 @@ public static final Font getDefaultFont() {
159163
}
160164
}
161165

162-
//System.out.println(font.getFamily() + ", " + font.getName());
166+
// System.out.println(font.getFamily() + ", " + font.getName());
163167
return font;
164168
}
165169

@@ -173,7 +177,8 @@ public static Map<String, Object> getStyledFont(String what, Font font) {
173177
boolean italic = style.contains("italic");
174178
boolean underlined = style.contains("underlined");
175179

176-
Font styledFont = new Font(font.getFamily(), (bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize());
180+
Font styledFont = new Font(font.getFamily(),
181+
(bold ? Font.BOLD : 0) | (italic ? Font.ITALIC : 0), font.getSize());
177182
if (underlined) {
178183
Map<TextAttribute, Object> attr = new Hashtable<TextAttribute, Object>();
179184
attr.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
@@ -187,4 +192,54 @@ public static Map<String, Object> getStyledFont(String what, Font font) {
187192
return result;
188193
}
189194

195+
/**
196+
* Return an Image object from inside the Processing lib folder.
197+
*/
198+
static public Image getLibImage(String filename, Component who) {
199+
Toolkit tk = Toolkit.getDefaultToolkit();
200+
201+
SplitFile name = FileUtils.splitFilename(filename);
202+
int scale = getInteger("gui.scalePercent");
203+
File libFolder = Base.getContentFile("lib");
204+
File imageFile1x = new File(libFolder, name.basename + "." + name.extension);
205+
File imageFile2x = new File(libFolder, name.basename + "@2x." + name.extension);
206+
207+
File imageFile;
208+
int sourceScale;
209+
if ((scale > 125 && imageFile2x.exists()) || !imageFile1x.exists()) {
210+
imageFile = imageFile2x;
211+
sourceScale = 200;
212+
} else {
213+
imageFile = imageFile1x;
214+
sourceScale = 100;
215+
}
216+
217+
Image image = tk.getImage(imageFile.getAbsolutePath());
218+
MediaTracker tracker = new MediaTracker(who);
219+
tracker.addImage(image, 0);
220+
try {
221+
tracker.waitForAll();
222+
} catch (InterruptedException e) {
223+
}
224+
225+
if (scale != sourceScale) {
226+
int width = image.getWidth(null) * scale / sourceScale;
227+
int height = image.getHeight(null) * scale / sourceScale;
228+
image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
229+
tracker.addImage(image, 1);
230+
try {
231+
tracker.waitForAll();
232+
} catch (InterruptedException e) {
233+
}
234+
}
235+
return image;
236+
}
237+
238+
/**
239+
* Get an image associated with the current color theme.
240+
*/
241+
static public Image getThemeImage(String name, Component who) {
242+
return getLibImage("theme/" + name, who);
243+
}
244+
190245
}

0 commit comments

Comments
 (0)