KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > looks > plastic > PlasticBorders


1 /*
2  * Copyright (c) 2001-2005 JGoodies Karsten Lentzsch. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * o Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * o Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * o Neither the name of JGoodies Karsten Lentzsch nor the names of
15  * its contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.jgoodies.looks.plastic;
32
33 import java.awt.Color JavaDoc;
34 import java.awt.Component JavaDoc;
35 import java.awt.Graphics JavaDoc;
36 import java.awt.Insets JavaDoc;
37
38 import javax.swing.AbstractButton JavaDoc;
39 import javax.swing.ButtonModel JavaDoc;
40 import javax.swing.JButton JavaDoc;
41 import javax.swing.JInternalFrame JavaDoc;
42 import javax.swing.JMenuItem JavaDoc;
43 import javax.swing.JToggleButton JavaDoc;
44 import javax.swing.UIManager JavaDoc;
45 import javax.swing.border.AbstractBorder JavaDoc;
46 import javax.swing.border.Border JavaDoc;
47 import javax.swing.border.CompoundBorder JavaDoc;
48 import javax.swing.border.EmptyBorder JavaDoc;
49 import javax.swing.plaf.BorderUIResource JavaDoc;
50 import javax.swing.plaf.UIResource JavaDoc;
51 import javax.swing.plaf.basic.BasicBorders JavaDoc;
52 import javax.swing.plaf.metal.MetalBorders JavaDoc;
53 import javax.swing.text.JTextComponent JavaDoc;
54
55 import com.jgoodies.looks.LookUtils;
56
57
58 /**
59  * This class consists of a set of <code>Border</code>s used
60  * by the JGoodies Plastic Look and Feel UI delegates.
61  *
62  * @author Karsten Lentzsch
63  * @version $Revision: 1.3 $
64  */

65
66 final class PlasticBorders {
67
68
69     // Accessing and Creating Borders ***************************************
70

71     private static Border JavaDoc buttonBorder;
72     private static Border JavaDoc comboBoxEditorBorder;
73     private static Border JavaDoc comboBoxArrowButtonBorder;
74     private static Border JavaDoc etchedBorder;
75     private static Border JavaDoc flush3DBorder;
76     private static Border JavaDoc menuBarHeaderBorder;
77     private static Border JavaDoc menuBorder;
78     private static Border JavaDoc menuItemBorder;
79     private static Border JavaDoc popupMenuBorder;
80     private static Border JavaDoc rolloverButtonBorder;
81     private static Border JavaDoc scrollPaneBorder;
82     private static Border JavaDoc separatorBorder;
83     private static Border JavaDoc textFieldBorder;
84     private static Border JavaDoc thinLoweredBorder;
85     private static Border JavaDoc thinRaisedBorder;
86     private static Border JavaDoc toggleButtonBorder;
87     private static Border JavaDoc toolBarHeaderBorder;
88
89
90     /**
91      * Returns a border instance for a <code>JButton</code>.
92      *
93      * @return the lazily created button border
94      */

95     static Border JavaDoc getButtonBorder() {
96         if (buttonBorder == null) {
97             buttonBorder = new BorderUIResource.CompoundBorderUIResource JavaDoc(
98                                     new ButtonBorder(),
99                                     new BasicBorders.MarginBorder JavaDoc());
100         }
101         return buttonBorder;
102     }
103
104     /**
105      * Returns a border for a <code>JComboBox</code>'s button.
106      *
107      * @return the lazily created combo box arrow button border
108      */

109     static Border JavaDoc getComboBoxArrowButtonBorder() {
110         if (comboBoxArrowButtonBorder == null) {
111             comboBoxArrowButtonBorder = new CompoundBorder JavaDoc( // No UIResource
112
new ComboBoxArrowButtonBorder(),
113                     new BasicBorders.MarginBorder JavaDoc());
114         }
115         return comboBoxArrowButtonBorder;
116     }
117
118     /**
119      * Returns a border for a <code>JComboBox</code>'s editor.
120      *
121      * @return the lazily created combo box editor border
122      */

123     static Border JavaDoc getComboBoxEditorBorder() {
124         if (comboBoxEditorBorder == null) {
125             comboBoxEditorBorder = new CompoundBorder JavaDoc( // No UIResource
126
new ComboBoxEditorBorder(),
127                             new BasicBorders.MarginBorder JavaDoc());
128         }
129         return comboBoxEditorBorder;
130     }
131
132     /**
133      * Returns an etched border instance for <code>JMenuBar</code> or
134      * <code>JToolBar</code>.
135      *
136      * @return the lazily created etched border
137      */

138     static Border JavaDoc getEtchedBorder() {
139         if (etchedBorder == null) {
140             etchedBorder = new BorderUIResource.CompoundBorderUIResource JavaDoc(
141                                     new EtchedBorder(),
142                                     new BasicBorders.MarginBorder JavaDoc());
143         }
144         return etchedBorder;
145     }
146
147     /**
148      * Returns a flushed 3D border.
149      *
150      * @return the lazily created flushed 3D border
151      */

152     static Border JavaDoc getFlush3DBorder() {
153         if (flush3DBorder == null) {
154             flush3DBorder = new Flush3DBorder();
155         }
156         return flush3DBorder;
157     }
158
159     /**
160      * Returns a border for a <code>JInternalFrame</code>.
161      *
162      * @return an internal frame border
163      */

164     static Border JavaDoc getInternalFrameBorder() {
165         return new InternalFrameBorder();
166     }
167
168     /**
169      * Returns a special border for a <code>JMenuBar</code> that
170      * is used in a header just above a <code>JToolBar</code>.
171      *
172      * @return the lazily created menu bar header border
173      */

174     static Border JavaDoc getMenuBarHeaderBorder() {
175         if (menuBarHeaderBorder == null) {
176             menuBarHeaderBorder = new BorderUIResource.CompoundBorderUIResource JavaDoc(
177                                     new MenuBarHeaderBorder(),
178                                     new BasicBorders.MarginBorder JavaDoc());
179         }
180         return menuBarHeaderBorder;
181     }
182
183     /**
184      * Returns a border instance for a <code>JMenu</code>.
185      *
186      * @return the lazily created menu border
187      */

188     static Border JavaDoc getMenuBorder() {
189         if (menuBorder == null) {
190             menuBorder = new BorderUIResource.CompoundBorderUIResource JavaDoc(
191                             new MenuBorder(),
192                             new BasicBorders.MarginBorder JavaDoc());
193         }
194         return menuBorder;
195     }
196
197     /**
198      * Returns a border instance for a <code>JMenuItem</code>.
199      *
200      * @return the lazily created menu item border
201      */

202     static Border JavaDoc getMenuItemBorder() {
203         if (menuItemBorder == null) {
204             menuItemBorder =
205                 new BorderUIResource JavaDoc(new BasicBorders.MarginBorder JavaDoc());
206         }
207         return menuItemBorder;
208     }
209
210     /**
211      * Returns a border instance for a <code>JPopupMenu</code>.
212      *
213      * @return the lazily created popup menu border
214      */

215     static Border JavaDoc getPopupMenuBorder() {
216         if (popupMenuBorder == null) {
217             popupMenuBorder = new PopupMenuBorder();
218         }
219         return popupMenuBorder;
220     }
221
222     /**
223      * Returns a border for a <code>JInternalFrame</code>'s palette.
224      *
225      * @return a border for an internal frame in palette mode
226      */

227     static Border JavaDoc getPaletteBorder() {
228         return new PaletteBorder();
229     }
230
231     /**
232      * Returns a rollover border for buttons in a <code>JToolBar</code>.
233      *
234      * @return the lazily created rollover button border
235      */

236     static Border JavaDoc getRolloverButtonBorder() {
237         if (rolloverButtonBorder == null) {
238             rolloverButtonBorder = new BorderUIResource.CompoundBorderUIResource JavaDoc(
239                                     new RolloverButtonBorder(),
240                                     new RolloverMarginBorder());
241         }
242         return rolloverButtonBorder;
243     }
244
245     /**
246      * Returns a separator border instance for <code>JScrollPane</code>.
247      *
248      * @return the lazily created scroll pane border
249      */

250     static Border JavaDoc getScrollPaneBorder() {
251         if (scrollPaneBorder == null) {
252             scrollPaneBorder = new ScrollPaneBorder();
253         }
254         return scrollPaneBorder;
255     }
256
257     /**
258      * Returns a separator border instance for <code>JMenuBar</code> or
259      * <code>JToolBar</code>.
260      *
261      * @return the lazily created separator border
262      */

263     static Border JavaDoc getSeparatorBorder() {
264         if (separatorBorder == null) {
265             separatorBorder = new BorderUIResource.CompoundBorderUIResource JavaDoc(
266                                     new SeparatorBorder(),
267                                     new BasicBorders.MarginBorder JavaDoc());
268         }
269         return separatorBorder;
270     }
271
272     /**
273      * Returns a border instance for a JTextField.
274      *
275      * @return the lazily created text field border
276      */

277     static Border JavaDoc getTextFieldBorder() {
278         if (textFieldBorder == null) {
279             textFieldBorder = new BorderUIResource.CompoundBorderUIResource JavaDoc(
280                                     new TextFieldBorder(),
281                                     new BasicBorders.MarginBorder JavaDoc());
282         }
283         return textFieldBorder;
284     }
285
286     /**
287      * Returns a thin lowered border.
288      *
289      * @return the lazily created thin lowered border
290      */

291     static Border JavaDoc getThinLoweredBorder() {
292         if (thinLoweredBorder == null) {
293             thinLoweredBorder = new ThinLoweredBorder();
294         }
295         return thinLoweredBorder;
296     }
297
298     /**
299      * Returns a thin raised border.
300      *
301      * @return the lazily created thin raised border
302      */

303     static Border JavaDoc getThinRaisedBorder() {
304         if (thinRaisedBorder == null) {
305             thinRaisedBorder = new ThinRaisedBorder();
306         }
307         return thinRaisedBorder;
308     }
309
310     /**
311      * Returns a border instance for a JToggleButton.
312      *
313      * @return the lazily created toggle button border
314      */

315     static Border JavaDoc getToggleButtonBorder() {
316         if (toggleButtonBorder == null) {
317             toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource JavaDoc(
318                                     new ToggleButtonBorder(),
319                                     new BasicBorders.MarginBorder JavaDoc());
320         }
321         return toggleButtonBorder;
322     }
323
324     /**
325      * Returns a special border for a <code>JToolBar</code> that
326      * is used in a header just below a <code>JMenuBar</code>.
327      *
328      * @return the lazily created toolbar header border
329      */

330     static Border JavaDoc getToolBarHeaderBorder() {
331         if (toolBarHeaderBorder == null) {
332             toolBarHeaderBorder = new BorderUIResource.CompoundBorderUIResource JavaDoc(
333                                     new ToolBarHeaderBorder(),
334                                     new BasicBorders.MarginBorder JavaDoc());
335         }
336         return toolBarHeaderBorder;
337     }
338
339     private static class Flush3DBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
340
341         private static final Insets JavaDoc INSETS = new Insets JavaDoc(2, 2, 2, 2);
342
343         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
344             if (c.isEnabled())
345                 PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
346             else
347                 PlasticUtils.drawDisabledBorder(g, x, y, w, h);
348         }
349         
350         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
351         
352         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets) {
353             newInsets.top = INSETS.top;
354             newInsets.left = INSETS.left;
355             newInsets.bottom = INSETS.bottom;
356             newInsets.right = INSETS.right;
357             return newInsets;
358         }
359     }
360     
361     
362     private static class ButtonBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
363
364         protected static final Insets JavaDoc INSETS = LookUtils.IS_LOW_RESOLUTION
365             ? new Insets JavaDoc(2, 3, 3, 3)
366             : new Insets JavaDoc(1, 3, 1, 3);
367
368         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
369             AbstractButton JavaDoc button = (AbstractButton JavaDoc) c;
370             ButtonModel JavaDoc model = button.getModel();
371
372             if (model.isEnabled()) {
373                 boolean isPressed = model.isPressed() && model.isArmed();
374                 boolean isDefault = button instanceof JButton JavaDoc
375                                      && ((JButton JavaDoc) button).isDefaultButton();
376
377                 if (isPressed && isDefault)
378                     PlasticUtils.drawDefaultButtonPressedBorder(g, x, y, w, h);
379                 else if (isPressed)
380                     PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
381                 else if (isDefault)
382                     PlasticUtils.drawDefaultButtonBorder(g, x, y, w, h, false);
383                 else
384                     PlasticUtils.drawButtonBorder(g, x, y, w, h, false);
385             } else { // disabled state
386
PlasticUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
387             }
388         }
389
390         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
391         
392         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets) {
393             newInsets.top = INSETS.top;
394             newInsets.left = INSETS.left;
395             newInsets.bottom = INSETS.bottom;
396             newInsets.right = INSETS.right;
397             return newInsets;
398         }
399     }
400     
401     
402     private static class ComboBoxArrowButtonBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
403
404         protected static final Insets JavaDoc INSETS = new Insets JavaDoc(1, 1, 1, 1);
405
406         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
407             AbstractButton JavaDoc button = (AbstractButton JavaDoc) c;
408             ButtonModel JavaDoc model = button.getModel();
409
410             if (model.isEnabled()) {
411                 boolean isPressed = model.isPressed() && model.isArmed();
412
413                 if (isPressed)
414                     PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
415                 else
416                     PlasticUtils.drawButtonBorder(g, x, y, w, h, false);
417             } else {
418                 PlasticUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
419             }
420         }
421
422         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
423     }
424
425     
426     private static class ComboBoxEditorBorder extends AbstractBorder JavaDoc {
427
428         private static final Insets JavaDoc INSETS = new Insets JavaDoc(2, 2, 2, 0);
429
430         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
431             if (c.isEnabled())
432                 PlasticUtils.drawFlush3DBorder(g, x, y, w + 2, h);
433             else {
434                 PlasticUtils.drawDisabledBorder(g, x, y, w + 2, h-1);
435                 g.setColor(UIManager.getColor("control"));
436                 g.drawLine(x, y + h-1, x + w, y + h-1);
437             }
438         }
439
440         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
441     }
442
443
444     /**
445      * A border used for <code>JInternalFrame</code>s.
446      */

447     private static class InternalFrameBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
448
449         private static final Insets JavaDoc NORMAL_INSETS = new Insets JavaDoc(2, 2, 3, 3);
450         private static final Insets JavaDoc MAXIMIZED_INSETS = new Insets JavaDoc(2, 2, 2, 2);
451                  static final int ALPHA1 = 150;
452                  static final int ALPHA2 = 50;
453
454
455         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
456             JInternalFrame JavaDoc frame = (JInternalFrame JavaDoc) c;
457             if (frame.isMaximum())
458                 PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
459             else
460                 paintShadowedBorder(g, x, y, w, h);
461         }
462         
463         private void paintShadowedBorder(Graphics JavaDoc g, int x, int y, int w, int h) {
464             Color JavaDoc background = UIManager.getColor("desktop");
465             Color JavaDoc highlight = UIManager.getColor("controlLtHighlight");
466             Color JavaDoc darkShadow = UIManager.getColor("controlDkShadow");
467             Color JavaDoc lightShadow = new Color JavaDoc(darkShadow.getRed(),
468                                             darkShadow.getGreen(),
469                                             darkShadow.getBlue(),
470                                             ALPHA1);
471             Color JavaDoc lighterShadow = new Color JavaDoc(darkShadow.getRed(),
472                                             darkShadow.getGreen(),
473                                             darkShadow.getBlue(),
474                                             ALPHA2);
475             g.translate(x, y);
476             // Dark border
477
g.setColor(darkShadow);
478             g.drawRect(0, 0, w-3, h-3);
479             // Highlight top and left
480
g.setColor(highlight);
481             g.drawLine(1, 1, w - 4, 1);
482             g.drawLine(1, 1, 1, h - 4);
483             // Paint background before painting the shadow
484
g.setColor(background);
485             g.fillRect(w - 2, 0, 2, h);
486             g.fillRect(0, h-2, w, 2);
487             // Shadow line 1
488
g.setColor(lightShadow);
489             g.drawLine(w - 2, 1, w - 2, h - 2);
490             g.drawLine(1, h - 2, w - 3, h - 2);
491             // Shadow line2
492
g.setColor(lighterShadow);
493             g.drawLine(w - 1, 2, w - 1, h - 2);
494             g.drawLine(2, h - 1, w - 2, h - 1);
495             g.translate(-x, -y);
496         }
497
498         public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
499             return ((JInternalFrame JavaDoc) c).isMaximum() ? MAXIMIZED_INSETS : NORMAL_INSETS;
500         }
501     }
502     
503     
504     /**
505      * A border used for the palette of <code>JInternalFrame</code>s.
506      */

507     private static class PaletteBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
508         
509         private static final Insets JavaDoc INSETS = new Insets JavaDoc(1, 1, 1, 1);
510
511         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h ) {
512             g.translate(x,y);
513             g.setColor(PlasticLookAndFeel.getControlDarkShadow());
514             g.drawRect(0, 0, w-1, h-1);
515             g.translate(-x,-y);
516         }
517
518         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
519     }
520     
521
522     /**
523      * A border that looks like a separator line; used for menu bars
524      * and tool bars.
525      */

526     private static class SeparatorBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
527
528         private static final Insets JavaDoc INSETS = new Insets JavaDoc(0, 0, 2, 1);
529
530         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
531             g.translate(x, y);
532             g.setColor( UIManager.getColor("Separator.foreground"));
533             g.drawLine( 0, h - 2, w - 1, h - 2 );
534
535             g.setColor( UIManager.getColor("Separator.background"));
536             g.drawLine( 0, h - 1, w - 1, h - 1 );
537             g.translate(-x, -y);
538         }
539         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
540     }
541
542
543     private static class ThinRaisedBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
544         private static final Insets JavaDoc INSETS = new Insets JavaDoc(2, 2, 2, 2);
545
546         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
547             PlasticUtils.drawThinFlush3DBorder(g, x, y, w, h);
548         }
549
550         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
551     }
552     
553
554     private static class ThinLoweredBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
555         private static final Insets JavaDoc INSETS = new Insets JavaDoc(2, 2, 2, 2);
556
557         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
558             PlasticUtils.drawThinPressed3DBorder(g, x, y, w, h);
559         }
560
561         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
562     }
563     
564
565     /**
566      * A border used for menu bars and tool bars in
567      * <code>HeaderStyle.SINGLE</code>. The bar is wrapped by an inner thin
568      * raised border, which in turn is wrapped by an outer thin lowered
569      * border.
570      */

571     private static class EtchedBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
572
573         private static final Insets JavaDoc INSETS = new Insets JavaDoc(2, 2, 2, 2);
574
575         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
576             PlasticUtils.drawThinPressed3DBorder(g, x, y, w, h);
577             PlasticUtils.drawThinFlush3DBorder (g, x + 1, y + 1, w - 2, h - 2);
578         }
579
580         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
581     }
582     
583     
584     /**
585      * A border used for menu bars in <code>HeaderStyle.BOTH</code>.
586      * The menu bar and tool bar are wrapped by a thin raised border,
587      * both together are wrapped by a thin lowered border.
588      */

589     private static class MenuBarHeaderBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
590
591         private static final Insets JavaDoc INSETS = new Insets JavaDoc(2, 2, 1, 2);
592
593         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
594             PlasticUtils.drawThinPressed3DBorder(g, x, y, w, h + 1);
595             PlasticUtils.drawThinFlush3DBorder (g, x + 1, y + 1, w - 2, h - 1);
596         }
597
598         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
599     }
600     
601     
602     /**
603      * A border used for tool bars in <code>HeaderStyle.BOTH</code>.
604      * The menu bar and tool bar are wrapped by a thin raised border,
605      * both together are wrapped by a thin lowered border.
606      */

607     private static class ToolBarHeaderBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
608
609         private static final Insets JavaDoc INSETS = new Insets JavaDoc(1, 2, 2, 2);
610
611         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
612             PlasticUtils.drawThinPressed3DBorder(g, x, y - 1, w, h + 1);
613             PlasticUtils.drawThinFlush3DBorder (g, x + 1, y, w - 2, h - 1);
614         }
615
616         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
617     }
618     
619     
620     private static class MenuBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
621         private static final Insets JavaDoc INSETS = new Insets JavaDoc( 2, 2, 2, 2 );
622
623         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
624             JMenuItem JavaDoc b = (JMenuItem JavaDoc) c;
625             ButtonModel JavaDoc model = b.getModel();
626
627             if (model.isArmed() || model.isSelected()) {
628                 g.setColor(PlasticLookAndFeel.getControlDarkShadow());
629                 g.drawLine(0, 0, w - 2, 0 );
630                 g.drawLine(0, 0, 0, h - 1 );
631                 //g.drawLine(w - 2, 2, w - 2, h - 1 );
632

633                 g.setColor(PlasticLookAndFeel.getPrimaryControlHighlight());
634                 g.drawLine(w - 1, 0, w - 1, h - 1 );
635             } else if (model.isRollover()) {
636                 g.translate(x, y);
637                 PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
638                 g.translate(-x, -y);
639             }
640         }
641         
642         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
643
644         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets) {
645             newInsets.top = INSETS.top;
646             newInsets.left = INSETS.left;
647             newInsets.bottom = INSETS.bottom;
648             newInsets.right = INSETS.right;
649             return newInsets;
650         }
651     }
652
653
654     private static class PopupMenuBorder extends AbstractBorder JavaDoc implements UIResource JavaDoc {
655         private static final Insets JavaDoc INSETS = new Insets JavaDoc(3, 3, 3, 3);
656
657         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
658             g.translate(x, y);
659             g.setColor(PlasticLookAndFeel.getControlDarkShadow());
660             g.drawRect(0, 0, w-1, h-1);
661             g.setColor(PlasticLookAndFeel.getMenuItemBackground());
662             g.drawRect(1, 1, w-3, h-3);
663             g.drawRect(2, 2, w-5, h-5);
664             g.translate(-x, -y);
665         }
666
667         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS; }
668     }
669     
670
671     private static class RolloverButtonBorder extends ButtonBorder {
672         private static final Insets JavaDoc INSETS_3 = new Insets JavaDoc(3, 3, 3, 3);
673
674         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
675             AbstractButton JavaDoc b = (AbstractButton JavaDoc) c;
676             ButtonModel JavaDoc model = b.getModel();
677
678             if (!model.isEnabled())
679                 return;
680
681             if (!(c instanceof JToggleButton JavaDoc)) {
682                 if ( model.isRollover() && !( model.isPressed() && !model.isArmed() ) ) {
683                     super.paintBorder( c, g, x, y, w, h );
684                 }
685                 return;
686             }
687
688             //if ( model.isRollover() && !( model.isPressed() && !model.isArmed() ) ) {
689
//super.paintBorder( c, g, x, y, w, h );
690
//}
691

692             if (model.isRollover()) {
693                 if (model.isPressed() && model.isArmed()) {
694                     PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
695                 } else {
696                     PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
697                 }
698             } else if (model.isSelected())
699                 PlasticUtils.drawDark3DBorder(g, x, y, w, h);
700         }
701         public Insets JavaDoc getBorderInsets(Component JavaDoc c) { return INSETS_3; }
702     }
703     
704     
705     /**
706      * A border which is like a Margin border but it will only honor the margin
707      * if the margin has been explicitly set by the developer.
708      */

709     private static class RolloverMarginBorder extends EmptyBorder JavaDoc {
710
711         private RolloverMarginBorder() {
712             super(1, 1, 1, 1);
713         }
714
715
716         public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
717             return getBorderInsets(c, new Insets JavaDoc(0, 0, 0, 0));
718         }
719
720
721         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc insets) {
722             Insets JavaDoc margin = null;
723
724             if (c instanceof AbstractButton JavaDoc) {
725                 margin = ((AbstractButton JavaDoc) c).getMargin();
726             }
727             if (margin == null || margin instanceof UIResource JavaDoc) {
728                 // default margin so replace
729
insets.left = left;
730                 insets.top = top;
731                 insets.right = right;
732                 insets.bottom = bottom;
733             } else {
734                 // Margin which has been explicitly set by the user.
735
insets.left = margin.left;
736                 insets.top = margin.top;
737                 insets.right = margin.right;
738                 insets.bottom = margin.bottom;
739             }
740             return insets;
741         }
742     }
743
744     /**
745      * Unlike Metal we don't paint the (misplaced) control color edges.
746      * Being a subclass of MetalBorders.ScrollPaneBorders ensures that
747      * the ScrollPaneUI will update the ScrollbarsFreeStanding property.
748      */

749     private static class ScrollPaneBorder extends MetalBorders.ScrollPaneBorder JavaDoc {
750         
751         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
752             g.translate(x, y);
753
754             g.setColor(PlasticLookAndFeel.getControlDarkShadow());
755             g.drawRect(0, 0, w - 2, h - 2);
756             g.setColor(PlasticLookAndFeel.getControlHighlight());
757             g.drawLine(w - 1, 0, w - 1, h - 1);
758             g.drawLine(0, h - 1, w - 1, h - 1);
759
760             g.translate(-x, -y);
761         }
762     }
763     
764     
765     private static class TextFieldBorder extends Flush3DBorder {
766         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
767         
768             if (!(c instanceof JTextComponent JavaDoc)) {
769                 // special case for non-text components (bug ID 4144840)
770
if (c.isEnabled()) {
771                     PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
772                 } else {
773                     PlasticUtils.drawDisabledBorder(g, x, y, w, h);
774                 }
775                 return;
776             }
777         
778             if (c.isEnabled() && ((JTextComponent JavaDoc) c).isEditable())
779                 PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
780             else
781                 PlasticUtils.drawDisabledBorder(g, x, y, w, h);
782         }
783     }
784
785
786     private static class ToggleButtonBorder extends ButtonBorder {
787         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
788             if (!c.isEnabled()) {
789                 PlasticUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
790             } else {
791                 AbstractButton JavaDoc button = (AbstractButton JavaDoc) c;
792                 ButtonModel JavaDoc model = button.getModel();
793                 if (model.isPressed() && model.isArmed())
794                     PlasticUtils.drawPressed3DBorder(g, x, y, w, h);
795                 else if (model.isSelected())
796                     PlasticUtils.drawDark3DBorder(g, x, y, w, h);
797                 else
798                     PlasticUtils.drawFlush3DBorder(g, x, y, w, h);
799             }
800         }
801     }
802     
803
804 }
Popular Tags