author | ohair |
Tue, 25 May 2010 15:58:33 -0700 | |
changeset 5506 | 202f599c92aa |
parent 4848 | ffcc849b9351 |
child 7668 | d4a77089c587 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2002, 2003, 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 javax.swing.*; |
|
29 |
import javax.swing.plaf.*; |
|
30 |
import javax.swing.plaf.basic.BasicPanelUI; |
|
31 |
import java.awt.*; |
|
32 |
import java.beans.*; |
|
33 |
||
34 |
/** |
|
4394 | 35 |
* Provides the Synth L&F UI delegate for |
36 |
* {@link javax.swing.JPanel}. |
|
2 | 37 |
* |
38 |
* @author Steve Wilson |
|
4394 | 39 |
* @since 1.7 |
2 | 40 |
*/ |
4394 | 41 |
public class SynthPanelUI extends BasicPanelUI |
42 |
implements PropertyChangeListener, SynthUI { |
|
2 | 43 |
private SynthStyle style; |
44 |
||
4394 | 45 |
/** |
46 |
* Creates a new UI object for the given component. |
|
47 |
* |
|
48 |
* @param c component to create UI object for |
|
49 |
* @return the UI object |
|
50 |
*/ |
|
2 | 51 |
public static ComponentUI createUI(JComponent c) { |
52 |
return new SynthPanelUI(); |
|
53 |
} |
|
54 |
||
4394 | 55 |
/** |
56 |
* @inheritDoc |
|
57 |
*/ |
|
58 |
@Override |
|
2 | 59 |
public void installUI(JComponent c) { |
60 |
JPanel p = (JPanel)c; |
|
61 |
||
62 |
super.installUI(c); |
|
63 |
installListeners(p); |
|
64 |
} |
|
65 |
||
4394 | 66 |
/** |
67 |
* @inheritDoc |
|
68 |
*/ |
|
69 |
@Override |
|
2 | 70 |
public void uninstallUI(JComponent c) { |
71 |
JPanel p = (JPanel)c; |
|
72 |
||
73 |
uninstallListeners(p); |
|
74 |
super.uninstallUI(c); |
|
75 |
} |
|
76 |
||
4394 | 77 |
/** |
78 |
* Installs listeners into the panel. |
|
79 |
* |
|
80 |
* @param p the {@code JPanel} object |
|
81 |
*/ |
|
2 | 82 |
protected void installListeners(JPanel p) { |
83 |
p.addPropertyChangeListener(this); |
|
84 |
} |
|
85 |
||
4394 | 86 |
/** |
87 |
* Uninstalls listeners from the panel. |
|
88 |
* |
|
89 |
* @param p the {@code JPanel} object |
|
90 |
*/ |
|
2 | 91 |
protected void uninstallListeners(JPanel p) { |
92 |
p.removePropertyChangeListener(this); |
|
93 |
} |
|
94 |
||
4394 | 95 |
/** |
96 |
* @inheritDoc |
|
97 |
*/ |
|
98 |
@Override |
|
2 | 99 |
protected void installDefaults(JPanel p) { |
100 |
updateStyle(p); |
|
101 |
} |
|
102 |
||
4394 | 103 |
/** |
104 |
* @inheritDoc |
|
105 |
*/ |
|
106 |
@Override |
|
2 | 107 |
protected void uninstallDefaults(JPanel p) { |
108 |
SynthContext context = getContext(p, ENABLED); |
|
109 |
||
110 |
style.uninstallDefaults(context); |
|
111 |
context.dispose(); |
|
112 |
style = null; |
|
113 |
} |
|
114 |
||
115 |
private void updateStyle(JPanel c) { |
|
116 |
SynthContext context = getContext(c, ENABLED); |
|
117 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
118 |
context.dispose(); |
|
119 |
} |
|
120 |
||
4394 | 121 |
/** |
122 |
* @inheritDoc |
|
123 |
*/ |
|
124 |
@Override |
|
2 | 125 |
public SynthContext getContext(JComponent c) { |
126 |
return getContext(c, getComponentState(c)); |
|
127 |
} |
|
128 |
||
129 |
private SynthContext getContext(JComponent c, int state) { |
|
130 |
return SynthContext.getContext(SynthContext.class, c, |
|
131 |
SynthLookAndFeel.getRegion(c), style, state); |
|
132 |
} |
|
133 |
||
134 |
private int getComponentState(JComponent c) { |
|
135 |
return SynthLookAndFeel.getComponentState(c); |
|
136 |
} |
|
137 |
||
4394 | 138 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
139 |
* 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
|
140 |
* 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
|
141 |
* 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
|
142 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
143 |
* <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
|
144 |
* 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
|
145 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
146 |
* @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
|
147 |
* @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
|
148 |
* @see #paint(SynthContext,Graphics) |
4394 | 149 |
*/ |
150 |
@Override |
|
2 | 151 |
public void update(Graphics g, JComponent c) { |
152 |
SynthContext context = getContext(c); |
|
153 |
||
154 |
SynthLookAndFeel.update(context, g); |
|
155 |
context.getPainter().paintPanelBackground(context, |
|
156 |
g, 0, 0, c.getWidth(), c.getHeight()); |
|
157 |
paint(context, g); |
|
158 |
context.dispose(); |
|
159 |
} |
|
160 |
||
4394 | 161 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
162 |
* 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
|
163 |
* <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
|
164 |
* 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
|
165 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
166 |
* @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
|
167 |
* @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
|
168 |
* @see #paint(SynthContext,Graphics) |
4394 | 169 |
*/ |
170 |
@Override |
|
2 | 171 |
public void paint(Graphics g, JComponent c) { |
172 |
SynthContext context = getContext(c); |
|
173 |
||
174 |
paint(context, g); |
|
175 |
context.dispose(); |
|
176 |
} |
|
177 |
||
4394 | 178 |
/** |
179 |
* Paints the specified component. This implementation does nothing. |
|
180 |
* |
|
181 |
* @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
|
182 |
* @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
|
183 |
* @see #update(Graphics,JComponent) |
4394 | 184 |
*/ |
2 | 185 |
protected void paint(SynthContext context, Graphics g) { |
186 |
// do actual painting |
|
187 |
} |
|
188 |
||
4394 | 189 |
/** |
190 |
* @inheritDoc |
|
191 |
*/ |
|
192 |
@Override |
|
2 | 193 |
public void paintBorder(SynthContext context, Graphics g, int x, |
194 |
int y, int w, int h) { |
|
195 |
context.getPainter().paintPanelBorder(context, g, x, y, w, h); |
|
196 |
} |
|
197 |
||
4394 | 198 |
/** |
199 |
* @inheritDoc |
|
200 |
*/ |
|
201 |
@Override |
|
2 | 202 |
public void propertyChange(PropertyChangeEvent pce) { |
203 |
if (SynthLookAndFeel.shouldUpdateStyle(pce)) { |
|
204 |
updateStyle((JPanel)pce.getSource()); |
|
205 |
} |
|
206 |
} |
|
207 |
} |