KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)SynthViewportUI.java 1.11 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.awt.*;
11 import java.beans.*;
12 import javax.swing.*;
13 import javax.swing.border.*;
14 import javax.swing.plaf.*;
15 import java.awt.*;
16 import java.awt.event.*;
17 import sun.swing.plaf.synth.SynthUI;
18
19
20 /**
21  * Synth's ViewportUI.
22  *
23  * @version 1.11, 12/19/03
24  */

25 class SynthViewportUI extends ViewportUI implements
26            PropertyChangeListener, SynthUI {
27     private SynthStyle JavaDoc style;
28
29     public static ComponentUI createUI(JComponent c) {
30         return new SynthViewportUI JavaDoc();
31     }
32
33     public void installUI(JComponent c) {
34         super.installUI(c);
35         installDefaults(c);
36         installListeners(c);
37     }
38
39     public void uninstallUI(JComponent c) {
40         super.uninstallUI(c);
41         uninstallListeners(c);
42         uninstallDefaults(c);
43     }
44
45     protected void installDefaults(JComponent c) {
46         updateStyle(c);
47     }
48
49     private void updateStyle(JComponent c) {
50         SynthContext JavaDoc context = getContext(c, ENABLED);
51
52         // Note: JViewport is special cased as it does not allow for
53
// a border to be set. JViewport.setBorder is overriden to throw
54
// an IllegalArgumentException. Refer to SynthScrollPaneUI for
55
// details of this.
56
SynthStyle JavaDoc newStyle = SynthLookAndFeel.getStyle(context.getComponent(),
57                                                         context.getRegion());
58         SynthStyle JavaDoc oldStyle = context.getStyle();
59
60         if (newStyle != oldStyle) {
61             if (oldStyle != null) {
62                 oldStyle.uninstallDefaults(context);
63             }
64             context.setStyle(newStyle);
65             newStyle.installDefaults(context);
66         }
67         this.style = newStyle;
68         context.dispose();
69     }
70
71     protected void installListeners(JComponent c) {
72         c.addPropertyChangeListener(this);
73     }
74
75     protected void uninstallListeners(JComponent c) {
76         c.removePropertyChangeListener(this);
77     }
78
79     protected void uninstallDefaults(JComponent c) {
80         SynthContext JavaDoc context = getContext(c, ENABLED);
81         style.uninstallDefaults(context);
82         context.dispose();
83         style = null;
84     }
85
86     public SynthContext JavaDoc getContext(JComponent c) {
87         return getContext(c, getComponentState(c));
88     }
89
90     private SynthContext JavaDoc getContext(JComponent c, int state) {
91         return SynthContext.getContext(SynthContext JavaDoc.class, c,
92                                        getRegion(c), style, state);
93     }
94
95     private Region JavaDoc getRegion(JComponent c) {
96         return SynthLookAndFeel.getRegion(c);
97     }
98
99     private int getComponentState(JComponent c) {
100         return SynthLookAndFeel.getComponentState(c);
101     }
102
103     public void update(Graphics g, JComponent c) {
104         SynthContext JavaDoc context = getContext(c);
105
106         SynthLookAndFeel.update(context, g);
107         context.getPainter().paintViewportBackground(context,
108                           g, 0, 0, c.getWidth(), c.getHeight());
109         paint(context, g);
110         context.dispose();
111     }
112
113     public void paintBorder(SynthContext JavaDoc context, Graphics g, int x,
114                             int y, int w, int h) {
115         // This does nothing on purpose, JViewport doesn't allow a border
116
// and therefor this will NEVER be called.
117
}
118
119     public void paint(Graphics g, JComponent c) {
120         SynthContext JavaDoc context = getContext(c);
121
122         paint(context, g);
123         context.dispose();
124     }
125
126     protected void paint(SynthContext JavaDoc context, Graphics g) {
127     }
128
129     public void propertyChange(PropertyChangeEvent e) {
130         if (SynthLookAndFeel.shouldUpdateStyle(e)) {
131             updateStyle((JComponent)e.getSource());
132         }
133     }
134 }
135
Popular Tags