@@ -78,14 +78,18 @@ public class EditorStatus extends BasicSplitPaneDivider { //JPanel {
7878 String url ;
7979 int rightEdge ;
8080 int mouseX ;
81- boolean urlRollover ;
81+ int rolloverState ;
82+ static final int ROLLOVER_NONE = 0 ;
83+ static final int ROLLOVER_URL = 1 ;
84+ static final int ROLLOVER_COLLAPSE = 2 ;
8285
8386 Font font ;
8487 FontMetrics metrics ;
8588 int ascent ;
8689
8790 Image offscreen ;
8891 int sizeW , sizeH ;
92+ boolean collapseState = false ;
8993
9094 int response ;
9195
@@ -108,19 +112,29 @@ public void mouseEntered(MouseEvent e) {
108112
109113 @ Override
110114 public void mousePressed (MouseEvent e ) {
111- if (urlRollover ) {
115+ if (rolloverState == ROLLOVER_URL ) {
112116 Platform .openURL (url );
117+ } else if (rolloverState == ROLLOVER_COLLAPSE ) {
118+ collapse (!collapseState );
113119 }
114120 }
115121
116122 @ Override
117123 public void mouseExited (MouseEvent e ) {
124+ mouseX = -100 ;
118125 updateMouse ();
119126 }
120127
121128 });
122129
123130 addMouseMotionListener (new MouseMotionAdapter () {
131+ @ Override
132+ public void mouseDragged (MouseEvent e ) {
133+ // BasicSplitPaneUI.startDragging gets called even when you click but
134+ // don't drag, so we can't expand the console whenever that gets called
135+ // or the button wouldn't work.
136+ collapse (false );
137+ }
124138
125139 @ Override
126140 public void mouseMoved (MouseEvent e ) {
@@ -131,11 +145,25 @@ public void mouseMoved(MouseEvent e) {
131145 }
132146
133147
148+ void collapse (boolean doCollapse ) {
149+ if (collapseState == doCollapse ) return ;
150+ collapseState = doCollapse ;
151+ editor .footer .setVisible (!doCollapse );
152+ splitPane .resetToPreferredSizes ();
153+ }
154+
155+
134156 void updateMouse () {
135- if (urlRollover ) {
157+ switch (rolloverState ) {
158+ case ROLLOVER_URL :
136159 setCursor (Cursor .getPredefinedCursor (Cursor .HAND_CURSOR ));
137- } else {
160+ break ;
161+ case ROLLOVER_COLLAPSE :
162+ setCursor (Cursor .getPredefinedCursor (Cursor .DEFAULT_CURSOR ));
163+ break ;
164+ case ROLLOVER_NONE :
138165 setCursor (Cursor .getPredefinedCursor (Cursor .MOVE_CURSOR ));
166+ break ;
139167 }
140168 repaint ();
141169 }
@@ -257,6 +285,7 @@ public void stopIndeterminate() {
257285 }
258286
259287
288+ private final Color whitishTint = new Color (0x40eeeeee , true );
260289 //public void paintComponent(Graphics screen) {
261290 public void paint (Graphics screen ) {
262291// if (okButton == null) setup();
@@ -285,31 +314,37 @@ public void paint(Graphics screen) {
285314
286315 g .drawImage (bgImage [mode ], 0 , 0 , sizeW , sizeH , this );
287316
288- g .setColor (fgColor [mode ]);
317+ // What's the mouse over?
318+ final int H = getHeight ();
319+ int collapseLeftEdge = sizeW - H ;
320+ if (collapseLeftEdge < mouseX && mouseX < sizeW ) {
321+ rolloverState = ROLLOVER_COLLAPSE ;
322+ } else if ((message != null && url != null && mouseX > LEFT_MARGIN ) &&
323+ // calculate right edge of the text for rollovers (otherwise the pane
324+ // cannot be resized up or down whenever a URL is being displayed)
325+ mouseX < (LEFT_MARGIN + g .getFontMetrics ().stringWidth (message ))) {
326+ rolloverState = ROLLOVER_URL ;
327+ } else {
328+ rolloverState = ROLLOVER_NONE ;
329+ }
330+
289331 // https://github.com/processing/processing/issues/3265
290332 if (message != null ) {
291333 // needs to be set each time on osx
292334 g .setFont (font );
293- // calculate right edge of the text for rollovers (otherwise the pane
294- // cannot be resized up or down whenever a URL is being displayed)
295- rightEdge = LEFT_MARGIN + g .getFontMetrics ().stringWidth (message );
296335 // set the highlight color on rollover so that the user's not surprised
297336 // to see the web browser open when they click
298- urlRollover = (url != null ) &&
299- (mouseX > LEFT_MARGIN && mouseX < rightEdge );
300- if (urlRollover ) {
301- g .setColor (urlColor );
302- }
337+ g .setColor ((rolloverState == ROLLOVER_URL ) ? urlColor : fgColor [mode ]);
303338 g .drawString (message , LEFT_MARGIN , (sizeH + ascent ) / 2 );
304339 }
305340
306341 if (indeterminate ) {
307342 //int x = cancelButton.getX();
308343 //int w = cancelButton.getWidth();
309344 int w = Toolkit .getButtonWidth ();
310- int x = getWidth () - RIGHT_MARGIN - w ;
311- int y = getHeight () / 3 ;
312- int h = getHeight () / 3 ;
345+ int x = getWidth () - Math . max ( RIGHT_MARGIN , ( int )( H * 1.2 )) - w ;
346+ int y = H / 3 ;
347+ int h = H / 3 ;
313348 g .setColor (new Color (0x80000000 , true ));
314349 g .drawRect (x , y , w , h );
315350 for (int i = 0 ; i < 10 ; i ++) {
@@ -318,6 +353,27 @@ public void paint(Graphics screen) {
318353 }
319354 }
320355
356+ // draw collapse/expand button
357+ int x = sizeW - H /3 ;
358+ int y1 , y2 ;
359+ if (collapseState ) {
360+ y1 = 7 *H /12 ;
361+ y2 = 5 *H /12 ;
362+ } else {
363+ y1 = 5 *H /12 ;
364+ y2 = 7 *H /12 ;
365+ }
366+ if (rolloverState == ROLLOVER_COLLAPSE ) {
367+ g .setColor (whitishTint );
368+ g .fillRect (sizeW - H , 0 , H , H );
369+ g .setColor (urlColor );
370+ } else {
371+ g .setColor (fgColor [mode ]);
372+ }
373+ // nb 2*((H/6) + 1) is always even, so there's a nice tip on the triangle.
374+ g .fillPolygon (new int [] {x , x - 2 *((H /6 ) + 1 ), x - (H /6 ) - 1 },
375+ new int [] {y1 , y1 , y2 }, 3 );
376+
321377 screen .drawImage (offscreen , 0 , 0 , sizeW , sizeH , null );
322378 }
323379
0 commit comments