author | weijun |
Thu, 11 Dec 2014 15:19:12 +0800 | |
changeset 28228 | be83f404724d |
parent 25859 | 3317bb8137f4 |
child 29249 | 4b9b5be3b7ad |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23697 | 2 |
* Copyright (c) 1997, 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.basic; |
|
27 |
||
28 |
import sun.swing.DefaultLookup; |
|
29 |
import sun.swing.UIAction; |
|
30 |
import javax.swing.border.Border; |
|
31 |
import javax.swing.border.EmptyBorder; |
|
32 |
import javax.swing.*; |
|
33 |
import javax.swing.event.*; |
|
34 |
import javax.swing.plaf.ActionMapUIResource; |
|
35 |
import javax.swing.plaf.ComponentUI; |
|
36 |
import javax.swing.plaf.OptionPaneUI; |
|
37 |
import java.awt.*; |
|
38 |
import java.awt.event.*; |
|
39 |
import java.beans.PropertyChangeEvent; |
|
40 |
import java.beans.PropertyChangeListener; |
|
41 |
import java.util.Locale; |
|
42 |
import java.security.AccessController; |
|
43 |
||
44 |
import sun.security.action.GetPropertyAction; |
|
45 |
||
46 |
||
47 |
/** |
|
48 |
* Provides the basic look and feel for a <code>JOptionPane</code>. |
|
49 |
* <code>BasicMessagePaneUI</code> provides a means to place an icon, |
|
50 |
* message and buttons into a <code>Container</code>. |
|
21982 | 51 |
* Generally, the layout will look like: |
2 | 52 |
* <pre> |
53 |
* ------------------ |
|
54 |
* | i | message | |
|
55 |
* | c | message | |
|
56 |
* | o | message | |
|
57 |
* | n | message | |
|
58 |
* ------------------ |
|
59 |
* | buttons | |
|
60 |
* |________________| |
|
61 |
* </pre> |
|
62 |
* icon is an instance of <code>Icon</code> that is wrapped inside a |
|
63 |
* <code>JLabel</code>. The message is an opaque object and is tested |
|
64 |
* for the following: if the message is a <code>Component</code> it is |
|
65 |
* added to the <code>Container</code>, if it is an <code>Icon</code> |
|
66 |
* it is wrapped inside a <code>JLabel</code> and added to the |
|
67 |
* <code>Container</code> otherwise it is wrapped inside a <code>JLabel</code>. |
|
68 |
* <p> |
|
69 |
* The above layout is used when the option pane's |
|
70 |
* <code>ComponentOrientation</code> property is horizontal, left-to-right. |
|
71 |
* The layout will be adjusted appropriately for other orientations. |
|
72 |
* <p> |
|
73 |
* The <code>Container</code>, message, icon, and buttons are all |
|
74 |
* determined from abstract methods. |
|
75 |
* |
|
76 |
* @author James Gosling |
|
77 |
* @author Scott Violet |
|
78 |
* @author Amy Fowler |
|
79 |
*/ |
|
80 |
public class BasicOptionPaneUI extends OptionPaneUI { |
|
81 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
82 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
83 |
* The mininum width of {@code JOptionPane}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
84 |
*/ |
2 | 85 |
public static final int MinimumWidth = 262; |
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
86 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
87 |
* The mininum height of {@code JOptionPane}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
88 |
*/ |
2 | 89 |
public static final int MinimumHeight = 90; |
90 |
||
91 |
private static String newline; |
|
92 |
||
93 |
/** |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
94 |
* {@code JOptionPane} that the receiver is providing the |
2 | 95 |
* look and feel for. |
96 |
*/ |
|
97 |
protected JOptionPane optionPane; |
|
98 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
99 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
100 |
* The size of {@code JOptionPane}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
101 |
*/ |
2 | 102 |
protected Dimension minimumSize; |
103 |
||
104 |
/** JComponent provide for input if optionPane.getWantsInput() returns |
|
105 |
* true. */ |
|
106 |
protected JComponent inputComponent; |
|
107 |
||
108 |
/** Component to receive focus when messaged with selectInitialValue. */ |
|
109 |
protected Component initialFocusComponent; |
|
110 |
||
111 |
/** This is set to true in validateComponent if a Component is contained |
|
112 |
* in either the message or the buttons. */ |
|
113 |
protected boolean hasCustomComponents; |
|
114 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
115 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
116 |
* The instance of {@code PropertyChangeListener}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
117 |
*/ |
2 | 118 |
protected PropertyChangeListener propertyChangeListener; |
119 |
||
120 |
private Handler handler; |
|
121 |
||
122 |
||
123 |
static { |
|
23307
5e534f20d09a
8035310: The line.separator property can be retrieved via public API
malenkov
parents:
21982
diff
changeset
|
124 |
newline = System.lineSeparator(); |
2 | 125 |
if (newline == null) { |
126 |
newline = "\n"; |
|
127 |
} |
|
128 |
} |
|
129 |
||
130 |
static void loadActionMap(LazyActionMap map) { |
|
131 |
map.put(new Actions(Actions.CLOSE)); |
|
132 |
BasicLookAndFeel.installAudioActionMap(map); |
|
133 |
} |
|
134 |
||
135 |
||
136 |
||
137 |
/** |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
138 |
* Creates a new {@code BasicOptionPaneUI} instance. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
139 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
140 |
* @return a new {@code BasicOptionPaneUI} instance |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
141 |
*/ |
2 | 142 |
public static ComponentUI createUI(JComponent x) { |
143 |
return new BasicOptionPaneUI(); |
|
144 |
} |
|
145 |
||
146 |
/** |
|
20169 | 147 |
* Installs the receiver as the L&F for the passed in |
2 | 148 |
* <code>JOptionPane</code>. |
149 |
*/ |
|
150 |
public void installUI(JComponent c) { |
|
151 |
optionPane = (JOptionPane)c; |
|
152 |
installDefaults(); |
|
153 |
optionPane.setLayout(createLayoutManager()); |
|
154 |
installComponents(); |
|
155 |
installListeners(); |
|
156 |
installKeyboardActions(); |
|
157 |
} |
|
158 |
||
159 |
/** |
|
20169 | 160 |
* Removes the receiver from the L&F controller of the passed in split |
2 | 161 |
* pane. |
162 |
*/ |
|
163 |
public void uninstallUI(JComponent c) { |
|
164 |
uninstallComponents(); |
|
165 |
optionPane.setLayout(null); |
|
166 |
uninstallKeyboardActions(); |
|
167 |
uninstallListeners(); |
|
168 |
uninstallDefaults(); |
|
169 |
optionPane = null; |
|
170 |
} |
|
171 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
172 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
173 |
* Installs default properties. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
174 |
*/ |
2 | 175 |
protected void installDefaults() { |
176 |
LookAndFeel.installColorsAndFont(optionPane, "OptionPane.background", |
|
177 |
"OptionPane.foreground", "OptionPane.font"); |
|
178 |
LookAndFeel.installBorder(optionPane, "OptionPane.border"); |
|
179 |
minimumSize = UIManager.getDimension("OptionPane.minimumSize"); |
|
180 |
LookAndFeel.installProperty(optionPane, "opaque", Boolean.TRUE); |
|
181 |
} |
|
182 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
183 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
184 |
* Uninstalls default properties. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
185 |
*/ |
2 | 186 |
protected void uninstallDefaults() { |
187 |
LookAndFeel.uninstallBorder(optionPane); |
|
188 |
} |
|
189 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
190 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
191 |
* Registers components. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
192 |
*/ |
2 | 193 |
protected void installComponents() { |
194 |
optionPane.add(createMessageArea()); |
|
195 |
||
196 |
Container separator = createSeparator(); |
|
197 |
if (separator != null) { |
|
198 |
optionPane.add(separator); |
|
199 |
} |
|
200 |
optionPane.add(createButtonArea()); |
|
201 |
optionPane.applyComponentOrientation(optionPane.getComponentOrientation()); |
|
202 |
} |
|
203 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
204 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
205 |
* Unregisters components. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
206 |
*/ |
2 | 207 |
protected void uninstallComponents() { |
208 |
hasCustomComponents = false; |
|
209 |
inputComponent = null; |
|
210 |
initialFocusComponent = null; |
|
211 |
optionPane.removeAll(); |
|
212 |
} |
|
213 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
214 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
215 |
* Returns a layout manager. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
216 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
217 |
* @return a layout manager |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
218 |
*/ |
2 | 219 |
protected LayoutManager createLayoutManager() { |
220 |
return new BoxLayout(optionPane, BoxLayout.Y_AXIS); |
|
221 |
} |
|
222 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
223 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
224 |
* Registers listeners. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
225 |
*/ |
2 | 226 |
protected void installListeners() { |
227 |
if ((propertyChangeListener = createPropertyChangeListener()) != null) { |
|
228 |
optionPane.addPropertyChangeListener(propertyChangeListener); |
|
229 |
} |
|
230 |
} |
|
231 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
232 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
233 |
* Unregisters listeners. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
234 |
*/ |
2 | 235 |
protected void uninstallListeners() { |
236 |
if (propertyChangeListener != null) { |
|
237 |
optionPane.removePropertyChangeListener(propertyChangeListener); |
|
238 |
propertyChangeListener = null; |
|
239 |
} |
|
240 |
handler = null; |
|
241 |
} |
|
242 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
243 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
244 |
* Returns an instance of {@code PropertyChangeListener}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
245 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
246 |
* @return an instance of {@code PropertyChangeListener} |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
247 |
*/ |
2 | 248 |
protected PropertyChangeListener createPropertyChangeListener() { |
249 |
return getHandler(); |
|
250 |
} |
|
251 |
||
252 |
private Handler getHandler() { |
|
253 |
if (handler == null) { |
|
254 |
handler = new Handler(); |
|
255 |
} |
|
256 |
return handler; |
|
257 |
} |
|
258 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
259 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
260 |
* Registers keyboard actions. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
261 |
*/ |
2 | 262 |
protected void installKeyboardActions() { |
263 |
InputMap map = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); |
|
264 |
||
265 |
SwingUtilities.replaceUIInputMap(optionPane, JComponent. |
|
266 |
WHEN_IN_FOCUSED_WINDOW, map); |
|
267 |
||
268 |
LazyActionMap.installLazyActionMap(optionPane, BasicOptionPaneUI.class, |
|
269 |
"OptionPane.actionMap"); |
|
270 |
} |
|
271 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
272 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
273 |
* Unregisters keyboard actions. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
274 |
*/ |
2 | 275 |
protected void uninstallKeyboardActions() { |
276 |
SwingUtilities.replaceUIInputMap(optionPane, JComponent. |
|
277 |
WHEN_IN_FOCUSED_WINDOW, null); |
|
278 |
SwingUtilities.replaceUIActionMap(optionPane, null); |
|
279 |
} |
|
280 |
||
281 |
InputMap getInputMap(int condition) { |
|
282 |
if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) { |
|
283 |
Object[] bindings = (Object[])DefaultLookup.get( |
|
284 |
optionPane, this, "OptionPane.windowBindings"); |
|
285 |
if (bindings != null) { |
|
286 |
return LookAndFeel.makeComponentInputMap(optionPane, bindings); |
|
287 |
} |
|
288 |
} |
|
289 |
return null; |
|
290 |
} |
|
291 |
||
292 |
/** |
|
293 |
* Returns the minimum size the option pane should be. Primarily |
|
294 |
* provided for subclassers wishing to offer a different minimum size. |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
295 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
296 |
* @return the minimum size of the option pane |
2 | 297 |
*/ |
298 |
public Dimension getMinimumOptionPaneSize() { |
|
299 |
if (minimumSize == null) { |
|
300 |
return new Dimension(MinimumWidth, MinimumHeight); |
|
301 |
} |
|
302 |
return new Dimension(minimumSize.width, |
|
303 |
minimumSize.height); |
|
304 |
} |
|
305 |
||
306 |
/** |
|
307 |
* If <code>c</code> is the <code>JOptionPane</code> the receiver |
|
308 |
* is contained in, the preferred |
|
309 |
* size that is returned is the maximum of the preferred size of |
|
310 |
* the <code>LayoutManager</code> for the <code>JOptionPane</code>, and |
|
311 |
* <code>getMinimumOptionPaneSize</code>. |
|
312 |
*/ |
|
313 |
public Dimension getPreferredSize(JComponent c) { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
438
diff
changeset
|
314 |
if (c == optionPane) { |
2 | 315 |
Dimension ourMin = getMinimumOptionPaneSize(); |
316 |
LayoutManager lm = c.getLayout(); |
|
317 |
||
318 |
if (lm != null) { |
|
319 |
Dimension lmSize = lm.preferredLayoutSize(c); |
|
320 |
||
321 |
if (ourMin != null) |
|
322 |
return new Dimension |
|
323 |
(Math.max(lmSize.width, ourMin.width), |
|
324 |
Math.max(lmSize.height, ourMin.height)); |
|
325 |
return lmSize; |
|
326 |
} |
|
327 |
return ourMin; |
|
328 |
} |
|
329 |
return null; |
|
330 |
} |
|
331 |
||
332 |
/** |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
333 |
* Messaged from {@code installComponents} to create a {@code Container} |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
334 |
* containing the body of the message. The icon is the created |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
335 |
* by calling {@code addIcon}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
336 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
337 |
* @return a instance of {@code Container} |
2 | 338 |
*/ |
339 |
protected Container createMessageArea() { |
|
340 |
JPanel top = new JPanel(); |
|
341 |
Border topBorder = (Border)DefaultLookup.get(optionPane, this, |
|
342 |
"OptionPane.messageAreaBorder"); |
|
343 |
if (topBorder != null) { |
|
344 |
top.setBorder(topBorder); |
|
345 |
} |
|
346 |
top.setLayout(new BorderLayout()); |
|
347 |
||
348 |
/* Fill the body. */ |
|
349 |
Container body = new JPanel(new GridBagLayout()); |
|
350 |
Container realBody = new JPanel(new BorderLayout()); |
|
351 |
||
352 |
body.setName("OptionPane.body"); |
|
353 |
realBody.setName("OptionPane.realBody"); |
|
354 |
||
355 |
if (getIcon() != null) { |
|
356 |
JPanel sep = new JPanel(); |
|
357 |
sep.setName("OptionPane.separator"); |
|
358 |
sep.setPreferredSize(new Dimension(15, 1)); |
|
359 |
realBody.add(sep, BorderLayout.BEFORE_LINE_BEGINS); |
|
360 |
} |
|
361 |
realBody.add(body, BorderLayout.CENTER); |
|
362 |
||
363 |
GridBagConstraints cons = new GridBagConstraints(); |
|
364 |
cons.gridx = cons.gridy = 0; |
|
365 |
cons.gridwidth = GridBagConstraints.REMAINDER; |
|
366 |
cons.gridheight = 1; |
|
367 |
cons.anchor = DefaultLookup.getInt(optionPane, this, |
|
368 |
"OptionPane.messageAnchor", GridBagConstraints.CENTER); |
|
369 |
cons.insets = new Insets(0,0,3,0); |
|
370 |
||
371 |
addMessageComponents(body, cons, getMessage(), |
|
372 |
getMaxCharactersPerLineCount(), false); |
|
373 |
top.add(realBody, BorderLayout.CENTER); |
|
374 |
||
375 |
addIcon(top); |
|
376 |
return top; |
|
377 |
} |
|
378 |
||
379 |
/** |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
380 |
* Creates the appropriate object to represent {@code msg} and |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
381 |
* places it into {@code container}. If {@code msg} is an instance of |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
382 |
* {@code Component}, it is added directly, if it is an {@code Icon}, |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
383 |
* a {@code JLabel} is created to represent it, otherwise a {@code JLabel} is |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
384 |
* created for the string, if {@code d} is an Object[], this method |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
385 |
* will be recursively invoked for the children. {@code internallyCreated} is |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
386 |
* {@code true} if Objc is an instance of {@code Component} and was created |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
387 |
* internally by this method (this is used to correctly set |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
388 |
* {@code hasCustomComponents} only if {@code internallyCreated} is {@code false}). |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
389 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
390 |
* @param container a container |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
391 |
* @param cons an instance of {@code GridBagConstraints} |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
392 |
* @param msg a message |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
393 |
* @param maxll a maximum length |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
394 |
* @param internallyCreated {@code true} if the component was internally created |
2 | 395 |
*/ |
396 |
protected void addMessageComponents(Container container, |
|
397 |
GridBagConstraints cons, |
|
398 |
Object msg, int maxll, |
|
399 |
boolean internallyCreated) { |
|
400 |
if (msg == null) { |
|
401 |
return; |
|
402 |
} |
|
403 |
if (msg instanceof Component) { |
|
404 |
// To workaround problem where Gridbad will set child |
|
405 |
// to its minimum size if its preferred size will not fit |
|
406 |
// within allocated cells |
|
407 |
if (msg instanceof JScrollPane || msg instanceof JPanel) { |
|
408 |
cons.fill = GridBagConstraints.BOTH; |
|
409 |
cons.weighty = 1; |
|
410 |
} else { |
|
411 |
cons.fill = GridBagConstraints.HORIZONTAL; |
|
412 |
} |
|
413 |
cons.weightx = 1; |
|
414 |
||
415 |
container.add((Component) msg, cons); |
|
416 |
cons.weightx = 0; |
|
417 |
cons.weighty = 0; |
|
418 |
cons.fill = GridBagConstraints.NONE; |
|
419 |
cons.gridy++; |
|
420 |
if (!internallyCreated) { |
|
421 |
hasCustomComponents = true; |
|
422 |
} |
|
423 |
||
424 |
} else if (msg instanceof Object[]) { |
|
425 |
Object [] msgs = (Object[]) msg; |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
438
diff
changeset
|
426 |
for (Object o : msgs) { |
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
438
diff
changeset
|
427 |
addMessageComponents(container, cons, o, maxll, false); |
2 | 428 |
} |
429 |
||
430 |
} else if (msg instanceof Icon) { |
|
431 |
JLabel label = new JLabel( (Icon)msg, SwingConstants.CENTER ); |
|
432 |
configureMessageLabel(label); |
|
433 |
addMessageComponents(container, cons, label, maxll, true); |
|
434 |
||
435 |
} else { |
|
436 |
String s = msg.toString(); |
|
437 |
int len = s.length(); |
|
438 |
if (len <= 0) { |
|
439 |
return; |
|
440 |
} |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
438
diff
changeset
|
441 |
int nl; |
2 | 442 |
int nll = 0; |
443 |
||
444 |
if ((nl = s.indexOf(newline)) >= 0) { |
|
445 |
nll = newline.length(); |
|
446 |
} else if ((nl = s.indexOf("\r\n")) >= 0) { |
|
447 |
nll = 2; |
|
448 |
} else if ((nl = s.indexOf('\n')) >= 0) { |
|
449 |
nll = 1; |
|
450 |
} |
|
451 |
if (nl >= 0) { |
|
452 |
// break up newlines |
|
453 |
if (nl == 0) { |
|
23697 | 454 |
@SuppressWarnings("serial") // anonymous class |
2 | 455 |
JPanel breakPanel = new JPanel() { |
456 |
public Dimension getPreferredSize() { |
|
457 |
Font f = getFont(); |
|
458 |
||
459 |
if (f != null) { |
|
460 |
return new Dimension(1, f.getSize() + 2); |
|
461 |
} |
|
462 |
return new Dimension(0, 0); |
|
463 |
} |
|
464 |
}; |
|
465 |
breakPanel.setName("OptionPane.break"); |
|
466 |
addMessageComponents(container, cons, breakPanel, maxll, |
|
467 |
true); |
|
468 |
} else { |
|
469 |
addMessageComponents(container, cons, s.substring(0, nl), |
|
470 |
maxll, false); |
|
471 |
} |
|
472 |
addMessageComponents(container, cons, s.substring(nl + nll), maxll, |
|
473 |
false); |
|
474 |
||
475 |
} else if (len > maxll) { |
|
476 |
Container c = Box.createVerticalBox(); |
|
477 |
c.setName("OptionPane.verticalBox"); |
|
478 |
burstStringInto(c, s, maxll); |
|
479 |
addMessageComponents(container, cons, c, maxll, true ); |
|
480 |
||
481 |
} else { |
|
482 |
JLabel label; |
|
483 |
label = new JLabel( s, JLabel.LEADING ); |
|
484 |
label.setName("OptionPane.label"); |
|
485 |
configureMessageLabel(label); |
|
486 |
addMessageComponents(container, cons, label, maxll, true); |
|
487 |
} |
|
488 |
} |
|
489 |
} |
|
490 |
||
491 |
/** |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
492 |
* Returns the message to display from the {@code JOptionPane} the receiver is |
2 | 493 |
* providing the look and feel for. |
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
494 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
495 |
* @return the message to display |
2 | 496 |
*/ |
497 |
protected Object getMessage() { |
|
498 |
inputComponent = null; |
|
499 |
if (optionPane != null) { |
|
500 |
if (optionPane.getWantsInput()) { |
|
501 |
/* Create a user component to capture the input. If the |
|
502 |
selectionValues are non null the component and there |
|
503 |
are < 20 values it'll be a combobox, if non null and |
|
504 |
>= 20, it'll be a list, otherwise it'll be a textfield. */ |
|
505 |
Object message = optionPane.getMessage(); |
|
506 |
Object[] sValues = optionPane.getSelectionValues(); |
|
507 |
Object inputValue = optionPane |
|
508 |
.getInitialSelectionValue(); |
|
509 |
JComponent toAdd; |
|
510 |
||
511 |
if (sValues != null) { |
|
512 |
if (sValues.length < 20) { |
|
25565
ce603b34c98d
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents:
23697
diff
changeset
|
513 |
JComboBox<Object> cBox = new JComboBox<>(); |
2 | 514 |
|
515 |
cBox.setName("OptionPane.comboBox"); |
|
516 |
for(int counter = 0, maxCounter = sValues.length; |
|
517 |
counter < maxCounter; counter++) { |
|
518 |
cBox.addItem(sValues[counter]); |
|
519 |
} |
|
520 |
if (inputValue != null) { |
|
521 |
cBox.setSelectedItem(inputValue); |
|
522 |
} |
|
523 |
inputComponent = cBox; |
|
524 |
toAdd = cBox; |
|
525 |
||
526 |
} else { |
|
25565
ce603b34c98d
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents:
23697
diff
changeset
|
527 |
JList<Object> list = new JList<>(sValues); |
2 | 528 |
JScrollPane sp = new JScrollPane(list); |
529 |
||
530 |
sp.setName("OptionPane.scrollPane"); |
|
531 |
list.setName("OptionPane.list"); |
|
532 |
list.setVisibleRowCount(10); |
|
533 |
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
534 |
if(inputValue != null) |
|
535 |
list.setSelectedValue(inputValue, true); |
|
536 |
list.addMouseListener(getHandler()); |
|
537 |
toAdd = sp; |
|
538 |
inputComponent = list; |
|
539 |
} |
|
540 |
||
541 |
} else { |
|
542 |
MultiplexingTextField tf = new MultiplexingTextField(20); |
|
543 |
||
544 |
tf.setName("OptionPane.textField"); |
|
545 |
tf.setKeyStrokes(new KeyStroke[] { |
|
546 |
KeyStroke.getKeyStroke("ENTER") } ); |
|
547 |
if (inputValue != null) { |
|
548 |
String inputString = inputValue.toString(); |
|
549 |
tf.setText(inputString); |
|
550 |
tf.setSelectionStart(0); |
|
551 |
tf.setSelectionEnd(inputString.length()); |
|
552 |
} |
|
553 |
tf.addActionListener(getHandler()); |
|
554 |
toAdd = inputComponent = tf; |
|
555 |
} |
|
556 |
||
557 |
Object[] newMessage; |
|
558 |
||
559 |
if (message == null) { |
|
560 |
newMessage = new Object[1]; |
|
561 |
newMessage[0] = toAdd; |
|
562 |
||
563 |
} else { |
|
564 |
newMessage = new Object[2]; |
|
565 |
newMessage[0] = message; |
|
566 |
newMessage[1] = toAdd; |
|
567 |
} |
|
568 |
return newMessage; |
|
569 |
} |
|
570 |
return optionPane.getMessage(); |
|
571 |
} |
|
572 |
return null; |
|
573 |
} |
|
574 |
||
575 |
/** |
|
576 |
* Creates and adds a JLabel representing the icon returned from |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
577 |
* {@code getIcon} to {@code top}. This is messaged from |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
578 |
* {@code createMessageArea}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
579 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
580 |
* @param top a container |
2 | 581 |
*/ |
582 |
protected void addIcon(Container top) { |
|
583 |
/* Create the icon. */ |
|
584 |
Icon sideIcon = getIcon(); |
|
585 |
||
586 |
if (sideIcon != null) { |
|
587 |
JLabel iconLabel = new JLabel(sideIcon); |
|
588 |
||
589 |
iconLabel.setName("OptionPane.iconLabel"); |
|
590 |
iconLabel.setVerticalAlignment(SwingConstants.TOP); |
|
591 |
top.add(iconLabel, BorderLayout.BEFORE_LINE_BEGINS); |
|
592 |
} |
|
593 |
} |
|
594 |
||
595 |
/** |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
596 |
* Returns the icon from the {@code JOptionPane} the receiver is providing |
2 | 597 |
* the look and feel for, or the default icon as returned from |
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
598 |
* {@code getDefaultIcon}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
599 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
600 |
* @return the icon |
2 | 601 |
*/ |
602 |
protected Icon getIcon() { |
|
603 |
Icon mIcon = (optionPane == null ? null : optionPane.getIcon()); |
|
604 |
||
605 |
if(mIcon == null && optionPane != null) |
|
606 |
mIcon = getIconForType(optionPane.getMessageType()); |
|
607 |
return mIcon; |
|
608 |
} |
|
609 |
||
610 |
/** |
|
611 |
* Returns the icon to use for the passed in type. |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
612 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
613 |
* @param messageType a type of message |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
614 |
* @return the icon to use for the passed in type |
2 | 615 |
*/ |
616 |
protected Icon getIconForType(int messageType) { |
|
617 |
if(messageType < 0 || messageType > 3) |
|
618 |
return null; |
|
619 |
String propertyName = null; |
|
620 |
switch(messageType) { |
|
621 |
case 0: |
|
622 |
propertyName = "OptionPane.errorIcon"; |
|
623 |
break; |
|
624 |
case 1: |
|
625 |
propertyName = "OptionPane.informationIcon"; |
|
626 |
break; |
|
627 |
case 2: |
|
628 |
propertyName = "OptionPane.warningIcon"; |
|
629 |
break; |
|
630 |
case 3: |
|
631 |
propertyName = "OptionPane.questionIcon"; |
|
632 |
break; |
|
633 |
} |
|
634 |
if (propertyName != null) { |
|
635 |
return (Icon)DefaultLookup.get(optionPane, this, propertyName); |
|
636 |
} |
|
637 |
return null; |
|
638 |
} |
|
639 |
||
640 |
/** |
|
641 |
* Returns the maximum number of characters to place on a line. |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
642 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
643 |
* @return the maximum number of characters to place on a line |
2 | 644 |
*/ |
645 |
protected int getMaxCharactersPerLineCount() { |
|
646 |
return optionPane.getMaxCharactersPerLineCount(); |
|
647 |
} |
|
648 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
649 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
650 |
* Recursively creates new {@code JLabel} instances to represent {@code d}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
651 |
* Each {@code JLabel} instance is added to {@code c}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
652 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
653 |
* @param c a container |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
654 |
* @param d a text |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
655 |
* @param maxll a maximum length of a text |
2 | 656 |
*/ |
657 |
protected void burstStringInto(Container c, String d, int maxll) { |
|
658 |
// Primitive line wrapping |
|
659 |
int len = d.length(); |
|
660 |
if (len <= 0) |
|
661 |
return; |
|
662 |
if (len > maxll) { |
|
663 |
int p = d.lastIndexOf(' ', maxll); |
|
664 |
if (p <= 0) |
|
665 |
p = d.indexOf(' ', maxll); |
|
666 |
if (p > 0 && p < len) { |
|
667 |
burstStringInto(c, d.substring(0, p), maxll); |
|
668 |
burstStringInto(c, d.substring(p + 1), maxll); |
|
669 |
return; |
|
670 |
} |
|
671 |
} |
|
672 |
JLabel label = new JLabel(d, JLabel.LEFT); |
|
673 |
label.setName("OptionPane.label"); |
|
674 |
configureMessageLabel(label); |
|
675 |
c.add(label); |
|
676 |
} |
|
677 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
678 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
679 |
* Returns a separator. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
680 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
681 |
* @return a separator |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
682 |
*/ |
2 | 683 |
protected Container createSeparator() { |
684 |
return null; |
|
685 |
} |
|
686 |
||
687 |
/** |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
688 |
* Creates and returns a {@code Container} containing the buttons. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
689 |
* The buttons are created by calling {@code getButtons}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
690 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
691 |
* @return a {@code Container} containing the buttons |
2 | 692 |
*/ |
693 |
protected Container createButtonArea() { |
|
694 |
JPanel bottom = new JPanel(); |
|
695 |
Border border = (Border)DefaultLookup.get(optionPane, this, |
|
696 |
"OptionPane.buttonAreaBorder"); |
|
697 |
bottom.setName("OptionPane.buttonArea"); |
|
698 |
if (border != null) { |
|
699 |
bottom.setBorder(border); |
|
700 |
} |
|
701 |
bottom.setLayout(new ButtonAreaLayout( |
|
702 |
DefaultLookup.getBoolean(optionPane, this, |
|
703 |
"OptionPane.sameSizeButtons", true), |
|
704 |
DefaultLookup.getInt(optionPane, this, "OptionPane.buttonPadding", |
|
705 |
6), |
|
706 |
DefaultLookup.getInt(optionPane, this, |
|
707 |
"OptionPane.buttonOrientation", SwingConstants.CENTER), |
|
708 |
DefaultLookup.getBoolean(optionPane, this, "OptionPane.isYesLast", |
|
709 |
false))); |
|
710 |
addButtonComponents(bottom, getButtons(), getInitialValueIndex()); |
|
711 |
return bottom; |
|
712 |
} |
|
713 |
||
714 |
/** |
|
715 |
* Creates the appropriate object to represent each of the objects in |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
716 |
* {@code buttons} and adds it to {@code container}. This |
2 | 717 |
* differs from addMessageComponents in that it will recurse on |
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
718 |
* {@code buttons} and that if button is not a Component |
2 | 719 |
* it will create an instance of JButton. |
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
720 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
721 |
* @param container a container |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
722 |
* @param buttons an array of buttons |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
723 |
* @param initialIndex an initial index |
2 | 724 |
*/ |
725 |
protected void addButtonComponents(Container container, Object[] buttons, |
|
726 |
int initialIndex) { |
|
727 |
if (buttons != null && buttons.length > 0) { |
|
728 |
boolean sizeButtonsToSame = getSizeButtonsToSameWidth(); |
|
729 |
boolean createdAll = true; |
|
730 |
int numButtons = buttons.length; |
|
731 |
JButton[] createdButtons = null; |
|
732 |
int maxWidth = 0; |
|
733 |
||
734 |
if (sizeButtonsToSame) { |
|
735 |
createdButtons = new JButton[numButtons]; |
|
736 |
} |
|
737 |
||
738 |
for(int counter = 0; counter < numButtons; counter++) { |
|
739 |
Object button = buttons[counter]; |
|
740 |
Component newComponent; |
|
741 |
||
742 |
if (button instanceof Component) { |
|
743 |
createdAll = false; |
|
744 |
newComponent = (Component)button; |
|
745 |
container.add(newComponent); |
|
746 |
hasCustomComponents = true; |
|
747 |
||
748 |
} else { |
|
749 |
JButton aButton; |
|
750 |
||
751 |
if (button instanceof ButtonFactory) { |
|
752 |
aButton = ((ButtonFactory)button).createButton(); |
|
753 |
} |
|
754 |
else if (button instanceof Icon) |
|
755 |
aButton = new JButton((Icon)button); |
|
756 |
else |
|
757 |
aButton = new JButton(button.toString()); |
|
758 |
||
759 |
aButton.setName("OptionPane.button"); |
|
760 |
aButton.setMultiClickThreshhold(DefaultLookup.getInt( |
|
761 |
optionPane, this, "OptionPane.buttonClickThreshhold", |
|
762 |
0)); |
|
763 |
configureButton(aButton); |
|
764 |
||
765 |
container.add(aButton); |
|
766 |
||
767 |
ActionListener buttonListener = createButtonActionListener(counter); |
|
768 |
if (buttonListener != null) { |
|
769 |
aButton.addActionListener(buttonListener); |
|
770 |
} |
|
771 |
newComponent = aButton; |
|
772 |
} |
|
773 |
if (sizeButtonsToSame && createdAll && |
|
774 |
(newComponent instanceof JButton)) { |
|
775 |
createdButtons[counter] = (JButton)newComponent; |
|
776 |
maxWidth = Math.max(maxWidth, |
|
777 |
newComponent.getMinimumSize().width); |
|
778 |
} |
|
779 |
if (counter == initialIndex) { |
|
780 |
initialFocusComponent = newComponent; |
|
781 |
if (initialFocusComponent instanceof JButton) { |
|
782 |
JButton defaultB = (JButton)initialFocusComponent; |
|
783 |
defaultB.addHierarchyListener(new HierarchyListener() { |
|
784 |
public void hierarchyChanged(HierarchyEvent e) { |
|
785 |
if ((e.getChangeFlags() & |
|
786 |
HierarchyEvent.PARENT_CHANGED) != 0) { |
|
787 |
JButton defaultButton = (JButton) e.getComponent(); |
|
788 |
JRootPane root = |
|
789 |
SwingUtilities.getRootPane(defaultButton); |
|
790 |
if (root != null) { |
|
791 |
root.setDefaultButton(defaultButton); |
|
792 |
} |
|
793 |
} |
|
794 |
} |
|
795 |
}); |
|
796 |
} |
|
797 |
} |
|
798 |
} |
|
799 |
((ButtonAreaLayout)container.getLayout()). |
|
800 |
setSyncAllWidths((sizeButtonsToSame && createdAll)); |
|
801 |
/* Set the padding, windows seems to use 8 if <= 2 components, |
|
802 |
otherwise 4 is used. It may actually just be the size of the |
|
803 |
buttons is always the same, not sure. */ |
|
804 |
if (DefaultLookup.getBoolean(optionPane, this, |
|
805 |
"OptionPane.setButtonMargin", true) && sizeButtonsToSame && |
|
806 |
createdAll) { |
|
807 |
JButton aButton; |
|
808 |
int padSize; |
|
809 |
||
810 |
padSize = (numButtons <= 2? 8 : 4); |
|
811 |
||
812 |
for(int counter = 0; counter < numButtons; counter++) { |
|
813 |
aButton = createdButtons[counter]; |
|
814 |
aButton.setMargin(new Insets(2, padSize, 2, padSize)); |
|
815 |
} |
|
816 |
} |
|
817 |
} |
|
818 |
} |
|
819 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
820 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
821 |
* Constructs a new instance of a {@code ButtonActionListener}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
822 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
823 |
* @param buttonIndex an index of the button |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
824 |
* @return a new instance of a {@code ButtonActionListener} |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
825 |
*/ |
2 | 826 |
protected ActionListener createButtonActionListener(int buttonIndex) { |
827 |
return new ButtonActionListener(buttonIndex); |
|
828 |
} |
|
829 |
||
830 |
/** |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
831 |
* Returns the buttons to display from the {@code JOptionPane} the receiver is |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
832 |
* providing the look and feel for. If the {@code JOptionPane} has options |
2 | 833 |
* set, they will be provided, otherwise if the optionType is |
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
834 |
* {@code YES_NO_OPTION}, {@code yesNoOptions} is returned, if the type is |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
835 |
* {@code YES_NO_CANCEL_OPTION} {@code yesNoCancelOptions} is returned, otherwise |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
836 |
* {@code defaultButtons} are returned. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
837 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
838 |
* @return the buttons to display from the JOptionPane |
2 | 839 |
*/ |
840 |
protected Object[] getButtons() { |
|
841 |
if (optionPane != null) { |
|
842 |
Object[] suppliedOptions = optionPane.getOptions(); |
|
843 |
||
844 |
if (suppliedOptions == null) { |
|
845 |
Object[] defaultOptions; |
|
846 |
int type = optionPane.getOptionType(); |
|
847 |
Locale l = optionPane.getLocale(); |
|
848 |
int minimumWidth = |
|
849 |
DefaultLookup.getInt(optionPane, this, |
|
850 |
"OptionPane.buttonMinimumWidth",-1); |
|
851 |
if (type == JOptionPane.YES_NO_OPTION) { |
|
852 |
defaultOptions = new ButtonFactory[2]; |
|
853 |
defaultOptions[0] = new ButtonFactory( |
|
854 |
UIManager.getString("OptionPane.yesButtonText", l), |
|
855 |
getMnemonic("OptionPane.yesButtonMnemonic", l), |
|
856 |
(Icon)DefaultLookup.get(optionPane, this, |
|
857 |
"OptionPane.yesIcon"), minimumWidth); |
|
858 |
defaultOptions[1] = new ButtonFactory( |
|
859 |
UIManager.getString("OptionPane.noButtonText", l), |
|
860 |
getMnemonic("OptionPane.noButtonMnemonic", l), |
|
861 |
(Icon)DefaultLookup.get(optionPane, this, |
|
862 |
"OptionPane.noIcon"), minimumWidth); |
|
863 |
} else if (type == JOptionPane.YES_NO_CANCEL_OPTION) { |
|
864 |
defaultOptions = new ButtonFactory[3]; |
|
865 |
defaultOptions[0] = new ButtonFactory( |
|
866 |
UIManager.getString("OptionPane.yesButtonText", l), |
|
867 |
getMnemonic("OptionPane.yesButtonMnemonic", l), |
|
868 |
(Icon)DefaultLookup.get(optionPane, this, |
|
869 |
"OptionPane.yesIcon"), minimumWidth); |
|
870 |
defaultOptions[1] = new ButtonFactory( |
|
871 |
UIManager.getString("OptionPane.noButtonText",l), |
|
872 |
getMnemonic("OptionPane.noButtonMnemonic", l), |
|
873 |
(Icon)DefaultLookup.get(optionPane, this, |
|
874 |
"OptionPane.noIcon"), minimumWidth); |
|
875 |
defaultOptions[2] = new ButtonFactory( |
|
876 |
UIManager.getString("OptionPane.cancelButtonText",l), |
|
877 |
getMnemonic("OptionPane.cancelButtonMnemonic", l), |
|
878 |
(Icon)DefaultLookup.get(optionPane, this, |
|
879 |
"OptionPane.cancelIcon"), minimumWidth); |
|
880 |
} else if (type == JOptionPane.OK_CANCEL_OPTION) { |
|
881 |
defaultOptions = new ButtonFactory[2]; |
|
882 |
defaultOptions[0] = new ButtonFactory( |
|
883 |
UIManager.getString("OptionPane.okButtonText",l), |
|
884 |
getMnemonic("OptionPane.okButtonMnemonic", l), |
|
885 |
(Icon)DefaultLookup.get(optionPane, this, |
|
886 |
"OptionPane.okIcon"), minimumWidth); |
|
887 |
defaultOptions[1] = new ButtonFactory( |
|
888 |
UIManager.getString("OptionPane.cancelButtonText",l), |
|
889 |
getMnemonic("OptionPane.cancelButtonMnemonic", l), |
|
890 |
(Icon)DefaultLookup.get(optionPane, this, |
|
891 |
"OptionPane.cancelIcon"), minimumWidth); |
|
892 |
} else { |
|
893 |
defaultOptions = new ButtonFactory[1]; |
|
894 |
defaultOptions[0] = new ButtonFactory( |
|
895 |
UIManager.getString("OptionPane.okButtonText",l), |
|
896 |
getMnemonic("OptionPane.okButtonMnemonic", l), |
|
897 |
(Icon)DefaultLookup.get(optionPane, this, |
|
898 |
"OptionPane.okIcon"), minimumWidth); |
|
899 |
} |
|
900 |
return defaultOptions; |
|
901 |
||
902 |
} |
|
903 |
return suppliedOptions; |
|
904 |
} |
|
905 |
return null; |
|
906 |
} |
|
907 |
||
908 |
private int getMnemonic(String key, Locale l) { |
|
909 |
String value = (String)UIManager.get(key, l); |
|
910 |
||
911 |
if (value == null) { |
|
912 |
return 0; |
|
913 |
} |
|
914 |
try { |
|
915 |
return Integer.parseInt(value); |
|
916 |
} |
|
917 |
catch (NumberFormatException nfe) { } |
|
918 |
return 0; |
|
919 |
} |
|
920 |
||
921 |
/** |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
922 |
* Returns {@code true}, basic L&F wants all the buttons to have the same |
2 | 923 |
* width. |
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
924 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
925 |
* @return {@code true} if all the buttons should have the same width |
2 | 926 |
*/ |
927 |
protected boolean getSizeButtonsToSameWidth() { |
|
928 |
return true; |
|
929 |
} |
|
930 |
||
931 |
/** |
|
932 |
* Returns the initial index into the buttons to select. The index |
|
933 |
* is calculated from the initial value from the JOptionPane and |
|
934 |
* options of the JOptionPane or 0. |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
935 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
936 |
* @return the initial index into the buttons to select |
2 | 937 |
*/ |
938 |
protected int getInitialValueIndex() { |
|
939 |
if (optionPane != null) { |
|
940 |
Object iv = optionPane.getInitialValue(); |
|
941 |
Object[] options = optionPane.getOptions(); |
|
942 |
||
943 |
if(options == null) { |
|
944 |
return 0; |
|
945 |
} |
|
946 |
else if(iv != null) { |
|
947 |
for(int counter = options.length - 1; counter >= 0; counter--){ |
|
948 |
if(options[counter].equals(iv)) |
|
949 |
return counter; |
|
950 |
} |
|
951 |
} |
|
952 |
} |
|
953 |
return -1; |
|
954 |
} |
|
955 |
||
956 |
/** |
|
957 |
* Sets the input value in the option pane the receiver is providing |
|
958 |
* the look and feel for based on the value in the inputComponent. |
|
959 |
*/ |
|
960 |
protected void resetInputValue() { |
|
961 |
if(inputComponent != null && (inputComponent instanceof JTextField)) { |
|
962 |
optionPane.setInputValue(((JTextField)inputComponent).getText()); |
|
963 |
||
964 |
} else if(inputComponent != null && |
|
965 |
(inputComponent instanceof JComboBox)) { |
|
966 |
optionPane.setInputValue(((JComboBox)inputComponent) |
|
967 |
.getSelectedItem()); |
|
968 |
} else if(inputComponent != null) { |
|
969 |
optionPane.setInputValue(((JList)inputComponent) |
|
970 |
.getSelectedValue()); |
|
971 |
} |
|
972 |
} |
|
973 |
||
974 |
||
975 |
/** |
|
976 |
* If inputComponent is non-null, the focus is requested on that, |
|
977 |
* otherwise request focus on the default value |
|
978 |
*/ |
|
979 |
public void selectInitialValue(JOptionPane op) { |
|
980 |
if (inputComponent != null) |
|
981 |
inputComponent.requestFocus(); |
|
982 |
else { |
|
983 |
if (initialFocusComponent != null) |
|
984 |
initialFocusComponent.requestFocus(); |
|
985 |
||
986 |
if (initialFocusComponent instanceof JButton) { |
|
987 |
JRootPane root = SwingUtilities.getRootPane(initialFocusComponent); |
|
988 |
if (root != null) { |
|
989 |
root.setDefaultButton((JButton)initialFocusComponent); |
|
990 |
} |
|
991 |
} |
|
992 |
} |
|
993 |
} |
|
994 |
||
995 |
/** |
|
996 |
* Returns true if in the last call to validateComponent the message |
|
997 |
* or buttons contained a subclass of Component. |
|
998 |
*/ |
|
999 |
public boolean containsCustomComponents(JOptionPane op) { |
|
1000 |
return hasCustomComponents; |
|
1001 |
} |
|
1002 |
||
1003 |
||
1004 |
/** |
|
1005 |
* <code>ButtonAreaLayout</code> behaves in a similar manner to |
|
1006 |
* <code>FlowLayout</code>. It lays out all components from left to |
|
1007 |
* right. If <code>syncAllWidths</code> is true, the widths of each |
|
1008 |
* component will be set to the largest preferred size width. |
|
1009 |
* |
|
1010 |
* This class should be treated as a "protected" inner class. |
|
9230
c5674561cb9e
6985329: 9 classes in swing.plaf contains words inappropriate for public spec - about some compiler bug
alexp
parents:
5506
diff
changeset
|
1011 |
* Instantiate it only within subclasses of {@code BasicOptionPaneUI}. |
2 | 1012 |
*/ |
1013 |
public static class ButtonAreaLayout implements LayoutManager { |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1014 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1015 |
* The value represents if the width of children should be synchronized. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1016 |
*/ |
2 | 1017 |
protected boolean syncAllWidths; |
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1018 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1019 |
* The padding value. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1020 |
*/ |
2 | 1021 |
protected int padding; |
1022 |
/** If true, children are lumped together in parent. */ |
|
1023 |
protected boolean centersChildren; |
|
1024 |
private int orientation; |
|
1025 |
private boolean reverseButtons; |
|
1026 |
/** |
|
1027 |
* Indicates whether or not centersChildren should be used vs |
|
21278 | 1028 |
* the orientation. This is done for backward compatibility |
2 | 1029 |
* for subclassers. |
1030 |
*/ |
|
1031 |
private boolean useOrientation; |
|
1032 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1033 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1034 |
* Constructs a new instance of {@code ButtonAreaLayout}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1035 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1036 |
* @param syncAllWidths if the width of children should be synchronized |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1037 |
* @param padding the padding value |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1038 |
*/ |
2 | 1039 |
public ButtonAreaLayout(boolean syncAllWidths, int padding) { |
1040 |
this.syncAllWidths = syncAllWidths; |
|
1041 |
this.padding = padding; |
|
1042 |
centersChildren = true; |
|
1043 |
useOrientation = false; |
|
1044 |
} |
|
1045 |
||
1046 |
ButtonAreaLayout(boolean syncAllSizes, int padding, int orientation, |
|
1047 |
boolean reverseButtons) { |
|
1048 |
this(syncAllSizes, padding); |
|
1049 |
useOrientation = true; |
|
1050 |
this.orientation = orientation; |
|
1051 |
this.reverseButtons = reverseButtons; |
|
1052 |
} |
|
1053 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1054 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1055 |
* Sets if the width of children should be synchronized. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1056 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1057 |
* @param newValue if the width of children should be synchronized |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1058 |
*/ |
2 | 1059 |
public void setSyncAllWidths(boolean newValue) { |
1060 |
syncAllWidths = newValue; |
|
1061 |
} |
|
1062 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1063 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1064 |
* Returns if the width of children should be synchronized. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1065 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1066 |
* @return if the width of children should be synchronized |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1067 |
*/ |
2 | 1068 |
public boolean getSyncAllWidths() { |
1069 |
return syncAllWidths; |
|
1070 |
} |
|
1071 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1072 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1073 |
* Sets the padding value. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1074 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1075 |
* @param newPadding the new padding |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1076 |
*/ |
2 | 1077 |
public void setPadding(int newPadding) { |
1078 |
this.padding = newPadding; |
|
1079 |
} |
|
1080 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1081 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1082 |
* Returns the padding. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1083 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1084 |
* @return the padding |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1085 |
*/ |
2 | 1086 |
public int getPadding() { |
1087 |
return padding; |
|
1088 |
} |
|
1089 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1090 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1091 |
* Sets whether or not center children should be used. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1092 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1093 |
* @param newValue a new value |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1094 |
*/ |
2 | 1095 |
public void setCentersChildren(boolean newValue) { |
1096 |
centersChildren = newValue; |
|
1097 |
useOrientation = false; |
|
1098 |
} |
|
1099 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1100 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1101 |
* Returns whether or not center children should be used. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1102 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1103 |
* @return whether or not center children should be used |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1104 |
*/ |
2 | 1105 |
public boolean getCentersChildren() { |
1106 |
return centersChildren; |
|
1107 |
} |
|
1108 |
||
1109 |
private int getOrientation(Container container) { |
|
1110 |
if (!useOrientation) { |
|
1111 |
return SwingConstants.CENTER; |
|
1112 |
} |
|
1113 |
if (container.getComponentOrientation().isLeftToRight()) { |
|
1114 |
return orientation; |
|
1115 |
} |
|
1116 |
switch (orientation) { |
|
1117 |
case SwingConstants.LEFT: |
|
1118 |
return SwingConstants.RIGHT; |
|
1119 |
case SwingConstants.RIGHT: |
|
1120 |
return SwingConstants.LEFT; |
|
1121 |
case SwingConstants.CENTER: |
|
1122 |
return SwingConstants.CENTER; |
|
1123 |
} |
|
1124 |
return SwingConstants.LEFT; |
|
1125 |
} |
|
1126 |
||
1127 |
public void addLayoutComponent(String string, Component comp) { |
|
1128 |
} |
|
1129 |
||
1130 |
public void layoutContainer(Container container) { |
|
1131 |
Component[] children = container.getComponents(); |
|
1132 |
||
1133 |
if(children != null && children.length > 0) { |
|
1134 |
int numChildren = children.length; |
|
1135 |
Insets insets = container.getInsets(); |
|
1136 |
int maxWidth = 0; |
|
1137 |
int maxHeight = 0; |
|
1138 |
int totalButtonWidth = 0; |
|
1139 |
int x = 0; |
|
1140 |
int xOffset = 0; |
|
1141 |
boolean ltr = container.getComponentOrientation(). |
|
1142 |
isLeftToRight(); |
|
1143 |
boolean reverse = (ltr) ? reverseButtons : !reverseButtons; |
|
1144 |
||
1145 |
for(int counter = 0; counter < numChildren; counter++) { |
|
1146 |
Dimension pref = children[counter].getPreferredSize(); |
|
1147 |
maxWidth = Math.max(maxWidth, pref.width); |
|
1148 |
maxHeight = Math.max(maxHeight, pref.height); |
|
1149 |
totalButtonWidth += pref.width; |
|
1150 |
} |
|
1151 |
if (getSyncAllWidths()) { |
|
1152 |
totalButtonWidth = maxWidth * numChildren; |
|
1153 |
} |
|
1154 |
totalButtonWidth += (numChildren - 1) * padding; |
|
1155 |
||
1156 |
switch (getOrientation(container)) { |
|
1157 |
case SwingConstants.LEFT: |
|
1158 |
x = insets.left; |
|
1159 |
break; |
|
1160 |
case SwingConstants.RIGHT: |
|
1161 |
x = container.getWidth() - insets.right - totalButtonWidth; |
|
1162 |
break; |
|
1163 |
case SwingConstants.CENTER: |
|
1164 |
if (getCentersChildren() || numChildren < 2) { |
|
1165 |
x = (container.getWidth() - totalButtonWidth) / 2; |
|
1166 |
} |
|
1167 |
else { |
|
1168 |
x = insets.left; |
|
1169 |
if (getSyncAllWidths()) { |
|
1170 |
xOffset = (container.getWidth() - insets.left - |
|
1171 |
insets.right - totalButtonWidth) / |
|
1172 |
(numChildren - 1) + maxWidth; |
|
1173 |
} |
|
1174 |
else { |
|
1175 |
xOffset = (container.getWidth() - insets.left - |
|
1176 |
insets.right - totalButtonWidth) / |
|
1177 |
(numChildren - 1); |
|
1178 |
} |
|
1179 |
} |
|
1180 |
break; |
|
1181 |
} |
|
1182 |
||
1183 |
for (int counter = 0; counter < numChildren; counter++) { |
|
1184 |
int index = (reverse) ? numChildren - counter - 1 : |
|
1185 |
counter; |
|
1186 |
Dimension pref = children[index].getPreferredSize(); |
|
1187 |
||
1188 |
if (getSyncAllWidths()) { |
|
1189 |
children[index].setBounds(x, insets.top, |
|
1190 |
maxWidth, maxHeight); |
|
1191 |
} |
|
1192 |
else { |
|
1193 |
children[index].setBounds(x, insets.top, pref.width, |
|
1194 |
pref.height); |
|
1195 |
} |
|
1196 |
if (xOffset != 0) { |
|
1197 |
x += xOffset; |
|
1198 |
} |
|
1199 |
else { |
|
1200 |
x += children[index].getWidth() + padding; |
|
1201 |
} |
|
1202 |
} |
|
1203 |
} |
|
1204 |
} |
|
1205 |
||
1206 |
public Dimension minimumLayoutSize(Container c) { |
|
1207 |
if(c != null) { |
|
1208 |
Component[] children = c.getComponents(); |
|
1209 |
||
1210 |
if(children != null && children.length > 0) { |
|
1211 |
Dimension aSize; |
|
1212 |
int numChildren = children.length; |
|
1213 |
int height = 0; |
|
1214 |
Insets cInsets = c.getInsets(); |
|
1215 |
int extraHeight = cInsets.top + cInsets.bottom; |
|
1216 |
int extraWidth = cInsets.left + cInsets.right; |
|
1217 |
||
1218 |
if (syncAllWidths) { |
|
1219 |
int maxWidth = 0; |
|
1220 |
||
1221 |
for(int counter = 0; counter < numChildren; counter++){ |
|
1222 |
aSize = children[counter].getPreferredSize(); |
|
1223 |
height = Math.max(height, aSize.height); |
|
1224 |
maxWidth = Math.max(maxWidth, aSize.width); |
|
1225 |
} |
|
1226 |
return new Dimension(extraWidth + (maxWidth * numChildren) + |
|
1227 |
(numChildren - 1) * padding, |
|
1228 |
extraHeight + height); |
|
1229 |
} |
|
1230 |
else { |
|
1231 |
int totalWidth = 0; |
|
1232 |
||
1233 |
for(int counter = 0; counter < numChildren; counter++){ |
|
1234 |
aSize = children[counter].getPreferredSize(); |
|
1235 |
height = Math.max(height, aSize.height); |
|
1236 |
totalWidth += aSize.width; |
|
1237 |
} |
|
1238 |
totalWidth += ((numChildren - 1) * padding); |
|
1239 |
return new Dimension(extraWidth + totalWidth, extraHeight + height); |
|
1240 |
} |
|
1241 |
} |
|
1242 |
} |
|
1243 |
return new Dimension(0, 0); |
|
1244 |
} |
|
1245 |
||
1246 |
public Dimension preferredLayoutSize(Container c) { |
|
1247 |
return minimumLayoutSize(c); |
|
1248 |
} |
|
1249 |
||
1250 |
public void removeLayoutComponent(Component c) { } |
|
1251 |
} |
|
1252 |
||
1253 |
||
1254 |
/** |
|
1255 |
* This class should be treated as a "protected" inner class. |
|
9230
c5674561cb9e
6985329: 9 classes in swing.plaf contains words inappropriate for public spec - about some compiler bug
alexp
parents:
5506
diff
changeset
|
1256 |
* Instantiate it only within subclasses of {@code BasicOptionPaneUI}. |
2 | 1257 |
*/ |
1258 |
public class PropertyChangeHandler implements PropertyChangeListener { |
|
1259 |
/** |
|
1260 |
* If the source of the PropertyChangeEvent <code>e</code> equals the |
|
1261 |
* optionPane and is one of the ICON_PROPERTY, MESSAGE_PROPERTY, |
|
1262 |
* OPTIONS_PROPERTY or INITIAL_VALUE_PROPERTY, |
|
1263 |
* validateComponent is invoked. |
|
1264 |
*/ |
|
1265 |
public void propertyChange(PropertyChangeEvent e) { |
|
1266 |
getHandler().propertyChange(e); |
|
1267 |
} |
|
1268 |
} |
|
1269 |
||
1270 |
/** |
|
1271 |
* Configures any necessary colors/fonts for the specified label |
|
1272 |
* used representing the message. |
|
1273 |
*/ |
|
1274 |
private void configureMessageLabel(JLabel label) { |
|
1275 |
Color color = (Color)DefaultLookup.get(optionPane, this, |
|
1276 |
"OptionPane.messageForeground"); |
|
1277 |
if (color != null) { |
|
1278 |
label.setForeground(color); |
|
1279 |
} |
|
1280 |
Font messageFont = (Font)DefaultLookup.get(optionPane, this, |
|
1281 |
"OptionPane.messageFont"); |
|
1282 |
if (messageFont != null) { |
|
1283 |
label.setFont(messageFont); |
|
1284 |
} |
|
1285 |
} |
|
1286 |
||
1287 |
/** |
|
1288 |
* Configures any necessary colors/fonts for the specified button |
|
1289 |
* used representing the button portion of the optionpane. |
|
1290 |
*/ |
|
1291 |
private void configureButton(JButton button) { |
|
1292 |
Font buttonFont = (Font)DefaultLookup.get(optionPane, this, |
|
1293 |
"OptionPane.buttonFont"); |
|
1294 |
if (buttonFont != null) { |
|
1295 |
button.setFont(buttonFont); |
|
1296 |
} |
|
1297 |
} |
|
1298 |
||
1299 |
/** |
|
1300 |
* This class should be treated as a "protected" inner class. |
|
9230
c5674561cb9e
6985329: 9 classes in swing.plaf contains words inappropriate for public spec - about some compiler bug
alexp
parents:
5506
diff
changeset
|
1301 |
* Instantiate it only within subclasses of {@code BasicOptionPaneUI}. |
2 | 1302 |
*/ |
1303 |
public class ButtonActionListener implements ActionListener { |
|
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1304 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1305 |
* The index of the button. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1306 |
*/ |
2 | 1307 |
protected int buttonIndex; |
1308 |
||
25772
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1309 |
/** |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1310 |
* Constructs a new instance of {@code ButtonActionListener}. |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1311 |
* |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1312 |
* @param buttonIndex an index of the button |
73e0efa29d55
8049870: Fix doclint warnings from javax.swing.plaf.basic package, 4 of 7
aeremeev
parents:
25565
diff
changeset
|
1313 |
*/ |
2 | 1314 |
public ButtonActionListener(int buttonIndex) { |
1315 |
this.buttonIndex = buttonIndex; |
|
1316 |
} |
|
1317 |
||
1318 |
public void actionPerformed(ActionEvent e) { |
|
1319 |
if (optionPane != null) { |
|
1320 |
int optionType = optionPane.getOptionType(); |
|
1321 |
Object[] options = optionPane.getOptions(); |
|
1322 |
||
1323 |
/* If the option pane takes input, then store the input value |
|
1324 |
* if custom options were specified, if the option type is |
|
1325 |
* DEFAULT_OPTION, OR if option type is set to a predefined |
|
1326 |
* one and the user chose the affirmative answer. |
|
1327 |
*/ |
|
1328 |
if (inputComponent != null) { |
|
1329 |
if (options != null || |
|
1330 |
optionType == JOptionPane.DEFAULT_OPTION || |
|
1331 |
((optionType == JOptionPane.YES_NO_OPTION || |
|
1332 |
optionType == JOptionPane.YES_NO_CANCEL_OPTION || |
|
1333 |
optionType == JOptionPane.OK_CANCEL_OPTION) && |
|
1334 |
buttonIndex == 0)) { |
|
1335 |
resetInputValue(); |
|
1336 |
} |
|
1337 |
} |
|
1338 |
if (options == null) { |
|
1339 |
if (optionType == JOptionPane.OK_CANCEL_OPTION && |
|
1340 |
buttonIndex == 1) { |
|
438
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
1341 |
optionPane.setValue(Integer.valueOf(2)); |
2 | 1342 |
|
1343 |
} else { |
|
438
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
1344 |
optionPane.setValue(Integer.valueOf(buttonIndex)); |
2 | 1345 |
} |
1346 |
} else { |
|
1347 |
optionPane.setValue(options[buttonIndex]); |
|
1348 |
} |
|
1349 |
} |
|
1350 |
} |
|
1351 |
} |
|
1352 |
||
1353 |
||
1354 |
private class Handler implements ActionListener, MouseListener, |
|
1355 |
PropertyChangeListener { |
|
1356 |
// |
|
1357 |
// ActionListener |
|
1358 |
// |
|
1359 |
public void actionPerformed(ActionEvent e) { |
|
1360 |
optionPane.setInputValue(((JTextField)e.getSource()).getText()); |
|
1361 |
} |
|
1362 |
||
1363 |
||
1364 |
// |
|
1365 |
// MouseListener |
|
1366 |
// |
|
1367 |
public void mouseClicked(MouseEvent e) { |
|
1368 |
} |
|
1369 |
||
1370 |
public void mouseReleased(MouseEvent e) { |
|
1371 |
} |
|
1372 |
||
1373 |
public void mouseEntered(MouseEvent e) { |
|
1374 |
} |
|
1375 |
||
1376 |
public void mouseExited(MouseEvent e) { |
|
1377 |
} |
|
1378 |
||
1379 |
public void mousePressed(MouseEvent e) { |
|
1380 |
if (e.getClickCount() == 2) { |
|
25565
ce603b34c98d
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents:
23697
diff
changeset
|
1381 |
JList<?> list = (JList)e.getSource(); |
2 | 1382 |
int index = list.locationToIndex(e.getPoint()); |
1383 |
||
1384 |
optionPane.setInputValue(list.getModel().getElementAt(index)); |
|
11809
d65aab67ee8a
7138665: JOptionPane.getValue() unexpected change between JRE 1.6 and JRE 1.7
rupashka
parents:
9230
diff
changeset
|
1385 |
optionPane.setValue(JOptionPane.OK_OPTION); |
2 | 1386 |
} |
1387 |
} |
|
1388 |
||
1389 |
// |
|
1390 |
// PropertyChangeListener |
|
1391 |
// |
|
1392 |
public void propertyChange(PropertyChangeEvent e) { |
|
1393 |
if(e.getSource() == optionPane) { |
|
1394 |
// Option Pane Auditory Cue Activation |
|
1395 |
// only respond to "ancestor" changes |
|
1396 |
// the idea being that a JOptionPane gets a JDialog when it is |
|
1397 |
// set to appear and loses it's JDialog when it is dismissed. |
|
1398 |
if ("ancestor" == e.getPropertyName()) { |
|
1399 |
JOptionPane op = (JOptionPane)e.getSource(); |
|
1400 |
boolean isComingUp; |
|
1401 |
||
1402 |
// if the old value is null, then the JOptionPane is being |
|
1403 |
// created since it didn't previously have an ancestor. |
|
1404 |
if (e.getOldValue() == null) { |
|
1405 |
isComingUp = true; |
|
1406 |
} else { |
|
1407 |
isComingUp = false; |
|
1408 |
} |
|
1409 |
||
1410 |
// figure out what to do based on the message type |
|
1411 |
switch (op.getMessageType()) { |
|
1412 |
case JOptionPane.PLAIN_MESSAGE: |
|
1413 |
if (isComingUp) { |
|
1414 |
BasicLookAndFeel.playSound(optionPane, |
|
1415 |
"OptionPane.informationSound"); |
|
1416 |
} |
|
1417 |
break; |
|
1418 |
case JOptionPane.QUESTION_MESSAGE: |
|
1419 |
if (isComingUp) { |
|
1420 |
BasicLookAndFeel.playSound(optionPane, |
|
1421 |
"OptionPane.questionSound"); |
|
1422 |
} |
|
1423 |
break; |
|
1424 |
case JOptionPane.INFORMATION_MESSAGE: |
|
1425 |
if (isComingUp) { |
|
1426 |
BasicLookAndFeel.playSound(optionPane, |
|
1427 |
"OptionPane.informationSound"); |
|
1428 |
} |
|
1429 |
break; |
|
1430 |
case JOptionPane.WARNING_MESSAGE: |
|
1431 |
if (isComingUp) { |
|
1432 |
BasicLookAndFeel.playSound(optionPane, |
|
1433 |
"OptionPane.warningSound"); |
|
1434 |
} |
|
1435 |
break; |
|
1436 |
case JOptionPane.ERROR_MESSAGE: |
|
1437 |
if (isComingUp) { |
|
1438 |
BasicLookAndFeel.playSound(optionPane, |
|
1439 |
"OptionPane.errorSound"); |
|
1440 |
} |
|
1441 |
break; |
|
1442 |
default: |
|
1443 |
System.err.println("Undefined JOptionPane type: " + |
|
1444 |
op.getMessageType()); |
|
1445 |
break; |
|
1446 |
} |
|
1447 |
} |
|
1448 |
// Visual activity |
|
1449 |
String changeName = e.getPropertyName(); |
|
1450 |
||
1451 |
if(changeName == JOptionPane.OPTIONS_PROPERTY || |
|
1452 |
changeName == JOptionPane.INITIAL_VALUE_PROPERTY || |
|
1453 |
changeName == JOptionPane.ICON_PROPERTY || |
|
1454 |
changeName == JOptionPane.MESSAGE_TYPE_PROPERTY || |
|
1455 |
changeName == JOptionPane.OPTION_TYPE_PROPERTY || |
|
1456 |
changeName == JOptionPane.MESSAGE_PROPERTY || |
|
1457 |
changeName == JOptionPane.SELECTION_VALUES_PROPERTY || |
|
1458 |
changeName == JOptionPane.INITIAL_SELECTION_VALUE_PROPERTY || |
|
1459 |
changeName == JOptionPane.WANTS_INPUT_PROPERTY) { |
|
1460 |
uninstallComponents(); |
|
1461 |
installComponents(); |
|
1462 |
optionPane.validate(); |
|
1463 |
} |
|
1464 |
else if (changeName == "componentOrientation") { |
|
1465 |
ComponentOrientation o = (ComponentOrientation)e.getNewValue(); |
|
1466 |
JOptionPane op = (JOptionPane)e.getSource(); |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
438
diff
changeset
|
1467 |
if (o != e.getOldValue()) { |
2 | 1468 |
op.applyComponentOrientation(o); |
1469 |
} |
|
1470 |
} |
|
1471 |
} |
|
1472 |
} |
|
1473 |
} |
|
1474 |
||
1475 |
||
1476 |
// |
|
1477 |
// Classes used when optionPane.getWantsInput returns true. |
|
1478 |
// |
|
1479 |
||
1480 |
/** |
|
1481 |
* A JTextField that allows you to specify an array of KeyStrokes that |
|
1482 |
* that will have their bindings processed regardless of whether or |
|
1483 |
* not they are registered on the JTextField. This is used as we really |
|
1484 |
* want the ActionListener to be notified so that we can push the |
|
1485 |
* change to the JOptionPane, but we also want additional bindings |
|
1486 |
* (those of the JRootPane) to be processed as well. |
|
1487 |
*/ |
|
23697 | 1488 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 1489 |
private static class MultiplexingTextField extends JTextField { |
1490 |
private KeyStroke[] strokes; |
|
1491 |
||
1492 |
MultiplexingTextField(int cols) { |
|
1493 |
super(cols); |
|
1494 |
} |
|
1495 |
||
1496 |
/** |
|
1497 |
* Sets the KeyStrokes that will be additional processed for |
|
1498 |
* ancestor bindings. |
|
1499 |
*/ |
|
1500 |
void setKeyStrokes(KeyStroke[] strokes) { |
|
1501 |
this.strokes = strokes; |
|
1502 |
} |
|
1503 |
||
1504 |
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, |
|
1505 |
int condition, boolean pressed) { |
|
1506 |
boolean processed = super.processKeyBinding(ks, e, condition, |
|
1507 |
pressed); |
|
1508 |
||
1509 |
if (processed && condition != JComponent.WHEN_IN_FOCUSED_WINDOW) { |
|
1510 |
for (int counter = strokes.length - 1; counter >= 0; |
|
1511 |
counter--) { |
|
1512 |
if (strokes[counter].equals(ks)) { |
|
1513 |
// Returning false will allow further processing |
|
1514 |
// of the bindings, eg our parent Containers will get a |
|
1515 |
// crack at them. |
|
1516 |
return false; |
|
1517 |
} |
|
1518 |
} |
|
1519 |
} |
|
1520 |
return processed; |
|
1521 |
} |
|
1522 |
} |
|
1523 |
||
1524 |
||
1525 |
||
1526 |
/** |
|
1527 |
* Registered in the ActionMap. Sets the value of the option pane |
|
1528 |
* to <code>JOptionPane.CLOSED_OPTION</code>. |
|
1529 |
*/ |
|
1530 |
private static class Actions extends UIAction { |
|
1531 |
private static final String CLOSE = "close"; |
|
1532 |
||
1533 |
Actions(String key) { |
|
1534 |
super(key); |
|
1535 |
} |
|
1536 |
||
1537 |
public void actionPerformed(ActionEvent e) { |
|
1538 |
if (getName() == CLOSE) { |
|
1539 |
JOptionPane optionPane = (JOptionPane)e.getSource(); |
|
1540 |
||
438
2ae294e4518c
6613529: Avoid duplicate object creation within JDK packages
dav
parents:
2
diff
changeset
|
1541 |
optionPane.setValue(Integer.valueOf(JOptionPane.CLOSED_OPTION)); |
2 | 1542 |
} |
1543 |
} |
|
1544 |
} |
|
1545 |
||
1546 |
||
1547 |
/** |
|
1548 |
* This class is used to create the default buttons. This indirection is |
|
1549 |
* used so that addButtonComponents can tell which Buttons were created |
|
1550 |
* by us vs subclassers or from the JOptionPane itself. |
|
1551 |
*/ |
|
1552 |
private static class ButtonFactory { |
|
1553 |
private String text; |
|
1554 |
private int mnemonic; |
|
1555 |
private Icon icon; |
|
1556 |
private int minimumWidth = -1; |
|
1557 |
||
1558 |
ButtonFactory(String text, int mnemonic, Icon icon, int minimumWidth) { |
|
1559 |
this.text = text; |
|
1560 |
this.mnemonic = mnemonic; |
|
1561 |
this.icon = icon; |
|
1562 |
this.minimumWidth = minimumWidth; |
|
1563 |
} |
|
1564 |
||
1565 |
JButton createButton() { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
438
diff
changeset
|
1566 |
JButton button; |
2 | 1567 |
|
1568 |
if (minimumWidth > 0) { |
|
1569 |
button = new ConstrainedButton(text, minimumWidth); |
|
1570 |
} else { |
|
1571 |
button = new JButton(text); |
|
1572 |
} |
|
1573 |
if (icon != null) { |
|
1574 |
button.setIcon(icon); |
|
1575 |
} |
|
1576 |
if (mnemonic != 0) { |
|
1577 |
button.setMnemonic(mnemonic); |
|
1578 |
} |
|
1579 |
return button; |
|
1580 |
} |
|
1581 |
||
23697 | 1582 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 1583 |
private static class ConstrainedButton extends JButton { |
1584 |
int minimumWidth; |
|
1585 |
||
1586 |
ConstrainedButton(String text, int minimumWidth) { |
|
1587 |
super(text); |
|
1588 |
this.minimumWidth = minimumWidth; |
|
1589 |
} |
|
1590 |
||
1591 |
public Dimension getMinimumSize() { |
|
1592 |
Dimension min = super.getMinimumSize(); |
|
1593 |
min.width = Math.max(min.width, minimumWidth); |
|
1594 |
return min; |
|
1595 |
} |
|
1596 |
||
1597 |
public Dimension getPreferredSize() { |
|
1598 |
Dimension pref = super.getPreferredSize(); |
|
1599 |
pref.width = Math.max(pref.width, minimumWidth); |
|
1600 |
return pref; |
|
1601 |
} |
|
1602 |
} |
|
1603 |
} |
|
1604 |
} |