KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > metal > MetalSeparatorUI


1 /*
2  * @(#)MetalSeparatorUI.java 1.16 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing.plaf.metal;
9
10 import javax.swing.*;
11 import java.awt.Color JavaDoc;
12 import java.awt.Dimension JavaDoc;
13 import java.awt.Graphics JavaDoc;
14 import java.awt.Insets JavaDoc;
15 import java.awt.Rectangle JavaDoc;
16 import javax.swing.plaf.*;
17 import javax.swing.plaf.basic.BasicSeparatorUI JavaDoc;
18
19
20 /**
21  * A Metal L&F implementation of SeparatorUI. This implementation
22  * is a "combined" view/controller.
23  * <p>
24  * <strong>Warning:</strong>
25  * Serialized objects of this class will not be compatible with
26  * future Swing releases. The current serialization support is
27  * appropriate for short term storage or RMI between applications running
28  * the same version of Swing. As of 1.4, support for long term storage
29  * of all JavaBeans<sup><font size="-2">TM</font></sup>
30  * has been added to the <code>java.beans</code> package.
31  * Please see {@link java.beans.XMLEncoder}.
32  *
33  * @version 1.16 12/19/03
34  * @author Jeff Shapiro
35  */

36
37 public class MetalSeparatorUI extends BasicSeparatorUI JavaDoc
38 {
39     public static ComponentUI createUI( JComponent c )
40     {
41         return new MetalSeparatorUI JavaDoc();
42     }
43
44     protected void installDefaults( JSeparator s )
45     {
46         LookAndFeel.installColors( s, "Separator.background", "Separator.foreground" );
47     }
48
49     public void paint( Graphics JavaDoc g, JComponent c )
50     {
51         Dimension JavaDoc s = c.getSize();
52
53     if ( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL )
54     {
55       g.setColor( c.getForeground() );
56       g.drawLine( 0, 0, 0, s.height );
57
58       g.setColor( c.getBackground() );
59       g.drawLine( 1, 0, 1, s.height );
60     }
61     else // HORIZONTAL
62
{
63       g.setColor( c.getForeground() );
64       g.drawLine( 0, 0, s.width, 0 );
65
66       g.setColor( c.getBackground() );
67       g.drawLine( 0, 1, s.width, 1 );
68     }
69     }
70
71     public Dimension JavaDoc getPreferredSize( JComponent c )
72     {
73     if ( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL )
74         return new Dimension JavaDoc( 2, 0 );
75     else
76         return new Dimension JavaDoc( 0, 2 );
77     }
78 }
79
80
81
82
83
Popular Tags