/[classpath]/classpath/javax/swing/plaf/basic/BasicBorders.java
ViewVC logotype

Diff of /classpath/javax/swing/plaf/basic/BasicBorders.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by brawer, Thu Jun 19 11:51:01 2003 UTC revision 1.6 by brawer, Thu Jun 19 15:20:35 2003 UTC
# Line 72  public class BasicBorders Line 72  public class BasicBorders
72    
73    
74    /**    /**
75     * Returns a border that is suitable for a button.     * Returns a border for drawing push buttons.
76     *     *
77     * <p>The colors of the border are retrieved from the     * <p>The colors of the border are retrieved from the
78     * <code>UIDefaults</code> of the currently active look and feel     * <code>UIDefaults</code> of the currently active look and feel
# Line 122  public class BasicBorders Line 122  public class BasicBorders
122    
123    
124    /**    /**
125       * Returns a border for drawing radio buttons.
126       *
127       * <p>The colors of the border are retrieved from the
128       * <code>UIDefaults</code> of the currently active look and feel
129       * using the keys <code>&#x201c;RadioButton.shadow&#x201d;</code>,
130       * <code>&#x201c;RadioButton.darkShadow&#x201d;</code>,
131       * <code>&#x201c;RadioButton.light&#x201d;</code>, and
132       * <code>&#x201c;RadioButton.highlight&#x201d;</code>.
133       *
134       * <p><img src="BasicBorders.RadioButtonBorder-1.png" width="300"
135       * height="135" alt="[A screen shot of the returned border]" />
136       *
137       * @return a {@link
138       *         javax.swing.plaf.BorderUIResource#CompoundBorderUIResource}
139       *         whose outer border is a {@link #RadioButtonBorder} and whose
140       *         inner border is a {@link #MarginBorder}.
141       */
142      public static Border getRadioButtonBorder()
143      {
144        UIDefaults defaults;
145        Border outer;
146    
147        defaults = UIManager.getLookAndFeelDefaults();
148    
149        /* The keys for UIDefaults have been determined by writing a
150         * test program that dumps the UIDefaults to stdout; that program
151         * was run on a JDK 1.4.1_01 for GNU/Linux. Note that in the API,
152         * the key "light" is usually called "highlight", and "highlight"
153         * is usually called "lightHighlight".
154         */
155        outer = new RadioButtonBorder(
156          defaults.getColor("RadioButton.shadow"),
157          defaults.getColor("RadioButton.darkShadow"),
158          defaults.getColor("RadioButton.light"),
159          defaults.getColor("RadioButton.highlight"));
160    
161        /* While the inner border is shared between multiple buttons, we
162         * do not share the outer border because RadioButtonBorders, being
163         * ButtonBorders, store their border colors. We cannot guarantee
164         * that the colors (which come from UIDefaults) are unchanged
165         * between invocations of getButtonBorder. We could store the last
166         * colors, and share the button border if the colors are the same
167         * as in the last invocation, but it probably is not worth the
168         * effort.
169         */
170        return new BorderUIResource.CompoundBorderUIResource(
171          outer,
172          /* inner */ getMarginBorder());
173      }
174    
175    
176      /**
177       * Returns a border for drawing toggle buttons.
178       *
179       * <p>The colors of the border are retrieved from the
180       * <code>UIDefaults</code> of the currently active look and feel
181       * using the keys <code>&#x201c;ToggleButton.shadow&#x201d;</code>,
182       * <code>&#x201c;ToggleButton.darkShadow&#x201d;</code>,
183       * <code>&#x201c;ToggleButton.light&#x201d;</code>, and
184       * <code>&#x201c;ToggleButton.highlight&#x201d;</code>.
185       *
186       * <p><img src="BasicBorders.ToggleButtonBorder-1.png" width="270"
187       * height="135" alt="[A screen shot of the returned border]" />
188       *
189       * @return a {@link
190       *         javax.swing.plaf.BorderUIResource#CompoundBorderUIResource}
191       *         whose outer border is a {@link #ToggleButtonBorder} and whose
192       *         inner border is a {@link #MarginBorder}.
193       */
194      public static Border getToggleButtonBorder()
195      {
196        UIDefaults defaults;
197        Border outer;
198    
199        defaults = UIManager.getLookAndFeelDefaults();
200    
201        /* The keys for UIDefaults have been determined by writing a
202         * test program that dumps the UIDefaults to stdout; that program
203         * was run on a JDK 1.4.1_01 for GNU/Linux. Note that in the API,
204         * the key "light" is usually called "highlight", and "highlight"
205         * is usually called "lightHighlight".
206         */
207        outer = new ToggleButtonBorder(
208          defaults.getColor("ToggleButton.shadow"),
209          defaults.getColor("ToggleButton.darkShadow"),
210          defaults.getColor("ToggleButton.light"),
211          defaults.getColor("ToggleButton.highlight"));
212    
213        /* While the inner border is shared between multiple buttons, we
214         * do not share the outer border because ToggleButtonBorders, being
215         * ButtonBorders, store their border colors. We cannot guarantee
216         * that the colors (which come from UIDefaults) are unchanged
217         * between invocations of getButtonBorder. We could store the last
218         * colors, and share the button border if the colors are the same
219         * as in the last invocation, but it probably is not worth the
220         * effort.
221         */
222        return new BorderUIResource.CompoundBorderUIResource(
223          outer,
224          /* inner */ getMarginBorder());
225      }
226    
227    
228      /**
229     * Returns a shared MarginBorder.     * Returns a shared MarginBorder.
230     */     */
231    static Border getMarginBorder()  // intentionally not public    static Border getMarginBorder()  // intentionally not public
# Line 428  public class BasicBorders Line 532  public class BasicBorders
532      {      {
533      }      }
534    } // class MenuBarBorder    } // class MenuBarBorder
535    
536    
537      /**
538       * A border for drawing radio buttons in the Basic look and feel.
539       *
540       * <p><img src="BasicBorders.RadioButtonBorder-1.png" width="300"
541       * height="135" alt="[A screen shot of this border]" />
542       *
543       * <p>Note about the screen shot: Normally, the
544       * <code>borderPainted</code> property is <code>false</code> for
545       * JRadioButtons. For this screen shot, it has been set to
546       * <code>true</code> so the borders get drawn. Also, a
547       * concretization of the Basic look and would typically provide
548       * icons for the various states of radio buttons.
549       *
550       * <p>Note that the focus rectangle is invisible If the radio button
551       * is currently selected. While it might be debatable whether this
552       * makes a lot of sense, this behavior can be observed in the Sun
553       * reference implementation (in JDK 1.3.1 and 1.4.1). The Classpath
554       * implementation tries to exactly replicate the JDK appearance.
555       *
556       * @see javax.swing.plaf.basic.BasicGraphicsUtils#drawBezel
557       *
558       * @author Sascha Brawer (brawer@dandelis.ch)
559       */
560    public static class RadioButtonBorder    public static class RadioButtonBorder
561        extends ButtonBorder
562    {    {
563    } // class RadioButtonBorder      /**
564         * Determined using the <code>serialver</code> tool
565         * of Apple/Sun JDK 1.3.1 on MacOS X 10.1.5.
566         */
567        static final long serialVersionUID = 1596945751743747369L;
568    
569    
570        /**
571         * Constructs a new border for drawing a JRadioButton in
572         * the Basic look and feel.
573         *
574         * @param shadow the shadow color.
575         * @param darkShadow a darker variant of the shadow color.
576         * @param highlight the highlight color.
577         * @param lightHighlight a brighter variant of the highlight  color.
578         */
579        public RadioButtonBorder(Color shadow, Color darkShadow,
580                                 Color highlight, Color lightHighlight)
581        {
582          /* The superclass ButtonBorder substitutes null arguments
583           * with fallback colors.
584           */
585          super(shadow, darkShadow, highlight, lightHighlight);
586        }
587    
588    
589        /**
590         * Paints the RadioButtonBorder around a given component.
591         *
592         * <p>The Sun implementation always seems to draw exactly
593         * the same border, irrespective of the state of the button.
594         * This is rather surprising, but GNU Classpath emulates the
595         * observable behavior.
596         *
597         * @param c the component whose border is to be painted.
598         * @param g the graphics for painting.
599         * @param x the horizontal position for painting the border.
600         * @param y the vertical position for painting the border.
601         * @param width the width of the available area for painting the border.
602         * @param height the height of the available area for painting the border.
603         *
604         * @see javax.swing.plaf.basic.BasicGraphicsUtils#drawBezel
605         */
606        public void paintBorder(Component c, Graphics  g,
607                                int x, int y, int width, int height)
608        {
609          AbstractButton button = null;
610          ButtonModel bmodel = null;
611          boolean lowered = false;
612          boolean focused = false;
613    
614          if (c instanceof AbstractButton)
615          {
616            button = (AbstractButton) c;
617            bmodel = button.getModel();
618          }
619    
620          if (bmodel != null)
621          {
622            lowered = button.isSelected()
623              || (/* mouse inside */ bmodel.isArmed() && bmodel.isPressed());
624            focused = button.hasFocus() && button.isFocusPainted();        
625          }
626    
627          if (lowered)
628            BasicGraphicsUtils.drawLoweredBezel(g, x, y, width, height,
629                                                shadow, darkShadow,
630                                                highlight, lightHighlight);
631          else
632            BasicGraphicsUtils.drawBezel(g, x, y, width, height,
633                                         /* isPressed */ false,
634                                         /* isPefault */ focused,
635                                         shadow, darkShadow,
636                                         highlight, lightHighlight);
637        }
638        
639        
640        /**
641         * Measures the width of this border.
642         *
643         * @param c the component whose border is to be measured.
644         *
645         * @return an Insets object whose <code>left</code>,
646         *         <code>right</code>, <code>top</code> and
647         *         <code>bottom</code> fields indicate the width of the
648         *         border at the respective edge.
649         *
650         * @see #getBorderInsets(java.awt.Component, java.awt.Insets)
651         */
652        public Insets getBorderInsets(Component c)
653        {
654          /* There is no obvious reason for overriding this method, but we
655           * try to have exactly the same API as the Sun reference
656           * implementation.
657           */
658          return getBorderInsets(c, null);
659        }
660    
661        
662        /**
663         * Measures the width of this border, storing the results into a
664         * pre-existing Insets object.
665         *
666         * @param insets an Insets object for holding the result values.
667         *        After invoking this method, the <code>left</code>,
668         *        <code>right</code>, <code>top</code> and
669         *        <code>bottom</code> fields indicate the width of the
670         *        border at the respective edge.
671         *
672         * @return the same object that was passed for <code>insets</code>.
673         *
674         * @see #getBorderInsets()
675         */
676        public Insets getBorderInsets(Component c, Insets insets)
677        {
678          /* The exact amount has been determined using a test program
679           * that was run on the Apple/Sun JDK 1.3.1 on MacOS X, and the
680           * Sun JDK 1.4.1_01 on GNU/Linux for x86. Both gave [2,2,2,2].
681           */
682          if (insets == null)
683            return new Insets(2, 2, 2, 2);
684    
685          insets.left = insets.right = insets.top = insets.bottom = 2;
686          return insets;
687        }
688      }
689    
690    
691    public static class RolloverButtonBorder    public static class RolloverButtonBorder
692    {    {
693    } // class RolloverButtonBorder    } // class RolloverButtonBorder

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26