author | alexsch |
Fri, 15 Apr 2016 19:15:12 +0400 | |
changeset 37698 | 4d798c873df0 |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
20168
diff
changeset
|
2 |
* Copyright (c) 2002, 2013, 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 |
/** |
|
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
35 |
* Provides the Synth L&F UI delegate for |
4394 | 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 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
56 |
* {@inheritDoc} |
4394 | 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 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
67 |
* {@inheritDoc} |
4394 | 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 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
96 |
* {@inheritDoc} |
4394 | 97 |
*/ |
98 |
@Override |
|
2 | 99 |
protected void installDefaults(JPanel p) { |
100 |
updateStyle(p); |
|
101 |
} |
|
102 |
||
4394 | 103 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
104 |
* {@inheritDoc} |
4394 | 105 |
*/ |
106 |
@Override |
|
2 | 107 |
protected void uninstallDefaults(JPanel p) { |
108 |
SynthContext context = getContext(p, ENABLED); |
|
109 |
||
110 |
style.uninstallDefaults(context); |
|
111 |
style = null; |
|
112 |
} |
|
113 |
||
114 |
private void updateStyle(JPanel c) { |
|
115 |
SynthContext context = getContext(c, ENABLED); |
|
116 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
117 |
} |
|
118 |
||
4394 | 119 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
120 |
* {@inheritDoc} |
4394 | 121 |
*/ |
122 |
@Override |
|
2 | 123 |
public SynthContext getContext(JComponent c) { |
124 |
return getContext(c, getComponentState(c)); |
|
125 |
} |
|
126 |
||
127 |
private SynthContext getContext(JComponent c, int state) { |
|
25100 | 128 |
return SynthContext.getContext(c, style, state); |
2 | 129 |
} |
130 |
||
131 |
private int getComponentState(JComponent c) { |
|
132 |
return SynthLookAndFeel.getComponentState(c); |
|
133 |
} |
|
134 |
||
4394 | 135 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
136 |
* 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
|
137 |
* 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
|
138 |
* 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
|
139 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
140 |
* <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
|
141 |
* 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
|
142 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
143 |
* @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
|
144 |
* @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
|
145 |
* @see #paint(SynthContext,Graphics) |
4394 | 146 |
*/ |
147 |
@Override |
|
2 | 148 |
public void update(Graphics g, JComponent c) { |
149 |
SynthContext context = getContext(c); |
|
150 |
||
151 |
SynthLookAndFeel.update(context, g); |
|
152 |
context.getPainter().paintPanelBackground(context, |
|
153 |
g, 0, 0, c.getWidth(), c.getHeight()); |
|
154 |
paint(context, g); |
|
155 |
} |
|
156 |
||
4394 | 157 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
158 |
* 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
|
159 |
* <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
|
160 |
* 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
|
161 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
162 |
* @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
|
163 |
* @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
|
164 |
* @see #paint(SynthContext,Graphics) |
4394 | 165 |
*/ |
166 |
@Override |
|
2 | 167 |
public void paint(Graphics g, JComponent c) { |
168 |
SynthContext context = getContext(c); |
|
169 |
||
170 |
paint(context, g); |
|
171 |
} |
|
172 |
||
4394 | 173 |
/** |
174 |
* Paints the specified component. This implementation does nothing. |
|
175 |
* |
|
176 |
* @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
|
177 |
* @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
|
178 |
* @see #update(Graphics,JComponent) |
4394 | 179 |
*/ |
2 | 180 |
protected void paint(SynthContext context, Graphics g) { |
181 |
// do actual painting |
|
182 |
} |
|
183 |
||
4394 | 184 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
185 |
* {@inheritDoc} |
4394 | 186 |
*/ |
187 |
@Override |
|
2 | 188 |
public void paintBorder(SynthContext context, Graphics g, int x, |
189 |
int y, int w, int h) { |
|
190 |
context.getPainter().paintPanelBorder(context, g, x, y, w, h); |
|
191 |
} |
|
192 |
||
4394 | 193 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
194 |
* {@inheritDoc} |
4394 | 195 |
*/ |
196 |
@Override |
|
2 | 197 |
public void propertyChange(PropertyChangeEvent pce) { |
198 |
if (SynthLookAndFeel.shouldUpdateStyle(pce)) { |
|
199 |
updateStyle((JPanel)pce.getSource()); |
|
200 |
} |
|
201 |
} |
|
202 |
} |