001: /*
002: * @(#)JideButtonUI.java Nov 20, 2002
003: *
004: * Copyright 2002 JIDE Software Inc. All rights reserved.
005: */
006:
007: package com.jidesoft.plaf.basic;
008:
009: import com.jidesoft.icons.IconsFactory;
010: import com.jidesoft.plaf.JideButtonUI;
011: import com.jidesoft.plaf.UIDefaultsLookup;
012: import com.jidesoft.swing.ComponentStateSupport;
013: import com.jidesoft.swing.JideButton;
014: import com.jidesoft.swing.JideSwingUtilities;
015: import com.jidesoft.utils.SecurityUtils;
016:
017: import javax.swing.*;
018: import javax.swing.plaf.ComponentUI;
019: import javax.swing.plaf.UIResource;
020: import javax.swing.plaf.basic.BasicButtonListener;
021: import javax.swing.plaf.basic.BasicGraphicsUtils;
022: import javax.swing.plaf.basic.BasicHTML;
023: import javax.swing.text.View;
024: import java.awt.*;
025: import java.awt.geom.AffineTransform;
026:
027: /**
028: * JideButtonUI implementation
029: */
030: public class BasicJideButtonUI extends JideButtonUI {
031: // Visual constants
032: protected int defaultTextIconGap;
033:
034: // Offset controlled by set method
035: private int shiftOffset = 0;
036: protected int defaultTextShiftOffset;
037:
038: // Has the shared instance defaults been initialized?
039: private boolean defaults_initialized = false;
040:
041: private final static String propertyPrefix = "JideButton" + ".";
042:
043: protected ThemePainter _painter;
044:
045: protected Color _shadowColor;
046: protected Color _darkShadowColor;
047: protected Color _highlight;
048: protected Color _lightHighlightColor;
049:
050: protected Color _focusColor;
051:
052: protected boolean _isFloatingIcon = false;
053:
054: // ********************************
055: // Create PLAF
056: // ********************************
057: public static ComponentUI createUI(JComponent c) {
058: return new BasicJideButtonUI();
059: }
060:
061: protected String getPropertyPrefix() {
062: return propertyPrefix;
063: }
064:
065: // ********************************
066: // Install PLAF
067: // ********************************
068: @Override
069: public void installUI(JComponent c) {
070: installDefaults((AbstractButton) c);
071: installListeners((AbstractButton) c);
072: installKeyboardActions((AbstractButton) c);
073: BasicHTML.updateRenderer(c, ((AbstractButton) c).getText());
074: }
075:
076: protected void installDefaults(AbstractButton b) {
077: // load shared instance defaults
078: _painter = (ThemePainter) UIDefaultsLookup.get("Theme.painter");
079:
080: String pp = getPropertyPrefix();
081: if (!defaults_initialized) {
082: defaultTextIconGap = (Integer) UIDefaultsLookup.get(pp
083: + "textIconGap");
084: defaultTextShiftOffset = (Integer) UIDefaultsLookup.get(pp
085: + "textShiftOffset");
086:
087: _focusColor = UIDefaultsLookup.getColor("Button.focus"); // use Button.focus since we didn't install JideButton.focus.
088:
089: // next four lines part of optimized component defaults installation
090: /* defaultForeground = UIManagerLookup.getColor(pp + "foreground");
091: defaultBackground = UIManagerLookup.getColor(pp + "background");
092: defaultFont = UIManagerLookup.getFont(pp + "font");
093: defaultBorder = UIManagerLookup.getBorder(pp + "border");*/
094:
095: _shadowColor = UIDefaultsLookup.getColor("controlShadow");
096: _darkShadowColor = UIDefaultsLookup
097: .getColor("controlDkShadow");
098: _highlight = UIDefaultsLookup.getColor("controlHighlight");
099: _lightHighlightColor = UIDefaultsLookup
100: .getColor("controlLtHighlight");
101:
102: defaults_initialized = true;
103: }
104:
105: // // set the following defaults on the button
106: // if (b.isContentAreaFilled()) {
107: // b.setOpaque(true);
108: // }
109: // else {
110: // b.setOpaque(false);
111: // }
112:
113: if (b.getMargin() == null
114: || (b.getMargin() instanceof UIResource)) {
115: b.setMargin(UIDefaultsLookup.getInsets(pp + "margin"));
116: }
117:
118: // *** begin optimized defaults install ***
119:
120: /* Color currentForeground = b.getForeground();
121: Color currentBackground = b.getBackground();
122: Font currentFont = b.getFont();
123: Border currentBorder = b.getBorder();
124:
125: if (currentForeground == null || currentForeground instanceof UIResource) {
126: b.setForeground(defaultForeground);
127: }
128:
129: if (currentBackground == null || currentBackground instanceof UIResource) {
130: b.setBackground(defaultBackground);
131: }
132:
133: if (currentFont == null || currentFont instanceof UIResource) {
134: b.setFont(defaultFont);
135: }
136:
137: if (currentBorder == null || currentBorder instanceof UIResource) {
138: b.setBorder(defaultBorder);
139: } */
140:
141: // *** end optimized defaults install ***
142: // old code below works for component defaults installation, but it is slow
143: LookAndFeel.installColorsAndFont(b, pp + "background", pp
144: + "foreground", pp + "font");
145: LookAndFeel.installBorder(b, pp + "border");
146:
147: _isFloatingIcon = UIDefaultsLookup.getBoolean("Icon.floating");
148: }
149:
150: protected void installListeners(AbstractButton b) {
151: BasicButtonListener listener = createButtonListener(b);
152: if (listener != null) {
153: // put the listener in the button's client properties so that
154: // we can get at it later
155: b.putClientProperty(this , listener);
156:
157: b.addMouseListener(listener);
158: b.addMouseMotionListener(listener);
159: b.addFocusListener(listener);
160: b.addPropertyChangeListener(listener);
161: b.addChangeListener(listener);
162: }
163: }
164:
165: protected void installKeyboardActions(AbstractButton b) {
166: BasicButtonListener listener = (BasicButtonListener) b
167: .getClientProperty(this );
168: if (listener != null) {
169: listener.installKeyboardActions(b);
170: }
171: }
172:
173: // ********************************
174: // Uninstall PLAF
175: // ********************************
176: @Override
177: public void uninstallUI(JComponent c) {
178: uninstallKeyboardActions((AbstractButton) c);
179: uninstallListeners((AbstractButton) c);
180: uninstallDefaults((AbstractButton) c);
181: BasicHTML.updateRenderer(c, "");
182: }
183:
184: protected void uninstallKeyboardActions(AbstractButton b) {
185: BasicButtonListener listener = (BasicButtonListener) b
186: .getClientProperty(this );
187: if (listener != null) {
188: listener.uninstallKeyboardActions(b);
189: }
190: }
191:
192: protected void uninstallListeners(AbstractButton b) {
193: BasicButtonListener listener = (BasicButtonListener) b
194: .getClientProperty(this );
195: b.putClientProperty(this , null);
196: if (listener != null) {
197: b.removeMouseListener(listener);
198: b.removeMouseMotionListener(listener);
199: b.removeFocusListener(listener);
200: b.removeChangeListener(listener);
201: b.removePropertyChangeListener(listener);
202: }
203: }
204:
205: protected void uninstallDefaults(AbstractButton b) {
206: _painter = null;
207: _focusColor = null;
208:
209: _shadowColor = null;
210: _highlight = null;
211: _lightHighlightColor = null;
212: _darkShadowColor = null;
213: defaults_initialized = false;
214: }
215:
216: // ********************************
217: // Create Listeners
218: // ********************************
219:
220: protected BasicButtonListener createButtonListener(AbstractButton b) {
221: return new BasicJideButtonListener(b);
222: }
223:
224: public int getDefaultTextIconGap(AbstractButton b) {
225: return defaultTextIconGap;
226: }
227:
228: protected Color getFocusColor() {
229: return _focusColor;
230: }
231:
232: /* These rectangles/insets are allocated once for all
233: * ButtonUI.paint() calls. Re-using rectangles rather than
234: * allocating them in each paint call substantially reduced the time
235: * it took paint to run. Obviously, this method can't be re-entered.
236: */
237: protected static Rectangle viewRect = new Rectangle();
238: protected static Rectangle textRect = new Rectangle();
239: protected static Rectangle iconRect = new Rectangle();
240:
241: // ********************************
242: // Paint Methods
243: // ********************************
244:
245: @Override
246: public void paint(Graphics g, JComponent c) {
247: AbstractButton b = (AbstractButton) c;
248: boolean isHorizontal = true;
249:
250: if (JideSwingUtilities.getOrientationOf(c) == SwingConstants.VERTICAL) {
251: isHorizontal = false;
252: }
253:
254: FontMetrics fm = g.getFontMetrics();
255:
256: Insets i = c.getInsets();
257:
258: viewRect.x = i.left;
259: viewRect.y = i.top;
260: viewRect.width = b.getWidth() - (i.right + viewRect.x);
261: viewRect.height = b.getHeight() - (i.bottom + viewRect.y);
262:
263: textRect.x = textRect.y = textRect.width = textRect.height = 0;
264: iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
265:
266: paintBackground(g, b, viewRect, textRect, iconRect);
267:
268: Font f = c.getFont();
269: g.setFont(f);
270:
271: // layout the text and icon
272: String text = JideSwingUtilities.layoutCompoundLabel(c, fm, b
273: .getText(), b.getIcon(), isHorizontal, b
274: .getVerticalAlignment(), b.getHorizontalAlignment(), b
275: .getVerticalTextPosition(), b
276: .getHorizontalTextPosition(), viewRect, iconRect,
277: textRect,
278: // JDK PORTING HINT
279: // JDK1.3: getIconTextGap, use defaultTextIconGap
280: b.getText() == null ? 0 : b.getIconTextGap()); // use the bigger one of both gaps. Not really the best way.
281:
282: clearTextShiftOffset();
283:
284: paintIcon(b, g);
285:
286: if (text != null && !text.equals("")) {
287: View v = (View) c.getClientProperty(BasicHTML.propertyKey);
288: if (v != null) {
289: v.paint(g, textRect);
290: } else {
291: paintText(g, b, textRect, text);
292: }
293: }
294: }
295:
296: protected void paintIcon(AbstractButton b, Graphics g) {
297: // Paint the Icon
298: if (b.getIcon() != null) {
299: Icon icon = getIcon(b);
300:
301: ButtonModel model = b.getModel();
302: if (icon != null) {
303: if (isFloatingIcon() && model.isEnabled()) {
304: if (model.isRollover() && !model.isPressed()
305: && !model.isSelected()) {
306: if (!"true".equals(SecurityUtils.getProperty(
307: "shadingtheme", "false"))
308: && b instanceof JideButton
309: && ((JideButton) b).getButtonStyle() == JideButton.TOOLBAR_STYLE) {
310: if (icon instanceof ImageIcon) {
311: ImageIcon shadow = IconsFactory
312: .createGrayImage(((ImageIcon) icon)
313: .getImage());
314: shadow.paintIcon(b, g, iconRect.x + 1,
315: iconRect.y + 1);
316: } else {
317: ImageIcon shadow = IconsFactory
318: .createGrayImage(b, icon);
319: shadow.paintIcon(b, g, iconRect.x + 1,
320: iconRect.y + 1);
321: }
322: icon.paintIcon(b, g, iconRect.x - 1,
323: iconRect.y - 1);
324: } else {
325: icon
326: .paintIcon(b, g, iconRect.x,
327: iconRect.y);
328: }
329: } else {
330: icon.paintIcon(b, g, iconRect.x, iconRect.y);
331: }
332: } else {
333: icon.paintIcon(b, g, iconRect.x, iconRect.y);
334: }
335: }
336: }
337: }
338:
339: protected Icon getIcon(AbstractButton b) {
340: ButtonModel model = b.getModel();
341: Icon icon = b.getIcon();
342: Icon tmpIcon = null;
343: if (!model.isEnabled()) {
344: if (model.isSelected()) {
345: tmpIcon = (Icon) b.getDisabledSelectedIcon();
346: } else {
347: tmpIcon = (Icon) b.getDisabledIcon();
348: }
349:
350: // create default diabled icon
351: if (tmpIcon == null) {
352: if (icon instanceof ImageIcon) {
353: icon = IconsFactory
354: .createGrayImage(((ImageIcon) icon)
355: .getImage());
356: } else {
357: icon = IconsFactory.createGrayImage(b, icon);
358: }
359: }
360: } else if (model.isPressed() && model.isArmed()) {
361: tmpIcon = (Icon) b.getPressedIcon();
362: if (tmpIcon != null) {
363: // revert back to 0 offset
364: clearTextShiftOffset();
365: }
366: } else if (b.isRolloverEnabled() && model.isRollover()) {
367: if (model.isSelected()) {
368: tmpIcon = (Icon) b.getRolloverSelectedIcon();
369: } else {
370: tmpIcon = (Icon) b.getRolloverIcon();
371: }
372: } else if (model.isSelected()) {
373: tmpIcon = (Icon) b.getSelectedIcon();
374: }
375:
376: if (tmpIcon != null) {
377: icon = tmpIcon;
378: }
379: return icon;
380: }
381:
382: protected boolean isFloatingIcon() {
383: return _isFloatingIcon;
384: }
385:
386: /**
387: * As of Java 2 platform v 1.4 this method should not be used or overriden.
388: * Use the paintText method which takes the AbstractButton argument.
389: */
390: protected void paintText(Graphics g, JComponent c,
391: Rectangle textRect, String text) {
392: AbstractButton b = (AbstractButton) c;
393: boolean isHorizontal = true;
394: if (JideSwingUtilities.getOrientationOf(c) == SwingConstants.VERTICAL) {
395: isHorizontal = false;
396: }
397:
398: ButtonModel model = b.getModel();
399: FontMetrics fm = g.getFontMetrics();
400: // JDK PORTING HINT
401: // JDK1.3: No getDisplayedMnemonicIndex, use getMnemonic
402: int mnemonicIndex = b.getDisplayedMnemonicIndex();
403:
404: if (!isHorizontal) {
405: Graphics2D g2d = (Graphics2D) g;
406: AffineTransform oldAt = g2d.getTransform();
407: g2d.rotate(Math.PI / 2);
408: g2d.translate(0, -c.getWidth() + 1);
409:
410: /* Draw the Text */
411: if (model.isEnabled()) {
412: /*** paint the text normally */
413: int state = JideSwingUtilities.getButtonState(b);
414: Color foreground = null;
415: if (b instanceof ComponentStateSupport) {
416: foreground = ((ComponentStateSupport) b)
417: .getForegroundOfState(state);
418: }
419: if (foreground == null
420: || foreground instanceof UIResource) {
421: foreground = b.getForeground();
422: }
423: g2d.setColor(foreground);
424:
425: // JDK PORTING HINT
426: // JDK1.3: No drawStringUnderlineCharAt, draw the string then draw the underline
427: JideSwingUtilities
428: .drawStringUnderlineCharAt(b, g2d, text,
429: mnemonicIndex, textRect.y
430: + getTextShiftOffset(),
431: textRect.x + fm.getAscent()
432: + getTextShiftOffset());
433: } else {
434: /*** paint the text disabled ***/
435: /*** paint the text disabled ***/
436: Color color = UIDefaultsLookup
437: .getColor("Button.disabledForeground");
438: g.setColor(color == null ? b.getBackground().darker()
439: : color);
440:
441: // JDK PORTING HINT
442: // JDK1.3: No drawStringUnderlineCharAt, draw the string then draw the underline
443: JideSwingUtilities.drawStringUnderlineCharAt(b, g2d,
444: text, mnemonicIndex, textRect.y, textRect.x
445: + fm.getAscent());
446: }
447:
448: g2d.setTransform(oldAt);
449: } else {
450: /* Draw the Text */
451: if (model.isEnabled()) {
452: /*** paint the text normally */
453: int state = JideSwingUtilities.getButtonState(b);
454: Color foreground = null;
455: if (b instanceof ComponentStateSupport) {
456: foreground = ((ComponentStateSupport) b)
457: .getForegroundOfState(state);
458: }
459: if (foreground == null
460: || foreground instanceof UIResource) {
461: foreground = b.getForeground();
462: }
463: g.setColor(foreground);
464:
465: // JDK PORTING HINT
466: // JDK1.3: No drawStringUnderlineCharAt, draw the string then draw the underline
467: JideSwingUtilities
468: .drawStringUnderlineCharAt(b, g, text,
469: mnemonicIndex, textRect.x
470: + getTextShiftOffset(),
471: textRect.y + fm.getAscent()
472: + getTextShiftOffset());
473: if (b instanceof JideButton
474: && ((JideButton) b).getButtonStyle() == JideButton.HYPERLINK_STYLE
475: && (((JideButton) b).isAlwaysShowHyperlink() || b
476: .getModel().isRollover())) {
477: g.drawLine(textRect.x, textRect.y + textRect.height
478: - 2, textRect.x + textRect.width,
479: textRect.y + textRect.height - 2);
480: }
481: } else {
482: /*** paint the text disabled ***/
483: Color color = UIDefaultsLookup
484: .getColor("Button.disabledForeground");
485: g.setColor(color == null ? b.getBackground().darker()
486: : color);
487:
488: // JDK PORTING HINT
489: // JDK1.3: No drawStringUnderlineCharAt, draw the string then draw the underline
490: JideSwingUtilities.drawStringUnderlineCharAt(b, g,
491: text, mnemonicIndex, textRect.x, textRect.y
492: + fm.getAscent());
493: }
494: }
495: }
496:
497: /**
498: * Method which renders the text of the current button.
499: * <p/>
500: *
501: * @param g Graphics context
502: * @param b Current button to render
503: * @param textRect Bounding rectangle to render the text.
504: * @param text String to render
505: * @since 1.4
506: */
507: protected void paintText(Graphics g, AbstractButton b,
508: Rectangle textRect, String text) {
509: paintText(g, (JComponent) b, textRect, text);
510: }
511:
512: // Method signature defined here overriden in subclasses.
513: // Perhaps this class should be abstract?
514: protected void paintBackground(Graphics g, AbstractButton b,
515: Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
516: boolean paintDefaultBorder = true;
517: boolean paintBackground;
518: Object o = b.getClientProperty("JideButton.paintDefaultBorder");
519: if (o instanceof Boolean) {
520: paintDefaultBorder = (Boolean) o;
521: }
522: o = b.getClientProperty("JideButton.alwaysPaintBackground");
523: if (o instanceof Boolean) {
524: paintBackground = (Boolean) o;
525: } else {
526: paintBackground = b.isOpaque();
527: }
528: Rectangle rect = new Rectangle(0, 0, b.getWidth(), b
529: .getHeight());
530: if (paintBackground) {
531: g.setColor(b.getBackground());
532: g.fillRect(rect.x, rect.y, rect.width, rect.height);
533: }
534:
535: if (b.isContentAreaFilled()) {
536: if (b instanceof JideButton
537: && ((JideButton) b).getButtonStyle() == JideButton.TOOLBAR_STYLE) {
538: // System.out.println(model.isSelected() + " " + model.isRollover() + " " + model.isArmed() + " " + model.isPressed());
539: int state = JideSwingUtilities.getButtonState(b);
540: if (state != ThemePainter.STATE_DEFAULT) {
541: getPainter().paintButtonBackground(b, g, rect, 0,
542: state);
543: } else {
544: if (paintBackground) {
545: getPainter().paintButtonBackground(b, g, rect,
546: 0, state);
547: if ("true".equals(SecurityUtils.getProperty(
548: "shadingtheme", "false"))) {
549: JideSwingUtilities.fillGradient(g, rect,
550: SwingConstants.HORIZONTAL);
551: }
552: }
553: }
554: } else if (b instanceof JideButton
555: && ((JideButton) b).getButtonStyle() == JideButton.FLAT_STYLE) {
556: if (b.getModel().isSelected()
557: && b.getModel().isPressed()) {
558: g.setColor(_shadowColor); // inner 3D border
559: g.drawLine(0, 0, b.getWidth() - 1, 0);
560: g.drawLine(0, 0, 0, b.getHeight() - 1);
561:
562: g.setColor(_lightHighlightColor); // black drop shadow __|
563: g.drawLine(0, b.getHeight() - 1, b.getWidth() - 1,
564: b.getHeight() - 1);
565: g.drawLine(b.getWidth() - 1, 0, b.getWidth() - 1, b
566: .getHeight() - 1);
567: } else if (b.getModel().isSelected()) {
568: JideSwingUtilities.paintBackground(g, rect,
569: _highlight, _highlight);
570: g.setColor(_shadowColor); // inner 3D border
571: g.drawLine(0, 0, b.getWidth() - 1, 0);
572: g.drawLine(0, 0, 0, b.getHeight() - 1);
573:
574: g.setColor(_lightHighlightColor); // black drop shadow __|
575: g.drawLine(0, b.getHeight() - 1, b.getWidth() - 1,
576: b.getHeight() - 1);
577: g.drawLine(b.getWidth() - 1, 0, b.getWidth() - 1, b
578: .getHeight() - 1);
579: } else if (b.getModel().isPressed()) {
580: JideSwingUtilities.paintBackground(g, rect,
581: _highlight, _highlight);
582: g.setColor(_shadowColor); // inner 3D border
583: g.drawLine(0, 0, b.getWidth() - 1, 0);
584: g.drawLine(0, 0, 0, b.getHeight() - 1);
585:
586: g.setColor(_lightHighlightColor); // black drop shadow __|
587: g.drawLine(0, b.getHeight() - 1, b.getWidth() - 1,
588: b.getHeight() - 1);
589: g.drawLine(b.getWidth() - 1, 0, b.getWidth() - 1, b
590: .getHeight() - 1);
591: } else if (b.getModel().isRollover()
592: || (b.hasFocus() && b.isFocusPainted())) {
593: JideSwingUtilities.paintBackground(g, rect,
594: _highlight, _highlight);
595: g.setColor(_lightHighlightColor); // inner 3D border
596: g.drawLine(0, 0, b.getWidth() - 1, 0);
597: g.drawLine(0, 0, 0, b.getHeight() - 1);
598:
599: g.setColor(_shadowColor); // black drop shadow __|
600: g.drawLine(0, b.getHeight() - 1, b.getWidth() - 1,
601: b.getHeight() - 1);
602: g.drawLine(b.getWidth() - 1, 0, b.getWidth() - 1, b
603: .getHeight() - 1);
604: } else {
605: if (paintBackground) {
606: getPainter().paintButtonBackground(b, g, rect,
607: 0, ThemePainter.STATE_DEFAULT);
608: }
609: }
610: } else if (b instanceof JideButton
611: && ((JideButton) b).getButtonStyle() == JideButton.TOOLBOX_STYLE) {
612: if (b.getModel().isPressed()) {
613: getPainter().paintButtonBackground(b, g, rect, 0,
614: ThemePainter.STATE_PRESSED);
615: if (paintDefaultBorder) {
616: g.setColor(_darkShadowColor); // inner 3D border
617: g.drawLine(0, 0, b.getWidth() - 2, 0);
618: g.drawLine(0, 0, 0, b.getHeight() - 2);
619:
620: g.setColor(_shadowColor); // inner 3D border
621: g.drawLine(1, 1, b.getWidth() - 3, 1);
622: g.drawLine(1, 1, 1, b.getHeight() - 3);
623:
624: g.setColor(_lightHighlightColor); // black drop shadow __|
625: g.drawLine(0, b.getHeight() - 1,
626: b.getWidth() - 1, b.getHeight() - 1);
627: g.drawLine(b.getWidth() - 1, 0,
628: b.getWidth() - 1, b.getHeight() - 1);
629: }
630: } else if (b.getModel().isSelected()
631: && b.getModel().isRollover()) {
632: getPainter().paintButtonBackground(b, g, rect, 0,
633: ThemePainter.STATE_PRESSED);
634: if (paintDefaultBorder) {
635: g.setColor(_darkShadowColor); // inner 3D border
636: g.drawLine(0, 0, b.getWidth() - 2, 0);
637: g.drawLine(0, 0, 0, b.getHeight() - 2);
638:
639: g.setColor(_shadowColor); // inner 3D border
640: g.drawLine(1, 1, b.getWidth() - 3, 1);
641: g.drawLine(1, 1, 1, b.getHeight() - 3);
642:
643: g.setColor(_lightHighlightColor); // black drop shadow __|
644: g.drawLine(0, b.getHeight() - 1,
645: b.getWidth() - 1, b.getHeight() - 1);
646: g.drawLine(b.getWidth() - 1, 0,
647: b.getWidth() - 1, b.getHeight() - 1);
648: }
649: } else if (b.getModel().isSelected()) {
650: getPainter().paintButtonBackground(b, g, rect, 0,
651: ThemePainter.STATE_SELECTED);
652: if (paintDefaultBorder) {
653: g.setColor(_darkShadowColor); // inner 3D border
654: g.drawLine(0, 0, b.getWidth() - 2, 0);
655: g.drawLine(0, 0, 0, b.getHeight() - 2);
656:
657: g.setColor(_shadowColor); // inner 3D border
658: g.drawLine(1, 1, b.getWidth() - 3, 1);
659: g.drawLine(1, 1, 1, b.getHeight() - 3);
660:
661: g.setColor(_lightHighlightColor); // black drop shadow __|
662: g.drawLine(0, b.getHeight() - 1,
663: b.getWidth() - 1, b.getHeight() - 1);
664: g.drawLine(b.getWidth() - 1, 0,
665: b.getWidth() - 1, b.getHeight() - 1);
666: }
667: } else if (b.getModel().isRollover()
668: || (b.hasFocus() && b.isFocusPainted())) {
669: getPainter().paintButtonBackground(b, g, rect, 0,
670: ThemePainter.STATE_ROLLOVER);
671: if (paintDefaultBorder) {
672: g.setColor(_lightHighlightColor); // inner 3D border
673: g.drawLine(0, 0, b.getWidth() - 1, 0);
674: g.drawLine(0, 0, 0, b.getHeight() - 1);
675:
676: g.setColor(_shadowColor); // gray drop shadow __|
677: g.drawLine(1, b.getHeight() - 2,
678: b.getWidth() - 2, b.getHeight() - 2);
679: g.drawLine(b.getWidth() - 2, 1,
680: b.getWidth() - 2, b.getHeight() - 2);
681:
682: g.setColor(_darkShadowColor); // black drop shadow __|
683: g.drawLine(0, b.getHeight() - 1,
684: b.getWidth() - 1, b.getHeight() - 1);
685: g.drawLine(b.getWidth() - 1, 0,
686: b.getWidth() - 1, b.getHeight() - 1);
687: }
688: } else {
689: if (paintBackground) {
690: getPainter().paintButtonBackground(b, g, rect,
691: 0, ThemePainter.STATE_DEFAULT);
692: } else {
693: g.setColor(_lightHighlightColor); // inner 3D border
694: g.drawLine(0, 0, b.getWidth() - 1, 0);
695: g.drawLine(0, 0, 0, b.getHeight() - 1);
696:
697: g.setColor(_shadowColor); // black drop shadow __|
698: g.drawLine(0, b.getHeight() - 1,
699: b.getWidth() - 1, b.getHeight() - 1);
700: g.drawLine(b.getWidth() - 1, 0,
701: b.getWidth() - 1, b.getHeight() - 1);
702: }
703: }
704:
705: if (paintBackground) {
706: g.setColor(_lightHighlightColor); // inner 3D border
707: g.drawLine(0, 0, b.getWidth() - 1, 0);
708: g.drawLine(0, 0, 0, b.getHeight() - 1);
709:
710: g.setColor(_shadowColor); // black drop shadow __|
711: g.drawLine(0, b.getHeight() - 1, b.getWidth() - 1,
712: b.getHeight() - 1);
713: g.drawLine(b.getWidth() - 1, 0, b.getWidth() - 1, b
714: .getHeight() - 1);
715: }
716: }
717: }
718: }
719:
720: protected void clearTextShiftOffset() {
721: this .shiftOffset = 0;
722: }
723:
724: protected void setTextShiftOffset() {
725: this .shiftOffset = defaultTextShiftOffset;
726: }
727:
728: protected int getTextShiftOffset() {
729: return shiftOffset;
730: }
731:
732: // ********************************
733: // Layout Methods
734: // ********************************
735: @Override
736: public Dimension getMinimumSize(JComponent c) {
737: Dimension d = getPreferredSize(c);
738: View v = (View) c.getClientProperty(BasicHTML.propertyKey);
739: if (v != null) {
740: if (JideSwingUtilities.getOrientationOf(c) == SwingConstants.HORIZONTAL)
741: d.width -= v.getPreferredSpan(View.X_AXIS)
742: - v.getMinimumSpan(View.X_AXIS);
743: else
744: // TODO: not sure if this is correct
745: d.height -= v.getPreferredSpan(View.X_AXIS)
746: - v.getMinimumSpan(View.X_AXIS);
747: }
748: return d;
749: }
750:
751: @Override
752: public Dimension getPreferredSize(JComponent c) {
753: AbstractButton b = (AbstractButton) c;
754:
755: Dimension d = BasicGraphicsUtils.getPreferredButtonSize(b, b
756: .getIconTextGap());
757: if (JideSwingUtilities.getOrientationOf(c) == SwingConstants.HORIZONTAL) {
758: return d;
759: } else {
760: return new Dimension(d.height, d.width); // swap width and height
761: }
762: }
763:
764: @Override
765: public Dimension getMaximumSize(JComponent c) {
766: Dimension d = getPreferredSize(c);
767: View v = (View) c.getClientProperty(BasicHTML.propertyKey);
768: if (v != null) {
769: d.width += v.getMaximumSpan(View.X_AXIS)
770: - v.getPreferredSpan(View.X_AXIS);
771: }
772: return d;
773: }
774:
775: public ThemePainter getPainter() {
776: return _painter;
777: }
778: }
|