/[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.2.3 by gnu_andrew, Tue Aug 2 20:12:38 2005 UTC revision 1.1.2.4 by gnu_andrew, Sat Sep 10 15:31:52 2005 UTC
# Line 45  import java.awt.Insets; Line 45  import java.awt.Insets;
45    
46  import javax.swing.AbstractButton;  import javax.swing.AbstractButton;
47  import javax.swing.ButtonModel;  import javax.swing.ButtonModel;
48  import javax.swing.JButton;  import javax.swing.JInternalFrame;
49  import javax.swing.JMenu;  import javax.swing.JMenu;
50  import javax.swing.JMenuBar;  import javax.swing.JMenuBar;
51  import javax.swing.JMenuItem;  import javax.swing.JMenuItem;
52    import javax.swing.JTextField;
53  import javax.swing.border.AbstractBorder;  import javax.swing.border.AbstractBorder;
54  import javax.swing.border.Border;  import javax.swing.border.Border;
55  import javax.swing.plaf.BorderUIResource;  import javax.swing.plaf.BorderUIResource;
56  import javax.swing.plaf.UIResource;  import javax.swing.plaf.UIResource;
 import javax.swing.plaf.basic.BasicGraphicsUtils;  
57  import javax.swing.plaf.basic.BasicBorders;  import javax.swing.plaf.basic.BasicBorders;
58    
59    
60  /**  /**
61   * This factory class creates borders for the different Swing components   * This factory class creates borders for the different Swing components
62   * UI.   * UI.
# Line 71  public class MetalBorders Line 72  public class MetalBorders
72    /** The shared instance for getRolloverButtonBorder(). */    /** The shared instance for getRolloverButtonBorder(). */
73    private static Border toolbarButtonBorder;    private static Border toolbarButtonBorder;
74    
75      /** The shared instance for getTextFieldBorder(). */
76      private static Border textFieldBorder;
77    
78    /**    /**
79     * A MarginBorder that gets shared by multiple components.     * A MarginBorder that gets shared by multiple components.
80     * Created on demand by the private helper function {@link     * Created on demand by the private helper function {@link
# Line 187  public class MetalBorders Line 191  public class MetalBorders
191    }    }
192    
193    /**    /**
194       * A simple 3D border.
195       */
196      public static class Flush3DBorder extends AbstractBorder
197        implements UIResource
198      {
199        /**
200         * Creates a new border instance.
201         */
202        public Flush3DBorder()
203        {
204        }
205        
206        /**
207         * Returns the border insets.
208         *
209         * @param c  the component (ignored).
210         *
211         * @return The border insets.
212         */
213        public Insets getBorderInsets(Component c)
214        {
215          return getBorderInsets(c, null);
216        }
217        
218        /**
219         * Returns the border insets.
220         *
221         * @param c  the component (ignored).
222         * @return The border insets.
223         */
224        public Insets getBorderInsets(Component c, Insets newInsets)
225        {
226          if (newInsets == null)
227            newInsets = new Insets(2, 2, 2, 2);
228          else
229            {
230              newInsets.top = 2;
231              newInsets.left = 2;
232              newInsets.bottom = 2;
233              newInsets.right = 2;
234            }
235          return newInsets;  
236        }
237        
238        /**
239         * Paints the border for the specified component.
240         *
241         * @param c  the component (ignored).
242         * @param g  the graphics device.
243         * @param x  the x-coordinate.
244         * @param y  the y-coordinate.
245         * @param w  the width.
246         * @param h  the height.
247         */
248        public void paintBorder(Component c, Graphics g, int x, int y, int w,
249            int h)
250        {              
251          Color savedColor = g.getColor();
252          g.setColor(MetalLookAndFeel.getControlDarkShadow());
253          g.drawRect(x, y, w - 2, h - 2);
254          g.setColor(MetalLookAndFeel.getControlHighlight());
255          g.drawRect(x + 1, y + 1, w - 2, h - 2);
256          g.setColor(MetalLookAndFeel.getControl());
257          g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
258          g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
259          g.setColor(savedColor);
260        }
261        
262      }
263        
264      /**
265       * A border used for the {@link JTextField} component.
266       */
267      public static class TextFieldBorder extends Flush3DBorder
268        implements UIResource
269      {
270        /**
271         * Creates a new border instance.
272         */
273        public TextFieldBorder()
274        {
275        }
276        
277        /**
278         * Paints the border for the specified component.
279         *
280         * @param c  the component (ignored).
281         * @param g  the graphics device.
282         * @param x  the x-coordinate.
283         * @param y  the y-coordinate.
284         * @param w  the width.
285         * @param h  the height.
286         */
287        public void paintBorder(Component c, Graphics g, int x, int y, int w,
288            int h)
289        {        
290          if (c.isEnabled())
291            super.paintBorder(c, g, x, y, w, h);
292          else
293            {
294              Color savedColor = g.getColor();
295              g.setColor(MetalLookAndFeel.getControlShadow());
296              g.drawRect(x, y, w - 1, h - 1);
297              g.setColor(savedColor);
298            }
299        }
300        
301      }
302    
303      /**
304       * A border used when painting {@link JInternalFrame} instances.
305       */
306      public static class InternalFrameBorder extends AbstractBorder
307        implements UIResource
308      {
309        /**
310         * Creates a new border instance.
311         */
312        public InternalFrameBorder()
313        {
314        }
315        
316        /**
317         * Returns the border insets.
318         *
319         * @param c  the component (ignored).
320         *
321         * @return The border insets.
322         */
323        public Insets getBorderInsets(Component c)
324        {
325          return getBorderInsets(c, null);
326        }
327        
328        /**
329         * Returns the border insets.
330         *
331         * @param c  the component (ignored).
332         * @return The border insets.
333         */
334        public Insets getBorderInsets(Component c, Insets newInsets)
335        {
336          if (newInsets == null)
337            newInsets = new Insets(5, 5, 5, 5);
338          else
339            {
340              newInsets.top = 5;
341              newInsets.left = 5;
342              newInsets.bottom = 5;
343              newInsets.right = 5;
344            }
345          return newInsets;  
346        }
347        
348        /**
349         * Paints the border for the specified component.
350         *
351         * @param c  the component.
352         * @param g  the graphics device.
353         * @param x  the x-coordinate.
354         * @param y  the y-coordinate.
355         * @param w  the width.
356         * @param h  the height.
357         */
358        public void paintBorder(Component c, Graphics g, int x, int y, int w,
359            int h)
360        {
361            
362          JInternalFrame f = (JInternalFrame) c;
363          if (f.isSelected())
364            g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
365          else
366            g.setColor(MetalLookAndFeel.getControlDarkShadow());
367          
368          // fill the border background
369          g.fillRect(x, y, w, 5);
370          g.fillRect(x, y, 5, h);
371          g.fillRect(x + w - 5, y, 5, h);
372          g.fillRect(x, y + h - 5, w, 5);
373          
374          // draw a dot in each corner
375          g.setColor(MetalLookAndFeel.getControl());
376          g.fillRect(x, y, 1, 1);
377          g.fillRect(x + w - 1, y, 1, 1);
378          g.fillRect(x + w - 1, y + h - 1, 1, 1);
379          g.fillRect(x, y + h - 1, 1, 1);
380          
381          // draw the lines
382          g.setColor(MetalLookAndFeel.getBlack());
383          g.drawLine(x + 14, y + 2, x + w - 15, y + 2);
384          g.drawLine(x + 14, y + h - 3, x + w - 15, y + h - 3);
385          g.drawLine(x + 2, y + 14, x + 2, y + h - 15);
386          g.drawLine(x + w - 3, y + 14, x + w - 3, y + h - 15);
387          
388          // draw the line highlights
389          g.setColor(MetalLookAndFeel.getControl());
390          g.drawLine(x + 15, y + 3, x + w - 14, y + 3);
391          g.drawLine(x + 15, y + h - 2, x + w - 14, y + h - 2);
392          g.drawLine(x + 3, y + 15, x + 3, y + h - 14);
393          g.drawLine(x + w - 2, y + 15, x + w - 2, y + h - 14);
394        }
395        
396      }
397    
398      /**
399     * A border used for {@link JMenu} and {@link JMenuItem} components.     * A border used for {@link JMenu} and {@link JMenuItem} components.
400     */     */
401    public static class MenuItemBorder    public static class MenuItemBorder
# Line 578  public class MetalBorders Line 787  public class MetalBorders
787    }    }
788    
789    /**    /**
790       * Returns a border for use by the {@link JTextField} component.
791       *
792       * @return A border.
793       *
794       * @since 1.3
795       */
796      public static Border getTextFieldBorder()
797      {
798        if (textFieldBorder == null)
799          textFieldBorder = new TextFieldBorder();
800        return textFieldBorder;
801      }
802    
803      /**
804     * Returns a border for Toolbar buttons in the Metal Look & Feel.     * Returns a border for Toolbar buttons in the Metal Look & Feel.
805     *     *
806     * @return a border for Toolbar buttons in the Metal Look & Feel     * @return a border for Toolbar buttons in the Metal Look & Feel

Legend:
Removed from v.1.1.2.3  
changed lines
  Added in v.1.1.2.4

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