2424
2525import java .awt .*;
2626import java .awt .event .*;
27+ import java .awt .image .BufferedImage ;
2728import java .util .ArrayList ;
2829
2930import javax .swing .*;
@@ -96,17 +97,6 @@ public EditorToolbar(Editor editor, Base base) { //, JMenu menu) {
9697// this.menu = menu;
9798
9899 buttons = new ArrayList <Button >();
99- // buttonCount = 0;
100- // which = new int[BUTTON_COUNT];
101-
102- // which[buttonCount++] = RUN;
103- // which[buttonCount++] = STOP;
104- // which[buttonCount++] = NEW;
105- // which[buttonCount++] = OPEN;
106- // which[buttonCount++] = SAVE;
107- // which[buttonCount++] = EXPORT;
108-
109- // currentRollover = -1;
110100 rollover = null ;
111101
112102 mode = editor .getMode ();
@@ -131,23 +121,37 @@ public EditorToolbar(Editor editor, Base base) { //, JMenu menu) {
131121 * otherwise createImage() might fail.
132122 */
133123 public Image [][] loadImages () {
134- // Image allButtons = Base.getThemeImage("buttons.gif", this);
135- // Image allButtons = Base.loadImage(file);
136- Image allButtons = mode .loadImage ("theme/buttons.gif" );
137- int count = allButtons .getWidth (this ) / BUTTON_WIDTH ;
138- // System.out.println("width is " + allButtons.getWidth(this));
124+ int res = Toolkit .isRetina () ? 2 : 1 ;
125+
126+ Image allButtons = null ;
127+ // Some modes may not have a 2x version. If a mode doesn't have a 1x
128+ // version, this will cause an error... they should always have 1x.
129+ if (res == 2 ) {
130+ allButtons = mode .loadImage ("theme/buttons-2x.png" );
131+ if (allButtons == null ) {
132+ res = 1 ; // take him down a notch
133+ }
134+ }
135+ if (res == 1 ) {
136+ allButtons = mode .loadImage ("theme/buttons.png" );
137+ if (allButtons == null ) {
138+ // use the old (pre-2.0b9) file name
139+ allButtons = mode .loadImage ("theme/buttons.gif" );
140+ }
141+ }
142+
143+ int count = allButtons .getWidth (this ) / BUTTON_WIDTH *res ;
139144 Image [][] buttonImages = new Image [count ][3 ];
140145
141146 for (int i = 0 ; i < count ; i ++) {
142147 for (int state = 0 ; state < 3 ; state ++) {
143- // Toolkit tk = Toolkit.getDefaultToolkit();
144- // Image image = tk.createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
145- // System.out.println("image is " + image + " " + BUTTON_WIDTH + " " + BUTTON_HEIGHT);
146- Image image = createImage (BUTTON_WIDTH , BUTTON_HEIGHT );
148+ // Image image = createImage(BUTTON_WIDTH*res, BUTTON_HEIGHT*res);
149+ Image image = new BufferedImage (BUTTON_WIDTH *res , BUTTON_HEIGHT *res , BufferedImage .TYPE_INT_ARGB );
147150 Graphics g = image .getGraphics ();
148151 g .drawImage (allButtons ,
149- -(i *BUTTON_IMAGE_SIZE ) - 3 ,
150- (-2 + state )*BUTTON_IMAGE_SIZE , null );
152+ -(i *BUTTON_IMAGE_SIZE *res ) - 3 ,
153+ (state -2 )*BUTTON_IMAGE_SIZE *res , null );
154+ g .dispose ();
151155 buttonImages [i ][state ] = image ;
152156 }
153157 }
0 commit comments