@@ -42,7 +42,7 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
4242 static final int BUTTON_HEIGHT = 32 ;
4343 /** The amount of space between groups of buttons on the toolbar. */
4444 static final int BUTTON_GAP = 5 ;
45- /** Size of the button image being chopped up . */
45+ /** Size (both width and height) of the buttons in the source image . */
4646 static final int BUTTON_IMAGE_SIZE = 33 ;
4747
4848 static final int INACTIVE = 0 ;
@@ -58,21 +58,8 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
5858
5959 Color bgcolor ;
6060
61- // static Image[][] buttonImages;
62- // int currentRollover;
6361 protected Button rollover ;
6462
65- // int buttonCount;
66- /** Current state for this button */
67- // int[] state; // = new int[BUTTON_COUNT];
68- /** Current image for this button's state */
69- // Image[] stateImage;
70- // int which[]; // mapping indices to implementation
71-
72- // int x1[], x2[];
73- static final int TOP = 2 ;
74- static final int BOTTOM = BUTTON_HEIGHT ;
75-
7663 Font statusFont ;
7764 Color statusColor ;
7865
@@ -82,19 +69,18 @@ public abstract class EditorToolbar extends JComponent implements MouseInputList
8269 Color modeButtonColor ;
8370 Font modeTextFont ;
8471 Color modeTextColor ;
85- String modeTitle ; // = "JAVA"; //"Java";
86- // String modeTitle = "ANDROID"; //"Java";
72+ String modeTitle ;
8773 int modeX1 , modeY1 ;
8874 int modeX2 , modeY2 ;
8975 JMenu modeMenu ;
9076
9177 protected ArrayList <Button > buttons ;
92-
78+
9379 static final int ARROW_WIDTH = 6 ;
9480 static final int ARROW_HEIGHT = 6 ;
95- Image modeArrow ;
96-
81+ static Image modeArrow ;
9782
83+
9884 public EditorToolbar (Editor editor , Base base ) { //, JMenu menu) {
9985 this .editor = editor ;
10086 this .base = base ;
@@ -112,6 +98,11 @@ public EditorToolbar(Editor editor, Base base) { //, JMenu menu) {
11298 modeTextFont = mode .getFont ("mode.button.font" );
11399 modeButtonColor = mode .getColor ("mode.button.color" );
114100
101+ if (modeArrow == null ) {
102+ String suffix = Toolkit .highResDisplay () ? "-2x.png" : ".png" ;
103+ modeArrow = Toolkit .getLibImage ("mode-arrow" + suffix );
104+ }
105+
115106 addMouseListener (this );
116107 addMouseMotionListener (this );
117108 }
@@ -122,11 +113,13 @@ public EditorToolbar(Editor editor, Base base) { //, JMenu menu) {
122113
123114
124115 /**
125- * Only call this from paintComponent, or when the comp is displayable,
126- * otherwise createImage() might fail.
116+ * Load button images and slice them up. Only call this from paintComponent,
117+ * or when the comp is displayable, otherwise createImage() might fail.
118+ * (Using BufferedImage instead of createImage() nowadays, so that may
119+ * no longer be relevant.)
127120 */
128121 public Image [][] loadImages () {
129- int res = Toolkit .isRetina () ? 2 : 1 ;
122+ int res = Toolkit .highResDisplay () ? 2 : 1 ;
130123
131124 String suffix = null ;
132125 Image allButtons = null ;
@@ -164,11 +157,6 @@ public Image[][] loadImages() {
164157 }
165158 }
166159
167- // Load the dropdown arrow, based on all the work done above
168- modeArrow = mode .loadImage ("theme/mode-arrow" + suffix );
169- // And the background image
170- // backgroundImage = mode.loadImage("theme/mode" + suffix);
171-
172160 return buttonImages ;
173161 }
174162
@@ -185,7 +173,7 @@ public void paintComponent(Graphics screen) {
185173 Dimension size = getSize ();
186174 if ((offscreen == null ) ||
187175 (size .width != width ) || (size .height != height )) {
188- if (Toolkit .isRetina ()) {
176+ if (Toolkit .highResDisplay ()) {
189177 offscreen = createImage (size .width *2 , size .height *2 );
190178 } else {
191179 offscreen = createImage (size .width , size .height );
@@ -213,7 +201,7 @@ public void paintComponent(Graphics screen) {
213201 Graphics g = offscreen .getGraphics ();
214202 Graphics2D g2 = (Graphics2D ) g ;
215203
216- if (Toolkit .isRetina ()) {
204+ if (Toolkit .highResDisplay ()) {
217205 // scale everything 2x, will be scaled down when drawn to the screen
218206 g2 .scale (2 , 2 );
219207 } else {
@@ -233,7 +221,7 @@ public void paintComponent(Graphics screen) {
233221// g.drawImage(stateImage[i], x1[i], y1, null);
234222// }
235223 for (Button b : buttons ) {
236- g .drawImage (b .stateImage , b .left , TOP , BUTTON_WIDTH , BUTTON_HEIGHT , null );
224+ g .drawImage (b .stateImage , b .left , 0 , BUTTON_WIDTH , BUTTON_HEIGHT , null );
237225 }
238226
239227 g .setColor (statusColor );
@@ -314,9 +302,8 @@ public void mouseMoved(MouseEvent e) {
314302 int y = e .getY ();
315303
316304 if (rollover != null ) {
317- // if ((x > x1[currentRollover]) && (y > y1) &&
318- // (x < x2[currentRollover]) && (y < y2)) {
319- if (y > TOP && y < BOTTOM && x > rollover .left && x < rollover .right ) {
305+ //if (y > TOP && y < BOTTOM && x > rollover.left && x < rollover.right) {
306+ if (y > 0 && y < getHeight () && x > rollover .left && x < rollover .right ) {
320307 // nothing has changed
321308 return ;
322309
@@ -386,7 +373,7 @@ public void mouseDragged(MouseEvent e) { }
386373 private Button findSelection (int x , int y ) {
387374 // if app loads slowly and cursor is near the buttons
388375 // when it comes up, the app may not have time to load
389- if (offscreen != null && y > TOP && y < BOTTOM ) {
376+ if (offscreen != null && y > 0 && y < getHeight () ) {
390377 for (Button b : buttons ) {
391378 if (x > b .left && x < b .right ) {
392379 return b ;
0 commit comments