001: /*
002: * Copyright (c) 2001-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.looks.plastic;
032:
033: import java.awt.Component;
034: import java.awt.Graphics;
035: import java.awt.Insets;
036:
037: import javax.swing.*;
038: import javax.swing.border.AbstractBorder;
039: import javax.swing.border.Border;
040: import javax.swing.border.CompoundBorder;
041: import javax.swing.border.EmptyBorder;
042: import javax.swing.plaf.BorderUIResource;
043: import javax.swing.plaf.UIResource;
044: import javax.swing.plaf.basic.BasicBorders;
045: import javax.swing.plaf.metal.MetalBorders;
046: import javax.swing.text.JTextComponent;
047:
048: /**
049: * This class consists of a set of <code>Border</code>s used
050: * by the JGoodies Plastic Look and Feel UI delegates.
051: *
052: * @author Karsten Lentzsch
053: * @version $Revision: 1.9 $
054: */
055:
056: final class PlasticBorders {
057:
058: private PlasticBorders() {
059: // Overrides default constructor; prevents instantiation.
060: }
061:
062: // Accessing and Creating Borders ***************************************
063:
064: private static Border comboBoxEditorBorder;
065: private static Border comboBoxArrowButtonBorder;
066: private static Border etchedBorder;
067: private static Border flush3DBorder;
068: private static Border menuBarHeaderBorder;
069: private static Border menuBorder;
070: private static Border menuItemBorder;
071: private static Border popupMenuBorder;
072: private static Border noMarginPopupMenuBorder;
073: private static Border rolloverButtonBorder;
074: private static Border scrollPaneBorder;
075: private static Border separatorBorder;
076: private static Border textFieldBorder;
077: private static Border thinLoweredBorder;
078: private static Border thinRaisedBorder;
079: private static Border toolBarHeaderBorder;
080:
081: /**
082: * Returns a border instance for a <code>JButton</code>.
083: *
084: * @return the lazily created button border
085: */
086: static Border getButtonBorder(Insets buttonMargin) {
087: return new BorderUIResource.CompoundBorderUIResource(
088: new ButtonBorder(buttonMargin),
089: new BasicBorders.MarginBorder());
090: }
091:
092: /**
093: * Returns a border for a <code>JComboBox</code>'s button.
094: *
095: * @return the lazily created combo box arrow button border
096: */
097: static Border getComboBoxArrowButtonBorder() {
098: if (comboBoxArrowButtonBorder == null) {
099: comboBoxArrowButtonBorder = new CompoundBorder(
100: // No UIResource
101: new ComboBoxArrowButtonBorder(),
102: new BasicBorders.MarginBorder());
103: }
104: return comboBoxArrowButtonBorder;
105: }
106:
107: /**
108: * Returns a border for a <code>JComboBox</code>'s editor.
109: *
110: * @return the lazily created combo box editor border
111: */
112: static Border getComboBoxEditorBorder() {
113: if (comboBoxEditorBorder == null) {
114: comboBoxEditorBorder = new CompoundBorder(
115: // No UIResource
116: new ComboBoxEditorBorder(),
117: new BasicBorders.MarginBorder());
118: }
119: return comboBoxEditorBorder;
120: }
121:
122: /**
123: * Returns an etched border instance for <code>JMenuBar</code> or
124: * <code>JToolBar</code>.
125: *
126: * @return the lazily created etched border
127: */
128: static Border getEtchedBorder() {
129: if (etchedBorder == null) {
130: etchedBorder = new BorderUIResource.CompoundBorderUIResource(
131: new EtchedBorder(), new BasicBorders.MarginBorder());
132: }
133: return etchedBorder;
134: }
135:
136: /**
137: * Returns a flushed 3D border.
138: *
139: * @return the lazily created flushed 3D border
140: */
141: static Border getFlush3DBorder() {
142: if (flush3DBorder == null) {
143: flush3DBorder = new Flush3DBorder();
144: }
145: return flush3DBorder;
146: }
147:
148: /**
149: * Returns a border for a <code>JInternalFrame</code>.
150: *
151: * @return an internal frame border
152: */
153: static Border getInternalFrameBorder() {
154: return new InternalFrameBorder();
155: }
156:
157: /**
158: * Returns a special border for a <code>JMenuBar</code> that
159: * is used in a header just above a <code>JToolBar</code>.
160: *
161: * @return the lazily created menu bar header border
162: */
163: static Border getMenuBarHeaderBorder() {
164: if (menuBarHeaderBorder == null) {
165: menuBarHeaderBorder = new BorderUIResource.CompoundBorderUIResource(
166: new MenuBarHeaderBorder(),
167: new BasicBorders.MarginBorder());
168: }
169: return menuBarHeaderBorder;
170: }
171:
172: /**
173: * Returns a border instance for a <code>JMenu</code>.
174: *
175: * @return the lazily created menu border
176: */
177: static Border getMenuBorder() {
178: if (menuBorder == null) {
179: menuBorder = new BorderUIResource.CompoundBorderUIResource(
180: new MenuBorder(), new BasicBorders.MarginBorder());
181: }
182: return menuBorder;
183: }
184:
185: /**
186: * Returns a border instance for a <code>JMenuItem</code>.
187: *
188: * @return the lazily created menu item border
189: */
190: static Border getMenuItemBorder() {
191: if (menuItemBorder == null) {
192: menuItemBorder = new BorderUIResource(
193: new BasicBorders.MarginBorder());
194: }
195: return menuItemBorder;
196: }
197:
198: /**
199: * Returns a border instance for a <code>JPopupMenu</code>.
200: *
201: * @return the lazily created popup menu border
202: */
203: static Border getPopupMenuBorder() {
204: if (popupMenuBorder == null) {
205: popupMenuBorder = new PopupMenuBorder();
206: }
207: return popupMenuBorder;
208: }
209:
210: /**
211: * Returns a border instance for a <code>JPopupMenu</code> that
212: * has no (extra) margin.
213: *
214: * @return the lazily created no-margin popup menu border
215: */
216: static Border getNoMarginPopupMenuBorder() {
217: if (noMarginPopupMenuBorder == null) {
218: noMarginPopupMenuBorder = new NoMarginPopupMenuBorder();
219: }
220: return noMarginPopupMenuBorder;
221: }
222:
223: /**
224: * Returns a border for a <code>JInternalFrame</code>'s palette.
225: *
226: * @return a border for an internal frame in palette mode
227: */
228: static Border getPaletteBorder() {
229: return new PaletteBorder();
230: }
231:
232: /**
233: * Returns a rollover border for buttons in a <code>JToolBar</code>.
234: *
235: * @return the lazily created rollover button border
236: */
237: static Border getRolloverButtonBorder() {
238: if (rolloverButtonBorder == null) {
239: rolloverButtonBorder = new CompoundBorder(
240: // No UIResource
241: new RolloverButtonBorder(),
242: new RolloverMarginBorder());
243: }
244: return rolloverButtonBorder;
245: }
246:
247: /**
248: * Returns a separator border instance for <code>JScrollPane</code>.
249: *
250: * @return the lazily created scroll pane border
251: */
252: static Border getScrollPaneBorder() {
253: if (scrollPaneBorder == null) {
254: scrollPaneBorder = new ScrollPaneBorder();
255: }
256: return scrollPaneBorder;
257: }
258:
259: /**
260: * Returns a separator border instance for <code>JMenuBar</code> or
261: * <code>JToolBar</code>.
262: *
263: * @return the lazily created separator border
264: */
265: static Border getSeparatorBorder() {
266: if (separatorBorder == null) {
267: separatorBorder = new BorderUIResource.CompoundBorderUIResource(
268: new SeparatorBorder(),
269: new BasicBorders.MarginBorder());
270: }
271: return separatorBorder;
272: }
273:
274: /**
275: * Returns a border instance for a JTextField.
276: *
277: * @return the lazily created text field border
278: */
279: static Border getTextFieldBorder() {
280: if (textFieldBorder == null) {
281: textFieldBorder = new BorderUIResource.CompoundBorderUIResource(
282: new TextFieldBorder(),
283: new BasicBorders.MarginBorder());
284: }
285: return textFieldBorder;
286: }
287:
288: /**
289: * Returns a thin lowered border.
290: *
291: * @return the lazily created thin lowered border
292: */
293: static Border getThinLoweredBorder() {
294: if (thinLoweredBorder == null) {
295: thinLoweredBorder = new ThinLoweredBorder();
296: }
297: return thinLoweredBorder;
298: }
299:
300: /**
301: * Returns a thin raised border.
302: *
303: * @return the lazily created thin raised border
304: */
305: static Border getThinRaisedBorder() {
306: if (thinRaisedBorder == null) {
307: thinRaisedBorder = new ThinRaisedBorder();
308: }
309: return thinRaisedBorder;
310: }
311:
312: /**
313: * Returns a border instance for a JToggleButton.
314: *
315: * @return the lazily created toggle button border
316: */
317: static Border getToggleButtonBorder(Insets buttonMargin) {
318: return new BorderUIResource.CompoundBorderUIResource(
319: new ToggleButtonBorder(buttonMargin),
320: new BasicBorders.MarginBorder());
321: }
322:
323: /**
324: * Returns a special border for a <code>JToolBar</code> that
325: * is used in a header just below a <code>JMenuBar</code>.
326: *
327: * @return the lazily created toolbar header border
328: */
329: static Border getToolBarHeaderBorder() {
330: if (toolBarHeaderBorder == null) {
331: toolBarHeaderBorder = new BorderUIResource.CompoundBorderUIResource(
332: new ToolBarHeaderBorder(),
333: new BasicBorders.MarginBorder());
334: }
335: return toolBarHeaderBorder;
336: }
337:
338: private static class Flush3DBorder extends AbstractBorder implements
339: UIResource {
340:
341: private static final Insets INSETS = new Insets(2, 2, 2, 2);
342:
343: public void paintBorder(Component c, Graphics g, int x, int y,
344: int w, int h) {
345: if (c.isEnabled())
346: PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
347: else
348: PlasticUtils.drawDisabledBorder(g, x, y, w, h);
349: }
350:
351: public Insets getBorderInsets(Component c) {
352: return INSETS;
353: }
354:
355: public Insets getBorderInsets(Component c, Insets newInsets) {
356: newInsets.top = INSETS.top;
357: newInsets.left = INSETS.left;
358: newInsets.bottom = INSETS.bottom;
359: newInsets.right = INSETS.right;
360: return newInsets;
361: }
362: }
363:
364: private static class ButtonBorder extends AbstractBorder implements
365: UIResource {
366:
367: protected final Insets insets;
368:
369: protected ButtonBorder(Insets insets) {
370: this .insets = insets;
371: }
372:
373: public void paintBorder(Component c, Graphics g, int x, int y,
374: int w, int h) {
375: AbstractButton button = (AbstractButton) c;
376: ButtonModel model = button.getModel();
377:
378: if (model.isEnabled()) {
379: boolean isPressed = model.isPressed()
380: && model.isArmed();
381: boolean isDefault = button instanceof JButton
382: && ((JButton) button).isDefaultButton();
383:
384: if (isPressed && isDefault)
385: PlasticUtils.drawDefaultButtonPressedBorder(g, x,
386: y, w, h);
387: else if (isPressed)
388: PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
389: else if (isDefault)
390: PlasticUtils.drawDefaultButtonBorder(g, x, y, w, h,
391: false);
392: else
393: PlasticUtils.drawButtonBorder(g, x, y, w, h, false);
394: } else { // disabled state
395: PlasticUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
396: }
397: }
398:
399: public Insets getBorderInsets(Component c) {
400: return insets;
401: }
402:
403: public Insets getBorderInsets(Component c, Insets newInsets) {
404: newInsets.top = insets.top;
405: newInsets.left = insets.left;
406: newInsets.bottom = insets.bottom;
407: newInsets.right = insets.right;
408: return newInsets;
409: }
410: }
411:
412: private static final class ComboBoxArrowButtonBorder extends
413: AbstractBorder implements UIResource {
414:
415: protected static final Insets INSETS = new Insets(1, 1, 1, 1);
416:
417: public void paintBorder(Component c, Graphics g, int x, int y,
418: int w, int h) {
419: AbstractButton button = (AbstractButton) c;
420: ButtonModel model = button.getModel();
421:
422: if (model.isEnabled()) {
423: boolean isPressed = model.isPressed()
424: && model.isArmed();
425:
426: if (isPressed)
427: PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
428: else
429: PlasticUtils.drawButtonBorder(g, x, y, w, h, false);
430: } else {
431: PlasticUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
432: }
433: }
434:
435: public Insets getBorderInsets(Component c) {
436: return INSETS;
437: }
438: }
439:
440: private static final class ComboBoxEditorBorder extends
441: AbstractBorder {
442:
443: private static final Insets INSETS = new Insets(2, 2, 2, 0);
444:
445: public void paintBorder(Component c, Graphics g, int x, int y,
446: int w, int h) {
447: if (c.isEnabled())
448: PlasticUtils.drawFlush3DBorder(g, x, y, w + 2, h);
449: else {
450: PlasticUtils.drawDisabledBorder(g, x, y, w + 2, h - 1);
451: g.setColor(UIManager.getColor("control"));
452: g.drawLine(x, y + h - 1, x + w, y + h - 1);
453: }
454: }
455:
456: public Insets getBorderInsets(Component c) {
457: return INSETS;
458: }
459: }
460:
461: /**
462: * A border used for <code>JInternalFrame</code>s.
463: */
464: private static final class InternalFrameBorder extends
465: AbstractBorder implements UIResource {
466:
467: private static final Insets NORMAL_INSETS = new Insets(1, 1, 1,
468: 1);
469: private static final Insets MAXIMIZED_INSETS = new Insets(1, 1,
470: 0, 0);
471:
472: public void paintBorder(Component c, Graphics g, int x, int y,
473: int w, int h) {
474: JInternalFrame frame = (JInternalFrame) c;
475: if (frame.isMaximum())
476: paintMaximizedBorder(g, x, y, w, h);
477: else
478: PlasticUtils.drawThinFlush3DBorder(g, x, y, w, h);
479: }
480:
481: private void paintMaximizedBorder(Graphics g, int x, int y,
482: int w, int h) {
483: g.translate(x, y);
484: g.setColor(PlasticLookAndFeel.getControlHighlight());
485: g.drawLine(0, 0, w - 2, 0);
486: g.drawLine(0, 0, 0, h - 2);
487: g.translate(-x, -y);
488: }
489:
490: public Insets getBorderInsets(Component c) {
491: return ((JInternalFrame) c).isMaximum() ? MAXIMIZED_INSETS
492: : NORMAL_INSETS;
493: }
494: }
495:
496: /**
497: * A border used for the palette of <code>JInternalFrame</code>s.
498: */
499: private static final class PaletteBorder extends AbstractBorder
500: implements UIResource {
501:
502: private static final Insets INSETS = new Insets(1, 1, 1, 1);
503:
504: public void paintBorder(Component c, Graphics g, int x, int y,
505: int w, int h) {
506: g.translate(x, y);
507: g.setColor(PlasticLookAndFeel.getControlDarkShadow());
508: g.drawRect(0, 0, w - 1, h - 1);
509: g.translate(-x, -y);
510: }
511:
512: public Insets getBorderInsets(Component c) {
513: return INSETS;
514: }
515: }
516:
517: /**
518: * A border that looks like a separator line; used for menu bars
519: * and tool bars.
520: */
521: private static final class SeparatorBorder extends AbstractBorder
522: implements UIResource {
523:
524: private static final Insets INSETS = new Insets(0, 0, 2, 1);
525:
526: public void paintBorder(Component c, Graphics g, int x, int y,
527: int w, int h) {
528: g.translate(x, y);
529: g.setColor(UIManager.getColor("Separator.foreground"));
530: g.drawLine(0, h - 2, w - 1, h - 2);
531:
532: g.setColor(UIManager.getColor("Separator.background"));
533: g.drawLine(0, h - 1, w - 1, h - 1);
534: g.translate(-x, -y);
535: }
536:
537: public Insets getBorderInsets(Component c) {
538: return INSETS;
539: }
540: }
541:
542: private static final class ThinRaisedBorder extends AbstractBorder
543: implements UIResource {
544: private static final Insets INSETS = new Insets(2, 2, 2, 2);
545:
546: public void paintBorder(Component c, Graphics g, int x, int y,
547: int w, int h) {
548: PlasticUtils.drawThinFlush3DBorder(g, x, y, w, h);
549: }
550:
551: public Insets getBorderInsets(Component c) {
552: return INSETS;
553: }
554: }
555:
556: private static final class ThinLoweredBorder extends AbstractBorder
557: implements UIResource {
558: private static final Insets INSETS = new Insets(2, 2, 2, 2);
559:
560: public void paintBorder(Component c, Graphics g, int x, int y,
561: int w, int h) {
562: PlasticUtils.drawThinPressed3DBorder(g, x, y, w, h);
563: }
564:
565: public Insets getBorderInsets(Component c) {
566: return INSETS;
567: }
568: }
569:
570: /**
571: * A border used for menu bars and tool bars in
572: * <code>HeaderStyle.SINGLE</code>. The bar is wrapped by an inner thin
573: * raised border, which in turn is wrapped by an outer thin lowered
574: * border.
575: */
576: private static final class EtchedBorder extends AbstractBorder
577: implements UIResource {
578:
579: private static final Insets INSETS = new Insets(2, 2, 2, 2);
580:
581: public void paintBorder(Component c, Graphics g, int x, int y,
582: int w, int h) {
583: PlasticUtils.drawThinPressed3DBorder(g, x, y, w, h);
584: PlasticUtils.drawThinFlush3DBorder(g, x + 1, y + 1, w - 2,
585: h - 2);
586: }
587:
588: public Insets getBorderInsets(Component c) {
589: return INSETS;
590: }
591: }
592:
593: /**
594: * A border used for menu bars in <code>HeaderStyle.BOTH</code>.
595: * The menu bar and tool bar are wrapped by a thin raised border,
596: * both together are wrapped by a thin lowered border.
597: */
598: private static final class MenuBarHeaderBorder extends
599: AbstractBorder implements UIResource {
600:
601: private static final Insets INSETS = new Insets(2, 2, 1, 2);
602:
603: public void paintBorder(Component c, Graphics g, int x, int y,
604: int w, int h) {
605: PlasticUtils.drawThinPressed3DBorder(g, x, y, w, h + 1);
606: PlasticUtils.drawThinFlush3DBorder(g, x + 1, y + 1, w - 2,
607: h - 1);
608: }
609:
610: public Insets getBorderInsets(Component c) {
611: return INSETS;
612: }
613: }
614:
615: /**
616: * A border used for tool bars in <code>HeaderStyle.BOTH</code>.
617: * The menu bar and tool bar are wrapped by a thin raised border,
618: * both together are wrapped by a thin lowered border.
619: */
620: private static final class ToolBarHeaderBorder extends
621: AbstractBorder implements UIResource {
622:
623: private static final Insets INSETS = new Insets(1, 2, 2, 2);
624:
625: public void paintBorder(Component c, Graphics g, int x, int y,
626: int w, int h) {
627: PlasticUtils.drawThinPressed3DBorder(g, x, y - 1, w, h + 1);
628: PlasticUtils.drawThinFlush3DBorder(g, x + 1, y, w - 2,
629: h - 1);
630: }
631:
632: public Insets getBorderInsets(Component c) {
633: return INSETS;
634: }
635: }
636:
637: private static final class MenuBorder extends AbstractBorder
638: implements UIResource {
639: private static final Insets INSETS = new Insets(2, 2, 2, 2);
640:
641: public void paintBorder(Component c, Graphics g, int x, int y,
642: int w, int h) {
643: JMenuItem b = (JMenuItem) c;
644: ButtonModel model = b.getModel();
645:
646: if (model.isArmed() || model.isSelected()) {
647: g.setColor(PlasticLookAndFeel.getControlDarkShadow());
648: g.drawLine(0, 0, w - 2, 0);
649: g.drawLine(0, 0, 0, h - 1);
650: //g.drawLine(w - 2, 2, w - 2, h - 1 );
651:
652: g.setColor(PlasticLookAndFeel
653: .getPrimaryControlHighlight());
654: g.drawLine(w - 1, 0, w - 1, h - 1);
655: } else if (model.isRollover()) {
656: g.translate(x, y);
657: PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
658: g.translate(-x, -y);
659: }
660: }
661:
662: public Insets getBorderInsets(Component c) {
663: return INSETS;
664: }
665:
666: public Insets getBorderInsets(Component c, Insets newInsets) {
667: newInsets.top = INSETS.top;
668: newInsets.left = INSETS.left;
669: newInsets.bottom = INSETS.bottom;
670: newInsets.right = INSETS.right;
671: return newInsets;
672: }
673: }
674:
675: private static final class PopupMenuBorder extends AbstractBorder
676: implements UIResource {
677: private static final Insets INSETS = new Insets(3, 3, 3, 3);
678:
679: public void paintBorder(Component c, Graphics g, int x, int y,
680: int w, int h) {
681: g.translate(x, y);
682: g.setColor(PlasticLookAndFeel.getControlDarkShadow());
683: g.drawRect(0, 0, w - 1, h - 1);
684: g.setColor(PlasticLookAndFeel.getMenuItemBackground());
685: g.drawRect(1, 1, w - 3, h - 3);
686: g.drawRect(2, 2, w - 5, h - 5);
687: g.translate(-x, -y);
688: }
689:
690: public Insets getBorderInsets(Component c) {
691: return INSETS;
692: }
693: }
694:
695: private static final class NoMarginPopupMenuBorder extends
696: AbstractBorder implements UIResource {
697: private static final Insets INSETS = new Insets(1, 1, 1, 1);
698:
699: public void paintBorder(Component c, Graphics g, int x, int y,
700: int w, int h) {
701: g.translate(x, y);
702: g.setColor(PlasticLookAndFeel.getControlDarkShadow());
703: g.drawRect(0, 0, w - 1, h - 1);
704: g.translate(-x, -y);
705: }
706:
707: public Insets getBorderInsets(Component c) {
708: return INSETS;
709: }
710: }
711:
712: private static class RolloverButtonBorder extends ButtonBorder {
713:
714: private RolloverButtonBorder() {
715: super (new Insets(3, 3, 3, 3));
716: }
717:
718: public void paintBorder(Component c, Graphics g, int x, int y,
719: int w, int h) {
720: AbstractButton b = (AbstractButton) c;
721: ButtonModel model = b.getModel();
722:
723: if (!model.isEnabled())
724: return;
725:
726: if (!(c instanceof JToggleButton)) {
727: if (model.isRollover()
728: && !(model.isPressed() && !model.isArmed())) {
729: super .paintBorder(c, g, x, y, w, h);
730: }
731: return;
732: }
733:
734: //if ( model.isRollover() && !( model.isPressed() && !model.isArmed() ) ) {
735: //super.paintBorder( c, g, x, y, w, h );
736: //}
737:
738: if (model.isRollover()) {
739: if (model.isPressed() && model.isArmed()) {
740: PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
741: } else {
742: PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
743: }
744: } else if (model.isSelected())
745: PlasticUtils.drawDark3DBorder(g, x, y, w, h);
746: }
747: }
748:
749: /**
750: * A border which is like a Margin border but it will only honor the margin
751: * if the margin has been explicitly set by the developer.
752: */
753: static final class RolloverMarginBorder extends EmptyBorder {
754:
755: RolloverMarginBorder() {
756: super (1, 1, 1, 1);
757: }
758:
759: public Insets getBorderInsets(Component c) {
760: return getBorderInsets(c, new Insets(0, 0, 0, 0));
761: }
762:
763: public Insets getBorderInsets(Component c, Insets insets) {
764: Insets margin = null;
765:
766: if (c instanceof AbstractButton) {
767: margin = ((AbstractButton) c).getMargin();
768: }
769: if (margin == null || margin instanceof UIResource) {
770: // default margin so replace
771: insets.left = left;
772: insets.top = top;
773: insets.right = right;
774: insets.bottom = bottom;
775: } else {
776: // Margin which has been explicitly set by the user.
777: insets.left = margin.left;
778: insets.top = margin.top;
779: insets.right = margin.right;
780: insets.bottom = margin.bottom;
781: }
782: return insets;
783: }
784: }
785:
786: /**
787: * Unlike Metal we don't paint the (misplaced) control color edges.
788: * Being a subclass of MetalBorders.ScrollPaneBorders ensures that
789: * the ScrollPaneUI will update the ScrollbarsFreeStanding property.
790: */
791: private static final class ScrollPaneBorder extends
792: MetalBorders.ScrollPaneBorder {
793:
794: public void paintBorder(Component c, Graphics g, int x, int y,
795: int w, int h) {
796: g.translate(x, y);
797:
798: g.setColor(PlasticLookAndFeel.getControlDarkShadow());
799: g.drawRect(0, 0, w - 2, h - 2);
800: g.setColor(PlasticLookAndFeel.getControlHighlight());
801: g.drawLine(w - 1, 0, w - 1, h - 1);
802: g.drawLine(0, h - 1, w - 1, h - 1);
803:
804: g.translate(-x, -y);
805: }
806: }
807:
808: private static final class TextFieldBorder extends Flush3DBorder {
809: public void paintBorder(Component c, Graphics g, int x, int y,
810: int w, int h) {
811:
812: if (!(c instanceof JTextComponent)) {
813: // special case for non-text components (bug ID 4144840)
814: if (c.isEnabled()) {
815: PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
816: } else {
817: PlasticUtils.drawDisabledBorder(g, x, y, w, h);
818: }
819: return;
820: }
821:
822: if (c.isEnabled() && ((JTextComponent) c).isEditable())
823: PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
824: else
825: PlasticUtils.drawDisabledBorder(g, x, y, w, h);
826: }
827: }
828:
829: private static final class ToggleButtonBorder extends ButtonBorder {
830:
831: private ToggleButtonBorder(Insets insets) {
832: super (insets);
833: }
834:
835: public void paintBorder(Component c, Graphics g, int x, int y,
836: int w, int h) {
837: if (!c.isEnabled()) {
838: PlasticUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
839: } else {
840: AbstractButton button = (AbstractButton) c;
841: ButtonModel model = button.getModel();
842: if (model.isPressed() && model.isArmed())
843: PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
844: else if (model.isSelected())
845: PlasticUtils.drawDark3DBorder(g, x, y, w, h);
846: else
847: PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
848: }
849: }
850:
851: }
852:
853: }
|