2 Copyright (C) 2005, 2006, Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax
.swing
.plaf
.metal
;
41 import java
.awt
.Color
;
42 import java
.awt
.Component
;
43 import java
.awt
.Graphics
;
44 import java
.awt
.Insets
;
46 import javax
.swing
.AbstractButton
;
47 import javax
.swing
.ButtonModel
;
48 import javax
.swing
.JButton
;
49 import javax
.swing
.JInternalFrame
;
50 import javax
.swing
.JMenu
;
51 import javax
.swing
.JMenuBar
;
52 import javax
.swing
.JMenuItem
;
53 import javax
.swing
.JOptionPane
;
54 import javax
.swing
.JScrollPane
;
55 import javax
.swing
.JTextField
;
56 import javax
.swing
.JToggleButton
;
57 import javax
.swing
.JToolBar
;
58 import javax
.swing
.SwingConstants
;
59 import javax
.swing
.UIManager
;
60 import javax
.swing
.border
.AbstractBorder
;
61 import javax
.swing
.border
.Border
;
62 import javax
.swing
.border
.CompoundBorder
;
63 import javax
.swing
.plaf
.BorderUIResource
;
64 import javax
.swing
.plaf
.UIResource
;
65 import javax
.swing
.plaf
.basic
.BasicBorders
;
66 import javax
.swing
.text
.JTextComponent
;
70 * A factory class that creates borders for the different Swing components.
72 * @author Roman Kennke (roman@kennke.org)
74 public class MetalBorders
77 /** The shared instance for getButtonBorder(). */
78 private static Border buttonBorder
;
80 /** The shared instance for getToggleButtonBorder(). */
81 private static Border toggleButtonBorder
;
83 /** The shared instance for getDesktopIconBorder(). */
84 private static Border desktopIconBorder
;
86 /** The shared instance for getRolloverButtonBorder(). */
87 private static Border toolbarButtonBorder
;
89 /** The shared instance for getTextFieldBorder(). */
90 private static Border textFieldBorder
;
92 /** The shared instance for getTextBorder(). */
93 private static Border textBorder
;
95 /** The shared instance for getRolloverBorder(). */
96 private static Border rolloverBorder
;
99 * A MarginBorder that gets shared by multiple components.
100 * Created on demand by the private helper function {@link
101 * #getMarginBorder()}.
103 private static BasicBorders
.MarginBorder marginBorder
;
106 * A border used for {@link JButton} components.
108 public static class ButtonBorder
extends AbstractBorder
implements UIResource
110 /** The borders insets. */
111 protected static Insets borderInsets
= new Insets(3, 3, 3, 3);
114 * Creates a new instance of <code>ButtonBorder</code>.
116 public ButtonBorder()
118 // Nothing to do here.
122 * Paints the button border.
124 * @param c the component for which we paint the border
125 * @param g the Graphics context to use
126 * @param x the X coordinate of the upper left corner of c
127 * @param y the Y coordinate of the upper left corner of c
128 * @param w the width of c
129 * @param h the height of c
131 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
134 // With the OceanTheme the button border is painted entirely different.
135 // However, I couldn't figure out how this is determined besides checking
136 // for instanceof OceanTheme. The button painting is definitely not
137 // influenced by a UI default property and it is definitely performed
138 // by the same Border class.
139 if (MetalLookAndFeel
.getCurrentTheme() instanceof OceanTheme
)
140 paintOceanButtonBorder(c
, g
, x
, y
, w
, h
);
142 paintDefaultButtonBorder(c
, g
, x
, y
, w
, h
);
146 * Paints the button border for the DefaultMetalTheme.
148 * @param c the component (button)
149 * @param g the graphics object to use
150 * @param x the upper left corner of the component, X coordinate
151 * @param y the upper left corner of the component, Y coordinate
152 * @param w the width of the component
153 * @param h the height of the component
155 private void paintDefaultButtonBorder(Component c
, Graphics g
, int x
,
158 ButtonModel bmodel
= null;
160 if (c
instanceof AbstractButton
)
161 bmodel
= ((AbstractButton
) c
).getModel();
163 Color darkShadow
= MetalLookAndFeel
.getControlDarkShadow();
164 Color shadow
= MetalLookAndFeel
.getControlShadow();
165 Color light
= MetalLookAndFeel
.getControlHighlight();
166 Color middle
= MetalLookAndFeel
.getControl();
171 g
.setColor(darkShadow
);
172 g
.drawRect(x
, y
, w
- 2, h
- 2);
174 // If the button is the default button, we paint a special border,
175 // regardless of the pressed state.
176 if (c
instanceof JButton
&& ((JButton
) c
).isDefaultButton())
178 g
.drawRect(x
+ 1, y
+ 1, w
- 4, h
- 4);
179 // Draw white highlight.
181 g
.drawLine(x
+ 2, y
+ 2, x
+ w
- 4, y
+ 2);
182 g
.drawLine(x
+ 2, y
+ 2, x
+ 2, y
+ h
- 4);
183 g
.drawLine(x
+ 2, y
+ h
- 1, x
+ w
- 1, y
+ h
- 1);
184 g
.drawLine(x
+ w
- 1, y
+ 2, x
+ w
- 1, y
+ h
- 1);
185 // Draw crossing pixels.
187 g
.fillRect(x
+ w
- 2, y
+ 2, 1, 1);
188 g
.fillRect(x
+ 2, y
+ h
- 2, 1, 1);
192 // The normal border. This is used when the button is not
193 // pressed or the button is not armed.
194 if (! (bmodel
.isPressed() && bmodel
.isArmed()) )
198 g
.drawRect(x
+ 1, y
+ 1, w
- 2, h
- 2);
200 // draw crossing pixels of both borders
202 g
.drawLine(x
+ 1, y
+ h
- 2, x
+ 1, y
+ h
- 2);
203 g
.drawLine(x
+ w
- 2, y
+ 1, x
+ w
- 2, y
+ 1);
205 // The pressed border. This border is painted only when
206 // the button is both pressed and armed.
211 g
.drawLine(x
+ w
- 1, y
+ 1, x
+ w
- 1, y
+ h
- 1);
212 g
.drawLine(x
+ 1, y
+ h
- 1, x
+ w
- 1, y
+ h
- 1);
214 // draw shadow border
216 g
.drawLine(x
+ 1, y
+ 1, x
+ w
- 2, y
+ 1);
217 g
.drawLine(x
+ 1, y
+ 1, x
+ 1, y
+ h
- 2);
219 // draw crossing pixels of both borders
221 g
.drawRect(x
+ 1, y
+ h
- 2, 0, 0);
222 g
.drawRect(x
+ w
- 2, y
+ 1, 0, 0);
228 // draw disabled border
229 g
.setColor(MetalLookAndFeel
.getInactiveControlTextColor());
230 g
.drawRect(x
, y
, w
- 2, h
- 2);
235 * Paints the button border for the OceanTheme.
237 * @param c the button
238 * @param g the graphics context
239 * @param x the X coordinate of the upper left corner of the painting rect
240 * @param y the Y coordinate of the upper left corner of the painting rect
241 * @param w the width of the painting rect
242 * @param h the height of the painting rect
244 private void paintOceanButtonBorder(Component c
, Graphics g
, int x
,
247 ButtonModel bmodel
= null;
249 if (c
instanceof AbstractButton
)
250 bmodel
= ((AbstractButton
) c
).getModel();
252 Color darkShadow
= MetalLookAndFeel
.getControlDarkShadow();
253 Color shadow
= MetalLookAndFeel
.getControlShadow();
254 Color light
= MetalLookAndFeel
.getControlHighlight();
255 Color middle
= MetalLookAndFeel
.getControl();
259 // Paint the pressed border if the button is pressed, or if
260 // the button is the default button. In the OceanTheme, the default
261 // button has the same border as a pressed button.
262 if (bmodel
.isPressed() || ((c
instanceof JButton
)
263 && ((JButton
) c
).isDefaultButton()))
266 g
.setColor(darkShadow
);
267 g
.drawRect(x
, y
, w
- 1, h
- 1);
268 g
.drawRect(x
+ 1, y
+ 1, w
- 3, h
- 3);
270 else if (bmodel
.isRollover())
273 g
.drawRect(x
, y
, w
- 1, h
- 1);
274 g
.drawRect(x
+ 2, y
+ 2, w
- 5, h
- 5);
275 g
.setColor(darkShadow
);
276 g
.drawRect(x
+ 1, y
+ 1, w
- 3, h
- 3);
280 g
.setColor(darkShadow
);
281 g
.drawRect(x
, y
, w
- 1, h
- 1);
286 // draw disabled border
287 g
.setColor(MetalLookAndFeel
.getInactiveControlTextColor());
288 g
.drawRect(x
, y
, w
- 2, h
- 2);
293 * Returns the insets of the <code>ButtonBorder</code>.
295 * @param c the component for which the border is used (ignored).
297 * @return The insets of the <code>ButtonBorder</code>.
299 public Insets
getBorderInsets(Component c
)
305 * Returns the insets of the <code>ButtonBorder</code> in the specified
306 * <code>newInsets</code> object.
308 * @param c the component for which the border is used (ignored).
309 * @param newInsets the insets object where to put the values (
310 * <code>null</code> not permitted).
312 * @return The <code>newInsets</code> reference.
314 public Insets
getBorderInsets(Component c
, Insets newInsets
)
316 newInsets
.bottom
= borderInsets
.bottom
;
317 newInsets
.left
= borderInsets
.left
;
318 newInsets
.right
= borderInsets
.right
;
319 newInsets
.top
= borderInsets
.top
;
325 * A border used when painting {@link JInternalFrame} instances.
327 static class DesktopIconBorder
extends AbstractBorder
328 implements UIResource
331 * Creates a new border instance.
333 public DesktopIconBorder()
335 // Nothing to do here.
339 * Returns the border insets.
341 * @param c the component (ignored).
343 * @return The border insets.
345 public Insets
getBorderInsets(Component c
)
347 return getBorderInsets(c
, null);
351 * Returns the border insets.
353 * @param c the component (ignored).
354 * @return The border insets.
356 public Insets
getBorderInsets(Component c
, Insets newInsets
)
358 if (newInsets
== null)
359 newInsets
= new Insets(3, 3, 2, 3);
364 newInsets
.bottom
= 2;
371 * Paints the border for the specified component.
373 * @param c the component.
374 * @param g the graphics device.
375 * @param x the x-coordinate.
376 * @param y the y-coordinate.
377 * @param w the width.
378 * @param h the height.
380 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
383 g
.setColor(MetalLookAndFeel
.getControlDarkShadow());
384 g
.drawRect(x
, y
, w
- 1, h
- 1);
390 * A simple 3D border.
392 public static class Flush3DBorder
extends AbstractBorder
393 implements UIResource
395 private static final Insets borderInsets
= new Insets(2, 2, 2, 2);
398 * Creates a new border instance.
400 public Flush3DBorder()
402 // Nothing to do here.
406 * Returns the border insets.
408 * @param c the component (ignored).
410 * @return The border insets.
412 public Insets
getBorderInsets(Component c
)
418 * Returns the border insets.
420 * @param c the component (ignored).
421 * @param newInsets an existing insets instance, that will be populated
422 * with the border insets and returned as the result
423 * (<code>null</code> not permitted).
425 * @return The <code>newInsets</code> reference.
427 public Insets
getBorderInsets(Component c
, Insets newInsets
)
429 newInsets
.top
= borderInsets
.top
;
430 newInsets
.left
= borderInsets
.left
;
431 newInsets
.bottom
= borderInsets
.bottom
;
432 newInsets
.right
= borderInsets
.right
;
437 * Paints the border for the specified component.
439 * @param c the component (ignored).
440 * @param g the graphics device.
441 * @param x the x-coordinate.
442 * @param y the y-coordinate.
443 * @param w the width.
444 * @param h the height.
446 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
449 Color savedColor
= g
.getColor();
450 g
.setColor(MetalLookAndFeel
.getControlDarkShadow());
451 g
.drawRect(x
, y
, w
- 2, h
- 2);
452 g
.setColor(MetalLookAndFeel
.getControlHighlight());
453 g
.drawRect(x
+ 1, y
+ 1, w
- 2, h
- 2);
454 g
.setColor(MetalLookAndFeel
.getControl());
455 g
.drawLine(x
+ 1, y
+ h
- 2, x
+ 1, y
+ h
- 2);
456 g
.drawLine(x
+ w
- 2, y
+ 1, x
+ w
- 2, y
+ 1);
457 g
.setColor(savedColor
);
463 * A border used for a {@link JInternalFrame} when it is being used as a
468 public static class PaletteBorder
extends AbstractBorder
469 implements UIResource
471 private static final Insets borderInsets
= new Insets(1, 1, 1, 1);
474 * Creates a new <code>PaletteBorder</code>.
476 public PaletteBorder()
478 // Nothing to do here.
482 * Returns the border insets.
484 * @param c the component (ignored).
486 * @return The border insets.
488 public Insets
getBorderInsets(Component c
)
494 * Returns the border insets.
496 * @param c the component (ignored).
497 * @param newInsets an existing insets instance, that will be populated
498 * with the border insets and returned as the result
499 * (<code>null</code> not permitted).
501 * @return The <code>newInsets</code> reference.
503 public Insets
getBorderInsets(Component c
, Insets newInsets
)
505 newInsets
.top
= borderInsets
.top
;
506 newInsets
.left
= borderInsets
.left
;
507 newInsets
.bottom
= borderInsets
.bottom
;
508 newInsets
.right
= borderInsets
.right
;
513 * Paints the border for the specified component.
515 * @param c the component (ignored).
516 * @param g the graphics device.
517 * @param x the x-coordinate.
518 * @param y the y-coordinate.
519 * @param w the width.
520 * @param h the height.
522 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
525 Color savedColor
= g
.getColor();
528 g
.setColor(MetalLookAndFeel
.getPrimaryControlDarkShadow());
529 g
.drawRect(x
, y
, w
- 1, h
- 1);
531 // put a dot in each corner
532 g
.setColor(MetalLookAndFeel
.getControl());
533 g
.fillRect(x
, y
, 1, 1);
534 g
.fillRect(x
+ w
- 1, y
, 1, 1);
535 g
.fillRect(x
+ w
- 1, y
+ h
- 1, 1, 1);
536 g
.fillRect(x
, y
+ h
- 1, 1, 1);
537 g
.setColor(savedColor
);
543 * A border used for the {@link JTextField} component.
545 public static class TextFieldBorder
extends Flush3DBorder
546 implements UIResource
549 * Creates a new border instance.
551 public TextFieldBorder()
553 // Nothing to do here.
557 * Paints the border for the specified component.
559 * @param c the component (ignored).
560 * @param g the graphics device.
561 * @param x the x-coordinate.
562 * @param y the y-coordinate.
563 * @param w the width.
564 * @param h the height.
566 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
569 boolean enabledTextBorder
;
570 if (c
instanceof JTextComponent
)
572 JTextComponent tc
= (JTextComponent
) c
;
573 enabledTextBorder
= tc
.isEnabled() && tc
.isEditable();
576 enabledTextBorder
= false;
578 if (enabledTextBorder
)
579 super.paintBorder(c
, g
, x
, y
, w
, h
);
582 Color savedColor
= g
.getColor();
583 g
.setColor(MetalLookAndFeel
.getControlShadow());
584 g
.drawRect(x
, y
, w
- 1, h
- 1);
585 g
.setColor(savedColor
);
592 * A border used for the {@link JInternalFrame} component.
594 public static class InternalFrameBorder
extends AbstractBorder
595 implements UIResource
597 private static final Insets borderInsets
= new Insets(5, 5, 5, 5);
600 * Creates a new border instance.
602 public InternalFrameBorder()
604 // Nothing to do here.
608 * Returns the border insets.
610 * @param c the component (ignored).
612 * @return The border insets.
614 public Insets
getBorderInsets(Component c
)
620 * Returns the border insets.
622 * @param c the component (ignored).
623 * @param newInsets an existing insets instance, that will be populated
624 * with the border insets and returned as the result
625 * (<code>null</code> not permitted).
627 * @return The <code>newInsets</code> reference.
629 public Insets
getBorderInsets(Component c
, Insets newInsets
)
631 newInsets
.top
= borderInsets
.top
;
632 newInsets
.left
= borderInsets
.left
;
633 newInsets
.bottom
= borderInsets
.bottom
;
634 newInsets
.right
= borderInsets
.right
;
639 * Paints the border for the specified component.
641 * @param c the component.
642 * @param g the graphics device.
643 * @param x the x-coordinate.
644 * @param y the y-coordinate.
645 * @param w the width.
646 * @param h the height.
648 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
652 JInternalFrame f
= (JInternalFrame
) c
;
654 g
.setColor(MetalLookAndFeel
.getPrimaryControlDarkShadow());
656 g
.setColor(MetalLookAndFeel
.getControlDarkShadow());
658 // fill the border background
659 g
.fillRect(x
, y
, w
, 5);
660 g
.fillRect(x
, y
, 5, h
);
661 g
.fillRect(x
+ w
- 5, y
, 5, h
);
662 g
.fillRect(x
, y
+ h
- 5, w
, 5);
664 // draw a dot in each corner
665 g
.setColor(MetalLookAndFeel
.getControl());
666 g
.fillRect(x
, y
, 1, 1);
667 g
.fillRect(x
+ w
- 1, y
, 1, 1);
668 g
.fillRect(x
+ w
- 1, y
+ h
- 1, 1, 1);
669 g
.fillRect(x
, y
+ h
- 1, 1, 1);
672 g
.setColor(MetalLookAndFeel
.getBlack());
673 g
.drawLine(x
+ 14, y
+ 2, x
+ w
- 15, y
+ 2);
674 g
.drawLine(x
+ 14, y
+ h
- 3, x
+ w
- 15, y
+ h
- 3);
675 g
.drawLine(x
+ 2, y
+ 14, x
+ 2, y
+ h
- 15);
676 g
.drawLine(x
+ w
- 3, y
+ 14, x
+ w
- 3, y
+ h
- 15);
678 // draw the line highlights
680 g
.setColor(MetalLookAndFeel
.getPrimaryControlShadow());
682 g
.setColor(MetalLookAndFeel
.getControlShadow());
683 g
.drawLine(x
+ 15, y
+ 3, x
+ w
- 14, y
+ 3);
684 g
.drawLine(x
+ 15, y
+ h
- 2, x
+ w
- 14, y
+ h
- 2);
685 g
.drawLine(x
+ 3, y
+ 15, x
+ 3, y
+ h
- 14);
686 g
.drawLine(x
+ w
- 2, y
+ 15, x
+ w
- 2, y
+ h
- 14);
692 * A border used for {@link JInternalFrame} components that are
693 * presented as dialogs (by the {@link JOptionPane} class).
695 public static class OptionDialogBorder
extends AbstractBorder
696 implements UIResource
700 * Creates a new border instance.
702 public OptionDialogBorder()
704 // Nothing to do here.
708 * Returns the border insets.
710 * @param c the component (ignored).
712 * @return The border insets.
714 public Insets
getBorderInsets(Component c
)
716 return getBorderInsets(c
, null);
720 * Returns the border insets.
722 * @param c the component (ignored).
723 * @return The border insets.
725 public Insets
getBorderInsets(Component c
, Insets newInsets
)
727 if (newInsets
== null)
728 newInsets
= new Insets(3, 3, 3, 3);
733 newInsets
.bottom
= 3;
740 * Paints the border for the specified component.
742 * @param c the component.
743 * @param g the graphics device.
744 * @param x the x-coordinate.
745 * @param y the y-coordinate.
746 * @param w the width.
747 * @param h the height.
749 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
753 JInternalFrame f
= (JInternalFrame
) c
;
754 g
.setColor(MetalLookAndFeel
.getPrimaryControlDarkShadow());
755 if (f
.getContentPane() instanceof JOptionPane
)
757 JOptionPane pane
= (JOptionPane
) f
.getContentPane();
758 int type
= pane
.getMessageType();
759 if (type
== JOptionPane
.QUESTION_MESSAGE
)
761 Color bc
= UIManager
.getColor(
762 "OptionPane.questionDialog.border.background");
766 if (type
== JOptionPane
.WARNING_MESSAGE
)
768 Color bc
= UIManager
.getColor(
769 "OptionPane.warningDialog.border.background");
773 else if (type
== JOptionPane
.ERROR_MESSAGE
)
775 Color bc
= UIManager
.getColor(
776 "OptionPane.errorDialog.border.background");
782 // fill the border background
783 g
.fillRect(x
, y
, w
, 3);
784 g
.fillRect(x
, y
, 3, h
);
785 g
.fillRect(x
+ w
- 3, y
, 3, h
);
786 g
.fillRect(x
, y
+ h
- 3, w
, 3);
788 // draw a dot in each corner
789 g
.setColor(MetalLookAndFeel
.getControl());
790 g
.fillRect(x
, y
, 1, 1);
791 g
.fillRect(x
+ w
- 1, y
, 1, 1);
792 g
.fillRect(x
+ w
- 1, y
+ h
- 1, 1, 1);
793 g
.fillRect(x
, y
+ h
- 1, 1, 1);
800 * A border used for {@link JMenu} and {@link JMenuItem} components.
802 public static class MenuItemBorder
extends AbstractBorder
803 implements UIResource
805 /** The border insets. */
806 protected static Insets borderInsets
= new Insets(2, 2, 2, 2);
809 * Creates a new border instance.
811 public MenuItemBorder()
813 // Nothing to do here.
817 * Paints the border for the component. A border is painted only if the
818 * component is a selected {@link JMenu} or an armed {@link JMenuItem}.
820 * @param c the component.
821 * @param g the graphics device.
822 * @param x the x-coordinate of the border area.
823 * @param y the y-coordinate of the border area.
824 * @param w the width of the border area.
825 * @param h the height of the border area.
827 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
830 Color dark
= MetalLookAndFeel
.getPrimaryControlDarkShadow();
831 Color light
= MetalLookAndFeel
.getPrimaryControlHighlight();
832 if (c
instanceof JMenu
) {
833 JMenu menu
= (JMenu
) c
;
834 if (menu
.isSelected())
837 g
.drawLine(x
, y
, x
, y
+ h
);
838 g
.drawLine(x
, y
, x
+ w
, y
);
839 g
.drawLine(x
+ w
- 2, y
+ 1, x
+ w
- 2, y
+ h
);
841 g
.drawLine(x
+ w
- 1, y
+ 1, x
+ w
- 1, y
+ h
);
844 else if (c
instanceof JMenuItem
)
846 JMenuItem item
= (JMenuItem
) c
;
850 g
.drawLine(x
, y
, x
+ w
, y
);
852 g
.drawLine(x
, y
+ h
- 1, x
+ w
, y
+ h
- 1);
856 // Normally we draw a light line on the left.
858 g
.drawLine(x
, y
, x
, y
+ h
);
864 * Returns the border insets.
866 * @param c the component (ignored).
868 * @return The border insets.
870 public Insets
getBorderInsets(Component c
)
876 * Populates <code>insets</code> with the border insets, then returns it.
878 * @param c the component (ignored).
879 * @param insets the object to populate with the border insets.
881 * @return The border insets.
883 * @throws NullPointerException if <code>insets</code> is <code>null</code>.
885 public Insets
getBorderInsets(Component c
, Insets insets
)
887 insets
.left
= borderInsets
.left
;
888 insets
.top
= borderInsets
.top
;
889 insets
.bottom
= borderInsets
.bottom
;
890 insets
.right
= borderInsets
.right
;
896 * A border used for {@link JMenuBar} components.
898 public static class MenuBarBorder
899 extends AbstractBorder
900 implements UIResource
902 /** The border insets. */
903 protected static Insets borderInsets
= new Insets(1, 0, 1, 0);
905 // TODO: find where this color really comes from
906 private static Color borderColor
= new Color(153, 153, 153);
909 * Creates a new border instance.
911 public MenuBarBorder()
913 // Nothing to do here.
917 * Paints the border for the component. A border is painted only if the
918 * component is a selected {@link JMenu} or an armed {@link JMenuItem}.
920 * @param c the component.
921 * @param g the graphics device.
922 * @param x the x-coordinate of the border area.
923 * @param y the y-coordinate of the border area.
924 * @param w the width of the border area.
925 * @param h the height of the border area.
927 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
930 g
.setColor(borderColor
);
931 g
.drawLine(x
, y
+ h
- 1, x
+ w
, y
+ h
- 1);
935 * Returns the border insets.
937 * @param c the component (ignored).
939 * @return The border insets.
941 public Insets
getBorderInsets(Component c
)
947 * Populates <code>insets</code> with the border insets, then returns it.
949 * @param c the component (ignored).
950 * @param insets the object to populate with the border insets.
952 * @return The border insets.
954 * @throws NullPointerException if <code>insets</code> is <code>null</code>.
956 public Insets
getBorderInsets(Component c
, Insets insets
)
958 insets
.left
= borderInsets
.left
;
959 insets
.top
= borderInsets
.top
;
960 insets
.bottom
= borderInsets
.bottom
;
961 insets
.right
= borderInsets
.right
;
967 * A border for {@link JScrollPane} components.
969 public static class ScrollPaneBorder
970 extends AbstractBorder
971 implements UIResource
973 /** The border insets. */
974 private static Insets insets
= new Insets(1, 1, 2, 2);
977 * Constructs a new ScrollPaneBorder.
979 public ScrollPaneBorder()
981 // Nothing to do here.
985 * Returns the insets of the border for the Component <code>c</code>.
987 * @param c the Component for which we return the border insets
989 public Insets
getBorderInsets(Component c
)
997 * @param c the Component for which the border is painted
998 * @param g the Graphics context
999 * @param x the X coordinate of the upper left corner of the border
1000 * @param y the Y coordinate of the upper left corner of the border
1001 * @param w the width of the border
1002 * @param h the height of the border
1004 public void paintBorder(Component c
, Graphics g
, int x
, int y
,
1007 Color darkShadow
= MetalLookAndFeel
.getControlDarkShadow();
1008 Color shadow
= MetalLookAndFeel
.getControlShadow();
1009 Color light
= MetalLookAndFeel
.getWhite();
1010 Color middle
= MetalLookAndFeel
.getControl();
1012 // paint top border line
1013 g
.setColor(darkShadow
);
1014 g
.drawLine(x
, y
, x
+ w
- 2, y
);
1016 // paint left border line
1017 g
.drawLine(x
, y
, x
, y
+ h
- 2);
1019 // paint right inner border line
1020 g
.drawLine(x
+ w
- 2, y
, x
+ w
- 2, y
+ h
+ 1);
1022 // paint bottom inner border line
1023 g
.drawLine(x
+ 2, y
+ h
- 2, x
+ w
- 2, y
+ h
- 2);
1025 // draw right outer border line
1027 g
.drawLine(x
+ w
- 1, y
, x
+ w
- 1, y
+ h
- 1);
1029 // draw bottom outer border line
1030 g
.drawLine(x
, y
+ h
- 1, x
+ w
- 1, y
+ h
- 1);
1032 // paint the lighter points
1034 g
.drawLine(x
+ w
- 1, y
, x
+ w
- 1, y
);
1035 g
.drawLine(x
+ w
- 2, y
+ 2, x
+ w
- 2, y
+ 2);
1036 g
.drawLine(x
, y
+ h
- 1, x
, y
+ h
- 1);
1037 g
.drawLine(x
+ 1, y
+ h
- 2, x
+ 1, y
+ h
- 2);
1044 * A button border that is only visible when the mouse pointer is within
1045 * the button's bounds.
1047 public static class RolloverButtonBorder
1048 extends MetalBorders
.ButtonBorder
1051 * Creates a new border instance.
1053 public RolloverButtonBorder()
1055 // Nothing to do here.
1059 * Paints the border.
1061 * @param c the component.
1062 * @param g the graphics device.
1063 * @param x the x-coordinate.
1064 * @param y the y-coordinate.
1065 * @param w the width.
1066 * @param h the height.
1068 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
1071 // TODO: What should be done here? Obviously the ButtonBorder already
1072 // handles the rollover state in Sun's impl. Maybe this is only there
1073 // for backwards compatibility.
1074 super.paintBorder(c
, g
, x
, y
, w
, h
);
1079 * This border is used in Toolbar buttons as inner border.
1081 static class RolloverMarginBorder
extends AbstractBorder
1083 /** The borders insets. */
1084 protected static Insets borderInsets
= new Insets(3, 3, 3, 3);
1087 * Creates a new instance of RolloverBorder.
1089 public RolloverMarginBorder()
1091 // Nothing to do here.
1095 * Returns the insets of the RolloverBorder.
1097 * @param c the component for which the border is used
1099 * @return the insets of the RolloverBorder
1101 public Insets
getBorderInsets(Component c
)
1103 return getBorderInsets(c
, null);
1107 * Returns the insets of the RolloverMarginBorder in the specified
1110 * @param c the component for which the border is used
1111 * @param newInsets the insets object where to put the values
1113 * @return the insets of the RolloverMarginBorder
1115 public Insets
getBorderInsets(Component c
, Insets newInsets
)
1117 if (newInsets
== null)
1118 newInsets
= new Insets(0, 0, 0, 0);
1120 AbstractButton b
= (AbstractButton
) c
;
1121 Insets margin
= b
.getMargin();
1122 newInsets
.bottom
= borderInsets
.bottom
;
1123 newInsets
.left
= borderInsets
.left
;
1124 newInsets
.right
= borderInsets
.right
;
1125 newInsets
.top
= borderInsets
.top
;
1131 * A border implementation for popup menus.
1133 public static class PopupMenuBorder
1134 extends AbstractBorder
1135 implements UIResource
1138 /** The border's insets. */
1139 protected static Insets borderInsets
= new Insets(3, 1, 2, 1);
1142 * Constructs a new PopupMenuBorder.
1144 public PopupMenuBorder()
1146 // Nothing to do here.
1150 * Returns the insets of the border, creating a new Insets instance
1153 * @param c the component for which we return the border insets
1156 public Insets
getBorderInsets(Component c
)
1158 return getBorderInsets(c
, null);
1162 * Returns the insets of the border, using the supplied Insets instance.
1164 * @param c the component for which we return the border insets
1166 * @param i the Insets instance to fill with the Insets values
1168 public Insets
getBorderInsets(Component c
, Insets i
)
1172 insets
= new Insets(borderInsets
.top
, borderInsets
.left
,
1173 borderInsets
.bottom
, borderInsets
.right
);
1177 insets
.top
= borderInsets
.top
;
1178 insets
.left
= borderInsets
.left
;
1179 insets
.bottom
= borderInsets
.bottom
;
1180 insets
.right
= borderInsets
.right
;
1187 * Paints the border for component <code>c</code> using the
1188 * Graphics context <code>g</code> with the dimension
1189 * <code>x, y, w, h</code>.
1191 * @param c the component for which we paint the border
1192 * @param g the Graphics context to use
1193 * @param x the X coordinate of the upper left corner of c
1194 * @param y the Y coordinate of the upper left corner of c
1195 * @param w the width of c
1196 * @param h the height of c
1198 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
1201 Color darkShadow
= MetalLookAndFeel
.getPrimaryControlDarkShadow();
1202 Color light
= MetalLookAndFeel
.getPrimaryControlHighlight();
1204 // draw dark outer border
1205 g
.setColor(darkShadow
);
1206 g
.drawRect(x
, y
, w
- 1, h
- 1);
1208 // draw highlighted inner border (only top and left)
1210 g
.drawLine(x
+ 1, y
+ 1, x
+ w
- 2, y
+ 1);
1216 * A border used for the {@link JToggleButton} component.
1220 public static class ToggleButtonBorder
1221 extends ButtonBorder
1224 * Creates a new border instance.
1226 public ToggleButtonBorder()
1228 // Nothing to do here.
1232 * Paints the toggle button border.
1234 * @param c the component for which we paint the border
1235 * @param g the Graphics context to use
1236 * @param x the X coordinate of the upper left corner of c
1237 * @param y the Y coordinate of the upper left corner of c
1238 * @param w the width of c
1239 * @param h the height of c
1241 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
1244 ButtonModel bmodel
= null;
1246 if (c
instanceof AbstractButton
)
1247 bmodel
= ((AbstractButton
) c
).getModel();
1249 Color darkShadow
= MetalLookAndFeel
.getControlDarkShadow();
1250 Color shadow
= MetalLookAndFeel
.getControlShadow();
1251 Color light
= MetalLookAndFeel
.getWhite();
1252 Color middle
= MetalLookAndFeel
.getControl();
1257 g
.setColor(darkShadow
);
1258 g
.drawRect(x
, y
, w
- 2, h
- 2);
1260 if (!bmodel
.isArmed())
1262 // draw light border
1264 g
.drawLine(x
+ 1, y
+ h
- 1, x
+ w
- 1, y
+ h
- 1);
1265 g
.drawLine(x
+ w
- 1, y
+ 1, x
+ w
- 1, y
+ h
- 1);
1266 if (bmodel
.isSelected())
1268 g
.drawLine(x
+ 1, y
+ 1, x
+ w
- 3, y
+ 1);
1269 g
.drawLine(x
+ 1, y
+ 1, x
+ 1, y
+ h
- 3);
1271 // draw crossing pixels of both borders
1273 g
.drawLine(x
+ 1, y
+ h
- 2, x
+ 1, y
+ h
- 2);
1274 g
.drawLine(x
+ w
- 2, y
+ 1, x
+ w
- 2, y
+ 1);
1278 // draw light border
1280 g
.drawLine(x
+ w
- 1, y
+ 1, x
+ w
- 1, y
+ h
- 1);
1281 g
.drawLine(x
+ 1, y
+ h
- 1, x
+ w
- 1, y
+ h
- 1);
1283 // draw shadow border
1285 g
.drawLine(x
+ 1, y
+ 1, x
+ w
- 2, y
+ 1);
1286 g
.drawLine(x
+ 1, y
+ 1, x
+ 1, y
+ h
- 2);
1288 // draw crossing pixels of both borders
1290 g
.drawLine(x
+ 1, y
+ h
- 2, x
+ 1, y
+ h
- 2);
1291 g
.drawLine(x
+ w
- 2, y
+ 1, x
+ w
- 2, y
+ 1);
1296 g
.drawLine(x
, y
+ h
- 1, x
, y
+ h
- 1);
1297 g
.drawLine(x
+ w
- 1, y
, x
+ w
- 1, y
);
1301 // draw disabled border
1302 g
.setColor(MetalLookAndFeel
.getControlDisabled());
1303 g
.drawRect(x
, y
, w
- 2, h
- 2);
1309 * A border used for the {@link JToolBar} component.
1311 public static class ToolBarBorder
extends AbstractBorder
1312 implements UIResource
, SwingConstants
1315 * Creates a new border instance.
1317 public ToolBarBorder()
1319 // Nothing to do here.
1323 * Returns the border insets.
1325 * @param c the component (ignored).
1327 * @return The border insets.
1329 public Insets
getBorderInsets(Component c
)
1331 return getBorderInsets(c
, null);
1335 * Returns the border insets.
1337 * @param c the component (ignored).
1338 * @return The border insets.
1340 public Insets
getBorderInsets(Component c
, Insets newInsets
)
1342 JToolBar tb
= (JToolBar
) c
;
1343 if (tb
.getOrientation() == JToolBar
.HORIZONTAL
)
1345 if (newInsets
== null)
1346 newInsets
= new Insets(2, 16, 2, 2);
1350 newInsets
.left
= 16;
1351 newInsets
.bottom
= 2;
1352 newInsets
.right
= 2;
1356 else // assume JToolBar.VERTICAL
1358 if (newInsets
== null)
1359 newInsets
= new Insets(16, 2, 2, 2);
1364 newInsets
.bottom
= 2;
1365 newInsets
.right
= 2;
1373 * Paints the border for the specified component.
1375 * @param c the component.
1376 * @param g the graphics device.
1377 * @param x the x-coordinate.
1378 * @param y the y-coordinate.
1379 * @param w the width.
1380 * @param h the height.
1382 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
,
1386 JToolBar tb
= (JToolBar
) c
;
1387 if (tb
.getOrientation() == JToolBar
.HORIZONTAL
)
1389 MetalUtils
.fillMetalPattern(tb
, g
, x
+ 2, y
+ 2, x
+ 11, y
+ h
- 5,
1390 MetalLookAndFeel
.getControlHighlight(),
1391 MetalLookAndFeel
.getControlDarkShadow());
1395 MetalUtils
.fillMetalPattern(tb
, g
, x
+ 2, y
+ 2, x
+ w
- 5, y
+ 11,
1396 MetalLookAndFeel
.getControlHighlight(),
1397 MetalLookAndFeel
.getControlDarkShadow());
1404 * A border for table header cells.
1408 public static class TableHeaderBorder
extends AbstractBorder
1411 * The insets of this border.
1413 // TODO: According to tests that I have done, this is really the border
1414 // that should be returned by getBorderInsets(). However, the name
1415 // is very distracting. Is there any deeper meaning in it?
1416 protected Insets editorBorderInsets
;
1419 * Creates a new instance of <code>TableHeaderBorder</code>.
1421 public TableHeaderBorder()
1423 editorBorderInsets
= new Insets(1, 1, 1, 1);
1427 * Return the insets of this border.
1429 * @return the insets of this border
1431 public Insets
getBorderInsets(Component c
)
1433 return editorBorderInsets
;
1437 * Paints the border.
1439 * @param c the component for which to paint the border
1440 * @param g the graphics context to use
1441 * @param x the x cooridinate of the border rectangle
1442 * @param y the y cooridinate of the border rectangle
1443 * @param w the width of the border rectangle
1444 * @param h the height of the border rectangle
1446 public void paintBorder(Component c
, Graphics g
, int x
, int y
, int w
, int h
)
1448 Color dark
= MetalLookAndFeel
.getControlDarkShadow();
1449 Color light
= MetalLookAndFeel
.getWhite();
1450 Color old
= g
.getColor();
1452 g
.drawLine(x
, y
, x
+ w
- 2, y
);
1453 g
.drawLine(x
, y
, x
, y
+ h
- 2);
1455 g
.drawLine(x
+ w
- 1, y
, x
+ w
- 1, y
+ h
- 1);
1456 g
.drawLine(x
+ 1, y
+ h
- 1, x
+ w
- 1, y
+ h
- 1);
1462 * Returns a border for Swing buttons in the Metal Look & Feel.
1464 * @return a border for Swing buttons in the Metal Look & Feel
1466 public static Border
getButtonBorder()
1468 if (buttonBorder
== null)
1470 Border outer
= new ButtonBorder();
1471 Border inner
= getMarginBorder();
1472 buttonBorder
= new BorderUIResource
.CompoundBorderUIResource
1475 return buttonBorder
;
1479 * Returns a border for use with {@link JToggleButton} components.
1485 public static Border
getToggleButtonBorder()
1487 if (toggleButtonBorder
== null)
1489 Border outer
= new ToggleButtonBorder();
1490 Border inner
= getMarginBorder();
1491 toggleButtonBorder
= new BorderUIResource
.CompoundBorderUIResource
1494 return toggleButtonBorder
;
1498 * Returns a border instance that is used with a {@link JInternalFrame} when
1499 * it is in the iconified state.
1505 public static Border
getDesktopIconBorder()
1507 if (desktopIconBorder
== null)
1508 desktopIconBorder
= new DesktopIconBorder();
1509 return desktopIconBorder
;
1513 * Returns a border for use by the {@link JTextField} component.
1519 public static Border
getTextFieldBorder()
1521 if (textFieldBorder
== null)
1523 Border inner
= getMarginBorder();
1524 Border outer
= new TextFieldBorder();
1526 new BorderUIResource
.CompoundBorderUIResource(outer
, inner
);
1528 return textFieldBorder
;
1532 * Returns the border that is used for text components (except text fields,
1533 * which use {@link #getTextFieldBorder}.
1535 * @return the border that is used for text components
1539 public static Border
getTextBorder()
1541 if (textBorder
== null)
1543 Border inner
= getMarginBorder();
1544 Border outer
= new Flush3DBorder();
1546 new BorderUIResource
.CompoundBorderUIResource(outer
, inner
);
1552 * Returns a border for Toolbar buttons in the Metal Look & Feel.
1554 * @return a border for Toolbar buttons in the Metal Look & Feel
1556 static Border
getToolbarButtonBorder()
1558 if (toolbarButtonBorder
== null)
1560 Border outer
= new ButtonBorder();
1561 Border inner
= new RolloverMarginBorder();
1562 toolbarButtonBorder
= new CompoundBorder(outer
, inner
);
1564 return toolbarButtonBorder
;
1568 * Returns a shared instance of {@link BasicBorders.MarginBorder}.
1570 * @return a shared instance of {@link BasicBorders.MarginBorder}
1572 static Border
getMarginBorder()
1574 if (marginBorder
== null)
1575 marginBorder
= new BasicBorders
.MarginBorder();
1576 return marginBorder
;
1580 * Returns a shared instance of a compound border for rollover buttons.
1582 * @return A shared border instance.
1584 static Border
getRolloverBorder()
1586 if (rolloverBorder
== null)
1588 Border outer
= new MetalBorders
.RolloverButtonBorder();
1589 Border inner
= MetalBorders
.getMarginBorder();
1590 rolloverBorder
= new BorderUIResource
.CompoundBorderUIResource(outer
,
1593 return rolloverBorder
;