Skip to content

Commit d0e016b

Browse files
committed
Add console hiding button
Also made the existing copy-message button consistent.
1 parent 4d4246b commit d0e016b

2 files changed

Lines changed: 96 additions & 28 deletions

File tree

app/src/processing/app/ui/Editor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,17 @@ public BasicSplitPaneDivider createDefaultDivider() {
320320
status = new EditorStatus(this, Editor.this);
321321
return status;
322322
}
323+
324+
325+
@Override
326+
public void finishDraggingTo(int location) {
327+
super.finishDraggingTo(location);
328+
// JSplitPane issue: if you only make the lower component visible at
329+
// the last minute, its minmum size is ignored.
330+
if (location > splitPane.getMaximumDividerLocation()) {
331+
splitPane.setDividerLocation(splitPane.getMaximumDividerLocation());
332+
}
333+
}
323334
});
324335

325336
box.add(splitPane);

app/src/processing/app/ui/EditorStatus.java

Lines changed: 85 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,22 @@ public class EditorStatus extends BasicSplitPaneDivider { //JPanel {
7979
String url;
8080
int rightEdge;
8181
int mouseX;
82-
boolean urlRollover;
82+
int rolloverState;
83+
static final int ROLLOVER_NONE = 0;
84+
static final int ROLLOVER_URL = 1;
85+
static final int ROLLOVER_COLLAPSE = 2;
86+
static final int ROLLOVER_EMOJI = 3;
8387

8488
Font font;
8589
FontMetrics metrics;
8690
int ascent;
8791

8892
// used to draw the clipboard icon
89-
static final int EMOJI_OFFSET = 27;
9093
Font emojiFont;
91-
int emojiLeft;
92-
boolean emojiRollover;
9394

9495
Image offscreen;
9596
int sizeW, sizeH;
97+
boolean collapseState = false;
9698

9799
int response;
98100

@@ -115,10 +117,10 @@ public void mouseEntered(MouseEvent e) {
115117

116118
@Override
117119
public void mousePressed(MouseEvent e) {
118-
if (urlRollover) {
120+
if (rolloverState == ROLLOVER_URL) {
119121
Platform.openURL(url);
120122

121-
} else if (emojiRollover) {
123+
} else if (rolloverState == ROLLOVER_EMOJI) {
122124
if (e.isShiftDown()) {
123125
// open the text in a browser window as a search
124126
final String fmt = Preferences.get("search.format");
@@ -131,17 +133,28 @@ public void mousePressed(MouseEvent e) {
131133
System.out.println("Copied to the clipboard. " +
132134
"Use shift-click to search the web instead.");
133135
}
136+
137+
} else if (rolloverState == ROLLOVER_COLLAPSE) {
138+
collapse(!collapseState);
134139
}
135140
}
136141

137142
@Override
138143
public void mouseExited(MouseEvent e) {
144+
mouseX = -100;
139145
updateMouse();
140146
}
141147

142148
});
143149

144150
addMouseMotionListener(new MouseMotionAdapter() {
151+
@Override
152+
public void mouseDragged(MouseEvent e) {
153+
// BasicSplitPaneUI.startDragging gets called even when you click but
154+
// don't drag, so we can't expand the console whenever that gets called
155+
// or the button wouldn't work.
156+
collapse(false);
157+
}
145158

146159
@Override
147160
public void mouseMoved(MouseEvent e) {
@@ -152,13 +165,26 @@ public void mouseMoved(MouseEvent e) {
152165
}
153166

154167

168+
void collapse(boolean doCollapse) {
169+
if (collapseState == doCollapse) return;
170+
collapseState = doCollapse;
171+
editor.footer.setVisible(!doCollapse);
172+
splitPane.resetToPreferredSizes();
173+
}
174+
175+
155176
void updateMouse() {
156-
if (urlRollover) {
157-
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
158-
} else if (emojiRollover) {
177+
switch (rolloverState) {
178+
case ROLLOVER_EMOJI:
179+
case ROLLOVER_URL:
159180
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
160-
} else {
181+
break;
182+
case ROLLOVER_COLLAPSE:
183+
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
184+
break;
185+
case ROLLOVER_NONE:
161186
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
187+
break;
162188
}
163189
repaint();
164190
}
@@ -282,8 +308,8 @@ public void stopIndeterminate() {
282308
}
283309

284310

311+
//public void paintComponent(Graphics screen) {
285312
public void paint(Graphics screen) {
286-
// public void paint(Graphics screen) {
287313
Dimension size = getSize();
288314
if ((size.width != sizeW) || (size.height != sizeH)) {
289315
// component has been resized
@@ -308,31 +334,41 @@ public void paint(Graphics screen) {
308334

309335
g.drawImage(bgImage[mode], 0, 0, sizeW, sizeH, this);
310336

311-
g.setColor(fgColor[mode]);
337+
// What's the mouse over?
338+
if (sizeW - sizeH < mouseX && mouseX < sizeW) {
339+
rolloverState = ROLLOVER_COLLAPSE;
340+
} else if (message != null && !message.isEmpty()) {
341+
if (sizeW - 2*sizeH < mouseX) {
342+
rolloverState = ROLLOVER_EMOJI;
343+
} else if (url != null && mouseX > LEFT_MARGIN &&
344+
// calculate right edge of the text for rollovers (otherwise the pane
345+
// cannot be resized up or down whenever a URL is being displayed)
346+
mouseX < (LEFT_MARGIN + g.getFontMetrics().stringWidth(message))) {
347+
rolloverState = ROLLOVER_URL;
348+
} else {
349+
rolloverState = ROLLOVER_NONE;
350+
}
351+
} else {
352+
rolloverState = ROLLOVER_NONE;
353+
}
354+
312355
// https://github.com/processing/processing/issues/3265
313356
if (message != null) {
314357
// needs to be set each time on osx
315358
g.setFont(font);
316-
// calculate right edge of the text for rollovers (otherwise the pane
317-
// cannot be resized up or down whenever a URL is being displayed)
318-
rightEdge = LEFT_MARGIN + g.getFontMetrics().stringWidth(message);
319359
// set the highlight color on rollover so that the user's not surprised
320360
// to see the web browser open when they click
321-
urlRollover = (url != null) &&
322-
(mouseX > LEFT_MARGIN && mouseX < rightEdge);
323-
if (urlRollover) {
324-
g.setColor(urlColor);
325-
}
361+
g.setColor((rolloverState == ROLLOVER_URL) ? urlColor : fgColor[mode]);
326362
g.drawString(message, LEFT_MARGIN, (sizeH + ascent) / 2);
327363
}
328364

329365
if (indeterminate) {
330366
//int x = cancelButton.getX();
331367
//int w = cancelButton.getWidth();
332368
int w = Toolkit.getButtonWidth();
333-
int x = getWidth() - RIGHT_MARGIN - w;
334-
int y = getHeight() / 3;
335-
int h = getHeight() / 3;
369+
int x = getWidth() - Math.max(RIGHT_MARGIN, (int)(sizeH*1.2)) - w;
370+
int y = sizeH / 3;
371+
int h = sizeH / 3;
336372
g.setColor(new Color(0x80000000, true));
337373
g.drawRect(x, y, w, h);
338374
for (int i = 0; i < 10; i++) {
@@ -341,20 +377,41 @@ public void paint(Graphics screen) {
341377
}
342378

343379
} else if (!message.isEmpty()) {
344-
g.setColor(Color.WHITE);
345380
g.setFont(emojiFont);
346381
// actual Clipboard character not available [fry 180326]
347382
//g.drawString("\uD83D\uDCCB", sizeW - LEFT_MARGIN, (sizeH + ascent) / 2);
348-
// other apps seem to use this one as a hack
349-
emojiLeft = sizeW - Toolkit.zoom(EMOJI_OFFSET);
350-
g.drawString("\u2398", emojiLeft, (sizeH + ascent) / 2);
351-
emojiRollover = mouseX > emojiLeft - 4;
383+
// other apps seem to use this one as a hack: ⎘
384+
drawButton(g, "\u2398", 1, rolloverState == ROLLOVER_EMOJI);
385+
g.setFont(font);
352386
}
353387

388+
// draw collapse/expand button
389+
drawButton(g, collapseState ? "▲" : "▼", 0, rolloverState == ROLLOVER_COLLAPSE);
390+
354391
screen.drawImage(offscreen, 0, 0, sizeW, sizeH, null);
355392
}
356393

357394

395+
private final Color whitishTint = new Color(0x40eeeeee, true);
396+
/**
397+
* @param pos A zero-based index with 0 on the right.
398+
*/
399+
private void drawButton(Graphics g, String symbol, int pos, boolean highlight) {
400+
int left = sizeW - (pos + 1) * sizeH;
401+
g.setColor(bgColor[mode]); // Overlap very long errors.
402+
g.fillRect(left, 0, sizeH, sizeH);
403+
if (highlight) {
404+
g.setColor(whitishTint);
405+
g.fillRect(left, 0, sizeH, sizeH);
406+
g.setColor(urlColor);
407+
} else {
408+
g.setColor(fgColor[mode]);
409+
}
410+
g.drawString(symbol,
411+
left + (sizeH - g.getFontMetrics().stringWidth(symbol))/2,
412+
(sizeH + ascent) / 2);
413+
}
414+
358415
public Dimension getPreferredSize() {
359416
return getMinimumSize();
360417
}

0 commit comments

Comments
 (0)