2121
2222package processing .app ;
2323
24+ import processing .app .helpers .FileUtils ;
25+ import processing .app .helpers .FileUtils .SplitFile ;
2426import processing .app .helpers .OSUtils ;
2527import processing .app .helpers .PreferencesHelper ;
2628import 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