author | alexsch |
Wed, 18 Nov 2015 19:13:42 +0400 | |
changeset 34407 | 2b40f400a30b |
parent 25859 | 3317bb8137f4 |
child 37698 | 4d798c873df0 |
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 java.awt.*; |
|
29 |
import java.beans.*; |
|
30 |
import javax.swing.*; |
|
31 |
import javax.swing.plaf.*; |
|
32 |
import javax.swing.plaf.basic.*; |
|
33 |
import sun.swing.DefaultLookup; |
|
34 |
||
35 |
/** |
|
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
36 |
* Provides the Synth L&F UI delegate for |
4394 | 37 |
* {@link javax.swing.JOptionPane}. |
2 | 38 |
* |
39 |
* @author James Gosling |
|
40 |
* @author Scott Violet |
|
41 |
* @author Amy Fowler |
|
4394 | 42 |
* @since 1.7 |
2 | 43 |
*/ |
4394 | 44 |
public class SynthOptionPaneUI extends BasicOptionPaneUI implements |
2 | 45 |
PropertyChangeListener, SynthUI { |
46 |
private SynthStyle style; |
|
47 |
||
48 |
/** |
|
4394 | 49 |
* Creates a new UI object for the given component. |
50 |
* |
|
51 |
* @param x component to create UI object for |
|
52 |
* @return the UI object |
|
53 |
*/ |
|
2 | 54 |
public static ComponentUI createUI(JComponent x) { |
55 |
return new SynthOptionPaneUI(); |
|
56 |
} |
|
57 |
||
4394 | 58 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
59 |
* {@inheritDoc} |
4394 | 60 |
*/ |
61 |
@Override |
|
2 | 62 |
protected void installDefaults() { |
63 |
updateStyle(optionPane); |
|
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 |
protected void installListeners() { |
71 |
super.installListeners(); |
|
72 |
optionPane.addPropertyChangeListener(this); |
|
73 |
} |
|
74 |
||
75 |
private void updateStyle(JComponent c) { |
|
76 |
SynthContext context = getContext(c, ENABLED); |
|
77 |
SynthStyle oldStyle = style; |
|
78 |
||
79 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
80 |
if (style != oldStyle) { |
|
81 |
minimumSize = (Dimension)style.get(context, |
|
82 |
"OptionPane.minimumSize"); |
|
83 |
if (minimumSize == null) { |
|
84 |
minimumSize = new Dimension(262, 90); |
|
85 |
} |
|
86 |
if (oldStyle != null) { |
|
87 |
uninstallKeyboardActions(); |
|
88 |
installKeyboardActions(); |
|
89 |
} |
|
90 |
} |
|
91 |
context.dispose(); |
|
92 |
} |
|
93 |
||
4394 | 94 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
95 |
* {@inheritDoc} |
4394 | 96 |
*/ |
97 |
@Override |
|
2 | 98 |
protected void uninstallDefaults() { |
99 |
SynthContext context = getContext(optionPane, ENABLED); |
|
100 |
||
101 |
style.uninstallDefaults(context); |
|
102 |
context.dispose(); |
|
103 |
style = null; |
|
104 |
} |
|
105 |
||
4394 | 106 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
107 |
* {@inheritDoc} |
4394 | 108 |
*/ |
109 |
@Override |
|
2 | 110 |
protected void uninstallListeners() { |
111 |
super.uninstallListeners(); |
|
112 |
optionPane.removePropertyChangeListener(this); |
|
113 |
} |
|
114 |
||
4394 | 115 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
116 |
* {@inheritDoc} |
4394 | 117 |
*/ |
118 |
@Override |
|
2 | 119 |
protected void installComponents() { |
120 |
optionPane.add(createMessageArea()); |
|
121 |
||
122 |
Container separator = createSeparator(); |
|
123 |
if (separator != null) { |
|
124 |
optionPane.add(separator); |
|
125 |
SynthContext context = getContext(optionPane, ENABLED); |
|
126 |
optionPane.add(Box.createVerticalStrut(context.getStyle(). |
|
127 |
getInt(context, "OptionPane.separatorPadding", 6))); |
|
128 |
context.dispose(); |
|
129 |
} |
|
130 |
optionPane.add(createButtonArea()); |
|
131 |
optionPane.applyComponentOrientation(optionPane.getComponentOrientation()); |
|
132 |
} |
|
133 |
||
4394 | 134 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
135 |
* {@inheritDoc} |
4394 | 136 |
*/ |
137 |
@Override |
|
2 | 138 |
public SynthContext getContext(JComponent c) { |
139 |
return getContext(c, getComponentState(c)); |
|
140 |
} |
|
141 |
||
142 |
private SynthContext getContext(JComponent c, int state) { |
|
25100 | 143 |
return SynthContext.getContext(c, style, state); |
2 | 144 |
} |
145 |
||
146 |
private int getComponentState(JComponent c) { |
|
147 |
return SynthLookAndFeel.getComponentState(c); |
|
148 |
} |
|
149 |
||
4394 | 150 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
151 |
* 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
|
152 |
* 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
|
153 |
* 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
|
154 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
155 |
* <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
|
156 |
* 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
|
157 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
158 |
* @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
|
159 |
* @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
|
160 |
* @see #paint(SynthContext,Graphics) |
4394 | 161 |
*/ |
162 |
@Override |
|
2 | 163 |
public void update(Graphics g, JComponent c) { |
164 |
SynthContext context = getContext(c); |
|
165 |
||
166 |
SynthLookAndFeel.update(context, g); |
|
167 |
context.getPainter().paintOptionPaneBackground(context, |
|
168 |
g, 0, 0, c.getWidth(), c.getHeight()); |
|
169 |
paint(context, g); |
|
170 |
context.dispose(); |
|
171 |
} |
|
172 |
||
4394 | 173 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
174 |
* 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
|
175 |
* <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
|
176 |
* 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
|
177 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
178 |
* @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
|
179 |
* @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
|
180 |
* @see #paint(SynthContext,Graphics) |
4394 | 181 |
*/ |
182 |
@Override |
|
2 | 183 |
public void paint(Graphics g, JComponent c) { |
184 |
SynthContext context = getContext(c); |
|
185 |
||
186 |
paint(context, g); |
|
187 |
context.dispose(); |
|
188 |
} |
|
189 |
||
4394 | 190 |
/** |
191 |
* Paints the specified component. This implementation does nothing. |
|
192 |
* |
|
193 |
* @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
|
194 |
* @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
|
195 |
* @see #update(Graphics,JComponent) |
4394 | 196 |
*/ |
2 | 197 |
protected void paint(SynthContext context, Graphics g) { |
198 |
} |
|
199 |
||
4394 | 200 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
201 |
* {@inheritDoc} |
4394 | 202 |
*/ |
203 |
@Override |
|
2 | 204 |
public void paintBorder(SynthContext context, Graphics g, int x, |
205 |
int y, int w, int h) { |
|
206 |
context.getPainter().paintOptionPaneBorder(context, g, x, y, w, h); |
|
207 |
} |
|
208 |
||
4394 | 209 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
210 |
* {@inheritDoc} |
4394 | 211 |
*/ |
212 |
@Override |
|
2 | 213 |
public void propertyChange(PropertyChangeEvent e) { |
214 |
if (SynthLookAndFeel.shouldUpdateStyle(e)) { |
|
215 |
updateStyle((JOptionPane)e.getSource()); |
|
216 |
} |
|
217 |
} |
|
218 |
||
4394 | 219 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
220 |
* {@inheritDoc} |
4394 | 221 |
*/ |
222 |
@Override |
|
2 | 223 |
protected boolean getSizeButtonsToSameWidth() { |
224 |
return DefaultLookup.getBoolean(optionPane, this, |
|
225 |
"OptionPane.sameSizeButtons", true); |
|
226 |
} |
|
227 |
||
228 |
/** |
|
4394 | 229 |
* Called from {@link #installComponents} to create a {@code Container} |
230 |
* containing the body of the message. The icon is the created by calling |
|
231 |
* {@link #addIcon}. |
|
2 | 232 |
*/ |
4394 | 233 |
@Override |
2 | 234 |
protected Container createMessageArea() { |
235 |
JPanel top = new JPanel(); |
|
236 |
top.setName("OptionPane.messageArea"); |
|
237 |
top.setLayout(new BorderLayout()); |
|
238 |
||
239 |
/* Fill the body. */ |
|
240 |
Container body = new JPanel(new GridBagLayout()); |
|
241 |
Container realBody = new JPanel(new BorderLayout()); |
|
242 |
||
243 |
body.setName("OptionPane.body"); |
|
244 |
realBody.setName("OptionPane.realBody"); |
|
245 |
||
246 |
if (getIcon() != null) { |
|
247 |
JPanel sep = new JPanel(); |
|
248 |
sep.setName("OptionPane.separator"); |
|
249 |
sep.setPreferredSize(new Dimension(15, 1)); |
|
250 |
realBody.add(sep, BorderLayout.BEFORE_LINE_BEGINS); |
|
251 |
} |
|
252 |
realBody.add(body, BorderLayout.CENTER); |
|
253 |
||
254 |
GridBagConstraints cons = new GridBagConstraints(); |
|
255 |
cons.gridx = cons.gridy = 0; |
|
256 |
cons.gridwidth = GridBagConstraints.REMAINDER; |
|
257 |
cons.gridheight = 1; |
|
258 |
||
259 |
SynthContext context = getContext(optionPane, ENABLED); |
|
260 |
cons.anchor = context.getStyle().getInt(context, |
|
261 |
"OptionPane.messageAnchor", GridBagConstraints.CENTER); |
|
262 |
context.dispose(); |
|
263 |
||
264 |
cons.insets = new Insets(0,0,3,0); |
|
265 |
||
266 |
addMessageComponents(body, cons, getMessage(), |
|
267 |
getMaxCharactersPerLineCount(), false); |
|
268 |
top.add(realBody, BorderLayout.CENTER); |
|
269 |
||
270 |
addIcon(top); |
|
271 |
return top; |
|
272 |
} |
|
273 |
||
4394 | 274 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
275 |
* {@inheritDoc} |
4394 | 276 |
*/ |
277 |
@Override |
|
2 | 278 |
protected Container createSeparator() { |
279 |
JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL); |
|
280 |
||
281 |
separator.setName("OptionPane.separator"); |
|
282 |
return separator; |
|
283 |
} |
|
284 |
} |