49 |
import javax.swing.JMenu; |
import javax.swing.JMenu; |
50 |
import javax.swing.JMenuBar; |
import javax.swing.JMenuBar; |
51 |
import javax.swing.JMenuItem; |
import javax.swing.JMenuItem; |
52 |
|
import javax.swing.JTextField; |
53 |
import javax.swing.border.AbstractBorder; |
import javax.swing.border.AbstractBorder; |
54 |
import javax.swing.border.Border; |
import javax.swing.border.Border; |
55 |
import javax.swing.plaf.BorderUIResource; |
import javax.swing.plaf.BorderUIResource; |
56 |
import javax.swing.plaf.UIResource; |
import javax.swing.plaf.UIResource; |
57 |
import javax.swing.plaf.basic.BasicBorders; |
import javax.swing.plaf.basic.BasicBorders; |
58 |
|
|
59 |
|
|
60 |
/** |
/** |
61 |
* This factory class creates borders for the different Swing components |
* This factory class creates borders for the different Swing components |
62 |
* UI. |
* UI. |
72 |
/** The shared instance for getRolloverButtonBorder(). */ |
/** The shared instance for getRolloverButtonBorder(). */ |
73 |
private static Border toolbarButtonBorder; |
private static Border toolbarButtonBorder; |
74 |
|
|
75 |
|
/** The shared instance for getTextFieldBorder(). */ |
76 |
|
private static Border textFieldBorder; |
77 |
|
|
78 |
/** |
/** |
79 |
* A MarginBorder that gets shared by multiple components. |
* A MarginBorder that gets shared by multiple components. |
80 |
* Created on demand by the private helper function {@link |
* Created on demand by the private helper function {@link |
191 |
} |
} |
192 |
|
|
193 |
/** |
/** |
194 |
|
* A simple 3D border. |
195 |
|
*/ |
196 |
|
public static class Flush3DBorder extends AbstractBorder |
197 |
|
implements UIResource |
198 |
|
{ |
199 |
|
/** |
200 |
|
* Creates a new border instance. |
201 |
|
*/ |
202 |
|
public Flush3DBorder() |
203 |
|
{ |
204 |
|
} |
205 |
|
|
206 |
|
/** |
207 |
|
* Returns the border insets. |
208 |
|
* |
209 |
|
* @param c the component (ignored). |
210 |
|
* |
211 |
|
* @return The border insets. |
212 |
|
*/ |
213 |
|
public Insets getBorderInsets(Component c) |
214 |
|
{ |
215 |
|
return getBorderInsets(c, null); |
216 |
|
} |
217 |
|
|
218 |
|
/** |
219 |
|
* Returns the border insets. |
220 |
|
* |
221 |
|
* @param c the component (ignored). |
222 |
|
* @return The border insets. |
223 |
|
*/ |
224 |
|
public Insets getBorderInsets(Component c, Insets newInsets) |
225 |
|
{ |
226 |
|
if (newInsets == null) |
227 |
|
newInsets = new Insets(2, 2, 2, 2); |
228 |
|
else |
229 |
|
{ |
230 |
|
newInsets.top = 2; |
231 |
|
newInsets.left = 2; |
232 |
|
newInsets.bottom = 2; |
233 |
|
newInsets.right = 2; |
234 |
|
} |
235 |
|
return newInsets; |
236 |
|
} |
237 |
|
|
238 |
|
/** |
239 |
|
* Paints the border for the specified component. |
240 |
|
* |
241 |
|
* @param c the component (ignored). |
242 |
|
* @param g the graphics device. |
243 |
|
* @param x the x-coordinate. |
244 |
|
* @param y the y-coordinate. |
245 |
|
* @param w the width. |
246 |
|
* @param h the height. |
247 |
|
*/ |
248 |
|
public void paintBorder(Component c, Graphics g, int x, int y, int w, |
249 |
|
int h) |
250 |
|
{ |
251 |
|
Color savedColor = g.getColor(); |
252 |
|
g.setColor(MetalLookAndFeel.getControlDarkShadow()); |
253 |
|
g.drawRect(x, y, w - 2, h - 2); |
254 |
|
g.setColor(MetalLookAndFeel.getControlHighlight()); |
255 |
|
g.drawRect(x + 1, y + 1, w - 2, h - 2); |
256 |
|
g.setColor(MetalLookAndFeel.getControl()); |
257 |
|
g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2); |
258 |
|
g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); |
259 |
|
g.setColor(savedColor); |
260 |
|
} |
261 |
|
|
262 |
|
} |
263 |
|
|
264 |
|
/** |
265 |
|
* A border used for the {@link JTextField} component. |
266 |
|
*/ |
267 |
|
public static class TextFieldBorder extends Flush3DBorder |
268 |
|
implements UIResource |
269 |
|
{ |
270 |
|
/** |
271 |
|
* Creates a new border instance. |
272 |
|
*/ |
273 |
|
public TextFieldBorder() |
274 |
|
{ |
275 |
|
} |
276 |
|
|
277 |
|
/** |
278 |
|
* Paints the border for the specified component. |
279 |
|
* |
280 |
|
* @param c the component (ignored). |
281 |
|
* @param g the graphics device. |
282 |
|
* @param x the x-coordinate. |
283 |
|
* @param y the y-coordinate. |
284 |
|
* @param w the width. |
285 |
|
* @param h the height. |
286 |
|
*/ |
287 |
|
public void paintBorder(Component c, Graphics g, int x, int y, int w, |
288 |
|
int h) |
289 |
|
{ |
290 |
|
if (c.isEnabled()) |
291 |
|
super.paintBorder(c, g, x, y, w, h); |
292 |
|
else |
293 |
|
{ |
294 |
|
Color savedColor = g.getColor(); |
295 |
|
g.setColor(MetalLookAndFeel.getControlShadow()); |
296 |
|
g.drawRect(x, y, w - 1, h - 1); |
297 |
|
g.setColor(savedColor); |
298 |
|
} |
299 |
|
} |
300 |
|
|
301 |
|
} |
302 |
|
|
303 |
|
/** |
304 |
* A border used when painting {@link JInternalFrame} instances. |
* A border used when painting {@link JInternalFrame} instances. |
305 |
*/ |
*/ |
306 |
public static class InternalFrameBorder extends AbstractBorder |
public static class InternalFrameBorder extends AbstractBorder |
787 |
} |
} |
788 |
|
|
789 |
/** |
/** |
790 |
|
* Returns a border for use by the {@link JTextField} component. |
791 |
|
* |
792 |
|
* @return A border. |
793 |
|
* |
794 |
|
* @since 1.3 |
795 |
|
*/ |
796 |
|
public static Border getTextFieldBorder() |
797 |
|
{ |
798 |
|
if (textFieldBorder == null) |
799 |
|
textFieldBorder = new TextFieldBorder(); |
800 |
|
return textFieldBorder; |
801 |
|
} |
802 |
|
|
803 |
|
/** |
804 |
* Returns a border for Toolbar buttons in the Metal Look & Feel. |
* Returns a border for Toolbar buttons in the Metal Look & Feel. |
805 |
* |
* |
806 |
* @return a border for Toolbar buttons in the Metal Look & Feel |
* @return a border for Toolbar buttons in the Metal Look & Feel |