KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > metal > MetalBorders


1 /*
2  * @(#)MetalBorders.java 1.39 04/04/16
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing.plaf.metal;
9
10 import javax.swing.*;
11 import javax.swing.border.*;
12 import javax.swing.plaf.*;
13 import javax.swing.plaf.basic.BasicBorders JavaDoc;
14 import javax.swing.text.JTextComponent JavaDoc;
15
16 import java.awt.Component JavaDoc;
17 import java.awt.Insets JavaDoc;
18 import java.awt.Dimension JavaDoc;
19 import java.awt.Rectangle JavaDoc;
20 import java.awt.Color JavaDoc;
21 import java.awt.Dialog JavaDoc;
22 import java.awt.Frame JavaDoc;
23 import java.awt.Graphics JavaDoc;
24 import java.awt.Window JavaDoc;
25 import java.io.Serializable JavaDoc;
26
27
28 /**
29  * Factory object that can vend Borders appropriate for the metal L & F.
30  * @author Steve Wilson
31  * @version 1.39 04/16/04
32  */

33
34 public class MetalBorders {
35
36     /**
37      * Client property indicating the button shouldn't provide a rollover
38      * indicator. Only used with the Ocean theme.
39      */

40     static Object JavaDoc NO_BUTTON_ROLLOVER = new StringBuffer JavaDoc("NoButtonRollover");
41
42
43     public static class Flush3DBorder extends AbstractBorder implements UIResource{
44
45         private static final Insets JavaDoc insets = new Insets JavaDoc(2, 2, 2, 2);
46
47         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y,
48               int w, int h) {
49             if (c.isEnabled()) {
50                 MetalUtils.drawFlush3DBorder(g, x, y, w, h);
51             } else {
52                 MetalUtils.drawDisabledBorder(g, x, y, w, h);
53             }
54         }
55         public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
56             return insets;
57         }
58         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets) {
59         newInsets.top = insets.top;
60         newInsets.left = insets.left;
61         newInsets.bottom = insets.bottom;
62         newInsets.right = insets.right;
63         return newInsets;
64     }
65     }
66
67     public static class ButtonBorder extends AbstractBorder implements UIResource {
68
69         protected static Insets JavaDoc borderInsets = new Insets JavaDoc( 3, 3, 3, 3 );
70
71         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
72             if (MetalLookAndFeel.usingOcean()) {
73                 paintOceanBorder(c, g, x, y, w, h);
74                 return;
75             }
76             AbstractButton button = (AbstractButton)c;
77         ButtonModel model = button.getModel();
78
79         if ( model.isEnabled() ) {
80                 boolean isPressed = model.isPressed() && model.isArmed();
81                 boolean isDefault = (button instanceof JButton && ((JButton)button).isDefaultButton());
82
83             if (isPressed && isDefault) {
84                     MetalUtils.drawDefaultButtonPressedBorder(g, x, y, w, h);
85                 } else if (isPressed) {
86                     MetalUtils.drawPressed3DBorder( g, x, y, w, h );
87             } else if (isDefault) {
88                     MetalUtils.drawDefaultButtonBorder( g, x, y, w, h, false);
89                 } else {
90                     MetalUtils.drawButtonBorder( g, x, y, w, h, false);
91             }
92         } else { // disabled state
93
MetalUtils.drawDisabledBorder( g, x, y, w-1, h-1 );
94         }
95         }
96
97         private void paintOceanBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y,
98                                       int w, int h) {
99             AbstractButton button = (AbstractButton)c;
100         ButtonModel model = ((AbstractButton)c).getModel();
101
102             g.translate(x, y);
103             if (MetalUtils.isToolBarButton(button)) {
104                 if (model.isEnabled()) {
105                     if (model.isPressed()) {
106                         g.setColor(MetalLookAndFeel.getWhite());
107                         g.fillRect(1, h - 1, w - 1, 1);
108                         g.fillRect(w - 1, 1, 1, h - 1);
109                         g.setColor(MetalLookAndFeel.getControlDarkShadow());
110                         g.drawRect(0, 0, w - 2, h - 2);
111                         g.fillRect(1, 1, w - 3, 1);
112                     }
113                     else if (model.isSelected() || model.isRollover()) {
114                         g.setColor(MetalLookAndFeel.getWhite());
115                         g.fillRect(1, h - 1, w - 1, 1);
116                         g.fillRect(w - 1, 1, 1, h - 1);
117                         g.setColor(MetalLookAndFeel.getControlDarkShadow());
118                         g.drawRect(0, 0, w - 2, h - 2);
119                     }
120                     else {
121                         g.setColor(MetalLookAndFeel.getWhite());
122                         g.drawRect(1, 1, w - 2, h - 2);
123                         g.setColor(UIManager.getColor(
124                                 "Button.toolBarBorderBackground"));
125                         g.drawRect(0, 0, w - 2, h - 2);
126                     }
127                 }
128                 else {
129                    g.setColor(UIManager.getColor(
130                            "Button.disabledToolBarBorderBackground"));
131                    g.drawRect(0, 0, w - 2, h - 2);
132                 }
133             }
134         else if (model.isEnabled()) {
135                 boolean pressed = model.isPressed();
136                 boolean armed = model.isArmed();
137
138                 if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) {
139                     g.setColor(MetalLookAndFeel.getControlDarkShadow());
140                     g.drawRect(0, 0, w - 1, h - 1);
141                     g.drawRect(1, 1, w - 3, h - 3);
142                 }
143                 else if (pressed) {
144                     g.setColor(MetalLookAndFeel.getControlDarkShadow());
145                     g.fillRect(0, 0, w, 2);
146                     g.fillRect(0, 2, 2, h - 2);
147                     g.fillRect(w - 1, 1, 1, h - 1);
148                     g.fillRect(1, h - 1, w - 2, 1);
149                 }
150                 else if (model.isRollover() && button.getClientProperty(
151                                NO_BUTTON_ROLLOVER) == null) {
152                     g.setColor(MetalLookAndFeel.getPrimaryControl());
153                     g.drawRect(0, 0, w - 1, h - 1);
154                     g.drawRect(2, 2, w - 5, h - 5);
155                     g.setColor(MetalLookAndFeel.getControlDarkShadow());
156                     g.drawRect(1, 1, w - 3, h - 3);
157                 }
158                 else {
159                     g.setColor(MetalLookAndFeel.getControlDarkShadow());
160                     g.drawRect(0, 0, w - 1, h - 1);
161                 }
162             }
163             else {
164                 g.setColor(MetalLookAndFeel.getInactiveControlTextColor());
165                 g.drawRect(0, 0, w - 1, h - 1);
166                 if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) {
167                     g.drawRect(1, 1, w - 3, h - 3);
168                 }
169             }
170         }
171
172         public Insets JavaDoc getBorderInsets( Component JavaDoc c ) {
173             return borderInsets;
174         }
175         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets) {
176         newInsets.top = borderInsets.top;
177         newInsets.left = borderInsets.left;
178         newInsets.bottom = borderInsets.bottom;
179         newInsets.right = borderInsets.right;
180         return newInsets;
181     }
182     }
183
184     public static class InternalFrameBorder extends AbstractBorder implements UIResource {
185
186         private static final Insets JavaDoc insets = new Insets JavaDoc(5, 5, 5, 5);
187
188         private static final int corner = 14;
189
190         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y,
191               int w, int h) {
192
193             Color JavaDoc background;
194             Color JavaDoc highlight;
195             Color JavaDoc shadow;
196
197             if (c instanceof JInternalFrame && ((JInternalFrame)c).isSelected()) {
198                 background = MetalLookAndFeel.getPrimaryControlDarkShadow();
199             highlight = MetalLookAndFeel.getPrimaryControlShadow();
200             shadow = MetalLookAndFeel.getPrimaryControlInfo();
201             } else {
202                 background = MetalLookAndFeel.getControlDarkShadow();
203             highlight = MetalLookAndFeel.getControlShadow();
204             shadow = MetalLookAndFeel.getControlInfo();
205             }
206
207               g.setColor(background);
208               // Draw outermost lines
209
g.drawLine( 1, 0, w-2, 0);
210               g.drawLine( 0, 1, 0, h-2);
211               g.drawLine( w-1, 1, w-1, h-2);
212               g.drawLine( 1, h-1, w-2, h-1);
213
214               // Draw the bulk of the border
215
for (int i = 1; i < 5; i++) {
216               g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1);
217               }
218
219               if (c instanceof JInternalFrame &&
220                                ((JInternalFrame)c).isResizable()) {
221                   g.setColor(highlight);
222                   // Draw the Long highlight lines
223
g.drawLine( corner+1, 3, w-corner, 3);
224                   g.drawLine( 3, corner+1, 3, h-corner);
225                   g.drawLine( w-2, corner+1, w-2, h-corner);
226                   g.drawLine( corner+1, h-2, w-corner, h-2);
227
228                   g.setColor(shadow);
229                   // Draw the Long shadow lines
230
g.drawLine( corner, 2, w-corner-1, 2);
231                   g.drawLine( 2, corner, 2, h-corner-1);
232                   g.drawLine( w-3, corner, w-3, h-corner-1);
233                   g.drawLine( corner, h-3, w-corner-1, h-3);
234               }
235
236           }
237
238           public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
239               return insets;
240           }
241           public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets) {
242           newInsets.top = insets.top;
243           newInsets.left = insets.left;
244           newInsets.bottom = insets.bottom;
245           newInsets.right = insets.right;
246           return newInsets;
247       }
248     }
249
250     /**
251      * Border for a Frame.
252      * @since 1.4
253      */

254     static class FrameBorder extends AbstractBorder implements UIResource {
255
256         private static final Insets JavaDoc insets = new Insets JavaDoc(5, 5, 5, 5);
257
258         private static final int corner = 14;
259
260         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y,
261             int w, int h) {
262
263             Color JavaDoc background;
264             Color JavaDoc highlight;
265             Color JavaDoc shadow;
266
267             Window JavaDoc window = SwingUtilities.getWindowAncestor(c);
268             if (window != null && window.isActive()) {
269                 background = MetalLookAndFeel.getPrimaryControlDarkShadow();
270                 highlight = MetalLookAndFeel.getPrimaryControlShadow();
271                 shadow = MetalLookAndFeel.getPrimaryControlInfo();
272             } else {
273                 background = MetalLookAndFeel.getControlDarkShadow();
274                 highlight = MetalLookAndFeel.getControlShadow();
275                 shadow = MetalLookAndFeel.getControlInfo();
276             }
277
278             g.setColor(background);
279             // Draw outermost lines
280
g.drawLine( x+1, y+0, x+w-2, y+0);
281             g.drawLine( x+0, y+1, x+0, y +h-2);
282             g.drawLine( x+w-1, y+1, x+w-1, y+h-2);
283             g.drawLine( x+1, y+h-1, x+w-2, y+h-1);
284
285             // Draw the bulk of the border
286
for (int i = 1; i < 5; i++) {
287                 g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1);
288             }
289
290             if ((window instanceof Frame JavaDoc) && ((Frame JavaDoc) window).isResizable()) {
291                 g.setColor(highlight);
292                 // Draw the Long highlight lines
293
g.drawLine( corner+1, 3, w-corner, 3);
294                 g.drawLine( 3, corner+1, 3, h-corner);
295                 g.drawLine( w-2, corner+1, w-2, h-corner);
296                 g.drawLine( corner+1, h-2, w-corner, h-2);
297
298                 g.setColor(shadow);
299                 // Draw the Long shadow lines
300
g.drawLine( corner, 2, w-corner-1, 2);
301                 g.drawLine( 2, corner, 2, h-corner-1);
302                 g.drawLine( w-3, corner, w-3, h-corner-1);
303                 g.drawLine( corner, h-3, w-corner-1, h-3);
304             }
305
306         }
307
308         public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
309             return insets;
310         }
311           
312         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets)
313         {
314             newInsets.top = insets.top;
315             newInsets.left = insets.left;
316             newInsets.bottom = insets.bottom;
317             newInsets.right = insets.right;
318             return newInsets;
319         }
320     }
321
322     /**
323      * Border for a Frame.
324      * @since 1.4
325      */

326     static class DialogBorder extends AbstractBorder implements UIResource
327     {
328         private static final Insets JavaDoc insets = new Insets JavaDoc(5, 5, 5, 5);
329         private static final int corner = 14;
330
331         protected Color JavaDoc getActiveBackground()
332         {
333             return MetalLookAndFeel.getPrimaryControlDarkShadow();
334         }
335
336         protected Color JavaDoc getActiveHighlight()
337         {
338             return MetalLookAndFeel.getPrimaryControlShadow();
339         }
340
341         protected Color JavaDoc getActiveShadow()
342         {
343             return MetalLookAndFeel.getPrimaryControlInfo();
344         }
345
346         protected Color JavaDoc getInactiveBackground()
347         {
348             return MetalLookAndFeel.getControlDarkShadow();
349         }
350
351         protected Color JavaDoc getInactiveHighlight()
352         {
353             return MetalLookAndFeel.getControlShadow();
354         }
355
356         protected Color JavaDoc getInactiveShadow()
357         {
358             return MetalLookAndFeel.getControlInfo();
359         }
360
361         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h)
362         {
363             Color JavaDoc background;
364             Color JavaDoc highlight;
365             Color JavaDoc shadow;
366
367             Window JavaDoc window = SwingUtilities.getWindowAncestor(c);
368             if (window != null && window.isActive()) {
369                 background = getActiveBackground();
370                 highlight = getActiveHighlight();
371                 shadow = getActiveShadow();
372             } else {
373                 background = getInactiveBackground();
374                 highlight = getInactiveHighlight();
375                 shadow = getInactiveShadow();
376             }
377
378             g.setColor(background);
379             // Draw outermost lines
380
g.drawLine( x + 1, y + 0, x + w-2, y + 0);
381             g.drawLine( x + 0, y + 1, x + 0, y + h - 2);
382             g.drawLine( x + w - 1, y + 1, x + w - 1, y + h - 2);
383             g.drawLine( x + 1, y + h - 1, x + w - 2, y + h - 1);
384
385             // Draw the bulk of the border
386
for (int i = 1; i < 5; i++) {
387                 g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1);
388             }
389
390
391             if ((window instanceof Dialog JavaDoc) && ((Dialog JavaDoc) window).isResizable()) {
392                 g.setColor(highlight);
393                 // Draw the Long highlight lines
394
g.drawLine( corner+1, 3, w-corner, 3);
395                 g.drawLine( 3, corner+1, 3, h-corner);
396                 g.drawLine( w-2, corner+1, w-2, h-corner);
397                 g.drawLine( corner+1, h-2, w-corner, h-2);
398
399                 g.setColor(shadow);
400                 // Draw the Long shadow lines
401
g.drawLine( corner, 2, w-corner-1, 2);
402                 g.drawLine( 2, corner, 2, h-corner-1);
403                 g.drawLine( w-3, corner, w-3, h-corner-1);
404                 g.drawLine( corner, h-3, w-corner-1, h-3);
405             }
406             
407         }
408
409         public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
410             return insets;
411         }
412
413         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets)
414         {
415             newInsets.top = insets.top;
416             newInsets.left = insets.left;
417             newInsets.bottom = insets.bottom;
418             newInsets.right = insets.right;
419             return newInsets;
420         }
421     }
422
423     /**
424      * Border for an Error Dialog.
425      * @since 1.4
426      */

427     static class ErrorDialogBorder extends DialogBorder implements UIResource
428     {
429         protected Color JavaDoc getActiveBackground() {
430             return UIManager.getColor("OptionPane.errorDialog.border.background");
431         }
432     }
433     
434
435     /**
436      * Border for a QuestionDialog. Also used for a JFileChooser and a
437      * JColorChooser..
438      * @since 1.4
439      */

440     static class QuestionDialogBorder extends DialogBorder implements UIResource
441     {
442         protected Color JavaDoc getActiveBackground() {
443             return UIManager.getColor("OptionPane.questionDialog.border.background");
444         }
445     }
446     
447
448     /**
449      * Border for a Warning Dialog.
450      * @since 1.4
451      */

452     static class WarningDialogBorder extends DialogBorder implements UIResource
453     {
454         protected Color JavaDoc getActiveBackground() {
455             return UIManager.getColor("OptionPane.warningDialog.border.background");
456         }
457     }
458     
459
460     /**
461      * Border for a Palette.
462      * @since 1.3
463      */

464     public static class PaletteBorder extends AbstractBorder implements UIResource {
465         private static final Insets JavaDoc insets = new Insets JavaDoc(1, 1, 1, 1);
466         int titleHeight = 0;
467
468         public void paintBorder( Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h ) {
469
470         g.translate(x,y);
471         g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
472         g.drawLine(0, 1, 0, h-2);
473         g.drawLine(1, h-1, w-2, h-1);
474         g.drawLine(w-1, 1, w-1, h-2);
475         g.drawLine( 1, 0, w-2, 0);
476         g.drawRect(1,1, w-3, h-3);
477         g.translate(-x,-y);
478       
479     }
480
481         public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
482             return insets;
483         }
484
485         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets) {
486         newInsets.top = insets.top;
487         newInsets.left = insets.left;
488         newInsets.bottom = insets.bottom;
489         newInsets.right = insets.right;
490         return newInsets;
491     }
492     }
493
494     public static class OptionDialogBorder extends AbstractBorder implements UIResource {
495         private static final Insets JavaDoc insets = new Insets JavaDoc(3, 3, 3, 3);
496         int titleHeight = 0;
497
498         public void paintBorder( Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h ) {
499
500         g.translate(x,y);
501
502             int messageType = JOptionPane.PLAIN_MESSAGE;
503             if (c instanceof JInternalFrame) {
504                 Object JavaDoc obj = ((JInternalFrame) c).getClientProperty(
505                               "JInternalFrame.messageType");
506                 if (obj != null && (obj instanceof Integer JavaDoc)) {
507                     messageType = ((Integer JavaDoc) obj).intValue();
508                 }
509             }
510
511             Color JavaDoc borderColor;
512
513         switch (messageType) {
514             case(JOptionPane.ERROR_MESSAGE):
515                 borderColor = UIManager.getColor(
516                     "OptionPane.errorDialog.border.background");
517                 break;
518             case(JOptionPane.QUESTION_MESSAGE):
519                 borderColor = UIManager.getColor(
520                     "OptionPane.questionDialog.border.background");
521                 break;
522             case(JOptionPane.WARNING_MESSAGE):
523                 borderColor = UIManager.getColor(
524                     "OptionPane.warningDialog.border.background");
525                 break;
526             case(JOptionPane.INFORMATION_MESSAGE):
527             case(JOptionPane.PLAIN_MESSAGE):
528             default:
529                 borderColor = MetalLookAndFeel.getPrimaryControlDarkShadow();
530                 break;
531         }
532
533         g.setColor(borderColor);
534
535               // Draw outermost lines
536
g.drawLine( 1, 0, w-2, 0);
537               g.drawLine( 0, 1, 0, h-2);
538               g.drawLine( w-1, 1, w-1, h-2);
539               g.drawLine( 1, h-1, w-2, h-1);
540
541               // Draw the bulk of the border
542
for (int i = 1; i < 3; i++) {
543               g.drawRect(i, i, w-(i*2)-1, h-(i*2)-1);
544               }
545
546         g.translate(-x,-y);
547       
548     }
549
550         public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
551             return insets;
552         }
553
554         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets) {
555         newInsets.top = insets.top;
556         newInsets.left = insets.left;
557         newInsets.bottom = insets.bottom;
558         newInsets.right = insets.right;
559         return newInsets;
560     }
561     }
562
563
564     public static class MenuBarBorder extends AbstractBorder implements UIResource {
565         protected static Insets JavaDoc borderInsets = new Insets JavaDoc( 1, 0, 1, 0 );
566
567         public void paintBorder( Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h ) {
568         g.translate( x, y );
569
570             if (MetalLookAndFeel.usingOcean()) {
571                 // Only paint a border if we're not next to a horizontal
572
// toolbar
573
if (!MetalToolBarUI.doesMenuBarBorderToolBar((JMenuBar)c)) {
574                     g.setColor(MetalLookAndFeel.getControl());
575                     g.drawLine(0, h - 2, w, h - 2);
576                     g.setColor(UIManager.getColor("MenuBar.borderColor"));
577                     g.drawLine(0, h - 1, w, h - 1);
578                 }
579             }
580             else {
581                 g.setColor( MetalLookAndFeel.getControlShadow() );
582                 g.drawLine( 0, h-1, w, h-1 );
583             }
584
585         g.translate( -x, -y );
586
587         }
588
589         public Insets JavaDoc getBorderInsets( Component JavaDoc c ) {
590             return getBorderInsets(c, new Insets JavaDoc(0, 0, 0, 0));
591         }
592
593         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets) {
594             if (MetalLookAndFeel.usingOcean()) {
595                 newInsets.set(0, 0, 2, 0);
596             }
597             else {
598                 newInsets.top = borderInsets.top;
599                 newInsets.left = borderInsets.left;
600                 newInsets.bottom = borderInsets.bottom;
601                 newInsets.right = borderInsets.right;
602             }
603         return newInsets;
604     }
605     }
606
607     public static class MenuItemBorder extends AbstractBorder implements UIResource {
608         protected static Insets JavaDoc borderInsets = new Insets JavaDoc( 2, 2, 2, 2 );
609
610         public void paintBorder( Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h ) {
611             JMenuItem b = (JMenuItem) c;
612         ButtonModel model = b.getModel();
613
614         g.translate( x, y );
615
616         if ( c.getParent() instanceof JMenuBar ) {
617             if ( model.isArmed() || model.isSelected() ) {
618                 g.setColor( MetalLookAndFeel.getControlDarkShadow() );
619                 g.drawLine( 0, 0, w - 2, 0 );
620                 g.drawLine( 0, 0, 0, h - 1 );
621                 g.drawLine( w - 2, 2, w - 2, h - 1 );
622
623                 g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
624                 g.drawLine( w - 1, 1, w - 1, h - 1 );
625
626                 g.setColor( MetalLookAndFeel.getMenuBackground() );
627                 g.drawLine( w - 1, 0, w - 1, 0 );
628             }
629         } else {
630             if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) {
631                 g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
632                 g.drawLine( 0, 0, w - 1, 0 );
633
634                 g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
635                 g.drawLine( 0, h - 1, w - 1, h - 1 );
636             } else {
637                 g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
638                 g.drawLine( 0, 0, 0, h - 1 );
639             }
640         }
641
642         g.translate( -x, -y );
643         }
644
645         public Insets JavaDoc getBorderInsets( Component JavaDoc c ) {
646             return borderInsets;
647         }
648
649         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets) {
650         newInsets.top = borderInsets.top;
651         newInsets.left = borderInsets.left;
652         newInsets.bottom = borderInsets.bottom;
653         newInsets.right = borderInsets.right;
654         return newInsets;
655     }
656     }
657
658     public static class PopupMenuBorder extends AbstractBorder implements UIResource {
659         protected static Insets JavaDoc borderInsets = new Insets JavaDoc( 3, 1, 2, 1 );
660
661         public void paintBorder( Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h ) {
662         g.translate( x, y );
663
664             g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
665         g.drawRect( 0, 0, w - 1, h - 1 );
666
667             g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
668         g.drawLine( 1, 1, w - 2, 1 );
669         g.drawLine( 1, 2, 1, 2 );
670         g.drawLine( 1, h - 2, 1, h - 2 );
671
672         g.translate( -x, -y );
673
674         }
675
676         public Insets JavaDoc getBorderInsets( Component JavaDoc c ) {
677              return borderInsets;
678         }
679
680         public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets) {
681         newInsets.top = borderInsets.top;
682         newInsets.left = borderInsets.left;
683         newInsets.bottom = borderInsets.bottom;
684         newInsets.right = borderInsets.right;
685         return newInsets;
686     }
687     }
688
689
690     public static class RolloverButtonBorder extends ButtonBorder {
691
692         public void paintBorder( Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h ) {
693             AbstractButton b = (AbstractButton) c;
694             ButtonModel model = b.getModel();
695
696             if ( model.isRollover() && !( model.isPressed() && !model.isArmed() ) ) {
697             super.paintBorder( c, g, x, y, w, h );
698             }
699         }
700
701     }
702
703     /**
704      * A border which is like a Margin border but it will only honor the margin
705      * if the margin has been explicitly set by the developer.
706      *
707      * Note: This is identical to the package private class
708      * BasicBorders.RolloverMarginBorder and should probably be consolidated.
709      */

710     static class RolloverMarginBorder extends EmptyBorder {
711     
712     public RolloverMarginBorder() {
713         super(3,3,3,3); // hardcoded margin for JLF requirements.
714
}
715
716     public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
717         return getBorderInsets(c, new Insets JavaDoc(0,0,0,0));
718     }
719
720     public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc insets) {
721         Insets JavaDoc margin = null;
722
723         if (c instanceof AbstractButton) {
724         margin = ((AbstractButton)c).getMargin();
725         }
726         if (margin == null || margin instanceof UIResource) {
727         // default margin so replace
728
insets.left = left;
729         insets.top = top;
730         insets.right = right;
731         insets.bottom = bottom;
732         } else {
733         // Margin which has been explicitly set by the user.
734
insets.left = margin.left;
735         insets.top = margin.top;
736         insets.right = margin.right;
737         insets.bottom = margin.bottom;
738         }
739         return insets;
740     }
741     }
742
743     public static class ToolBarBorder extends AbstractBorder implements UIResource, SwingConstants
744     {
745         protected MetalBumps JavaDoc bumps = new MetalBumps JavaDoc( 10, 10,
746                       MetalLookAndFeel.getControlHighlight(),
747                       MetalLookAndFeel.getControlDarkShadow(),
748                                      UIManager.getColor("ToolBar.background"));
749
750         public void paintBorder( Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h )
751     {
752         g.translate( x, y );
753
754         if ( ((JToolBar) c).isFloatable() )
755         {
756             if ( ((JToolBar) c).getOrientation() == HORIZONTAL )
757         {
758                     int shift = MetalLookAndFeel.usingOcean() ? -1 : 0;
759             bumps.setBumpArea( 10, c.getSize().height - 4 );
760                     if( MetalUtils.isLeftToRight(c) ) {
761                         bumps.paintIcon( c, g, 2, 2 + shift );
762                     } else {
763                         bumps.paintIcon( c, g, c.getBounds().width-12,
764                                          2 + shift );
765                     }
766             }
767         else // vertical
768
{
769             bumps.setBumpArea( c.getSize().width - 4, 10 );
770             bumps.paintIcon( c, g, 2, 2 );
771             }
772
773         }
774
775             if (((JToolBar) c).getOrientation() == HORIZONTAL &&
776                                MetalLookAndFeel.usingOcean()) {
777                 g.setColor(MetalLookAndFeel.getControl());
778                 g.drawLine(0, h - 2, w, h - 2);
779                 g.setColor(UIManager.getColor("ToolBar.borderColor"));
780                 g.drawLine(0, h - 1, w, h - 1);
781             }
782
783         g.translate( -x, -y );
784         }
785
786         public Insets JavaDoc getBorderInsets( Component JavaDoc c ) {
787         return getBorderInsets(c, new Insets JavaDoc(0,0,0,0));
788     }
789
790     public Insets JavaDoc getBorderInsets(Component JavaDoc c, Insets JavaDoc newInsets) {
791             if (MetalLookAndFeel.usingOcean()) {
792                 newInsets.set(1, 2, 3, 2);
793             }
794             else {
795                 newInsets.top = newInsets.left = newInsets.bottom = newInsets.right = 2;
796             }
797
798         if ( ((JToolBar) c).isFloatable() ) {
799             if ( ((JToolBar) c).getOrientation() == HORIZONTAL ) {
800             if (c.getComponentOrientation().isLeftToRight()) {
801                 newInsets.left = 16;
802             } else {
803                 newInsets.right = 16;
804             }
805             } else {// vertical
806
newInsets.top = 16;
807             }
808         }
809
810         Insets JavaDoc margin = ((JToolBar) c).getMargin();
811
812         if ( margin != null ) {
813             newInsets.left += margin.left;
814             newInsets.top += margin.top;
815             newInsets.right += margin.right;
816             newInsets.bottom += margin.bottom;
817         }
818
819             return newInsets;
820         }
821     }
822
823     private static Border buttonBorder;
824
825     /**
826      * Returns a border instance for a JButton
827      * @since 1.3
828      */

829     public static Border getButtonBorder() {
830     if (buttonBorder == null) {
831         buttonBorder = new BorderUIResource.CompoundBorderUIResource(
832                            new MetalBorders.ButtonBorder JavaDoc(),
833                            new BasicBorders.MarginBorder JavaDoc());
834     }
835     return buttonBorder;
836     }
837
838     private static Border textBorder;
839
840     /**
841      * Returns a border instance for a text component
842      * @since 1.3
843      */

844     public static Border getTextBorder() {
845     if (textBorder == null) {
846         textBorder = new BorderUIResource.CompoundBorderUIResource(
847                            new MetalBorders.Flush3DBorder JavaDoc(),
848                            new BasicBorders.MarginBorder JavaDoc());
849     }
850     return textBorder;
851     }
852
853     private static Border textFieldBorder;
854
855     /**
856      * Returns a border instance for a JTextField
857      * @since 1.3
858      */

859     public static Border getTextFieldBorder() {
860     if (textFieldBorder == null) {
861         textFieldBorder = new BorderUIResource.CompoundBorderUIResource(
862                            new MetalBorders.TextFieldBorder JavaDoc(),
863                            new BasicBorders.MarginBorder JavaDoc());
864     }
865     return textFieldBorder;
866     }
867
868     public static class TextFieldBorder extends Flush3DBorder {
869
870         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y,
871                 int w, int h) {
872
873       if (!(c instanceof JTextComponent JavaDoc)) {
874             // special case for non-text components (bug ID 4144840)
875
if (c.isEnabled()) {
876             MetalUtils.drawFlush3DBorder(g, x, y, w, h);
877         } else {
878             MetalUtils.drawDisabledBorder(g, x, y, w, h);
879         }
880         return;
881         }
882
883         if (c.isEnabled() && ((JTextComponent JavaDoc)c).isEditable()) {
884             MetalUtils.drawFlush3DBorder(g, x, y, w, h);
885         } else {
886             MetalUtils.drawDisabledBorder(g, x, y, w, h);
887         }
888
889     }
890     }
891
892     public static class ScrollPaneBorder extends AbstractBorder implements UIResource {
893
894        private static final Insets JavaDoc insets = new Insets JavaDoc(1, 1, 2, 2);
895
896         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y,
897               int w, int h) {
898
899             JScrollPane scroll = (JScrollPane)c;
900             JComponent colHeader = scroll.getColumnHeader();
901             int colHeaderHeight = 0;
902             if (colHeader != null)
903                colHeaderHeight = colHeader.getHeight();
904
905             JComponent rowHeader = scroll.getRowHeader();
906             int rowHeaderWidth = 0;
907             if (rowHeader != null)
908                rowHeaderWidth = rowHeader.getWidth();
909
910
911             g.translate( x, y);
912
913             g.setColor( MetalLookAndFeel.getControlDarkShadow() );
914             g.drawRect( 0, 0, w-2, h-2 );
915             g.setColor( MetalLookAndFeel.getControlHighlight() );
916
917             g.drawLine( w-1, 1, w-1, h-1);
918             g.drawLine( 1, h-1, w-1, h-1);
919
920             g.setColor( MetalLookAndFeel.getControl() );
921             g.drawLine( w-2, 2+colHeaderHeight, w-2, 2+colHeaderHeight );
922             g.drawLine( 1+rowHeaderWidth, h-2, 1+rowHeaderWidth, h-2 );
923
924             g.translate( -x, -y);
925
926         }
927
928         public Insets JavaDoc getBorderInsets(Component JavaDoc c) {
929             return insets;
930         }
931     }
932
933     private static Border toggleButtonBorder;
934
935     /**
936      * Returns a border instance for a JToggleButton
937      * @since 1.3
938      */

939     public static Border getToggleButtonBorder() {
940     if (toggleButtonBorder == null) {
941         toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource(
942                            new MetalBorders.ToggleButtonBorder JavaDoc(),
943                            new BasicBorders.MarginBorder JavaDoc());
944     }
945     return toggleButtonBorder;
946     }
947
948     /**
949      * @since 1.3
950      */

951     public static class ToggleButtonBorder extends ButtonBorder {
952         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
953         AbstractButton button = (AbstractButton)c;
954         ButtonModel model = button.getModel();
955             if (MetalLookAndFeel.usingOcean()) {
956                 if(model.isArmed()) {
957                     super.paintBorder(c, g, x, y, w, h);
958                 }
959                 else {
960                     MetalUtils.drawPressed3DBorder( g, x, y, w + 1, h + 1 );
961                 }
962                 return;
963             }
964         if (! c.isEnabled() ) {
965             MetalUtils.drawDisabledBorder( g, x, y, w-1, h-1 );
966         } else {
967             if ( model.isPressed() && model.isArmed() ) {
968                    MetalUtils.drawPressed3DBorder( g, x, y, w, h );
969         } else if ( model.isSelected() ) {
970             MetalUtils.drawDark3DBorder( g, x, y, w, h );
971                 } else {
972             MetalUtils.drawFlush3DBorder( g, x, y, w, h );
973                 }
974         }
975     }
976     }
977
978     /**
979      * Border for a Table Header
980      * @since 1.3
981      */

982     public static class TableHeaderBorder extends javax.swing.border.AbstractBorder JavaDoc {
983         protected Insets JavaDoc editorBorderInsets = new Insets JavaDoc( 2, 2, 2, 0 );
984
985         public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int w, int h) {
986         g.translate( x, y );
987         
988         g.setColor( MetalLookAndFeel.getControlDarkShadow() );
989         g.drawLine( w-1, 0, w-1, h-1 );
990         g.drawLine( 1, h-1, w-1, h-1 );
991         g.setColor( MetalLookAndFeel.getControlHighlight() );
992         g.drawLine( 0, 0, w-2, 0 );
993         g.drawLine( 0, 0, 0, h-2 );
994
995         g.translate( -x, -y );
996     }
997
998         public Insets JavaDoc getBorderInsets( Component JavaDoc c ) {
999         return editorBorderInsets;
1000    }
1001    }
1002
1003    /**
1004     * Returns a border instance for a Desktop Icon
1005     * @since 1.3
1006     */

1007    public static Border getDesktopIconBorder() {
1008    return new BorderUIResource.CompoundBorderUIResource(
1009                                          new LineBorder(MetalLookAndFeel.getControlDarkShadow(), 1),
1010                                          new MatteBorder (2,2,1,2, MetalLookAndFeel.getControl()));
1011    }
1012
1013    static Border getToolBarRolloverBorder() {
1014        if (MetalLookAndFeel.usingOcean()) {
1015            return new CompoundBorder(
1016                new MetalBorders.ButtonBorder JavaDoc(),
1017                new MetalBorders.RolloverMarginBorder JavaDoc());
1018        }
1019    return new CompoundBorder(new MetalBorders.RolloverButtonBorder JavaDoc(),
1020                  new MetalBorders.RolloverMarginBorder JavaDoc());
1021    }
1022
1023    static Border getToolBarNonrolloverBorder() {
1024        if (MetalLookAndFeel.usingOcean()) {
1025            new CompoundBorder(
1026                new MetalBorders.ButtonBorder JavaDoc(),
1027                new MetalBorders.RolloverMarginBorder JavaDoc());
1028        }
1029    return new CompoundBorder(new MetalBorders.ButtonBorder JavaDoc(),
1030                  new MetalBorders.RolloverMarginBorder JavaDoc());
1031    }
1032}
1033
1034
Popular Tags