/[classpath]/classpath/javax/swing/border/CompoundBorder.java
ViewVC logotype

Diff of /classpath/javax/swing/border/CompoundBorder.java

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

revision 1.4 by mkoch, Tue Jun 10 14:34:48 2003 UTC revision 1.5 by brawer, Tue Jun 10 17:21:02 2003 UTC
# Line 1  Line 1 
1  /* CompoundBorder.java --  /* CompoundBorder.java --
2     Copyright (C) 2002 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 42  import java.awt.Component; Line 42  import java.awt.Component;
42  import java.awt.Graphics;  import java.awt.Graphics;
43  import java.awt.Insets;  import java.awt.Insets;
44    
45  public class CompoundBorder extends AbstractBorder  /**
46     * A Border that is composed of an interior and an exterior border,
47     * where the interior border is tightly nested into the exterior.
48     *
49     * @author Sascha Brawer (brawer@dandelis.ch)
50     */
51    public class CompoundBorder
52      extends AbstractBorder
53  {  {
54      /**
55       * The inside border, which is painted between the bordered
56       * Component and the outside border. It is valid for
57       * <code>insideBorder</code> to be <code>null</code>.
58       */
59    protected Border insideBorder;    protected Border insideBorder;
60    
61    
62      /**
63       * The outside border, which is painted outside both the
64       * bordered Component and the inside border. It is valid for
65       * <code>outsideBorder</code> to be <code>null</code>.
66       */
67    protected Border outsideBorder;    protected Border outsideBorder;
68    
69    
70      /**
71       * Constructs a CompoundBorder whose inside and outside borders
72       * are both <code>null</code>. While this does not really make
73       * any sense (there exists a class EmptyBorder as well, and not
74       * every Component needs to have a border at all), the API
75       * specification requires the existence of this constructor.
76       *
77       * @see EmptyBorder
78       */
79    public CompoundBorder ()    public CompoundBorder ()
80    {    {
81      this (null, null);      this (null, null);
82    }    }
83    
84    
85      /**
86       * Constructs a CompoundBorder with the specified inside and
87       * outside borders.
88       *
89       * @param outsideBorder the outside border, which is painted to the
90       *        outside of both <code>insideBorder</code> and the bordered
91       *        compoonent. It is acceptable to pass <code>null</code>, in
92       *        which no outside border is painted.
93       *
94       * @param insideBorder the inside border, which is painted to
95       *        between <code>outsideBorder</code> and the bordered
96       *        component. It is acceptable to pass <code>null</code>, in
97       *        which no intside border is painted.
98       */
99    public CompoundBorder (Border outsideBorder, Border insideBorder)    public CompoundBorder (Border outsideBorder, Border insideBorder)
100    {    {
101      this.outsideBorder = outsideBorder;      this.outsideBorder = outsideBorder;
102      this.insideBorder = insideBorder;      this.insideBorder = insideBorder;
103    }    }
104    
105    
106      /**
107       * Determines whether or not this border is opaque. An opaque
108       * border fills every pixel in its area when painting. Partially
109       * translucent borders must return <code>false</code>, or ugly
110       * artifacts can appear on screen.
111       *
112       * @return <code>true</code> if both the inside and outside borders
113       *         are opaque, or <code>false</code> otherwise.
114       */
115      public boolean isBorderOpaque ()
116      {
117        /* While it would be safe to assume true for the opacity of
118         * a null border, this behavior would not be according to
119         * the API specification. Also, it is pathological to have
120         * null borders anyway.
121         */
122        if ((insideBorder == null) || (outsideBorder == null))
123          return false;
124    
125        return insideBorder.isBorderOpaque()
126          && outsideBorder.isBorderOpaque();
127      }
128            
129      public Insets getBorderInsets(Component  c,  
130                                    Insets s)    /**
131       * Paints the compound border by first painting the outside border,
132       * then painting the inside border tightly nested into the outside.
133       *
134       * @param c the component whose border is to be painted.
135       * @param g the graphics for painting.
136       * @param x the horizontal position for painting the border.
137       * @param y the vertical position for painting the border.
138       * @param width the width of the available area for painting the border.
139       * @param height the height of the available area for painting the border.
140       */
141      public void paintBorder(Component c, Graphics g,
142                              int x, int y, int width, int height)
143      {
144        /* If there is an outside border, paint it and reduce the
145         * boundig box by its insets.
146         */
147        if (outsideBorder != null)
148      {      {
149          if (s == null)        Insets outsideInsets;
150              s = new Insets(0,0,0,0);  
151                  outsideBorder.paintBorder(c, g, x, y, width, height);
152          s.left = s.right = s.top = s.bottom = 5;        outsideInsets = outsideBorder.getBorderInsets(c);
153            
154          return s;        x += outsideInsets.left;
155          y += outsideInsets.top;
156    
157          /* Reduce width and height by the respective extent of the
158           * outside border.
159           */
160          width -= outsideInsets.left + outsideInsets.right;
161          height -= outsideInsets.top + outsideInsets.bottom;
162      }      }
163        
164      public boolean isBorderOpaque()      if (insideBorder != null)
165          insideBorder.paintBorder(c, g, x, y, width, height);
166      }
167    
168    
169      /**
170       * Changes the specified insets to the insets of this border,
171       * which is the sum of the insets of the inside and the outside
172       * border.
173       *
174       * @param c the component in the center of this border.
175       * @param insets an Insets object for holding the added insets.
176       *
177       * @return the <code>insets</code> object.
178       */
179      public Insets getBorderInsets(Component c, Insets insets)
180      {
181        Insets borderInsets;
182    
183        if (insets == null)
184          insets = new Insets (0,0,0,0);
185        else
186          insets.left = insets.right = insets.top = insets.bottom = 0;
187    
188        /* If there is an outside border, add it to insets. */
189        if (outsideBorder != null)
190      {      {
191          return false;        borderInsets = outsideBorder.getBorderInsets(c);
192          insets.left += borderInsets.left;
193          insets.right += borderInsets.right;
194          insets.top += borderInsets.top;
195          insets.bottom += borderInsets.bottom;
196      }      }
197        
198      public void paintBorder(Component  c,      /* If there is an inside border, add it to insets. */
199                              Graphics  g,      if (insideBorder != null)
                             int  x,  
                             int  y,  
                             int  width,  
                             int  height)  
200      {      {
201          borderInsets = insideBorder.getBorderInsets(c);
202          insets.left += borderInsets.left;
203          insets.right += borderInsets.right;
204          insets.top += borderInsets.top;
205          insets.bottom += borderInsets.bottom;
206      }      }
207    
208        return insets;
209      }
210    
211    
212      /**
213       * Determines the insets of this border, which is the sum of the
214       * insets of the inside and the outside border.
215       *
216       * @param c the component in the center of this border.
217       */
218      public Insets getBorderInsets (Component c)
219      {
220        /* It is not clear why CompoundBorder does not simply inherit
221         * the implementation from AbstractBorder. However, we want
222         * to be compatible with the API specification, which overrides
223         * the getBorderInsets(Component) method.
224         */
225        return getBorderInsets (c, null);
226      }
227    
228    
229      /**
230       * Returns the outside border, which is painted outside both the
231       * bordered Component and the inside border. It is valid for the
232       * result to be <code>null</code>.
233       */
234      public Border getOutsideBorder ()
235      {
236        return outsideBorder;
237      }
238    
239    
240      /**
241       * Returns the inside border, which is painted between the bordered
242       * Component and the outside border. It is valid for the result to
243       * be <code>null</code>.
244       */
245      public Border getInsideBorder ()
246      {
247        return insideBorder;
248      }
249  }  }
250    

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

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