author | alexsch |
Fri, 15 Apr 2016 19:15:12 +0400 | |
changeset 37698 | 4d798c873df0 |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
25173
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
2 |
* Copyright (c) 2002, 2014, 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 java.awt.Dimension; |
|
31 |
import java.awt.Graphics; |
|
32 |
import java.awt.Insets; |
|
33 |
import javax.swing.plaf.ComponentUI; |
|
34 |
import javax.swing.plaf.SeparatorUI; |
|
35 |
import javax.swing.plaf.UIResource; |
|
36 |
import javax.swing.plaf.DimensionUIResource; |
|
37 |
||
38 |
/** |
|
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
39 |
* Provides the Synth L&F UI delegate for |
4394 | 40 |
* {@link javax.swing.JSeparator}. |
2 | 41 |
* |
42 |
* @author Shannon Hickey |
|
43 |
* @author Joshua Outwater |
|
4394 | 44 |
* @since 1.7 |
2 | 45 |
*/ |
4394 | 46 |
public class SynthSeparatorUI extends SeparatorUI |
47 |
implements PropertyChangeListener, SynthUI { |
|
2 | 48 |
private SynthStyle style; |
49 |
||
4394 | 50 |
/** |
51 |
* Creates a new UI object for the given component. |
|
52 |
* |
|
53 |
* @param c component to create UI object for |
|
54 |
* @return the UI object |
|
55 |
*/ |
|
2 | 56 |
public static ComponentUI createUI(JComponent c) { |
57 |
return new SynthSeparatorUI(); |
|
58 |
} |
|
59 |
||
4394 | 60 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
61 |
* {@inheritDoc} |
4394 | 62 |
*/ |
63 |
@Override |
|
2 | 64 |
public void installUI(JComponent c) { |
65 |
installDefaults((JSeparator)c); |
|
66 |
installListeners((JSeparator)c); |
|
67 |
} |
|
68 |
||
4394 | 69 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
70 |
* {@inheritDoc} |
4394 | 71 |
*/ |
72 |
@Override |
|
73 |
public void uninstallUI(JComponent c) { |
|
2 | 74 |
uninstallListeners((JSeparator)c); |
75 |
uninstallDefaults((JSeparator)c); |
|
76 |
} |
|
77 |
||
4394 | 78 |
/** |
79 |
* Installs default setting. This method is called when a |
|
80 |
* {@code LookAndFeel} is installed. |
|
25173
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
81 |
* |
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
82 |
* @param c specifies the {@code JSeparator} for the installed |
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
83 |
* {@code LookAndFeel}. |
4394 | 84 |
*/ |
2 | 85 |
public void installDefaults(JSeparator c) { |
86 |
updateStyle(c); |
|
87 |
} |
|
88 |
||
89 |
private void updateStyle(JSeparator sep) { |
|
90 |
SynthContext context = getContext(sep, ENABLED); |
|
91 |
SynthStyle oldStyle = style; |
|
92 |
||
93 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
94 |
||
95 |
if (style != oldStyle) { |
|
96 |
if (sep instanceof JToolBar.Separator) { |
|
97 |
Dimension size = ((JToolBar.Separator)sep).getSeparatorSize(); |
|
98 |
if (size == null || size instanceof UIResource) { |
|
99 |
size = (DimensionUIResource)style.get( |
|
100 |
context, "ToolBar.separatorSize"); |
|
101 |
if (size == null) { |
|
102 |
size = new DimensionUIResource(10, 10); |
|
103 |
} |
|
104 |
((JToolBar.Separator)sep).setSeparatorSize(size); |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
108 |
||
109 |
} |
|
110 |
||
4394 | 111 |
/** |
112 |
* Uninstalls default setting. This method is called when a |
|
113 |
* {@code LookAndFeel} is uninstalled. |
|
25173
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
114 |
* |
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
115 |
* @param c specifies the {@code JSeparator} for the (un)installed |
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
116 |
* {@code LookAndFeel}. |
4394 | 117 |
*/ |
2 | 118 |
public void uninstallDefaults(JSeparator c) { |
119 |
SynthContext context = getContext(c, ENABLED); |
|
120 |
||
121 |
style.uninstallDefaults(context); |
|
122 |
style = null; |
|
123 |
} |
|
124 |
||
4394 | 125 |
/** |
126 |
* Installs listeners. This method is called when a |
|
127 |
* {@code LookAndFeel} is installed. |
|
25173
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
128 |
* |
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
129 |
* @param c specifies the {@code JSeparator} for the installed |
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
130 |
* {@code LookAndFeel}. |
4394 | 131 |
*/ |
2 | 132 |
public void installListeners(JSeparator c) { |
133 |
c.addPropertyChangeListener(this); |
|
134 |
} |
|
135 |
||
4394 | 136 |
/** |
137 |
* Uninstalls listeners. This method is called when a |
|
138 |
* {@code LookAndFeel} is uninstalled. |
|
25173
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
139 |
* |
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
140 |
* @param c specifies the {@code JSeparator} for the (un)installed |
4f093fa54fa1
8044276: Fix doclint warnings (missing javadoc tags) in javax.swing.plaf.synth
yan
parents:
25100
diff
changeset
|
141 |
* {@code LookAndFeel}. |
4394 | 142 |
*/ |
2 | 143 |
public void uninstallListeners(JSeparator c) { |
144 |
c.removePropertyChangeListener(this); |
|
145 |
} |
|
146 |
||
4394 | 147 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
148 |
* 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
|
149 |
* 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
|
150 |
* 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
|
151 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
152 |
* <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
|
153 |
* 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
|
154 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
155 |
* @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
|
156 |
* @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
|
157 |
* @see #paint(SynthContext,Graphics) |
4394 | 158 |
*/ |
159 |
@Override |
|
2 | 160 |
public void update(Graphics g, JComponent c) { |
161 |
SynthContext context = getContext(c); |
|
162 |
||
163 |
JSeparator separator = (JSeparator)context.getComponent(); |
|
164 |
SynthLookAndFeel.update(context, g); |
|
165 |
context.getPainter().paintSeparatorBackground(context, |
|
166 |
g, 0, 0, c.getWidth(), c.getHeight(), |
|
167 |
separator.getOrientation()); |
|
168 |
paint(context, g); |
|
169 |
} |
|
170 |
||
4394 | 171 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
172 |
* 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
|
173 |
* <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
|
174 |
* 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
|
175 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
176 |
* @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
|
177 |
* @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
|
178 |
* @see #paint(SynthContext,Graphics) |
4394 | 179 |
*/ |
180 |
@Override |
|
2 | 181 |
public void paint(Graphics g, JComponent c) { |
182 |
SynthContext context = getContext(c); |
|
183 |
||
184 |
paint(context, g); |
|
185 |
} |
|
186 |
||
4394 | 187 |
/** |
188 |
* Paints the specified component. |
|
189 |
* |
|
190 |
* @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
|
191 |
* @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
|
192 |
* @see #update(Graphics,JComponent) |
4394 | 193 |
*/ |
2 | 194 |
protected void paint(SynthContext context, Graphics g) { |
195 |
JSeparator separator = (JSeparator)context.getComponent(); |
|
196 |
context.getPainter().paintSeparatorForeground(context, g, 0, 0, |
|
197 |
separator.getWidth(), separator.getHeight(), |
|
198 |
separator.getOrientation()); |
|
199 |
} |
|
200 |
||
4394 | 201 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
202 |
* {@inheritDoc} |
4394 | 203 |
*/ |
204 |
@Override |
|
2 | 205 |
public void paintBorder(SynthContext context, Graphics g, int x, |
206 |
int y, int w, int h) { |
|
207 |
JSeparator separator = (JSeparator)context.getComponent(); |
|
208 |
context.getPainter().paintSeparatorBorder(context, g, x, y, w, h, |
|
209 |
separator.getOrientation()); |
|
210 |
} |
|
211 |
||
4394 | 212 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
213 |
* {@inheritDoc} |
4394 | 214 |
*/ |
215 |
@Override |
|
2 | 216 |
public Dimension getPreferredSize(JComponent c) { |
217 |
SynthContext context = getContext(c); |
|
218 |
||
219 |
int thickness = style.getInt(context, "Separator.thickness", 2); |
|
220 |
Insets insets = c.getInsets(); |
|
221 |
Dimension size; |
|
222 |
||
223 |
if (((JSeparator)c).getOrientation() == JSeparator.VERTICAL) { |
|
224 |
size = new Dimension(insets.left + insets.right + thickness, |
|
225 |
insets.top + insets.bottom); |
|
226 |
} else { |
|
227 |
size = new Dimension(insets.left + insets.right, |
|
228 |
insets.top + insets.bottom + thickness); |
|
229 |
} |
|
230 |
return size; |
|
231 |
} |
|
232 |
||
4394 | 233 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
234 |
* {@inheritDoc} |
4394 | 235 |
*/ |
236 |
@Override |
|
2 | 237 |
public Dimension getMinimumSize(JComponent c) { |
238 |
return getPreferredSize(c); |
|
239 |
} |
|
240 |
||
4394 | 241 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
242 |
* {@inheritDoc} |
4394 | 243 |
*/ |
244 |
@Override |
|
2 | 245 |
public Dimension getMaximumSize(JComponent c) { |
246 |
return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); |
|
247 |
} |
|
248 |
||
4394 | 249 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
250 |
* {@inheritDoc} |
4394 | 251 |
*/ |
252 |
@Override |
|
2 | 253 |
public SynthContext getContext(JComponent c) { |
4394 | 254 |
return getContext(c, SynthLookAndFeel.getComponentState(c)); |
2 | 255 |
} |
256 |
||
257 |
private SynthContext getContext(JComponent c, int state) { |
|
25100 | 258 |
return SynthContext.getContext(c, style, state); |
2 | 259 |
} |
260 |
||
261 |
public void propertyChange(PropertyChangeEvent evt) { |
|
262 |
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { |
|
263 |
updateStyle((JSeparator)evt.getSource()); |
|
264 |
} |
|
265 |
} |
|
266 |
} |