/[classpath]/classpath/javax/swing/plaf/BorderUIResource.java
ViewVC logotype

Diff of /classpath/javax/swing/plaf/BorderUIResource.java

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

revision 1.7 by mkoch, Mon Jun 9 15:48:11 2003 UTC revision 1.8 by brawer, Tue Jun 17 07:13:48 2003 UTC
# Line 1  Line 1 
1  /* BorderUIResource.java  /* BorderUIResource.java
2     Copyright (C) 1999 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    
# Line 37  exception statement from your version. * Line 37  exception statement from your version. *
37    
38    
39  package javax.swing.plaf;  package javax.swing.plaf;
40    
41  import javax.swing.border.*;  import javax.swing.border.*;
42  import javax.swing.Icon;  import javax.swing.Icon;
43  import java.io.Serializable;  import java.io.Serializable;
# Line 47  import java.awt.Font; Line 48  import java.awt.Font;
48  import java.awt.Color;  import java.awt.Color;
49    
50  /**  /**
51     * A wrapper for {@link javax.swing.border.Border} that also
52     * implements the {@link UIResource} marker interface.  This is useful
53     * for implementing pluggable look-and-feels: When switching the
54     * current LookAndFeel, only those borders are replaced that are
55     * marked as {@link UIResource}.  For this reason, a look-and-feel
56     * should always install borders that implement
57     * <code>UIResource</code>, such as the borders provided by this
58     * class.
59     *
60   * @serial   * @serial
61   * @serialField delegate Border the <code>Border</code> wrapped   * @serialField delegate Border the <code>Border</code> wrapped
62     *
63   * @author Brian Jones   * @author Brian Jones
64     * @author Sascha Brawer
65   */   */
66  public class BorderUIResource  public class BorderUIResource
67      extends Object    extends Object
68      implements Border, UIResource, Serializable    implements Border, UIResource, Serializable
69  {  {
70    static final long serialVersionUID = -3440553684010079691L;    static final long serialVersionUID = -3440553684010079691L;
71    
     private Border delegate;  
   
     /**  
      * Creates a <code>UIResource</code> wrapper for a <code>Border</code>  
      * object.  
      *  
      * @param delegate the border to be wrapped  
      */  
     public BorderUIResource(Border delegate)  
     {  
         this.delegate = delegate;  
     }  
   
     /**  
      */  
     public static Border getEtchedBorderUIResource() {  
         return null;  
     }  
   
     /**  
      */  
     public static Border getLoweredBevelBorderUIResource() {  
         return null;  
     }  
72    
73      /**    /**
74       */     * A shared instance of an {@link EtchedBorderUIResource}, or
75      public static Border getRaisedBevelBorderUIResource() {     * <code>null</code> if the {@link #getEtchedBorderUIResource()}
76          return null;     * method has not yet been called.
77      }     */
78      private static Border etchedBorderUIResource;
79    
80    
81      /**
82       * A shared instance of a {@link BevelBorderUIResource} whose
83       * <code>bevelType</code> is {@link
84       * javax.swing.border.BevelBorder#LOWERED}, or <code>null</code> if
85       * the {@link #getLoweredBevelBorderUIResource()} has not yet been
86       * called.
87       */
88      private static Border loweredBevelBorderUIResource;
89      
90      
91      /**
92       * A shared instance of a {@link BevelBorderUIResource} whose
93       * <code>bevelType</code> is {@link
94       * javax.swing.border.BevelBorder#RAISED}, or <code>null</code> if
95       * the {@link #getRaisedBevelBorderUIResource()} has not yet been
96       * called.
97       */
98      private static Border raisedBevelBorderUIResource;
99      
100      
101      /**
102       * A shared instance of a {@link LineBorderUIResource} for
103       * a one-pixel thick black line, or <code>null</code> if
104       * the {@link #getBlackLineBorderUIResource()} has not yet been
105       * called.
106       */
107      private static Border blackLineBorderUIResource;
108    
109    
110      /**
111       * Returns a shared instance of an etched border which also
112       * is marked as an {@link UIResource}.
113       *
114       * @see javax.swing.border.EtchedBorder
115       */
116      public static Border getEtchedBorderUIResource()
117      {
118        /* Swing is not designed to be thread-safe, so there is no
119         * need to synchronize the access to the global variable.
120         */
121        if (etchedBorderUIResource == null)
122          etchedBorderUIResource = new EtchedBorderUIResource();
123        return etchedBorderUIResource;
124      }
125      
126    
127      /**
128       * Returns a shared instance of {@link BevelBorderUIResource} whose
129       * <code>bevelType</code> is {@link
130       * javax.swing.border.BevelBorder#LOWERED}.
131       *
132       * @see javax.swing.border.BevelBorder
133       */
134      public static Border getLoweredBevelBorderUIResource()
135      {
136        /* Swing is not designed to be thread-safe, so there is no
137         * need to synchronize the access to the global variable.
138         */
139        if (loweredBevelBorderUIResource == null)
140          loweredBevelBorderUIResource = new BevelBorderUIResource(
141            BevelBorder.LOWERED);
142        return loweredBevelBorderUIResource;
143      }
144    
145    
146      /**
147       * Returns a shared instance of {@link BevelBorderUIResource} whose
148       * <code>bevelType</code> is {@link
149       * javax.swing.border.BevelBorder#RAISED}.
150       *
151       * @see javax.swing.border.BevelBorder
152       */
153      public static Border getRaisedBevelBorderUIResource()
154      {
155        /* Swing is not designed to be thread-safe, so there is no
156         * need to synchronize the access to the global variable.
157         */
158        if (raisedBevelBorderUIResource == null)
159          raisedBevelBorderUIResource = new BevelBorderUIResource(
160            BevelBorder.RAISED);
161        return raisedBevelBorderUIResource;
162      }
163      
164      
165      /**
166       * Returns a shared instance of {@link LineBorderUIResource} for
167       * a black, one-pixel width border.
168       *
169       * @see javax.swing.border.LineBorder
170       */
171      public static Border getBlackLineBorderUIResource()
172      {
173        /* Swing is not designed to be thread-safe, so there is no
174         * need to synchronize the access to the global variable.
175         */
176        if (blackLineBorderUIResource == null)
177          blackLineBorderUIResource = new LineBorderUIResource(Color.black);
178        return blackLineBorderUIResource;
179      }
180    
181    
182      /**
183       * The wrapped border.
184       */
185      private Border delegate;
186      
187      
188      /**
189       * Constructs a <code>BorderUIResource</code> for wrapping
190       * a <code>Border</code> object.
191       *
192       * @param delegate the border to be wrapped.
193       */
194      public BorderUIResource(Border delegate)
195      {
196        if (delegate == null)
197          throw new IllegalArgumentException();
198        
199        this.delegate = delegate;
200      }
201    
202      
203      /**
204       * Paints the border around an enclosed component by calling
205       * the <code>paintBorder</code> method of the wrapped delegate.
206       *
207       * @param c the component whose border is to be painted.
208       * @param g the graphics for painting.
209       * @param x the horizontal position for painting the border.
210       * @param y the vertical position for painting the border.
211       * @param width the width of the available area for painting the border.
212       * @param height the height of the available area for painting the border.
213       */
214      public void paintBorder(Component c, Graphics g,
215                              int x, int y, int width, int height)
216      {
217        delegate.paintBorder(c, g, x, y, width, height);
218      }
219      
220      
221      /**
222       * Measures the width of this border by calling the
223       * <code>getBorderInsets</code> method of the wrapped
224       * delegate.
225       *
226       * @param c the component whose border is to be measured.
227       *
228       * @return an Insets object whose <code>left</code>, <code>right</code>,
229       *         <code>top</code> and <code>bottom</code> fields indicate the
230       *         width of the border at the respective edge.
231       */
232      public Insets getBorderInsets(Component c)
233      {
234        return delegate.getBorderInsets(c);
235      }
236      
237      
238      /**
239       * Determines whether this border fills every pixel in its area
240       * when painting by calling the <code>isBorderOpaque</code>
241       * method of the wrapped delegate.
242       *
243       * @return <code>true</code> if the border is fully opaque, or
244       *         <code>false</code> if some pixels of the background
245       *         can shine through the border.
246       */
247      public boolean isBorderOpaque()
248      {
249        return delegate.isBorderOpaque();
250      }
251    
     /**  
      */  
     public static Border getBlackLineBorderUIResource() {  
         return null;  
     }  
   
     /**  
      */  
     public void paintBorder(Component c, Graphics g, int x, int y,  
                             int width, int height) { }  
   
     /**  
      */  
     public Insets getBorderInsets(Component c) {  
         return null;  
     }  
   
     /**  
      */  
     public boolean isBorderOpaque() {  
         return false;  
     }  
252    
253      /**      /**
254       * @serial       * @serial

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

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