001: package com.jidesoft.plaf.basic;
002:
003: import com.jidesoft.plaf.UIDefaultsLookup;
004: import com.jidesoft.swing.ComponentStateSupport;
005: import com.jidesoft.swing.JideSwingUtilities;
006: import com.jidesoft.utils.SecurityUtils;
007:
008: import javax.swing.*;
009: import javax.swing.plaf.ColorUIResource;
010: import javax.swing.plaf.UIResource;
011: import java.awt.*;
012:
013: /**
014: * Painter for JIDE styles.
015: * <p/>
016: * Please note, this class is an internal class which is meant to be used by other JIDE classes only.
017: * Future version might break your build if you use it.
018: */
019: public class BasicPainter implements SwingConstants, ThemePainter {
020: private static BasicPainter _instance;
021:
022: public static ThemePainter getInstance() {
023: if (_instance == null) {
024: _instance = new BasicPainter();
025: }
026: return _instance;
027: }
028:
029: protected Color _bk0;
030: protected Color _bk1;
031: protected Color _bk2;
032: protected Color _bk3;
033: protected Color _borderColor;
034:
035: public BasicPainter() {
036: }
037:
038: public void installDefaults() {
039: if (_bk0 == null) {
040: _bk0 = UIDefaultsLookup.getColor("JideButton.background");
041: }
042: if (_bk1 == null) {
043: _bk1 = UIDefaultsLookup
044: .getColor("JideButton.focusedBackground");
045: }
046: if (_bk2 == null) {
047: _bk2 = UIDefaultsLookup
048: .getColor("JideButton.selectedBackground");
049: }
050: if (_bk3 == null) {
051: _bk3 = UIDefaultsLookup
052: .getColor("JideButton.selectedAndFocusedBackground");
053: }
054: if (_borderColor == null) {
055: _borderColor = UIDefaultsLookup
056: .getColor("JideButton.borderColor");
057: }
058: }
059:
060: public void uninstallDefaults() {
061: _borderColor = null;
062: _bk0 = null;
063: _bk1 = null;
064: _bk2 = null;
065: _bk3 = null;
066: }
067:
068: public Color getGripperForeground() {
069: return UIDefaultsLookup.getColor("Gripper.foreground");
070: }
071:
072: public Color getGripperForegroundLt() {
073: return UIDefaultsLookup.getColor("JideButton.highlight");
074: }
075:
076: public Color getSeparatorForeground() {
077: return UIDefaultsLookup.getColor("JideButton.shadow");
078: }
079:
080: public Color getSeparatorForegroundLt() {
081: return UIDefaultsLookup.getColor("JideButton.highlight");
082: }
083:
084: public Color getCollapsiblePaneContentBackground() {
085: return UIDefaultsLookup
086: .getColor("CollapsiblePane.contentBackground");
087: }
088:
089: public Color getCollapsiblePaneTitleForeground() {
090: return UIDefaultsLookup.getColor("CollapsiblePane.foreground");
091: }
092:
093: public Color getCollapsiblePaneTitleForegroundEmphasized() {
094: return UIDefaultsLookup
095: .getColor("CollapsiblePane.emphasizedForeground");
096: }
097:
098: public Color getCollapsiblePaneFocusTitleForegroundEmphasized() {
099: return UIDefaultsLookup
100: .getColor("CollapsiblePane.emphasizedForeground");
101: }
102:
103: public Color getCollapsiblePaneFocusTitleForeground() {
104: return UIDefaultsLookup.getColor("CollapsiblePane.foreground");
105: }
106:
107: public ImageIcon getCollapsiblePaneUpIcon() {
108: return (ImageIcon) UIDefaultsLookup
109: .getIcon("CollapsiblePane.upIcon");
110: }
111:
112: public ImageIcon getCollapsiblePaneDownIcon() {
113: return (ImageIcon) UIDefaultsLookup
114: .getIcon("CollapsiblePane.downIcon");
115: }
116:
117: public ImageIcon getCollapsiblePaneUpIconEmphasized() {
118: return getCollapsiblePaneUpIcon();
119: }
120:
121: public ImageIcon getCollapsiblePaneDownIconEmphasized() {
122: return getCollapsiblePaneDownIcon();
123: }
124:
125: public ImageIcon getCollapsiblePaneTitleButtonBackground() {
126: return (ImageIcon) UIDefaultsLookup
127: .getIcon("CollapsiblePane.titleButtonBackground");
128: }
129:
130: public ImageIcon getCollapsiblePaneTitleButtonBackgroundEmphasized() {
131: return (ImageIcon) UIDefaultsLookup
132: .getIcon("CollapsiblePane.titleButtonBackground.emphasized");
133: }
134:
135: public ImageIcon getCollapsiblePaneUpMask() {
136: return getCollapsiblePaneUpIcon();
137: }
138:
139: public ImageIcon getCollapsiblePaneDownMask() {
140: return getCollapsiblePaneDownIcon();
141: }
142:
143: public Color getBackgroundDk() {
144: return UIDefaultsLookup.getColor("JideButton.background");
145: }
146:
147: public Color getBackgroundLt() {
148: return UIDefaultsLookup.getColor("JideButton.background");
149: }
150:
151: public Color getSelectionSelectedDk() {
152: return _bk2;
153: }
154:
155: public Color getSelectionSelectedLt() {
156: return _bk2;
157: }
158:
159: public Color getMenuItemBorderColor() {
160: return UIDefaultsLookup
161: .getColor("MenuItem.selectionBorderColor");
162: }
163:
164: public Color getMenuItemBackground() {
165: return UIDefaultsLookup.getColor("MenuItem.background");
166: }
167:
168: public Color getCommandBarTitleBarBackground() {
169: return UIDefaultsLookup
170: .getColor("CommandBar.titleBarBackground");
171: }
172:
173: public Color getControl() {
174: return UIDefaultsLookup.getColor("JideButton.background");
175: }
176:
177: public Color getControlLt() {
178: return getControlShadow();
179: }
180:
181: public Color getControlDk() {
182: return getControlShadow();
183: }
184:
185: public Color getControlShadow() {
186: return UIDefaultsLookup.getColor("JideButton.shadow");
187: }
188:
189: public Color getTitleBarBackground() {
190: return UIDefaultsLookup
191: .getColor("DockableFrame.activeTitleBackground");
192: }
193:
194: public Color getDockableFrameTitleBarActiveForeground() {
195: return UIDefaultsLookup
196: .getColor("DockableFrame.activeTitleForeground");
197: }
198:
199: public Color getDockableFrameTitleBarInactiveForeground() {
200: return UIDefaultsLookup
201: .getColor("DockableFrame.inactiveTitleForeground");
202: }
203:
204: public Color getOptionPaneBannerForeground() {
205: return new ColorUIResource(255, 255, 255);
206: }
207:
208: public Color getTabbedPaneSelectDk() {
209: return new ColorUIResource(230, 139, 44);
210: }
211:
212: public Color getTabbedPaneSelectLt() {
213: return new ColorUIResource(255, 199, 60);
214: }
215:
216: public Color getTabAreaBackgroundDk() {
217: return getBackgroundLt();
218: }
219:
220: public Color getTabAreaBackgroundLt() {
221: return new ColorUIResource(255, 255, 255);
222: }
223:
224: public Color getOptionPaneBannerDk() {
225: return new ColorUIResource(45, 96, 249);
226: }
227:
228: public Color getOptionPaneBannerLt() {
229: return new ColorUIResource(0, 52, 206);
230: }
231:
232: public void paintSelectedMenu(JComponent c, Graphics g,
233: Rectangle rect, int orientation, int state) {
234: Color oldColor = g.getColor();
235: g.setColor(UIDefaultsLookup.getColor("JideButton.darkShadow"));
236: g.drawLine(rect.x, rect.y + rect.height, rect.x, rect.y + 1);
237: g.drawLine(rect.x + rect.width - 2, rect.y, rect.x + rect.width
238: - 2, rect.y + rect.height);
239: if (orientation == SwingConstants.HORIZONTAL) {
240: g.drawLine(rect.x, rect.y, rect.x + rect.width - 3, rect.y);
241: } else {
242: g.drawLine(rect.x, rect.y + rect.height - 1, rect.x
243: + rect.width - 3, rect.y + rect.height - 1);
244: }
245: g.setColor(oldColor);
246: }
247:
248: public void paintMenuItemBackground(JComponent c, Graphics g,
249: Rectangle rect, int orientation, int state) {
250: paintMenuItemBackground(c, g, rect, orientation, state, true);
251: }
252:
253: public void paintMenuItemBackground(JComponent c, Graphics g,
254: Rectangle rect, int orientation, int state,
255: boolean showBorder) {
256: paintButtonBackground(c, g, rect, orientation, state,
257: showBorder);
258: }
259:
260: public void paintButtonBackground(JComponent c, Graphics g,
261: Rectangle rect, int orientation, int state) {
262: paintButtonBackground(c, g, rect, orientation, state, true);
263: }
264:
265: public void paintButtonBackground(JComponent c, Graphics g,
266: Rectangle rect, int orientation, int state,
267: boolean showBorder) {
268: installDefaults();
269: Color background = null;
270: switch (state) {
271: case STATE_DEFAULT:
272:
273: background = c.getBackground();
274: if (background == null || background instanceof UIResource) {
275: background = _bk0;
276: }
277: paintBackground(c, g, rect, background, background,
278: orientation);
279: break;
280: case STATE_ROLLOVER:
281: if (c instanceof ComponentStateSupport) {
282: background = ((ComponentStateSupport) c)
283: .getBackgroundOfState(STATE_ROLLOVER);
284: }
285: if (background == null || background instanceof UIResource) {
286: background = _bk1;
287: }
288: paintBackground(c, g, rect, _borderColor, background,
289: orientation);
290: break;
291: case STATE_SELECTED:
292: if (c instanceof ComponentStateSupport) {
293: background = ((ComponentStateSupport) c)
294: .getBackgroundOfState(STATE_SELECTED);
295: }
296: if (background == null || background instanceof UIResource) {
297: background = _bk2;
298: }
299: paintBackground(c, g, rect, _borderColor, background,
300: orientation);
301: break;
302: case STATE_PRESSED:
303: if (c instanceof ComponentStateSupport) {
304: background = ((ComponentStateSupport) c)
305: .getBackgroundOfState(STATE_PRESSED);
306: }
307: if (background == null || background instanceof UIResource) {
308: background = _bk3;
309: }
310: paintBackground(c, g, rect, _borderColor, background,
311: orientation);
312: break;
313: }
314: }
315:
316: protected void paintBackground(JComponent c, Graphics g,
317: Rectangle rect, Color borderColor, Color background,
318: int orientation) {
319: Color oldColor = g.getColor();
320: if (borderColor != null) {
321: boolean paintDefaultBorder = true;
322: Object o = c
323: .getClientProperty("JideButton.paintDefaultBorder");
324: if (o instanceof Boolean) {
325: paintDefaultBorder = (Boolean) o;
326: }
327: if (paintDefaultBorder) {
328: g.setColor(borderColor);
329: g.drawRect(rect.x, rect.y, rect.width - 1,
330: rect.height - 1);
331: }
332: g.setColor(background);
333: g.fillRect(rect.x + 1, rect.y + 1, rect.width - 2,
334: rect.height - 2);
335: } else {
336: g.setColor(background);
337: g.fillRect(rect.x, rect.y, rect.width, rect.height);
338: }
339: g.setColor(oldColor);
340: }
341:
342: public void paintChevronBackground(JComponent c, Graphics g,
343: Rectangle rect, int orientation, int state) {
344: if (state != STATE_DEFAULT) {
345: paintButtonBackground(c, g, rect, orientation, state);
346: }
347: }
348:
349: public void paintDividerBackground(JComponent c, Graphics g,
350: Rectangle rect, int orientation, int state) {
351: Color oldColor = g.getColor();
352: g.setColor(UIDefaultsLookup.getColor("SplitPane.background"));
353: g.fillRect(0, 0, rect.width, rect.height);
354: g.setColor(oldColor);
355: }
356:
357: public void paintCommandBarBackground(JComponent c, Graphics g,
358: Rectangle rect, int orientation, int state) {
359: g.setColor(UIDefaultsLookup.getColor("CommandBar.background"));
360: g.fillRoundRect(rect.x, rect.y, rect.width, rect.height, 2, 2);
361: }
362:
363: public void paintFloatingCommandBarBackground(JComponent c,
364: Graphics g, Rectangle rect, int orientation, int state) {
365: g.setColor(UIDefaultsLookup.getColor("CommandBar.background"));
366: g.fillRect(rect.x, rect.y, rect.width, rect.height);
367: }
368:
369: public void paintMenuShadow(JComponent c, Graphics g,
370: Rectangle rect, int orientation, int state) {
371: Color oldColor = g.getColor();
372: g.setColor(UIDefaultsLookup.getColor("MenuItem.shadowColor"));
373: g.fillRect(0, 0, rect.width, rect.height);
374: g.setColor(oldColor);
375: }
376:
377: public void paintContentBackground(JComponent c, Graphics g,
378: Rectangle rect, int orientation, int state) {
379: g.setColor(UIDefaultsLookup.getColor("JideButton.background"));
380: g.fillRect(rect.x, rect.y, rect.width, rect.height);
381: }
382:
383: public void paintStatusBarBackground(JComponent c, Graphics g,
384: Rectangle rect, int orientation, int state) {
385: paintContentBackground(c, g, rect, orientation, state);
386: }
387:
388: public void paintCommandBarTitlePane(JComponent c, Graphics g,
389: Rectangle rect, int orientation, int state) {
390: g.setColor(getCommandBarTitleBarBackground());
391: g.fillRect(rect.x, rect.y, rect.width, rect.height);
392: }
393:
394: public void paintGripper(JComponent c, Graphics g, Rectangle rect,
395: int orientation, int state) {
396: int w = Math.min(30, rect.width);
397: int h = rect.height;
398:
399: // basic painter always use horizontal line to paint grippers. It's just they are short and more lines when paints vertical gripper
400: // and long and fewer lines when paints horizontally.
401: g.setColor(getGripperForeground());
402: if (orientation == SwingConstants.HORIZONTAL) {
403: if (rect.width <= 30) {
404: final int MARGIN = 3;
405: for (int i = 0; i < (h - 2 * MARGIN) / 2; i++) {
406: g.drawLine(rect.x + 3, rect.y + MARGIN + i * 2,
407: rect.x + w - MARGIN, rect.y + MARGIN + i
408: * 2);
409: }
410: } else { // for gripper in popup
411: final int MARGIN = 2;
412: for (int i = 0; i < (h - 2 * MARGIN) / 2; i++) {
413: g.drawLine((rect.width - w) / 2, rect.y + MARGIN
414: + i * 2, (rect.width + w) / 2, rect.y
415: + MARGIN + i * 2);
416: }
417: }
418: } else {
419: final int MARGIN = 3;
420: int count = (w - 2 * MARGIN) / 2;
421: for (int i = 0; i < count; i++) {
422: int x = rect.x + rect.width / 2 - count + i * 2;
423: g.drawLine(x, rect.y + MARGIN, x, rect.y + h - MARGIN);
424: }
425: }
426: }
427:
428: public void paintChevronMore(JComponent c, Graphics g,
429: Rectangle rect, int orientation, int state) {
430: g.setColor(UIDefaultsLookup.getColor("CommandBar.darkShadow"));
431: int y = rect.y + 4;
432: for (int i = -2; i <= 2; i++) {
433: int offset = -Math.abs(i);
434: g.drawLine(rect.x + 4 + offset, y, rect.x + 5 + offset, y);
435: g.drawLine(rect.x + 8 + offset, y, rect.x + 9 + offset, y);
436: y++;
437: }
438: }
439:
440: public void paintChevronOption(JComponent c, Graphics g,
441: Rectangle rect, int orientation, int state) {
442: int startX = 0;
443: int startY = 0;
444: if (orientation == SwingConstants.HORIZONTAL) {
445: startX = rect.x + 3;
446: startY = rect.y + rect.height - 7;
447: } else {
448: startX = rect.x + rect.width - 7;
449: startY = rect.y + 3;
450: }
451: JideSwingUtilities.paintArrow(g, UIDefaultsLookup
452: .getColor("CommandBar.darkShadow"), startX, startY, 5,
453: orientation);
454: }
455:
456: public void paintFloatingChevronOption(JComponent c, Graphics g,
457: Rectangle rect, int orientation, int state) {
458: int startX = 0;
459: int startY = 0;
460: startX = rect.width / 2 - 4;
461: startY = rect.height / 2 - 2;
462: if (state == STATE_ROLLOVER) {
463: JideSwingUtilities.paintArrow(g, Color.BLACK, startX,
464: startY, 9, orientation);
465: } else {
466: JideSwingUtilities.paintArrow(g, Color.WHITE, startX,
467: startY, 9, orientation);
468: }
469: }
470:
471: public void paintDockableFrameBackground(JComponent c, Graphics g,
472: Rectangle rect, int orientation, int state) {
473: g.setColor(UIDefaultsLookup
474: .getColor("DockableFrame.background"));
475: g.fillRect(rect.x, rect.y, rect.width, rect.height);
476: }
477:
478: public void paintDockableFrameTitlePane(JComponent c, Graphics g,
479: Rectangle rect, int orientation, int state) {
480: int x = rect.x;
481: int y = rect.y;
482: int w = rect.width - 1;
483: int h = rect.height;
484: if (c.getBorder() != null) {
485: Insets insets = c.getBorder().getBorderInsets(c);
486: x += insets.left;
487: y += insets.top;
488: w -= insets.right + insets.left;
489: h -= insets.top + insets.bottom;
490: }
491: rect = new Rectangle(x + 1, y + 1, w - 1, h - 1);
492: if (state == STATE_SELECTED) {
493: g.setColor(UIDefaultsLookup
494: .getColor("DockableFrame.activeTitleBorderColor"));
495: if ("true".equals(SecurityUtils.getProperty("shadingtheme",
496: "false"))) {
497: g.drawRoundRect(x, y, w, h, 2, 2);
498: } else {
499: g.drawRect(x, y, w, h);
500: }
501: g.setColor(UIDefaultsLookup
502: .getColor("DockableFrame.activeTitleBackground"));
503: g.fillRect(rect.x, rect.y, rect.width, rect.height);
504: } else {
505: g
506: .setColor(UIDefaultsLookup
507: .getColor("DockableFrame.inactiveTitleBorderColor"));
508: g.drawRoundRect(x, y, w, h, 2, 2);
509: g.setColor(UIDefaultsLookup
510: .getColor("DockableFrame.inactiveTitleBackground"));
511: g.fillRect(rect.x, rect.y, rect.width, rect.height);
512: }
513: if ("true".equals(SecurityUtils.getProperty("shadingtheme",
514: "false"))) {
515: JideSwingUtilities.fillGradient(g, rect,
516: SwingConstants.HORIZONTAL);
517: }
518: }
519:
520: public void paintCollapsiblePaneTitlePaneBackground(JComponent c,
521: Graphics g, Rectangle rect, int orientation, int state) {
522: if (!(c.getBackground() instanceof UIResource)) {
523: g.setColor(c.getBackground());
524: } else {
525: g.setColor(UIDefaultsLookup
526: .getColor("CollapsiblePane.background"));
527: }
528: g.fillRect(rect.x, rect.y, rect.width, rect.height);
529: }
530:
531: public void paintCollapsiblePaneTitlePaneBackgroundEmphasized(
532: JComponent c, Graphics g, Rectangle rect, int orientation,
533: int state) {
534: g.setColor(UIDefaultsLookup
535: .getColor("CollapsiblePane.emphasizedBackground"));
536: g.fillRect(rect.x, rect.y, rect.width, rect.height);
537: }
538:
539: public void paintCollapsiblePanesBackground(JComponent c,
540: Graphics g, Rectangle rect, int orientation, int state) {
541: g.setColor(UIDefaultsLookup.getColor("TextField.background"));
542: g.fillRect(rect.x, rect.y, rect.width, rect.height);
543: }
544:
545: public void paintCollapsiblePaneTitlePaneBackgroundPlainEmphasized(
546: JComponent c, Graphics g, Rectangle rect, int orientation,
547: int state) {
548: g.setColor(UIDefaultsLookup
549: .getColor("CollapsiblePane.emphasizedBackground"));
550: g.drawLine(rect.x, rect.y + rect.height - 1, rect.x
551: + rect.width, rect.y + rect.height - 1);
552: }
553:
554: public void paintCollapsiblePaneTitlePaneBackgroundPlain(
555: JComponent c, Graphics g, Rectangle rect, int orientation,
556: int state) {
557: if (!(c.getBackground() instanceof UIResource)) {
558: g.setColor(c.getBackground());
559: } else {
560: g.setColor(UIDefaultsLookup
561: .getColor("CollapsiblePane.background"));
562: }
563: g.drawLine(rect.x, rect.y + rect.height - 1, rect.x
564: + rect.width, rect.y + rect.height - 1);
565: }
566:
567: public Color getColor(Object key) {
568: return UIDefaultsLookup.getColor(key);
569: }
570: }
|