author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 5506 | 202f599c92aa |
child 20168 | 137788883a22 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.swing.plaf.synth; |
|
27 |
||
28 |
import java.beans.*; |
|
29 |
import javax.swing.*; |
|
30 |
import javax.swing.plaf.*; |
|
31 |
import java.awt.*; |
|
32 |
||
33 |
||
34 |
/** |
|
4394 | 35 |
* Provides the Synth L&F UI delegate for |
36 |
* {@link javax.swing.JViewport}. |
|
2 | 37 |
* |
4394 | 38 |
* @since 1.7 |
2 | 39 |
*/ |
4394 | 40 |
public class SynthViewportUI extends ViewportUI |
41 |
implements PropertyChangeListener, SynthUI { |
|
2 | 42 |
private SynthStyle style; |
43 |
||
4394 | 44 |
/** |
45 |
* Creates a new UI object for the given component. |
|
46 |
* |
|
47 |
* @param c component to create UI object for |
|
48 |
* @return the UI object |
|
49 |
*/ |
|
2 | 50 |
public static ComponentUI createUI(JComponent c) { |
51 |
return new SynthViewportUI(); |
|
52 |
} |
|
53 |
||
4394 | 54 |
/** |
55 |
* @inheritDoc |
|
56 |
*/ |
|
57 |
@Override |
|
2 | 58 |
public void installUI(JComponent c) { |
59 |
super.installUI(c); |
|
60 |
installDefaults(c); |
|
61 |
installListeners(c); |
|
62 |
} |
|
63 |
||
4394 | 64 |
/** |
65 |
* @inheritDoc |
|
66 |
*/ |
|
67 |
@Override |
|
2 | 68 |
public void uninstallUI(JComponent c) { |
69 |
super.uninstallUI(c); |
|
70 |
uninstallListeners(c); |
|
71 |
uninstallDefaults(c); |
|
72 |
} |
|
73 |
||
4394 | 74 |
/** |
75 |
* Installs defaults for a viewport. |
|
76 |
* |
|
77 |
* @param c a {@code JViewport} object |
|
78 |
*/ |
|
2 | 79 |
protected void installDefaults(JComponent c) { |
80 |
updateStyle(c); |
|
81 |
} |
|
82 |
||
83 |
private void updateStyle(JComponent c) { |
|
84 |
SynthContext context = getContext(c, ENABLED); |
|
85 |
||
86 |
// Note: JViewport is special cased as it does not allow for |
|
87 |
// a border to be set. JViewport.setBorder is overriden to throw |
|
88 |
// an IllegalArgumentException. Refer to SynthScrollPaneUI for |
|
89 |
// details of this. |
|
90 |
SynthStyle newStyle = SynthLookAndFeel.getStyle(context.getComponent(), |
|
91 |
context.getRegion()); |
|
92 |
SynthStyle oldStyle = context.getStyle(); |
|
93 |
||
94 |
if (newStyle != oldStyle) { |
|
95 |
if (oldStyle != null) { |
|
96 |
oldStyle.uninstallDefaults(context); |
|
97 |
} |
|
98 |
context.setStyle(newStyle); |
|
99 |
newStyle.installDefaults(context); |
|
100 |
} |
|
101 |
this.style = newStyle; |
|
102 |
context.dispose(); |
|
103 |
} |
|
104 |
||
4394 | 105 |
/** |
106 |
* Installs listeners into the viewport. |
|
107 |
* |
|
108 |
* @param c a {@code JViewport} object |
|
109 |
*/ |
|
2 | 110 |
protected void installListeners(JComponent c) { |
111 |
c.addPropertyChangeListener(this); |
|
112 |
} |
|
113 |
||
4394 | 114 |
/** |
115 |
* Uninstalls listeners from the viewport. |
|
116 |
* |
|
117 |
* @param c a {@code JViewport} object |
|
118 |
*/ |
|
2 | 119 |
protected void uninstallListeners(JComponent c) { |
120 |
c.removePropertyChangeListener(this); |
|
121 |
} |
|
122 |
||
4394 | 123 |
/** |
124 |
* Uninstalls defaults from a viewport. |
|
125 |
* |
|
126 |
* @param c a {@code JViewport} object |
|
127 |
*/ |
|
2 | 128 |
protected void uninstallDefaults(JComponent c) { |
129 |
SynthContext context = getContext(c, ENABLED); |
|
130 |
style.uninstallDefaults(context); |
|
131 |
context.dispose(); |
|
132 |
style = null; |
|
133 |
} |
|
134 |
||
4394 | 135 |
/** |
136 |
* @inheritDoc |
|
137 |
*/ |
|
138 |
@Override |
|
2 | 139 |
public SynthContext getContext(JComponent c) { |
4394 | 140 |
return getContext(c, SynthLookAndFeel.getComponentState(c)); |
2 | 141 |
} |
142 |
||
143 |
private SynthContext getContext(JComponent c, int state) { |
|
144 |
return SynthContext.getContext(SynthContext.class, c, |
|
145 |
getRegion(c), style, state); |
|
146 |
} |
|
147 |
||
148 |
private Region getRegion(JComponent c) { |
|
149 |
return SynthLookAndFeel.getRegion(c); |
|
150 |
} |
|
151 |
||
4394 | 152 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
153 |
* Notifies this UI delegate to repaint the specified component. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
154 |
* This method paints the component background, then calls |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
155 |
* the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
156 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
157 |
* <p>In general, this method does not need to be overridden by subclasses. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
158 |
* All Look and Feel rendering code should reside in the {@code paint} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
159 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
160 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
161 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
162 |
* @see #paint(SynthContext,Graphics) |
4394 | 163 |
*/ |
164 |
@Override |
|
2 | 165 |
public void update(Graphics g, JComponent c) { |
166 |
SynthContext context = getContext(c); |
|
167 |
||
168 |
SynthLookAndFeel.update(context, g); |
|
169 |
context.getPainter().paintViewportBackground(context, |
|
170 |
g, 0, 0, c.getWidth(), c.getHeight()); |
|
171 |
paint(context, g); |
|
172 |
context.dispose(); |
|
173 |
} |
|
174 |
||
4394 | 175 |
/** |
4961
782d808b538f
6913758: Specification for SynthViewportUI.paintBorder(...) should mention that this method is never called
rupashka
parents:
4848
diff
changeset
|
176 |
* Paints the border. The method is never called, |
782d808b538f
6913758: Specification for SynthViewportUI.paintBorder(...) should mention that this method is never called
rupashka
parents:
4848
diff
changeset
|
177 |
* because the {@code JViewport} class does not support a border. |
782d808b538f
6913758: Specification for SynthViewportUI.paintBorder(...) should mention that this method is never called
rupashka
parents:
4848
diff
changeset
|
178 |
* This implementation does nothing. |
782d808b538f
6913758: Specification for SynthViewportUI.paintBorder(...) should mention that this method is never called
rupashka
parents:
4848
diff
changeset
|
179 |
* |
782d808b538f
6913758: Specification for SynthViewportUI.paintBorder(...) should mention that this method is never called
rupashka
parents:
4848
diff
changeset
|
180 |
* @param context a component context |
782d808b538f
6913758: Specification for SynthViewportUI.paintBorder(...) should mention that this method is never called
rupashka
parents:
4848
diff
changeset
|
181 |
* @param g the {@code Graphics} to paint on |
782d808b538f
6913758: Specification for SynthViewportUI.paintBorder(...) should mention that this method is never called
rupashka
parents:
4848
diff
changeset
|
182 |
* @param x the X coordinate |
782d808b538f
6913758: Specification for SynthViewportUI.paintBorder(...) should mention that this method is never called
rupashka
parents:
4848
diff
changeset
|
183 |
* @param y the Y coordinate |
782d808b538f
6913758: Specification for SynthViewportUI.paintBorder(...) should mention that this method is never called
rupashka
parents:
4848
diff
changeset
|
184 |
* @param w width of the border |
782d808b538f
6913758: Specification for SynthViewportUI.paintBorder(...) should mention that this method is never called
rupashka
parents:
4848
diff
changeset
|
185 |
* @param h height of the border |
4394 | 186 |
*/ |
187 |
@Override |
|
2 | 188 |
public void paintBorder(SynthContext context, Graphics g, int x, |
189 |
int y, int w, int h) { |
|
190 |
} |
|
191 |
||
4394 | 192 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
193 |
* Paints the specified component according to the Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
194 |
* <p>This method is not used by Synth Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
195 |
* Painting is handled by the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
196 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
197 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
198 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
199 |
* @see #paint(SynthContext,Graphics) |
4394 | 200 |
*/ |
201 |
@Override |
|
2 | 202 |
public void paint(Graphics g, JComponent c) { |
203 |
SynthContext context = getContext(c); |
|
204 |
||
205 |
paint(context, g); |
|
206 |
context.dispose(); |
|
207 |
} |
|
208 |
||
4394 | 209 |
/** |
210 |
* Paints the specified component. This implementation does nothing. |
|
211 |
* |
|
212 |
* @param context context for the component being painted |
|
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
213 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
214 |
* @see #update(Graphics,JComponent) |
4394 | 215 |
*/ |
2 | 216 |
protected void paint(SynthContext context, Graphics g) { |
217 |
} |
|
218 |
||
4394 | 219 |
/** |
220 |
* @inheritDoc |
|
221 |
*/ |
|
222 |
@Override |
|
2 | 223 |
public void propertyChange(PropertyChangeEvent e) { |
224 |
if (SynthLookAndFeel.shouldUpdateStyle(e)) { |
|
225 |
updateStyle((JComponent)e.getSource()); |
|
226 |
} |
|
227 |
} |
|
228 |
} |