KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > synth > SynthSeparatorUI


1 /*
2  * @(#)SynthSeparatorUI.java 1.14 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.synth;
9
10 import java.beans.*;
11 import javax.swing.*;
12 import java.awt.Dimension JavaDoc;
13 import java.awt.Graphics JavaDoc;
14 import java.awt.Insets JavaDoc;
15 import javax.swing.plaf.ComponentUI JavaDoc;
16 import javax.swing.plaf.SeparatorUI JavaDoc;
17 import javax.swing.plaf.UIResource JavaDoc;
18 import javax.swing.plaf.DimensionUIResource JavaDoc;
19 import sun.swing.plaf.synth.SynthUI;
20
21 /**
22  * A Synth L&F implementation of SeparatorUI. This implementation
23  * is a "combined" view/controller.
24  *
25  * @version 1.14 12/19/03
26  * @author Shannon Hickey
27  * @author Joshua Outwater
28  */

29 class SynthSeparatorUI extends SeparatorUI JavaDoc implements PropertyChangeListener,
30                                     SynthUI {
31     private SynthStyle JavaDoc style;
32
33     public static ComponentUI JavaDoc createUI(JComponent c) {
34         return new SynthSeparatorUI JavaDoc();
35     }
36     
37     public void installUI(JComponent c) {
38         installDefaults((JSeparator)c);
39         installListeners((JSeparator)c);
40     }
41
42     public void uninstallDefaults(JComponent c) {
43         uninstallListeners((JSeparator)c);
44         uninstallDefaults((JSeparator)c);
45     }
46
47     public void installDefaults(JSeparator c) {
48         updateStyle(c);
49     }
50     
51     private void updateStyle(JSeparator sep) {
52         SynthContext JavaDoc context = getContext(sep, ENABLED);
53         SynthStyle JavaDoc oldStyle = style;
54
55         style = SynthLookAndFeel.updateStyle(context, this);
56
57         if (style != oldStyle) {
58             if (sep instanceof JToolBar.Separator) {
59                 Dimension JavaDoc size = ((JToolBar.Separator)sep).getSeparatorSize();
60                 if (size == null || size instanceof UIResource JavaDoc) {
61                     size = (DimensionUIResource JavaDoc)style.get(
62                                       context, "ToolBar.separatorSize");
63                     if (size == null) {
64                         size = new DimensionUIResource JavaDoc(10, 10);
65                     }
66                     ((JToolBar.Separator)sep).setSeparatorSize(size);
67                 }
68             }
69         }
70
71         context.dispose();
72     }
73
74     public void uninstallDefaults(JSeparator c) {
75         SynthContext JavaDoc context = getContext(c, ENABLED);
76
77         style.uninstallDefaults(context);
78         context.dispose();
79         style = null;
80     }
81     
82     public void installListeners(JSeparator c) {
83         c.addPropertyChangeListener(this);
84     }
85     
86     public void uninstallListeners(JSeparator c) {
87         c.removePropertyChangeListener(this);
88     }
89     
90     public void update(Graphics JavaDoc g, JComponent c) {
91         SynthContext JavaDoc context = getContext(c);
92
93         SynthLookAndFeel.update(context, g);
94         context.getPainter().paintSeparatorBackground(context,
95                           g, 0, 0, c.getWidth(), c.getHeight());
96         paint(context, g);
97         context.dispose();
98     }
99
100     public void paint(Graphics JavaDoc g, JComponent c) {
101         SynthContext JavaDoc context = getContext(c);
102
103         paint(context, g);
104         context.dispose();
105     }
106
107     protected void paint(SynthContext JavaDoc context, Graphics JavaDoc g) {
108         JSeparator separator = (JSeparator)context.getComponent();
109         context.getPainter().paintSeparatorForeground(context, g, 0, 0,
110                              separator.getWidth(), separator.getHeight(),
111                              separator.getOrientation());
112     }
113     
114     public void paintBorder(SynthContext JavaDoc context, Graphics JavaDoc g, int x,
115                             int y, int w, int h) {
116         context.getPainter().paintSeparatorBorder(context, g, x, y, w, h);
117     }
118
119     public Dimension JavaDoc getPreferredSize(JComponent c) {
120         SynthContext JavaDoc context = getContext(c);
121
122         int thickness = style.getInt(context, "Separator.thickness", 2);
123         Insets JavaDoc insets = c.getInsets();
124         Dimension JavaDoc size;
125
126         if (((JSeparator)c).getOrientation() == JSeparator.VERTICAL) {
127             size = new Dimension JavaDoc(insets.left + insets.right + thickness,
128                                  insets.top + insets.bottom);
129         } else {
130             size = new Dimension JavaDoc(insets.left + insets.right,
131                                  insets.top + insets.bottom + thickness);
132         }
133         context.dispose();
134         return size;
135     }
136     
137     public Dimension JavaDoc getMinimumSize(JComponent c) {
138         return getPreferredSize(c);
139     }
140     
141     public Dimension JavaDoc getMaximumSize(JComponent c) {
142         return new Dimension JavaDoc(Short.MAX_VALUE, Short.MAX_VALUE);
143     }
144     
145     public SynthContext JavaDoc getContext(JComponent c) {
146         return getContext(c, getComponentState(c));
147     }
148
149     private SynthContext JavaDoc getContext(JComponent c, int state) {
150         return SynthContext.getContext(SynthContext JavaDoc.class, c,
151                     SynthLookAndFeel.getRegion(c), style, state);
152     }
153
154     private Region JavaDoc getRegion(JComponent c) {
155         return SynthLookAndFeel.getRegion(c);
156     }
157
158     private int getComponentState(JComponent c) {
159         return SynthLookAndFeel.getComponentState(c);
160     }
161     
162     public void propertyChange(PropertyChangeEvent evt) {
163         if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
164             updateStyle((JSeparator)evt.getSource());
165         }
166     }
167 }
168
Popular Tags