/[classpath]/classpath/javax/swing/plaf/metal/MetalBorders.java
ViewVC logotype

Diff of /classpath/javax/swing/plaf/metal/MetalBorders.java

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

revision 1.1 by rabbit78, Fri Apr 15 12:01:01 2005 UTC revision 1.2 by rabbit78, Mon Apr 18 07:45:18 2005 UTC
# Line 61  import javax.swing.plaf.basic.BasicBorde Line 61  import javax.swing.plaf.basic.BasicBorde
61  public class MetalBorders  public class MetalBorders
62  {  {
63    
64      /** The shared instance for getButtonBorder(). */
65      private static Border buttonBorder;
66    
67      /** The shared instance for getRolloverButtonBorder(). */
68      private static Border toolbarButtonBorder;
69    
70    /**    /**
71     * A MarginBorder that gets shared by multiple components.     * A MarginBorder that gets shared by multiple components.
72     * Created on demand by the private helper function {@link     * Created on demand by the private helper function {@link
73     * #getMarginBorder()}.     * #getMarginBorder()}.
74     */     */
75    private static BasicBorders.MarginBorder sharedMarginBorder;    private static BasicBorders.MarginBorder marginBorder;
76    
77    /**    /**
78     * The border that is drawn around Swing buttons.     * The border that is drawn around Swing buttons.
# Line 75  public class MetalBorders Line 81  public class MetalBorders
81      extends AbstractBorder      extends AbstractBorder
82    {    {
83      /** The borders insets. */      /** The borders insets. */
84      protected static Insets borderInsets = new Insets(2, 2, 2, 2);      protected static Insets borderInsets = new Insets(3, 3, 3, 3);
85    
86      /**      /**
87       * Creates a new instance of ButtonBorder.       * Creates a new instance of ButtonBorder.
# Line 166  public class MetalBorders Line 172  public class MetalBorders
172        if (newInsets == null)        if (newInsets == null)
173          newInsets = new Insets(0, 0, 0, 0);          newInsets = new Insets(0, 0, 0, 0);
174    
175          AbstractButton b = (AbstractButton) c;
176          Insets margin = b.getMargin();
177        newInsets.bottom = borderInsets.bottom;        newInsets.bottom = borderInsets.bottom;
178        newInsets.left = borderInsets.left;        newInsets.left = borderInsets.left;
179        newInsets.right = borderInsets.right;        newInsets.right = borderInsets.right;
# Line 174  public class MetalBorders Line 182  public class MetalBorders
182      }      }
183    }    }
184    
185      /**
186       * This border is used in Toolbar buttons as inner border.
187       */
188      static class RolloverMarginBorder extends AbstractBorder
189      {
190        /** The borders insets. */
191        protected static Insets borderInsets = new Insets(3, 3, 3, 3);
192    
193        /**
194         * Creates a new instance of RolloverBorder.
195         */
196        public RolloverMarginBorder()
197        {
198        }
199        
200        /**
201         * Returns the insets of the RolloverBorder.
202         *
203         * @param c the component for which the border is used
204         *
205         * @return the insets of the RolloverBorder
206         */
207        public Insets getBorderInsets(Component c)
208        {
209          return getBorderInsets(c, null);
210        }
211    
212        /**
213         * Returns the insets of the RolloverMarginBorder in the specified
214         * Insets object.
215         *
216         * @param c the component for which the border is used
217         * @param newInsets the insets object where to put the values
218         *
219         * @return the insets of the RolloverMarginBorder
220         */
221        public Insets getBorderInsets(Component c, Insets newInsets)
222        {
223          if (newInsets == null)
224            newInsets = new Insets(0, 0, 0, 0);
225    
226          AbstractButton b = (AbstractButton) c;
227          Insets margin = b.getMargin();
228          newInsets.bottom = borderInsets.bottom;
229          newInsets.left = borderInsets.left;
230          newInsets.right = borderInsets.right;
231          newInsets.top = borderInsets.top;
232          return newInsets;
233        }
234      }
235    
236    /**    /**
237     * Returns a border for Swing buttons in the Metal Look & Feel.     * Returns a border for Swing buttons in the Metal Look & Feel.
# Line 182  public class MetalBorders Line 240  public class MetalBorders
240     */     */
241    public static Border getButtonBorder()    public static Border getButtonBorder()
242    {    {
243      Border outer = new MetalButtonBorder();      if (buttonBorder == null)
244      Border inner = getMarginBorder();        {
245            Border outer = new MetalButtonBorder();
246      return new BorderUIResource.CompoundBorderUIResource(outer, inner);          Border inner = getMarginBorder();
247            buttonBorder = new BorderUIResource.CompoundBorderUIResource
248                (outer, inner);
249          }
250        return buttonBorder;
251    }    }
252    
253    /**    /**
254     * Returns a shared MarginBorder.     * Returns a border for Toolbar buttons in the Metal Look & Feel.
255       *
256       * @return a border for Toolbar buttons in the Metal Look & Feel
257     */     */
258    static Border getMarginBorder()  // intentionally not public    static Border getToolbarButtonBorder()
259    {    {
260      /* Swing is not designed to be thread-safe, so there is no      if (toolbarButtonBorder == null)
261       * need to synchronize the access to the global variable.        {
262       */          Border outer = new MetalButtonBorder();
263      if (sharedMarginBorder == null)          Border inner = new RolloverMarginBorder();
264        sharedMarginBorder = new BasicBorders.MarginBorder();          toolbarButtonBorder = new BorderUIResource.CompoundBorderUIResource
265              (outer, inner);
266      return sharedMarginBorder;        }
267        return toolbarButtonBorder;
268    }    }
269    
270      /**
271       * Returns a shared instance of {@link BasicBorders.MarginBorder}.
272       *
273       * @return a shared instance of {@link BasicBorders.MarginBorder}
274       */
275      static Border getMarginBorder()
276      {
277        if (marginBorder == null)
278          marginBorder = new BasicBorders.MarginBorder();
279        return marginBorder;
280      }
281  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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