1 |
/* BasicBorders.java |
/* BasicBorders.java |
2 |
Copyright (C) 2002 Free Software Foundation, Inc. |
Copyright (C) 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
37 |
|
|
38 |
|
|
39 |
package javax.swing.plaf.basic; |
package javax.swing.plaf.basic; |
40 |
|
|
41 |
import java.awt.Color; |
import java.awt.Color; |
42 |
|
import java.awt.Component; |
43 |
|
import java.awt.Insets; |
44 |
|
|
45 |
|
import java.io.Serializable; |
46 |
|
|
47 |
|
import javax.swing.AbstractButton; |
48 |
|
import javax.swing.JPopupMenu; |
49 |
|
import javax.swing.JToolBar; |
50 |
|
import javax.swing.border.AbstractBorder; |
51 |
|
import javax.swing.plaf.UIResource; |
52 |
|
|
53 |
|
|
54 |
/** |
/** |
55 |
* STUBBED |
* STUBBED (except MarginBorder) |
56 |
*/ |
*/ |
57 |
public class BasicBorders |
public class BasicBorders |
58 |
{ |
{ |
66 |
{ |
{ |
67 |
} |
} |
68 |
} // class FieldBorder |
} // class FieldBorder |
69 |
|
|
70 |
|
|
71 |
|
/** |
72 |
|
* An invisible, but spacing border whose margin is determined |
73 |
|
* by calling the <code>getMargin()</code> method of the enclosed |
74 |
|
* component. If the enclosed component has no such method, |
75 |
|
* this border will not occupy any space. |
76 |
|
* |
77 |
|
* <p><img src="BasicBorders.MarginBorder-1.png" width="325" |
78 |
|
* height="200" alt="[An illustration that shows how MarginBorder |
79 |
|
* determines its borders]" /> |
80 |
|
* |
81 |
|
* @author Sascha Brawer (brawer@dandelis.ch) |
82 |
|
*/ |
83 |
public static class MarginBorder |
public static class MarginBorder |
84 |
|
extends AbstractBorder |
85 |
|
implements Serializable, UIResource |
86 |
{ |
{ |
87 |
} // class MarginBorder |
/** |
88 |
|
* Determined using the <code>serialver</code> tool |
89 |
|
* of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5. |
90 |
|
*/ |
91 |
|
static final long serialVersionUID = -3035848353448896090L; |
92 |
|
|
93 |
|
|
94 |
|
/** |
95 |
|
* Constructs a new MarginBorder. |
96 |
|
*/ |
97 |
|
public MarginBorder() |
98 |
|
{ |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
/** |
103 |
|
* Measures the width of this border. |
104 |
|
* |
105 |
|
* @param c the component whose border is to be measured. |
106 |
|
* |
107 |
|
* @return an Insets object whose <code>left</code>, <code>right</code>, |
108 |
|
* <code>top</code> and <code>bottom</code> fields indicate the |
109 |
|
* width of the border at the respective edge. |
110 |
|
* |
111 |
|
* @see #getBorderInsets(java.awt.Component, java.awt.Insets) |
112 |
|
*/ |
113 |
|
public Insets getBorderInsets(Component c) |
114 |
|
{ |
115 |
|
return getBorderInsets(c, new Insets(0, 0, 0, 0)); |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
|
/** |
120 |
|
* Determines the insets of this border by calling the |
121 |
|
* <code>getMargin()</code> method of the enclosed component. The |
122 |
|
* resulting margin will be stored into the the <code>left</code>, |
123 |
|
* <code>right</code>, <code>top</code> and <code>bottom</code> |
124 |
|
* fields of the passed <code>insets</code> parameter. |
125 |
|
* |
126 |
|
* <p>Unfortunately, <code>getMargin()</code> is not a method of |
127 |
|
* {@link javax.swing.JComponent} or some other common superclass |
128 |
|
* of things with margins. While reflection could be used to |
129 |
|
* determine the existence of this method, this would be slow on |
130 |
|
* many virtual machines. Therefore, the current implementation |
131 |
|
* knows about {@link javax.swing.AbstractButton#getMargin()}, |
132 |
|
* {@link javax.swing.JPopupMenu#getMargin()}, and {@link |
133 |
|
* javax.swing.JToolBar#getMargin()}. If <code>c</code> is an |
134 |
|
* instance of a known class, the respective |
135 |
|
* <code>getMargin()</code> method is called to determine the |
136 |
|
* correct margin. Otherwise, a zero-width margin is returned. |
137 |
|
* |
138 |
|
* @param c the component whose border is to be measured. |
139 |
|
* |
140 |
|
* @return the same object that was passed for <code>insets</code>, |
141 |
|
* but with changed fields. |
142 |
|
*/ |
143 |
|
public Insets getBorderInsets(Component c, Insets insets) |
144 |
|
{ |
145 |
|
Insets margin = null; |
146 |
|
|
147 |
|
/* This is terrible object-oriented design. See the above Javadoc |
148 |
|
* for an excuse. |
149 |
|
*/ |
150 |
|
if (c instanceof AbstractButton) |
151 |
|
margin = ((AbstractButton) c).getMargin(); |
152 |
|
else if (c instanceof JPopupMenu) |
153 |
|
margin = ((JPopupMenu) c).getMargin(); |
154 |
|
else if (c instanceof JToolBar) |
155 |
|
margin = ((JToolBar) c).getMargin(); |
156 |
|
|
157 |
|
if (margin == null) |
158 |
|
insets.top = insets.left = insets.bottom = insets.right = 0; |
159 |
|
else |
160 |
|
{ |
161 |
|
insets.top = margin.top; |
162 |
|
insets.left = margin.left; |
163 |
|
insets.bottom = margin.bottom; |
164 |
|
insets.right = margin.right; |
165 |
|
} |
166 |
|
|
167 |
|
return insets; |
168 |
|
} |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
public static class MenuBarBorder |
public static class MenuBarBorder |
173 |
{ |
{ |
174 |
public MenuBarBorder(Color shadow, Color highlight) |
public MenuBarBorder(Color shadow, Color highlight) |