KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > synth > SynthBorder


1 /*
2  * @(#)SynthBorder.java 1.12 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing.plaf.synth;
8
9 import java.awt.*;
10 import javax.swing.*;
11 import javax.swing.border.*;
12 import javax.swing.plaf.UIResource JavaDoc;
13 import sun.swing.plaf.synth.SynthUI;
14
15 /**
16  * SynthBorder is a border that delegates to a Painter. The Insets
17  * are determined at construction time.
18  *
19  * @version 1.12, 12/19/03
20  * @author Scott Violet
21  */

22 class SynthBorder extends AbstractBorder implements UIResource JavaDoc {
23     private SynthUI ui;
24     private Insets insets;
25
26     SynthBorder(SynthUI ui, Insets insets) {
27         this.ui = ui;
28         this.insets = insets;
29     }
30
31     SynthBorder(SynthUI ui) {
32         this(ui, null);
33     }
34
35     public void paintBorder(Component c, Graphics g, int x, int y,
36                             int width, int height) {
37         JComponent jc = (JComponent)c;
38         SynthContext JavaDoc context = ui.getContext(jc);
39         SynthStyle JavaDoc style = context.getStyle();
40         if (style == null) {
41             assert false: "SynthBorder is being used outside after the UI " +
42                           "has been uninstalled";
43             return;
44         }
45         ui.paintBorder(context, g, x, y, width, height);
46         context.dispose();
47     }
48
49     /**
50      * This default implementation returns a new <code>Insets</code>
51      * instance where the <code>top</code>, <code>left</code>,
52      * <code>bottom</code>, and
53      * <code>right</code> fields are set to <code>0</code>.
54      * @param c the component for which this border insets value applies
55      * @return the new <code>Insets</code> object initialized to 0
56      */

57     public Insets getBorderInsets(Component c) {
58         return getBorderInsets(c, null);
59     }
60
61     /**
62      * Reinitializes the insets parameter with this Border's current Insets.
63      * @param c the component for which this border insets value applies
64      * @param insets the object to be reinitialized
65      * @return the <code>insets</code> object
66      */

67     public Insets getBorderInsets(Component c, Insets insets) {
68         if (this.insets != null) {
69             if (insets == null) {
70                 insets = new Insets(this.insets.top, this.insets.left,
71                                   this.insets.bottom, this.insets.right);
72             }
73             else {
74                 insets.top = this.insets.top;
75                 insets.bottom = this.insets.bottom;
76                 insets.left = this.insets.left;
77                 insets.right = this.insets.left;
78             }
79         }
80         else if (insets == null) {
81             insets = new Insets(0, 0, 0, 0);
82         }
83         else {
84             insets.top = insets.bottom = insets.left = insets.right = 0;
85         }
86         if (c instanceof JComponent) {
87             Region JavaDoc region = Region.getRegion((JComponent)c);
88             Insets margin = null;
89             if ((region == Region.ARROW_BUTTON || region == Region.BUTTON ||
90                  region == Region.CHECK_BOX ||
91                  region == Region.CHECK_BOX_MENU_ITEM ||
92                  region == Region.MENU || region == Region.MENU_ITEM ||
93                  region == Region.RADIO_BUTTON ||
94                  region == Region.RADIO_BUTTON_MENU_ITEM ||
95                  region == Region.TOGGLE_BUTTON) &&
96                        (c instanceof AbstractButton)) {
97                 margin = ((AbstractButton)c).getMargin();
98             }
99             else if (region == Region.TOOL_BAR && (c instanceof JToolBar)) {
100                 margin = ((JToolBar)c).getMargin();
101             }
102             else if (region == Region.MENU_BAR && (c instanceof JMenuBar)) {
103                 margin = ((JMenuBar)c).getMargin();
104             }
105             if (margin != null) {
106                 insets.top += margin.top;
107                 insets.bottom += margin.bottom;
108                 insets.left += margin.left;
109                 insets.right += margin.right;
110             }
111         }
112         return insets;
113     }
114
115     /**
116      * This default implementation returns false.
117      * @return false
118      */

119     public boolean isBorderOpaque() {
120         return false;
121     }
122 }
123
Popular Tags