source: src/main/java/genius/gui/panels/tab/CloseTabPaneEnhancedUI.java

Last change on this file was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 10.9 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package genius.gui.panels.tab;
7
8import java.awt.Color;
9import java.awt.Dimension;
10import java.awt.Font;
11import java.awt.FontMetrics;
12import java.awt.GradientPaint;
13import java.awt.Graphics;
14import java.awt.Graphics2D;
15import java.awt.Rectangle;
16import javax.swing.JComponent;
17import javax.swing.plaf.ComponentUI;
18import javax.swing.plaf.basic.BasicGraphicsUtils;
19import javax.swing.text.View;
20
21/**
22 * This UI displays a different interface, which is independent from the look
23 * and feel.
24 *
25 *
26 * @author David Bismut, davidou@mageos.com
27 *
28 */
29public class CloseTabPaneEnhancedUI extends CloseTabPaneUI {
30
31 private static final Color whiteColor = Color.white;
32
33 private static final Color transparent = new Color(0x184EB6);//0, 0, 0, 0);
34 private static final Color lightBlue = new Color(0x8CA9FF);//70, 150, 200, 50);
35 private static final Color lightWhite = new Color(150, 150, 150, 50);
36
37 //private static final Color selectedColor = new Color(15, 70, 180);
38 //Wouter: this color seems way off to me, both for windows and OSX?
39 private static final Color selectedColor = new Color(131, 188, 249);
40
41 public static ComponentUI createUI(JComponent c) {
42 return new CloseTabPaneEnhancedUI();
43 }
44
45 protected void paintFocusIndicator(Graphics g, int tabPlacement,
46 Rectangle[] rects, int tabIndex, Rectangle iconRect,
47 Rectangle textRect, boolean isSelected) {
48 }
49
50 protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex,
51 int x, int y, int w, int h, boolean isSelected) {
52 g.setColor(shadow);
53
54 g.drawLine(x, y + 2, x, y + h - 1); // left highlight
55 g.drawLine(x + 1, y + 1, x + 1, y + 1); // top-left highlight
56 g.drawLine(x + 2, y, x + w - 3, y); // top highlight
57 g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1);
58 g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); // top-right shadow
59
60 if (isSelected) {
61 //Do the highlights
62 g.setColor(lightHighlight);
63 g.drawLine(x + 2, y + 2, x + 2, y + h - 1);
64 g.drawLine(x + 3, y + 1, x + w - 3, y + 1);
65 g.drawLine(x + w - 3, y + 2, x + w - 3, y + 2);
66 g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 1);
67
68 }
69
70 }
71
72 protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
73 int selectedIndex, int x, int y, int w, int h) {
74
75 if (tabPane.getTabCount() < 1)
76 return;
77
78 g.setColor(shadow);
79 g.drawLine(x, y, x + w - 2, y);
80 }
81
82 protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement,
83 int selectedIndex, int x, int y, int w, int h) {
84
85 if (tabPane.getTabCount() < 1)
86 return;
87
88 g.setColor(shadow);
89
90 g.drawLine(x, y, x, y + h - 3);
91 }
92
93 protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
94 int selectedIndex, int x, int y, int w, int h) {
95
96 if (tabPane.getTabCount() < 1)
97 return;
98
99 g.setColor(shadow);
100 g.drawLine(x + 1, y + h - 3, x + w - 2, y + h - 3);
101 g.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
102 g.setColor(shadow.brighter());
103 g.drawLine(x + 2, y + h - 1, x + w - 1, y + h - 1);
104
105 }
106
107 protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
108 int selectedIndex, int x, int y, int w, int h) {
109
110 if (tabPane.getTabCount() < 1)
111 return;
112
113 g.setColor(shadow);
114
115 g.drawLine(x + w - 3, y + 1, x + w - 3, y + h - 3);
116 g.drawLine(x + w - 2, y + 1, x + w - 2, y + h - 3);
117 g.setColor(shadow.brighter());
118 g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 2);
119
120 }
121
122 /** Wouter: hacked, we don't need the fancy but nonstandard backgnd */
123 protected void paintTabBackground(Graphics g, int tabPlacement,
124 int tabIndex, int x, int y, int w, int h, boolean isSelected) {
125
126 if (isSelected) {
127 Graphics2D g2 = (Graphics2D) g;
128 int delta2=8;
129
130 if (isCloseEnabled()) {
131 delta2 += BUTTONSIZE;
132 }
133
134 g2.setPaintMode();
135 g2.setColor(selectedColor);
136 g2.fillRect(x + 2, y + 2, w-delta2 , h - 2);
137 }
138 }
139
140 protected void paintTabBackgroundOld(Graphics g, int tabPlacement,
141 int tabIndex, int x, int y, int w, int h, boolean isSelected) {
142 if (isSelected) {
143
144 GradientPaint leftGradient;
145 GradientPaint rightGradient;
146
147 int delta = 10;
148 int delta2 = 8;
149
150 if (isCloseEnabled()) {
151 delta += BUTTONSIZE + WIDTHDELTA;
152 delta2 += BUTTONSIZE;
153 }
154
155
156 if (tabPane.isEnabledAt(tabIndex)) {
157 leftGradient = new GradientPaint(x, y, selectedColor,
158 x + w / 2, y, lightBlue);
159
160 rightGradient = new GradientPaint(x + w / 2, y, lightBlue, x
161 + w + delta, y, transparent);
162 } else {
163 leftGradient = new GradientPaint(x, y, shadow, x + w / 2, y,
164 lightWhite);
165
166 rightGradient = new GradientPaint(x + w / 2, y, lightWhite, x
167 + w + delta, y, transparent);
168 }
169
170 Graphics2D g2 = (Graphics2D) g;
171 g2.setPaint(leftGradient);
172 //g2.setPaintMode();
173 //g2.setColor(selectedColor);
174 g2.fillRect(x + 2, y + 2, w / 2, h - 2);
175 g2.setPaint(rightGradient);
176 //g2.setPaintMode();
177 //g2.setColor(lightBlue);
178 g2.fillRect(x + 2 + w / 2, y + 2, w / 2 - delta2, h - 2);
179 }
180 }
181
182 protected void paintText(Graphics g, int tabPlacement, Font font,
183 FontMetrics metrics, int tabIndex, String title,
184 Rectangle textRect, boolean isSelected) {
185
186 g.setFont(font);
187
188 View v = getTextViewForTab(tabIndex);
189 if (v != null) {
190 // html
191 v.paint(g, textRect);
192 } else {
193 // plain text
194 int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
195
196 if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
197 /*Wouter: always black is usual in Win and OSX.
198 if (isSelected){
199 Graphics2D g2d = (Graphics2D)g;
200 g2d.setColor(nearBlack);
201 g2d.drawString(title, textRect.x+1, textRect.y+metrics.getAscent()+1);
202 g.setColor(whiteColor);
203 }else
204 */
205 g.setColor(tabPane.getForegroundAt(tabIndex));
206
207 BasicGraphicsUtils
208 .drawStringUnderlineCharAt(g, title, mnemIndex,
209 textRect.x, textRect.y + metrics.getAscent());
210
211 } else { // tab disabled
212 g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
213 BasicGraphicsUtils
214 .drawStringUnderlineCharAt(g, title, mnemIndex,
215 textRect.x, textRect.y + metrics.getAscent());
216 g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
217 BasicGraphicsUtils.drawStringUnderlineCharAt(g, title,
218 mnemIndex, textRect.x - 1, textRect.y
219 + metrics.getAscent() - 1);
220
221 }
222 }
223 }
224
225 protected class ScrollableTabButton extends
226 CloseTabPaneUI.ScrollableTabButton {
227
228 private static final long serialVersionUID = 1854834043556447949L;
229
230 public ScrollableTabButton(int direction) {
231 super(direction);
232 setRolloverEnabled(true);
233 }
234
235 public Dimension getPreferredSize() {
236 return new Dimension(16, calculateMaxTabHeight(0));
237 }
238
239 public void paint(Graphics g) {
240 Color origColor;
241 boolean isPressed, isRollOver, isEnabled;
242 int w, h, size;
243
244 w = getSize().width;
245 h = getSize().height;
246 origColor = g.getColor();
247 isPressed = getModel().isPressed();
248 isRollOver = getModel().isRollover();
249 isEnabled = isEnabled();
250
251 g.setColor(getBackground());
252 g.fillRect(0, 0, w, h);
253
254 g.setColor(shadow);
255 // Using the background color set above
256 if (direction == WEST) {
257 g.drawLine(0, 0, 0, h - 1); //left
258 g.drawLine(w - 1, 0, w - 1, 0); //right
259 } else
260 g.drawLine(w - 2, h - 1, w - 2, 0); //right
261
262 g.drawLine(0, 0, w - 2, 0); //top
263
264 if (isRollOver) {
265 //do highlights or shadows
266
267 Color color1;
268 Color color2;
269
270 if (isPressed) {
271 color2 = whiteColor;
272 color1 = shadow;
273 } else {
274 color1 = whiteColor;
275 color2 = shadow;
276 }
277
278 g.setColor(color1);
279
280 if (direction == WEST) {
281 g.drawLine(1, 1, 1, h - 1); //left
282 g.drawLine(1, 1, w - 2, 1); //top
283 g.setColor(color2);
284 g.drawLine(w - 1, h - 1, w - 1, 1); //right
285 } else {
286 g.drawLine(0, 1, 0, h - 1);
287 g.drawLine(0, 1, w - 3, 1); //top
288 g.setColor(color2);
289 g.drawLine(w - 3, h - 1, w - 3, 1); //right
290 }
291
292 }
293
294 //g.drawLine(0, h - 1, w - 1, h - 1); //bottom
295
296 // If there's no room to draw arrow, bail
297 if (h < 5 || w < 5) {
298 g.setColor(origColor);
299 return;
300 }
301
302 if (isPressed) {
303 g.translate(1, 1);
304 }
305
306 // Draw the arrow
307 size = Math.min((h - 4) / 3, (w - 4) / 3);
308 size = Math.max(size, 2);
309 paintTriangle(g, (w - size) / 2, (h - size) / 2, size, direction,
310 isEnabled);
311
312 // Reset the Graphics back to it's original settings
313 if (isPressed) {
314 g.translate(-1, -1);
315 }
316 g.setColor(origColor);
317
318 }
319
320 }
321
322 protected CloseTabPaneUI.ScrollableTabButton createScrollableTabButton(
323 int direction) {
324 return new ScrollableTabButton(direction);
325 }
326
327}
Note: See TracBrowser for help on using the repository browser.