Debian Codegraph @

src/com/jidesoft/plaf/office2007/Office2007Painter.java

raw
1 /*
2 * @(#)Office2007Painter.java 7/7/2009
3 *
4 * Copyright 2002 - 2009 JIDE Software Inc. All rights reserved.
5 */
6
7 package com.jidesoft.plaf.office2007;
8
9 import com.jidesoft.icons.IconsFactory;
10 import com.jidesoft.plaf.UIDefaultsLookup;
11 import com.jidesoft.plaf.basic.BasicJideButtonUI;
12 import com.jidesoft.plaf.basic.BasicPainter;
13 import com.jidesoft.plaf.basic.ThemePainter;
14 import com.jidesoft.plaf.office2003.Office2003Painter;
15 import com.jidesoft.swing.ComponentStateSupport;
16 import com.jidesoft.swing.JideButton;
17 import com.jidesoft.swing.JideSplitButton;
18 import com.jidesoft.swing.JideSwingUtilities;
19 import com.jidesoft.utils.ColorUtils;
20 import com.jidesoft.utils.SystemInfo;
21
22 import javax.swing.*;
23 import javax.swing.plaf.ColorUIResource;
24 import javax.swing.plaf.UIResource;
25 import java.awt.*;
26 import java.awt.geom.Area;
27
28 /**
29 * Painter for Office2007 L&F.
30 * <p/>
31 * Please note, this class is an internal class which is meant to be used by other JIDE classes only. Future version
32 * might break your build if you use it.
33 */
34 public class Office2007Painter extends BasicPainter {
35
36 public static final String IS_MENU_PART_BUTTON = "isMenuPartButton";
37
38 private static Office2007Painter _instance;
39 private ThemePainter _defaultPainter;
40
41 public static ThemePainter getInstance() {
42 if (_instance == null) {
43 _instance = new Office2007Painter();
44 }
45 return _instance;
46 }
47
48 protected Office2007Painter() {
49 }
50
51 /**
52 * Creates a default painter that paints something that could not be painted by Office2007Painter.'
53 * <p/>
54 * By default, it returns an Office2003Painter. However, if you doesn't like the painting theme of
55 * Office2003Painter, you could override this method to offer another default painter.
56 *
57 * @return the default painter instance.
58 */
59 protected ThemePainter createDefaultPainter() {
60 return Office2003Painter.getInstance();
61 }
62
63 public ThemePainter getDefaultPainter() {
64 if (_defaultPainter == null) {
65 _defaultPainter = createDefaultPainter();
66 }
67 return _defaultPainter;
68 }
69
70 public void installDefaults() {
71 Boolean highContrast = UIManager.getBoolean("Theme.highContrast");
72 if (highContrast) {
73 super.installDefaults();
74 }
75 }
76
77 public void uninstallDefaults() {
78 Boolean highContrast = UIManager.getBoolean("Theme.highContrast");
79 if (highContrast) {
80 super.uninstallDefaults();
81 }
82 }
83
84 @Override
85 public Color getMenuItemBorderColor() {
86 return new Color(100, 100, 100);
87 }
88
89
90 public void paintContentBackground(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
91 Graphics2D g2d = (Graphics2D) g.create();
92 Boolean highContrast = UIManager.getBoolean("Theme.highContrast");
93 g2d.setColor(highContrast ? UIDefaultsLookup.getColor("Content.background") : new Color(0xBFDBFF));
94 g2d.fillRect(rect.x, rect.y, rect.width, rect.height);
95
96 // JideSwingUtilities.fillGradient(g2d, new Rectangle(rect.x, rect.y, rect.width, 160), CONTENT_BG[0], CONTENT_BG[1], true);
97 // if (rect.height > 160) {
98 // int remainHeight = rect.height - 160;
99 // Rectangle rect1 = new Rectangle(rect.x, 0, rect.width, 0);
100 // Rectangle rect2 = new Rectangle(rect.x, 0, rect.width, 0);
101 // rect1.y = 160;
102 // if (remainHeight < 200) {
103 // rect1.height = remainHeight / 2;
104 // }
105 // else {
106 // rect1.height = 100 + ((remainHeight - 200) * 4 / 5);
107 // }
108 // rect2.y = rect1.y + rect1.height;
109 // rect2.height = rect.height - rect2.y;
110 //
111 // JideSwingUtilities.fillGradient(g2d, rect1, CONTENT_BG[1], CONTENT_BG[2], true);
112 // JideSwingUtilities.fillGradient(g2d, rect2, CONTENT_BG[2], CONTENT_BG[3], true);
113 // }
114 //
115 // ImageIcon imageIcon = IconsFactory.getImageIcon(Office2007Painter.class, "icons/background_top.png");
116 // g2d.drawImage(imageIcon.getImage(), 0, 0, c);
117 g2d.dispose();
118 }
119
120 @SuppressWarnings({"ConstantConditions"})
121 private void paintButtonBorder(Component c, Graphics g, Rectangle rect, int state) {
122 int x = rect.x;
123 int y = rect.y;
124 int w = rect.width;
125 int h = rect.height;
126
127 Graphics2D gfx = (Graphics2D) g;
128 if (state == STATE_SELECTED || state == STATE_PRESSED) {
129 gfx.setColor(new Color(0x8b7654));
130 gfx.drawLine(x + 1, y, x + w - 2, y);
131 gfx.setPaint(new GradientPaint(x, y + 1, new Color(0x8b7654), x, y + h - 3, new Color(0xc4b9a8)));
132 gfx.drawLine(x, y + 1, x, y + h - 3);
133 gfx.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 3);
134 gfx.setColor(new Color(0xf3ca7a));
135 gfx.drawLine(x, y + h - 3, x, y + h - 3);
136 gfx.drawLine(x + w - 1, y + h - 3, x + w - 1, y + h - 3);
137
138 if (c instanceof JideSplitButton && BasicJideButtonUI.shouldWrapText(c)) {
139 gfx.setColor(new Color(0xd0bf85));
140 gfx.drawLine(x, y + h - 30, x + w, y + h - 30);
141 }
142 }
143 else if (state == STATE_ROLLOVER) {
144 if (h != 0) {
145 Paint lgp = JideSwingUtilities.getLinearGradientPaint(x, y, x, y + h,
146 new float[]{.0f, .5f, 1f},
147 new Color[]{new Color(0xd8ca96), new Color(0xb9a074), new Color(0xb8a98e)});
148 gfx.setPaint(lgp);
149 }
150 gfx.drawLine(x, y + 1, x, h - 2);
151 gfx.setColor(new Color(0xdbce99));
152 gfx.drawLine(x + 1, y, x + w - 2, y);
153 gfx.setPaint(new GradientPaint(x, y + h, new Color(0xbbae97), x + (w >> 1), y + h, new Color(0xcbc3aa), true));
154 gfx.drawLine(x + 1, y + h - 1, x + w - 2, y + h - 1);
155 if (h - 1 != 0) {
156 gfx.setPaint(JideSwingUtilities.getLinearGradientPaint(x + w - 1, y, x + w - 1, y + h - 1,
157 new float[]{.0f, .5f, 1f},
158 new Color[]{new Color(0xdcce9a), new Color(0xc3ab7a), new Color(0xd2ceb9)}));
159 }
160 gfx.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 2);
161 gfx.setColor(new Color(0xeae2a8));
162 gfx.drawLine(x + 1, y + 1, x + 1, y + 1);
163 gfx.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
164 gfx.setColor(new Color(0xf0e3bc));
165 gfx.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
166 gfx.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2);
167
168 // if (c instanceof JideSplitButton) {
169 // gfx.setColor(new Color(0xd0bf85));
170 // if (BasicJideButtonUI.shouldWrapText(c)) {
171 // gfx.drawLine(x, y + h - 30, x + w, y + h - 30);
172 // }
173 // else {
174 // int arrowSize = ((JMenu) c).isTopLevelMenu() ? 12 : 20;
175 // gfx.drawLine(x + w - arrowSize, y, x + w - arrowSize, y + h);
176 // }
177 // }
178 }
179 else if (state == STATE_DEFAULT) {
180 // paint border
181 gfx.setColor(new Color(0x7793b9));
182
183 if (c instanceof JideButton && ((JideButton) c).getButtonStyle() == JideButton.TOOLBAR_STYLE) {
184 gfx.drawLine(x + 1, y, x + w - 2, y); // top
185 gfx.drawLine(x, y + 1, x, y + h - 2); // left
186 gfx.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 2); // right
187 gfx.drawLine(x + 1, y + h - 1, x + w - 2, y + h - 1); // bottom
188
189 // paint dots
190 gfx.setColor(new Color(0x9cb4d4));
191 gfx.drawLine(x + 1, y + 1, x + 1, y + 1); // top left
192 gfx.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); // bottom left
193 gfx.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); // top right
194 gfx.drawLine(x + w - 2, y + h - 2, x + w - 2, y + h - 2); // bottom right
195 }
196 else {
197 gfx.drawLine(x + 1, y, x + w - 1, y); // top
198 gfx.drawLine(x, y + 1, x, y + h - 1); // left
199 gfx.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); // right
200 gfx.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1); // bottom
201 }
202 }
203 }
204
205 public void paintButtonBackground(JComponent c, Graphics g, Rectangle rect, int orientation, int state, boolean showBorder) {
206 Boolean highContrast = UIManager.getBoolean("Theme.highContrast");
207 if (highContrast) {
208 super.paintButtonBackground(c, g, rect, orientation, state, showBorder);
209 return;
210 }
211
212 if (!SystemInfo.isJdk6Above()) {
213 getDefaultPainter().paintButtonBackground(c, g, rect, orientation, state, showBorder);
214 return;
215 }
216 Color background = null;
217 switch (state) {
218 case STATE_DEFAULT:
219 background = c.getBackground();
220 break;
221 case STATE_ROLLOVER:
222 if (c instanceof ComponentStateSupport) {
223 background = ((ComponentStateSupport) c).getBackgroundOfState(state);
224 }
225 break;
226 case STATE_SELECTED:
227 if (c instanceof ComponentStateSupport) {
228 background = ((ComponentStateSupport) c).getBackgroundOfState(state);
229 }
230 break;
231 case STATE_DISABLE_SELECTED:
232 if (c instanceof ComponentStateSupport) {
233 background = ((ComponentStateSupport) c).getBackgroundOfState(state);
234 }
235 break;
236 case STATE_PRESSED:
237 if (c instanceof ComponentStateSupport) {
238 background = ((ComponentStateSupport) c).getBackgroundOfState(state);
239 }
240 break;
241 }
242 if (background != null && !(background instanceof UIResource)) {
243 getDefaultPainter().paintButtonBackground(c, g, rect, orientation, state, showBorder);
244 return;
245 }
246 int x = rect.x;
247 int y = rect.y;
248 int width = rect.width;
249 int height = rect.height;
250 // readjust if we do not paint a border
251 if (!showBorder) {
252 x -= 1;
253 y -= 1;
254 width += 2;
255 height += 2;
256 }
257
258 Graphics2D g2d = (Graphics2D) g.create();
259
260 // ButtonModel model = btn.getModel();
261 if (state == STATE_PRESSED) {
262 paintShadowedButtonBackground(g2d, rect,
263 new Color[]{new Color(0xfdad11), new Color(0xf69c18), new Color(0xf7a427), new Color(0xf0a85c)},
264 new Color[]{new Color(0xfda868), new Color(0xfc8f3d), new Color(0xfcb33d)});
265 }
266 else if (state == STATE_ROLLOVER) {
267 if (c.getClientProperty(IS_MENU_PART_BUTTON) == Boolean.TRUE) {
268 if (1 != height - 2) {
269 g2d.setPaint(JideSwingUtilities.getLinearGradientPaint(x + 1, y + 1, x + 1, y + height - 2,
270 new float[]{0f, .5f, .51f, 1f},
271 new Color[]{new Color(0xfffee2), new Color(0xffdc73), new Color(0xffd660), new Color(0xffeaa8)}));
272 }
273 g2d.fillRect(x + 1, y + 1, width - 2, height - 2);
274 }
275 else {
276 // paint background
277 g2d.setPaint(new GradientPaint(x, y, new Color(0xFFFFFF), x, y + height, new Color(0xfff35e)));
278 g2d.fillRect(x + 1, y + 1, width - 2, height - 2);
279 g2d.setPaint(new GradientPaint(x, y, new Color(0xfff792), x + width >> 1, y, new Color(0xFFFFFF), true));
280 g2d.drawLine(x, y + height - 2, x + width, y + height - 2);
281 if (2 != height - 4) {
282 g2d.setPaint(JideSwingUtilities.getLinearGradientPaint(x + 2, y + 2, x + 2, y + height - 4,
283 new float[]{0f, .36f, .37f, .38f, 1f},
284 new Color[]{new Color(0xfffddf), new Color(0xffe794), new Color(0xfed160), new Color(0xfecd58), new Color(0xffe794)}));
285 }
286 g2d.fillRect(x + 2, y + 2, width - 4, height - 4);
287 // g2d.setPaint(JideSwingUtilities.getRadialGradientPaint(x + width >> 1, y + height - 4, (int) (height * .53f),
288 // new float[]{0f, 1f},
289 // new Color[]{new Color(0xFFFFFFFF, true), new Color(0x00FFFFFF, true)}));
290 // Composite oldComp = g2d.getComposite();
291 // g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .36f));
292 // g2d.fillRect(x + 2, y + 2, width - 4, height - 4);
293 // g2d.setComposite(oldComp);
294 }
295 // }
296 }
297 else if (state == STATE_SELECTED) {
298 paintShadowedButtonBackground(g2d, rect,
299 new Color[]{new Color(0xF3CFA5), new Color(0xF0B159), new Color(0xF1B151), new Color(0xFBC860)},
300 new Color[]{new Color(0xFDCD98), new Color(0xF8B35B), new Color(0xFBD582)});
301 }
302 else if (state == STATE_DISABLE_SELECTED) {
303 Color[] baseColors = {new Color(0xF3CFA5), new Color(0xF0B159), new Color(0xF1B151), new Color(0xFBC860)};
304 Color[] innerBackgroundColors = {new Color(0xFDCD98), new Color(0xF8B35B), new Color(0xFBD582)};
305 for (int i = 0, length = baseColors.length; i < length; i++) {
306 baseColors[i] = ColorUtils.toGrayscale(baseColors[i]);
307 }
308 for (int i = 0, length = innerBackgroundColors.length; i < length; i++) {
309 innerBackgroundColors[i] = ColorUtils.toGrayscale(innerBackgroundColors[i]);
310 }
311 paintShadowedButtonBackground(g2d, rect, baseColors, innerBackgroundColors);
312 }
313 else if (state == STATE_DEFAULT) {
314 if (1 != height - 2) {
315 g2d.setPaint(JideSwingUtilities.getLinearGradientPaint(x + 1, y + 1, x + 1, y + height - 2,
316 new float[]{0f, .5f, .51f, 1f},
317 new Color[]{new Color(0xe8f1fc), new Color(0xe8f1fc), new Color(0xd2e1f4), new Color(0xebf3fd)}));
318 }
319 g2d.fillRect(x + 1, y + 1, width - 2, height - 2);
320 }
321
322 if (showBorder) {
323 g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP));
324 paintButtonBorder(c, g2d, rect, state);
325 }
326
327 g2d.dispose();
328 }
329
330 static void paintShadowedButtonBackground(Graphics2D gfx, Rectangle rect, Color[] baseColors, Color[] innerBackgroundColors) {
331 assert baseColors.length == 4 && innerBackgroundColors.length == 3;
332
333 int x = rect.x;
334 int y = rect.y;
335 int width = rect.width;
336 int height = rect.height;
337
338 // base background
339 if (1 != height - 2) {
340 gfx.setPaint(JideSwingUtilities.getLinearGradientPaint(x + 1, y + 1, x + width - 2, y + height - 2,
341 new float[]{0f, .6f, .61f, 1f},
342 baseColors));
343 }
344 //new Color[]{new Color(0xfdad11), new Color(0xf69c18), new Color(0xf7a427), new Color(0xf0a85c)}));
345 gfx.fillRect(x + 1, y + 1, width - 2, height - 2);
346 // inner background
347 Area base = new Area(new Rectangle(x + 2, y + 1, width - 4, height - 3));
348 base.subtract(new Area(new Rectangle(x + 2, y + height - 3, 1, 1)));
349 base.subtract(new Area(new Rectangle(x + width - 3, y + height - 3, 1, 1)));
350 if (2 != height - 4) {
351 gfx.setPaint(JideSwingUtilities.getLinearGradientPaint(x + 2, y + 2, x + 2, y + height - 4,
352 new float[]{.39f, .4f, 1f},
353 innerBackgroundColors));
354 }
355 //new Color[]{new Color(0xfda868), new Color(0xfc8f3d), new Color(0xfcb33d)}));
356 gfx.fill(base);
357 // highlight
358 // int h = (int) (height * .53f);
359 // if (h > 0) {
360 // gfx.setPaint(JideSwingUtilities.getRadialGradientPaint(x + width >> 1, y + height - 4, h,
361 // new float[]{0f, 1f},
362 // new Color[]{new Color(0xFFFFFFFF, true), new Color(0x00FFFFFF, true)}));
363 // }
364 // Composite oldComp = gfx.getComposite();
365 // gfx.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .20f));
366 // gfx.fill(base);
367 // gfx.setComposite(oldComp);
368 // paint "shadow"
369 // Area shadow = new Area(new Rectangle(x + 1, y + 1, width - 2, height - 3));
370 // shadow.subtract(new Area(new RoundRectangle2D.Double(x + 2, y + 4, width - 4, 5, 3, 3)));
371 // gfx.setPaint(new GradientPaint(x, y, new Color(0x4B000000, true), x, y + 6, new Color(0x07000000, true)));
372 // gfx.fill(shadow);
373 }
374
375
376 private static final Color[] STATUS_BAR_BG = new Color[]{
377 new Color(0x567DB0), // 1 line
378 new Color(0xFFFFFF), // 1 line
379 new Color(0xD7E6F9),
380 new Color(0xC7DCF8), // 0.333
381 new Color(0xB3D0F5),
382 new Color(0xD7E5F7), // 1
383 new Color(0xCDE0F7), // 1 line
384 new Color(0xBAD4F7), // 1 line
385 };
386
387 private static final Color[] SPECIAL_STATUS_BAR_BG = new Color[]{
388 new Color(0x567DB0), // 1 line
389 new Color(0xC5DCF8), // 1 line
390 new Color(0xC2D9F7),
391 new Color(0xA9CAF7), // 0.333
392 new Color(0x90B6EA),
393 new Color(0x7698C5), // 1
394 new Color(0x7495C2), // 1 line
395 new Color(0x95ADCE), // 1 line
396 };
397
398 public void paintStatusBarBackground(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
399 if (c.isOpaque()) {
400 Color[] bg = state == STATE_DEFAULT ? STATUS_BAR_BG : SPECIAL_STATUS_BAR_BG;
401 Graphics2D g2d = (Graphics2D) g.create();
402 int y = rect.y;
403 g2d.setColor(bg[0]);
404 g2d.drawLine(rect.x, y, rect.x + rect.width, y);
405 y++;
406 g2d.setColor(bg[1]);
407 g2d.drawLine(rect.x, y, rect.x + rect.width, y);
408 y++;
409
410 Rectangle r = new Rectangle(rect.x, y, rect.width, (rect.height - 4) / 3);
411 JideSwingUtilities.fillGradient(g2d, r, bg[2], bg[3], true);
412 r.y = r.y + r.height;
413 r.height = rect.height - r.y - 2;
414 JideSwingUtilities.fillGradient(g2d, r, bg[4], bg[5], true);
415 y = r.y + r.height;
416
417 g2d.setColor(bg[6]);
418 g2d.drawLine(rect.x, y, rect.x + rect.width, y);
419 y++;
420 g2d.setColor(bg[7]);
421 g2d.drawLine(rect.x, y, rect.x + rect.width, y);
422
423 g2d.dispose();
424 }
425 }
426
427 @Override
428 public void paintStatusBarSeparator
429 (JComponent
430 c, Graphics
431 g, Rectangle
432 rect, int orientation,
433 int state) {
434 g.setColor(new Color(0x8DACD5));
435 g.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height);
436 g.setColor(new Color(0xFFFFFF));
437 g.drawLine(rect.x + 1, rect.y, rect.x + 1, rect.y + rect.height);
438 }
439
440 public void paintMenuShadow(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
441 if (c.getClientProperty("vsnet.paintShadow") != Boolean.FALSE) {
442 super.paintMenuShadow(c, g, rect, orientation, state);
443 g.setColor(new Color(0xC5C5C5));
444 g.drawLine(rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + rect.height);
445 }
446 else {
447 g.setColor(getMenuItemBackground());
448 g.fillRect(rect.x, rect.y, rect.width, rect.height);
449 }
450 }
451
452 public void paintMenuItemBackground(JComponent c, Graphics g, Rectangle rect, int orientation, int state, boolean showBorder) {
453 if (c.getClientProperty(IS_MENU_PART_BUTTON) == Boolean.TRUE) {
454 paintButtonBackground(c, g, rect, orientation, state, showBorder);
455 }
456 else {
457 JideSwingUtilities.drawImageBorder(g, IconsFactory.getImageIcon(Office2007Painter.class, "icons/menu_item_bg.png"), rect, new Insets(2, 2, 2, 2), true);
458 }
459 }
460
461 @Override
462 public void paintPopupMenuSeparator(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
463 int defaultShadowWidth = UIDefaultsLookup.getInt("MenuItem.shadowWidth");
464 super.paintPopupMenuSeparator(c, g, rect, orientation, state);
465 g.setColor(new Color(0xC5C5C5));
466 g.drawLine(rect.x + defaultShadowWidth, rect.y, rect.x + defaultShadowWidth, rect.y + rect.height);
467 }
468
469 public void paintDropDownIcon(Graphics g, int x, int y) {
470 g.setColor(new Color(0x567db1));
471 g.drawLine(x, y, x + 5, y);
472 g.drawLine(x + 1, y + 1, x + 4, y + 1);
473 g.drawLine(x + 2, y + 2, x + 3, y + 2);
474 }
475
476 @Override
477 public void paintCommandBarBackground(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
478 Boolean highContrast = UIManager.getBoolean("Theme.highContrast");
479 if (highContrast) {
480 super.paintCommandBarBackground(c, g, rect, orientation, state);
481 return;
482 }
483
484 if (!SystemInfo.isJdk6Above()) {
485 getDefaultPainter().paintCommandBarBackground(c, g, rect, orientation, state);
486 return;
487 }
488 int x = rect.x;
489 int y = rect.y;
490 int width = rect.width;
491 int height = rect.height;
492
493 Graphics2D g2d = (Graphics2D) g.create();
494 Color[] colors = {new Color(0xe8f1fc), new Color(0xe8f1fc), new Color(0xd2e1f4), new Color(0xebf3fd)};
495 for (int i = 0; i < colors.length; i++) {
496 Color color = colors[i];
497 colors[i] = ColorUtils.getDerivedColor(color, .47f);
498 }
499 if (1 != height - 2) {
500 g2d.setPaint(JideSwingUtilities.getLinearGradientPaint(x + 1, y + 1, x + 1, y + height - 2,
501 new float[]{0f, .5f, .51f, 1f},
502 colors));
503 }
504 g2d.fillRect(x + 1, y + 1, width - 2, height - 2);
505 AlphaComposite alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_ATOP);
506 g2d.setComposite(SystemInfo.isJdk6Above() ? alphaComposite.derive(0.1f) : AlphaComposite.getInstance(alphaComposite.getRule(), 0.1f));
507 paintButtonBorder(c, g2d, rect, state);
508 g2d.dispose();
509 }
510
511 @Override
512 public void paintFloatingCommandBarBackground(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
513 if (!SystemInfo.isJdk6Above()) {
514 getDefaultPainter().paintFloatingCommandBarBackground(c, g, rect, orientation, state);
515 return;
516 }
517 int x = rect.x;
518 int y = rect.y;
519 int width = rect.width;
520 int height = rect.height;
521
522 Graphics2D g2d = (Graphics2D) g.create();
523 Color[] colors = {new Color(0xe8f1fc), new Color(0xe8f1fc), new Color(0xd2e1f4), new Color(0xebf3fd)};
524 for (int i = 0; i < colors.length; i++) {
525 Color color = colors[i];
526 colors[i] = ColorUtils.getDerivedColor(color, .48f);
527 }
528 if (height != 0) {
529 g2d.setPaint(JideSwingUtilities.getLinearGradientPaint(x, y, x, y + height,
530 new float[]{0f, .5f, .51f, 1f},
531 colors));
532 }
533 g2d.fillRect(x, y, width, height);
534 g2d.dispose();
535 }
536
537 private static final Color[] DOCKABLE_FRAME_TITLE_BAR_BG = new Color[]{
538 new Color(0xe5f4fd), // 0.333
539 new Color(0xd8effc),
540 new Color(0xbee6fd), // 0.666
541 new Color(0xa6d9f4), // 1
542 };
543
544 private static final Color[] ACTIVE_DOCKABLE_FRAME_TITLE_BAR_BG = new Color[]{
545 new Color(0xffe3a7), // 0.333
546 new Color(0xffcf71),
547 new Color(0xffc34f), // 0.666
548 new Color(0xffc854), // 1
549 };
550
551 private static final Color[] COLLAPSIBLE_PANE_TITLE_BAR_BG = new Color[]{
552 new Color(0xd7e6f9), // 0.333
553 new Color(0xc7dcf8),
554 new Color(0xb3d0f5), // 0.666
555 new Color(0xd7e5f7), // 1
556 };
557
558 private static final Color[] EMPHASIZED_COLLAPSIBLE_PANE_TITLE_BAR_BG = new Color[]{
559 new Color(0xe7f0fe), // 0.333
560 new Color(0xb9d3f7),
561 new Color(0xa5c4ed), // 0.666
562 new Color(0x8fa9cd), // 1
563 };
564
565 private static final Color[] COLLAPSIBLE_PANE_TITLE_BAR_SEPARATOR_BG = new Color[]{
566 new Color(0xc7dcf8),
567 new Color(0xd7e6f9), // 0.5
568 new Color(0xc7dcf8),
569 };
570
571 private static final Color[] EMPHASIZED_COLLAPSIBLE_PANE_TITLE_BAR_SEPARATOR_BG = new Color[]{
572 new Color(0xb9d3f7),
573 new Color(0xe7f0fe), // 0.5
574 new Color(0xb9d3f7),
575 };
576
577 @Override
578 public void paintDockableFrameTitlePane(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
579 Boolean highContrast = UIManager.getBoolean("Theme.highContrast");
580 if (highContrast) {
581 super.paintDockableFrameTitlePane(c, g, rect, orientation, state);
582 return;
583 }
584
585 if (!SystemInfo.isJdk6Above()) {
586 getDefaultPainter().paintDockableFrameTitlePane(c, g, rect, orientation, state);
587 return;
588 }
589 int x = rect.x;
590 int y = rect.y;
591 int w = rect.width;
592 int h = rect.height;
593 if (c.getBorder() != null) {
594 Insets insets = c.getBorder().getBorderInsets(c);
595 x += insets.left;
596 y += insets.top;
597 w -= insets.right + insets.left;
598 h -= insets.top + insets.bottom;
599 }
600 boolean active = state == STATE_SELECTED;
601 Color[] colors = active ? ACTIVE_DOCKABLE_FRAME_TITLE_BAR_BG : DOCKABLE_FRAME_TITLE_BAR_BG;
602 Graphics2D g2d = (Graphics2D) g.create();
603 Color old = g2d.getColor();
604 g2d.setColor(Color.WHITE);
605 g2d.drawLine(x, y, x + w, y);
606 g2d.drawLine(x, y, x, y + h);
607 g2d.setColor(old);
608 if (h != 0) {
609 g2d.setPaint(JideSwingUtilities.getLinearGradientPaint(x + 1, y + 1, x + 1, y + h - 1,
610 new float[]{0f, .333f, .334f, 1f},
611 colors));
612 }
613 g2d.fillRect(x + 1, y + 1, w - 1, h - 1);
614 g2d.dispose();
615 }
616
617 @Override
618 public void paintCollapsiblePaneTitlePaneBackground(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
619 Boolean highContrast = UIManager.getBoolean("Theme.highContrast");
620 if (highContrast) {
621 super.paintCollapsiblePaneTitlePaneBackground(c, g, rect, orientation, state);
622 return;
623 }
624 if (!SystemInfo.isJdk6Above()) {
625 getDefaultPainter().paintCollapsiblePaneTitlePaneBackground(c, g, rect, orientation, state);
626 return;
627 }
628 paintCollapsiblePaneTitlePane(c, g, rect, COLLAPSIBLE_PANE_TITLE_BAR_BG, orientation, state);
629 }
630
631 @Override
632 public void paintCollapsiblePaneTitlePaneBackgroundEmphasized(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
633 Boolean highContrast = UIManager.getBoolean("Theme.highContrast");
634 if (highContrast) {
635 super.paintCollapsiblePaneTitlePaneBackgroundEmphasized(c, g, rect, orientation, state);
636 return;
637 }
638 if (!SystemInfo.isJdk6Above()) {
639 getDefaultPainter().paintCollapsiblePaneTitlePaneBackgroundEmphasized(c, g, rect, orientation, state);
640 return;
641 }
642 paintCollapsiblePaneTitlePane(c, g, rect, EMPHASIZED_COLLAPSIBLE_PANE_TITLE_BAR_BG, orientation, state);
643 }
644
645 @Override
646 public void paintCollapsiblePaneTitlePaneBackgroundSeparatorEmphasized(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
647 Boolean highContrast = UIManager.getBoolean("Theme.highContrast");
648 if (highContrast) {
649 super.paintCollapsiblePaneTitlePaneBackgroundSeparatorEmphasized(c, g, rect, orientation, state);
650 return;
651 }
652 if (!SystemInfo.isJdk6Above()) {
653 getDefaultPainter().paintCollapsiblePaneTitlePaneBackgroundSeparatorEmphasized(c, g, rect, orientation, state);
654 return;
655 }
656 paintCollapsiblePaneTitlePaneSeparator(c, g, rect, EMPHASIZED_COLLAPSIBLE_PANE_TITLE_BAR_SEPARATOR_BG, state);
657 }
658
659 @Override
660 public void paintCollapsiblePaneTitlePaneBackgroundSeparator(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
661 Boolean highContrast = UIManager.getBoolean("Theme.highContrast");
662 if (highContrast) {
663 super.paintCollapsiblePaneTitlePaneBackgroundSeparator(c, g, rect, orientation, state);
664 return;
665 }
666 if (!SystemInfo.isJdk6Above()) {
667 getDefaultPainter().paintCollapsiblePaneTitlePaneBackgroundSeparator(c, g, rect, orientation, state);
668 return;
669 }
670 paintCollapsiblePaneTitlePaneSeparator(c, g, rect, COLLAPSIBLE_PANE_TITLE_BAR_SEPARATOR_BG, state);
671 }
672
673 private void paintCollapsiblePaneTitlePane(JComponent c, Graphics g, Rectangle rect, Color[] colors, int orientation, int state) {
674 int x = rect.x;
675 int y = rect.y;
676 int w = rect.width;
677 int h = rect.height;
678 if (c.getBorder() != null) {
679 Insets insets = c.getBorder().getBorderInsets(c);
680 x += insets.left;
681 y += insets.top;
682 w -= insets.right + insets.left;
683 h -= insets.top + insets.bottom;
684 }
685 if (h != 0) {
686 Graphics2D g2d = (Graphics2D) g.create();
687 Paint paint = null;
688 switch (orientation) {
689 case SwingConstants.EAST:
690 if (state == ThemePainter.STATE_ROLLOVER) {
691 Color[] newColors = new Color[colors.length];
692 for (int i = 0; i < colors.length; i++) {
693 Color color = colors[i];
694 newColors[i] = ColorUtils.getDerivedColor(color, 0.60f);
695 }
696 paint = JideSwingUtilities.getLinearGradientPaint(x, y, x + w, y, new float[]{0f, .333f, .334f, 1f}, newColors);
697 }
698 else {
699 paint = JideSwingUtilities.getLinearGradientPaint(x, y, x + w, y, new float[]{0f, .333f, .334f, 1f}, colors);
700 }
701 break;
702 case SwingConstants.WEST:
703 if (state == ThemePainter.STATE_ROLLOVER) {
704 Color[] newColors = new Color[colors.length];
705 for (int i = 0; i < colors.length; i++) {
706 Color color = colors[i];
707 newColors[i] = ColorUtils.getDerivedColor(color, 0.60f);
708 }
709 paint = JideSwingUtilities.getLinearGradientPaint(x + w, y, x, y, new float[]{0f, .333f, .334f, 1f}, newColors);
710 }
711 else {
712 paint = JideSwingUtilities.getLinearGradientPaint(x + w, y, x, y, new float[]{0f, .333f, .334f, 1f}, colors);
713 }
714 break;
715 case SwingConstants.NORTH:
716 if (state == ThemePainter.STATE_ROLLOVER) {
717 Color[] newColors = new Color[colors.length];
718 for (int i = 0; i < colors.length; i++) {
719 Color color = colors[i];
720 newColors[i] = ColorUtils.getDerivedColor(color, 0.60f);
721 }
722 paint = JideSwingUtilities.getLinearGradientPaint(x, y + h, x, y, new float[]{0f, .333f, .334f, 1f}, newColors);
723 }
724 else {
725 paint = JideSwingUtilities.getLinearGradientPaint(x, y + h, x, y, new float[]{0f, .333f, .334f, 1f}, colors);
726 }
727 break;
728 case SwingConstants.SOUTH:
729 if (state == ThemePainter.STATE_ROLLOVER) {
730 Color[] newColors = new Color[colors.length];
731 for (int i = 0; i < colors.length; i++) {
732 Color color = colors[i];
733 newColors[i] = ColorUtils.getDerivedColor(color, 0.60f);
734 }
735 paint = JideSwingUtilities.getLinearGradientPaint(x, y, x, y + h, new float[]{0f, .333f, .334f, 1f}, newColors);
736 }
737 else {
738 paint = JideSwingUtilities.getLinearGradientPaint(x, y, x, y + h, new float[]{0f, .333f, .334f, 1f}, colors);
739 }
740 break;
741 }
742 g2d.setPaint(paint);
743 g2d.fillRect(x, y, w, h);
744 g2d.dispose();
745 }
746 }
747
748 private void paintCollapsiblePaneTitlePaneSeparator(JComponent c, Graphics g, Rectangle rect, Color[] colors, int state) {
749 int x = rect.x;
750 int y = rect.y;
751 int w = rect.width;
752 int h = rect.height;
753 if (c.getBorder() != null) {
754 Insets insets = c.getBorder().getBorderInsets(c);
755 x += insets.left;
756 y += insets.top;
757 w -= insets.right + insets.left;
758 h -= insets.top + insets.bottom;
759 }
760 if (h != 0) {
761 Graphics2D g2d = (Graphics2D) g.create();
762 if (state == ThemePainter.STATE_ROLLOVER) {
763 Color[] newColors = new Color[colors.length];
764 for (int i = 0; i < colors.length; i++) {
765 Color color = colors[i];
766 newColors[i] = ColorUtils.getDerivedColor(color, 0.60f);
767 }
768 g2d.setPaint(JideSwingUtilities.getLinearGradientPaint(x, y, x + w, y, new float[]{0f, .5f, 1f}, newColors));
769 }
770 else {
771 g2d.setPaint(JideSwingUtilities.getLinearGradientPaint(x, y, x + w, y, new float[]{0f, .5f, 1f}, colors));
772 }
773 g2d.fillRect(x, y, w, h);
774 g2d.dispose();
775 }
776 }
777
778 @Override
779 public void paintCollapsiblePanesBackground(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
780 if (!c.isOpaque()) {
781 return;
782 }
783 Boolean highContrast = UIManager.getBoolean("Theme.highContrast");
784 if (highContrast) {
785 super.paintCollapsiblePanesBackground(c, g, rect, orientation, state);
786 return;
787 }
788 Graphics2D g2d = (Graphics2D) g;
789 if (!(c.getBackground() instanceof UIResource)) {
790 JideSwingUtilities.fillGradient(g2d,
791 new Rectangle(rect.x, rect.y, rect.width, rect.height),
792 c.getBackground(),
793 ColorUtils.getDerivedColor(c.getBackground(), 0.6f),
794 orientation == SwingConstants.HORIZONTAL);
795 }
796 else {
797 JideSwingUtilities.fillGradient(g2d,
798 new Rectangle(rect.x, rect.y, rect.width, rect.height),
799 UIDefaultsLookup.getColor("CollapsiblePanes.backgroundLt"),
800 UIDefaultsLookup.getColor("CollapsiblePanes.backgroundDk"),
801 orientation == SwingConstants.HORIZONTAL);
802 }
803 }
804
805 @Override
806 public void paintSidePaneItemBackground(JComponent c, Graphics g, Rectangle rect, Color[] colors, int orientation, int state) {
807 Boolean highContrast = UIManager.getBoolean("Theme.highContrast");
808 if (highContrast || (colors != null && colors.length >= 1 && colors[0] != null && !(colors[0] instanceof UIResource))) {
809 super.paintSidePaneItemBackground(c, g, rect, colors, orientation, state);
810 return;
811 }
812 Graphics2D g2d = (Graphics2D) g.create();
813 switch (orientation) {
814 case SwingConstants.WEST:
815 case SwingConstants.EAST:
816 g2d.rotate(-Math.toRadians(90), rect.x, rect.y);
817 g2d.translate(-rect.height, rect.y);
818 //noinspection SuspiciousNameCombination
819 paintButtonBackground(c, g2d, new Rectangle(0, 0, rect.height, rect.width), SwingConstants.HORIZONTAL, state, false);
820 break;
821 case SwingConstants.NORTH:
822 case SwingConstants.SOUTH:
823 paintButtonBackground(c, g2d, rect, SwingConstants.HORIZONTAL, state, false);
824 break;
825 }
826 g2d.dispose();
827 }
828
829 @Override
830 public void paintHeaderBoxBackground(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
831 boolean paintBorder = !(c instanceof AbstractButton) || ((AbstractButton) c).isBorderPainted();
832 paintButtonBackground(c, g, rect, orientation, state, paintBorder);
833 if (!paintBorder) {
834 Color old = g.getColor();
835 g.setColor(UIDefaultsLookup.getColor("Table.gridColor"));
836 g.drawLine(rect.x + rect.width - 1, rect.y, rect.x + rect.width - 1, rect.y + rect.height - 1);
837 g.drawLine(rect.x, rect.y + rect.height - 1, rect.x + rect.width - 1, rect.y + rect.height - 1);
838 g.setColor(old);
839 }
840 }
841
842 @Override
843 public void paintGripper(JComponent c, Graphics g, Rectangle rect, int orientation, int state) {
844 if (rect.width > 30) {
845 orientation = SwingConstants.VERTICAL;
846 }
847 else if (rect.height > 30) {
848 orientation = SwingConstants.HORIZONTAL;
849 }
850
851 int h = (orientation == SwingConstants.HORIZONTAL) ? rect.height : rect.width;
852 int count = Math.min(9, (h - 6) / 4);
853 int y = rect.y;
854 int x = rect.x;
855
856 if (orientation == SwingConstants.HORIZONTAL) {
857 y += rect.height / 2 - count * 2;
858 x += rect.width / 2 - 1;
859 }
860 else {
861 x += rect.width / 2 - count * 2;
862 y += rect.height / 2 - 1;
863 }
864
865 for (int i = 0; i < count; i++) {
866 g.setColor(getGripperForegroundLt());
867 g.fillRect(x + 1, y + 1, 2, 2);
868 g.setColor(getGripperForeground());
869 g.fillRect(x, y, 2, 2);
870 g.setColor(ColorUtils.getDerivedColor(getGripperForeground(), 0.55f));
871 g.fillRect(x + 1, y + 1, 1, 1);
872 if (orientation == SwingConstants.HORIZONTAL) {
873 y += 4;
874 }
875 else {
876 x += 4;
877 }
878 }
879 }
880
881 public Color getGripperForegroundLt() {
882 return UIDefaultsLookup.getColor("Gripper.light");
883 }
884
885 @Override
886 public Color getSelectionSelectedDk() {
887 return new ColorUIResource(0xf8cb73);
888 }
889
890 @Override
891 public Color getSelectionSelectedLt() {
892 return new ColorUIResource(0xfefbd5);
893 }
894
895 public Color getBackgroundDk() {
896 return UIDefaultsLookup.getColor("JideTabbedPane.background");
897 }
898
899 public Color getBackgroundLt() {
900 return UIDefaultsLookup.getColor("JideTabbedPane.background");
901 }
902
903 public void fillBackground(JComponent c, Graphics g, Rectangle rect, int orientation, int state, Color color) {
904 Graphics2D g2d = (Graphics2D) g.create();
905 if (orientation == SwingConstants.HORIZONTAL) {
906 int topHeight = rect.height / 3;
907 JideSwingUtilities.fillGradient((Graphics2D) g, new Rectangle(rect.x, rect.y, rect.width, topHeight), ColorUtils.getDerivedColor(color, 0.74f),
908 ColorUtils.getDerivedColor(color, 0.64f), true);
909 JideSwingUtilities.fillGradient((Graphics2D) g, new Rectangle(rect.x, rect.y + topHeight, rect.width, rect.height - topHeight), color,
910 ColorUtils.getDerivedColor(color, 0.64f), true);
911 }
912 else {
913 int leftWidth = rect.width / 3;
914 JideSwingUtilities.fillGradient((Graphics2D) g, new Rectangle(rect.x, rect.y, leftWidth, rect.height), ColorUtils.getDerivedColor(color, 0.74f),
915 ColorUtils.getDerivedColor(color, 0.64f), false);
916 JideSwingUtilities.fillGradient((Graphics2D) g, new Rectangle(rect.x + leftWidth, rect.y, rect.width - leftWidth, rect.height), color,
917 ColorUtils.getDerivedColor(color, 0.64f), false);
918 }
919 g2d.dispose();
920 }
921 }