Skip to content

Commit b0d786a

Browse files
committed
working through tabbing
1 parent 53c8f12 commit b0d786a

3 files changed

Lines changed: 289 additions & 0 deletions

File tree

java/src/processing/mode/java/JavaEditor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ public Container createConsolePanel() {
210210
//JPanel consolePanel = new JPanel();
211211
JTabbedPane tabPane = new JTabbedPane(JTabbedPane.BOTTOM);
212212
// tabPane.setUI(new BasicTabbedPaneUI());
213+
tabPane.setUI(new SimpleTabbedPaneUI());
213214
// tabPane.setBorder(BorderFactory.createEmptyBorder());
215+
// tabPane.setBackground(Color.RED);
214216

215217
// Adding Error Table in a scroll pane
216218
errorTableScrollPane = new JScrollPane();
Lines changed: 286 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,286 @@
1+
package processing.mode.java;
2+
3+
import javax.swing.*;
4+
import javax.swing.plaf.basic.BasicTabbedPaneUI;
5+
6+
import java.awt.*;
7+
import java.awt.event.MouseAdapter;
8+
import java.awt.event.MouseEvent;
9+
import java.awt.event.MouseListener;
10+
import java.awt.event.MouseMotionListener;
11+
12+
13+
public class SimpleTabbedPaneUI extends BasicTabbedPaneUI {
14+
// private static final Insets NO_INSETS = new Insets(0, 0, 0, 0);
15+
16+
private ColorSet selectedColorSet;
17+
private ColorSet defaultColorSet;
18+
private ColorSet hoverColorSet;
19+
20+
private boolean contentTopBorderDrawn = true;
21+
private Color lineColor = new Color(158, 158, 158);
22+
private Color dividerColor = new Color(200, 200, 200);
23+
private Insets contentInsets = new Insets(10, 10, 10, 10);
24+
private int lastRollOverTab = -1;
25+
26+
27+
// public static ComponentUI createUI(JComponent c) {
28+
// return new SimpleTabbedPaneUI();
29+
// }
30+
31+
32+
public SimpleTabbedPaneUI() {
33+
selectedColorSet = new ColorSet();
34+
selectedColorSet.topGradColor1 = new Color(233, 237, 248);
35+
selectedColorSet.topGradColor2 = new Color(158, 199, 240);
36+
selectedColorSet.bottomGradColor1 = new Color(112, 173, 239);
37+
selectedColorSet.bottomGradColor2 = new Color(183, 244, 253);
38+
39+
defaultColorSet = new ColorSet();
40+
defaultColorSet.topGradColor1 = new Color(253, 253, 253);
41+
defaultColorSet.topGradColor2 = new Color(237, 237, 237);
42+
defaultColorSet.bottomGradColor1 = new Color(222, 222, 222);
43+
defaultColorSet.bottomGradColor2 = new Color(255, 255, 255);
44+
45+
hoverColorSet = new ColorSet();
46+
hoverColorSet.topGradColor1 = new Color(244, 244, 244);
47+
hoverColorSet.topGradColor2 = new Color(223, 223, 223);
48+
hoverColorSet.bottomGradColor1 = new Color(211, 211, 211);
49+
hoverColorSet.bottomGradColor2 = new Color(235, 235, 235);
50+
51+
maxTabHeight = 20;
52+
53+
setContentInsets(0);
54+
}
55+
56+
57+
public void setContentTopBorderDrawn(boolean b) {
58+
contentTopBorderDrawn = b;
59+
}
60+
61+
62+
public void setContentInsets(Insets i) {
63+
contentInsets = i;
64+
}
65+
66+
67+
public void setContentInsets(int i) {
68+
contentInsets = new Insets(i, i, i, i);
69+
}
70+
71+
72+
public int getTabRunCount(JTabbedPane pane) {
73+
return 1;
74+
}
75+
76+
77+
protected void installDefaults() {
78+
super.installDefaults();
79+
80+
// RollOverListener l = new RollOverListener();
81+
// tabPane.addMouseListener(l);
82+
// tabPane.addMouseMotionListener(l);
83+
84+
MouseAdapter adapter = new MouseAdapter() {
85+
public void mouseMoved(MouseEvent e) {
86+
checkRollOver();
87+
}
88+
89+
public void mouseEntered(MouseEvent e) {
90+
checkRollOver();
91+
}
92+
93+
public void mouseExited(MouseEvent e) {
94+
tabPane.repaint();
95+
}
96+
97+
private void checkRollOver() {
98+
int currentRollOver = getRolloverTab();
99+
if (currentRollOver != lastRollOverTab) {
100+
lastRollOverTab = currentRollOver;
101+
Rectangle tabsRect = new Rectangle(0, 0, tabPane.getWidth(), 20);
102+
tabPane.repaint(tabsRect);
103+
}
104+
}
105+
};
106+
tabPane.addMouseListener(adapter);
107+
tabPane.addMouseMotionListener(adapter);
108+
109+
tabAreaInsets = new Insets(0, 0, 0, 0); //NO_INSETS;
110+
tabInsets = new Insets(0, 0, 0, 1);
111+
}
112+
113+
114+
protected boolean scrollableTabLayoutEnabled() {
115+
return false;
116+
}
117+
118+
119+
protected Insets getContentBorderInsets(int tabPlacement) {
120+
return contentInsets;
121+
}
122+
123+
124+
protected int calculateTabHeight(int tabPlacement, int tabIndex,
125+
int fontHeight) {
126+
return 21;
127+
}
128+
129+
130+
protected int calculateTabWidth(int tabPlacement, int tabIndex,
131+
FontMetrics metrics) {
132+
int w = super.calculateTabWidth(tabPlacement, tabIndex, metrics);
133+
int wid = metrics.charWidth('M');
134+
w += wid * 2;
135+
return w;
136+
}
137+
138+
139+
protected int calculateMaxTabHeight(int tabPlacement) {
140+
return 21;
141+
}
142+
143+
144+
// paint the area that has no tabs
145+
protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex) {
146+
Graphics2D g2d = (Graphics2D) g;
147+
148+
g2d.setPaint(new GradientPaint(0, 0, defaultColorSet.topGradColor1,
149+
0, 10, defaultColorSet.topGradColor2));
150+
g2d.fillRect(0, 0, tabPane.getWidth(), 10);
151+
152+
g2d.setPaint(new GradientPaint(0, 10, defaultColorSet.bottomGradColor1,
153+
0, 21, defaultColorSet.bottomGradColor2));
154+
g2d.fillRect(0, 10, tabPane.getWidth(), 11);
155+
156+
super.paintTabArea(g, tabPlacement, selectedIndex);
157+
158+
if (contentTopBorderDrawn) {
159+
g2d.setColor(lineColor);
160+
g2d.drawLine(0, 20, tabPane.getWidth() - 1, 20);
161+
}
162+
}
163+
164+
165+
// paint the background of individual tabs
166+
protected void paintTabBackground(Graphics g, int tabPlacement,
167+
int tabIndex, int x, int y, int w, int h,
168+
boolean isSelected) {
169+
Graphics2D g2d = (Graphics2D) g;
170+
ColorSet colorSet;
171+
172+
Rectangle rect = rects[tabIndex];
173+
174+
if (isSelected) {
175+
colorSet = selectedColorSet;
176+
} else if (getRolloverTab() == tabIndex) {
177+
colorSet = hoverColorSet;
178+
} else {
179+
colorSet = defaultColorSet;
180+
}
181+
182+
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
183+
RenderingHints.VALUE_ANTIALIAS_ON);
184+
185+
int width = rect.width;
186+
int xpos = rect.x;
187+
if (tabIndex > 0) {
188+
width--;
189+
xpos++;
190+
}
191+
192+
g2d.setPaint(new GradientPaint(xpos, 0, colorSet.topGradColor1,
193+
xpos, 10, colorSet.topGradColor2));
194+
g2d.fillRect(xpos, 0, width, 10);
195+
196+
g2d.setPaint(new GradientPaint(0, 10, colorSet.bottomGradColor1,
197+
0, 21, colorSet.bottomGradColor2));
198+
g2d.fillRect(xpos, 10, width, 11);
199+
200+
if (contentTopBorderDrawn) {
201+
g2d.setColor(lineColor);
202+
g2d.drawLine(rect.x, 20, rect.x + rect.width - 1, 20);
203+
}
204+
}
205+
206+
207+
protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex,
208+
int x, int y, int w, int h,
209+
boolean isSelected) {
210+
Rectangle rect = getTabBounds(tabIndex, new Rectangle(x, y, w, h));
211+
g.setColor(dividerColor);
212+
g.drawLine(rect.x + rect.width, 0, rect.x + rect.width, 20);
213+
}
214+
215+
216+
protected void paintContentBorderTopEdge(Graphics g, int place, int index,
217+
int x, int y, int w, int h) { }
218+
219+
protected void paintContentBorderRightEdge(Graphics g, int place, int index,
220+
int x, int y, int w, int h) { }
221+
222+
protected void paintContentBorderLeftEdge(Graphics g, int place, int index,
223+
int x, int y, int w, int h) { }
224+
225+
protected void paintContentBorderBottomEdge(Graphics g, int place, int index,
226+
int x, int y, int w, int h) { }
227+
228+
protected void paintFocusIndicator(Graphics g, int place,
229+
Rectangle[] rects, int tabIndex,
230+
Rectangle iconRect, Rectangle textRect,
231+
boolean isSelected) { }
232+
233+
protected int getTabLabelShiftY(int place, int index, boolean selected) {
234+
return 0;
235+
}
236+
237+
238+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
239+
240+
241+
private class ColorSet {
242+
Color topGradColor1;
243+
Color topGradColor2;
244+
245+
Color bottomGradColor1;
246+
Color bottomGradColor2;
247+
}
248+
249+
250+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
251+
252+
253+
/*
254+
private class RollOverListener implements MouseMotionListener, MouseListener {
255+
256+
public void mouseDragged(MouseEvent e) { }
257+
258+
public void mouseMoved(MouseEvent e) {
259+
checkRollOver();
260+
}
261+
262+
public void mouseClicked(MouseEvent e) { }
263+
264+
public void mousePressed(MouseEvent e) { }
265+
266+
public void mouseReleased(MouseEvent e) { }
267+
268+
public void mouseEntered(MouseEvent e) {
269+
checkRollOver();
270+
}
271+
272+
public void mouseExited(MouseEvent e) {
273+
tabPane.repaint();
274+
}
275+
276+
private void checkRollOver() {
277+
int currentRollOver = getRolloverTab();
278+
if (currentRollOver != lastRollOverTab) {
279+
lastRollOverTab = currentRollOver;
280+
Rectangle tabsRect = new Rectangle(0, 0, tabPane.getWidth(), 20);
281+
tabPane.repaint(tabsRect);
282+
}
283+
}
284+
}
285+
*/
286+
}

todo.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ _ two new fonts have been added, other languages will need more
7777
_ need a decent sans with with Unicode coverage
7878
_ i.e. https://github.com/processing/processing/pull/3025
7979
_ deactivate step, continue, stop when not running?
80+
_ update EditorButton rollover label when pressing shift or alt
8081

8182

8283
pde/build

0 commit comments

Comments
 (0)