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

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

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

revision 1.1.2.2 by gnu_andrew, Tue Aug 2 20:12:38 2005 UTC revision 1.1.2.3 by gnu_andrew, Wed Nov 2 00:44:01 2005 UTC
# Line 38  exception statement from your version. * Line 38  exception statement from your version. *
38    
39  package javax.swing.plaf.metal;  package javax.swing.plaf.metal;
40    
41    import java.awt.Color;
42    import java.awt.Graphics;
43    import java.awt.Rectangle;
44    
45  import javax.swing.JComponent;  import javax.swing.JComponent;
46    import javax.swing.JSeparator;
47    import javax.swing.SwingUtilities;
48    import javax.swing.UIManager;
49  import javax.swing.plaf.ComponentUI;  import javax.swing.plaf.ComponentUI;
50  import javax.swing.plaf.basic.BasicSeparatorUI;  import javax.swing.plaf.basic.BasicSeparatorUI;
51    
52    /**
53     * A UI delegate for the {@link JSeparator} component.
54     */
55  public class MetalSeparatorUI  public class MetalSeparatorUI
56    extends BasicSeparatorUI    extends BasicSeparatorUI
57  {  {
# Line 51  public class MetalSeparatorUI Line 61  public class MetalSeparatorUI
61    private static MetalSeparatorUI instance = null;    private static MetalSeparatorUI instance = null;
62    
63    /**    /**
64     * Constructs a new instance of MetalSeparatorUI.     * Constructs a new instance of <code>MetalSeparatorUI</code>.
65     */     */
66    public MetalSeparatorUI()    public MetalSeparatorUI()
67    {    {
# Line 59  public class MetalSeparatorUI Line 69  public class MetalSeparatorUI
69    }    }
70    
71    /**    /**
72     * Returns an instance of MetalSeparatorUI.     * Returns a shared instance of <code>MetalSeparatorUI</code>.
73     *     *
74     * @param component the component for which we return an UI instance     * @param component the component for which we return an UI instance
75     *     *
76     * @return an instance of MetalSeparatorUI     * @return A shared instance of <code>MetalSeparatorUI</code>.
77     */     */
78    public static ComponentUI createUI(JComponent component)    public static ComponentUI createUI(JComponent component)
79    {    {
# Line 71  public class MetalSeparatorUI Line 81  public class MetalSeparatorUI
81        instance = new MetalSeparatorUI();        instance = new MetalSeparatorUI();
82      return instance;      return instance;
83    }    }
84    
85      /**
86       * The separator is made of two lines. The top line will be
87       * the Metal theme color separatorForeground (or left line if it's vertical).
88       * The bottom or right line will be the Metal theme color
89       * separatorBackground.
90       * The two lines will
91       * be centered inside the bounds box. If the separator is horizontal,
92       * then it will be vertically centered, or if it's vertical, it will
93       * be horizontally centered.
94       *
95       * @param g The Graphics object to paint with
96       * @param c The JComponent to paint.
97       */
98      public void paint(Graphics g, JComponent c)
99      {
100        Rectangle r = new Rectangle();
101        SwingUtilities.calculateInnerArea(c, r);
102        Color saved = g.getColor();
103        Color c1 = UIManager.getColor("Separator.foreground");
104        Color c2 = UIManager.getColor("Separator.background");
105        JSeparator s;
106        if (c instanceof JSeparator)
107          s = (JSeparator) c;
108        else
109          return;
110          
111        if (s.getOrientation() == JSeparator.HORIZONTAL)
112          {    
113            int midAB = r.height / 2;
114            g.setColor(c1);
115            g.drawLine(r.x, r.y + midAB - 1, r.x + r.width, r.y + midAB - 1);
116    
117            g.setColor(c2);
118            g.fillRect(r.x, r.y + midAB, r.x + r.width, r.y + midAB);
119          }
120          else
121          {
122            int midAD = r.height / 2 + r.y;
123            g.setColor(c1);
124            g.drawLine(r.x, r.y, r.x, r.y + r.height);
125    
126            g.setColor(c2);
127            g.fillRect(r.x + midAD, r.y + r.height, r.x + midAD, r.y + r.height);
128          }
129        g.setColor(saved);
130      }
131  }  }

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

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