author | malenkov |
Tue, 29 Oct 2013 17:01:06 +0400 | |
changeset 21278 | ef8a3a2a72f2 |
parent 21259 | 4780cf380d96 |
child 22574 | 7f8ce0c8c20a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1997, 2008, 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.SwingUtilities2; |
|
29 |
import java.awt.*; |
|
30 |
import java.awt.event.*; |
|
31 |
import javax.accessibility.AccessibleContext; |
|
32 |
import javax.swing.*; |
|
33 |
import javax.swing.plaf.*; |
|
34 |
import javax.swing.border.*; |
|
35 |
import javax.swing.event.InternalFrameEvent; |
|
36 |
import java.util.EventListener; |
|
37 |
import java.beans.PropertyChangeListener; |
|
38 |
import java.beans.PropertyChangeEvent; |
|
39 |
import java.beans.VetoableChangeListener; |
|
40 |
import java.beans.PropertyVetoException; |
|
41 |
||
42 |
import sun.swing.DefaultLookup; |
|
43 |
import sun.swing.UIAction; |
|
44 |
||
45 |
/** |
|
46 |
* The class that manages a basic title bar |
|
47 |
* <p> |
|
48 |
* <strong>Warning:</strong> |
|
49 |
* Serialized objects of this class will not be compatible with |
|
50 |
* future Swing releases. The current serialization support is |
|
51 |
* appropriate for short term storage or RMI between applications running |
|
52 |
* the same version of Swing. As of 1.4, support for long term storage |
|
20458 | 53 |
* of all JavaBeans™ |
2 | 54 |
* has been added to the <code>java.beans</code> package. |
55 |
* Please see {@link java.beans.XMLEncoder}. |
|
56 |
* |
|
57 |
* @author David Kloba |
|
58 |
* @author Steve Wilson |
|
59 |
*/ |
|
60 |
public class BasicInternalFrameTitlePane extends JComponent |
|
61 |
{ |
|
62 |
protected JMenuBar menuBar; |
|
63 |
protected JButton iconButton; |
|
64 |
protected JButton maxButton; |
|
65 |
protected JButton closeButton; |
|
66 |
||
67 |
protected JMenu windowMenu; |
|
68 |
protected JInternalFrame frame; |
|
69 |
||
70 |
protected Color selectedTitleColor; |
|
71 |
protected Color selectedTextColor; |
|
72 |
protected Color notSelectedTitleColor; |
|
73 |
protected Color notSelectedTextColor; |
|
74 |
||
75 |
protected Icon maxIcon; |
|
76 |
protected Icon minIcon; |
|
77 |
protected Icon iconIcon; |
|
78 |
protected Icon closeIcon; |
|
79 |
||
80 |
protected PropertyChangeListener propertyChangeListener; |
|
81 |
||
82 |
protected Action closeAction; |
|
83 |
protected Action maximizeAction; |
|
84 |
protected Action iconifyAction; |
|
85 |
protected Action restoreAction; |
|
86 |
protected Action moveAction; |
|
87 |
protected Action sizeAction; |
|
88 |
||
1285
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
89 |
// These constants are not used in JDK code |
2 | 90 |
protected static final String CLOSE_CMD = |
91 |
UIManager.getString("InternalFrameTitlePane.closeButtonText"); |
|
92 |
protected static final String ICONIFY_CMD = |
|
93 |
UIManager.getString("InternalFrameTitlePane.minimizeButtonText"); |
|
94 |
protected static final String RESTORE_CMD = |
|
95 |
UIManager.getString("InternalFrameTitlePane.restoreButtonText"); |
|
96 |
protected static final String MAXIMIZE_CMD = |
|
97 |
UIManager.getString("InternalFrameTitlePane.maximizeButtonText"); |
|
98 |
protected static final String MOVE_CMD = |
|
99 |
UIManager.getString("InternalFrameTitlePane.moveButtonText"); |
|
100 |
protected static final String SIZE_CMD = |
|
101 |
UIManager.getString("InternalFrameTitlePane.sizeButtonText"); |
|
102 |
||
103 |
private String closeButtonToolTip; |
|
104 |
private String iconButtonToolTip; |
|
105 |
private String restoreButtonToolTip; |
|
106 |
private String maxButtonToolTip; |
|
107 |
private Handler handler; |
|
108 |
||
109 |
public BasicInternalFrameTitlePane(JInternalFrame f) { |
|
110 |
frame = f; |
|
111 |
installTitlePane(); |
|
112 |
} |
|
113 |
||
114 |
protected void installTitlePane() { |
|
115 |
installDefaults(); |
|
116 |
installListeners(); |
|
117 |
||
118 |
createActions(); |
|
119 |
enableActions(); |
|
120 |
createActionMap(); |
|
121 |
||
122 |
setLayout(createLayout()); |
|
123 |
||
124 |
assembleSystemMenu(); |
|
125 |
createButtons(); |
|
126 |
addSubComponents(); |
|
127 |
||
128 |
} |
|
129 |
||
130 |
protected void addSubComponents() { |
|
131 |
add(menuBar); |
|
132 |
add(iconButton); |
|
133 |
add(maxButton); |
|
134 |
add(closeButton); |
|
135 |
} |
|
136 |
||
137 |
protected void createActions() { |
|
138 |
maximizeAction = new MaximizeAction(); |
|
139 |
iconifyAction = new IconifyAction(); |
|
140 |
closeAction = new CloseAction(); |
|
141 |
restoreAction = new RestoreAction(); |
|
142 |
moveAction = new MoveAction(); |
|
143 |
sizeAction = new SizeAction(); |
|
144 |
} |
|
145 |
||
146 |
ActionMap createActionMap() { |
|
147 |
ActionMap map = new ActionMapUIResource(); |
|
148 |
map.put("showSystemMenu", new ShowSystemMenuAction(true)); |
|
149 |
map.put("hideSystemMenu", new ShowSystemMenuAction(false)); |
|
150 |
return map; |
|
151 |
} |
|
152 |
||
153 |
protected void installListeners() { |
|
154 |
if( propertyChangeListener == null ) { |
|
155 |
propertyChangeListener = createPropertyChangeListener(); |
|
156 |
} |
|
157 |
frame.addPropertyChangeListener(propertyChangeListener); |
|
158 |
} |
|
159 |
||
160 |
protected void uninstallListeners() { |
|
161 |
frame.removePropertyChangeListener(propertyChangeListener); |
|
162 |
handler = null; |
|
163 |
} |
|
164 |
||
165 |
protected void installDefaults() { |
|
166 |
maxIcon = UIManager.getIcon("InternalFrame.maximizeIcon"); |
|
167 |
minIcon = UIManager.getIcon("InternalFrame.minimizeIcon"); |
|
168 |
iconIcon = UIManager.getIcon("InternalFrame.iconifyIcon"); |
|
169 |
closeIcon = UIManager.getIcon("InternalFrame.closeIcon"); |
|
170 |
||
171 |
selectedTitleColor = UIManager.getColor("InternalFrame.activeTitleBackground"); |
|
172 |
selectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground"); |
|
173 |
notSelectedTitleColor = UIManager.getColor("InternalFrame.inactiveTitleBackground"); |
|
174 |
notSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground"); |
|
175 |
setFont(UIManager.getFont("InternalFrame.titleFont")); |
|
176 |
closeButtonToolTip = |
|
177 |
UIManager.getString("InternalFrame.closeButtonToolTip"); |
|
178 |
iconButtonToolTip = |
|
179 |
UIManager.getString("InternalFrame.iconButtonToolTip"); |
|
180 |
restoreButtonToolTip = |
|
181 |
UIManager.getString("InternalFrame.restoreButtonToolTip"); |
|
182 |
maxButtonToolTip = |
|
183 |
UIManager.getString("InternalFrame.maxButtonToolTip"); |
|
184 |
} |
|
185 |
||
186 |
||
187 |
protected void uninstallDefaults() { |
|
188 |
} |
|
189 |
||
190 |
protected void createButtons() { |
|
191 |
iconButton = new NoFocusButton( |
|
192 |
"InternalFrameTitlePane.iconifyButtonAccessibleName", |
|
193 |
"InternalFrameTitlePane.iconifyButtonOpacity"); |
|
194 |
iconButton.addActionListener(iconifyAction); |
|
195 |
if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) { |
|
196 |
iconButton.setToolTipText(iconButtonToolTip); |
|
197 |
} |
|
198 |
||
199 |
maxButton = new NoFocusButton( |
|
200 |
"InternalFrameTitlePane.maximizeButtonAccessibleName", |
|
201 |
"InternalFrameTitlePane.maximizeButtonOpacity"); |
|
202 |
maxButton.addActionListener(maximizeAction); |
|
203 |
||
204 |
closeButton = new NoFocusButton( |
|
205 |
"InternalFrameTitlePane.closeButtonAccessibleName", |
|
206 |
"InternalFrameTitlePane.closeButtonOpacity"); |
|
207 |
closeButton.addActionListener(closeAction); |
|
208 |
if (closeButtonToolTip != null && closeButtonToolTip.length() != 0) { |
|
209 |
closeButton.setToolTipText(closeButtonToolTip); |
|
210 |
} |
|
211 |
||
212 |
setButtonIcons(); |
|
213 |
} |
|
214 |
||
215 |
protected void setButtonIcons() { |
|
216 |
if(frame.isIcon()) { |
|
217 |
if (minIcon != null) { |
|
218 |
iconButton.setIcon(minIcon); |
|
219 |
} |
|
220 |
if (restoreButtonToolTip != null && |
|
221 |
restoreButtonToolTip.length() != 0) { |
|
222 |
iconButton.setToolTipText(restoreButtonToolTip); |
|
223 |
} |
|
224 |
if (maxIcon != null) { |
|
225 |
maxButton.setIcon(maxIcon); |
|
226 |
} |
|
227 |
if (maxButtonToolTip != null && maxButtonToolTip.length() != 0) { |
|
228 |
maxButton.setToolTipText(maxButtonToolTip); |
|
229 |
} |
|
230 |
} else if (frame.isMaximum()) { |
|
231 |
if (iconIcon != null) { |
|
232 |
iconButton.setIcon(iconIcon); |
|
233 |
} |
|
234 |
if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) { |
|
235 |
iconButton.setToolTipText(iconButtonToolTip); |
|
236 |
} |
|
237 |
if (minIcon != null) { |
|
238 |
maxButton.setIcon(minIcon); |
|
239 |
} |
|
240 |
if (restoreButtonToolTip != null && |
|
241 |
restoreButtonToolTip.length() != 0) { |
|
242 |
maxButton.setToolTipText(restoreButtonToolTip); |
|
243 |
} |
|
244 |
} else { |
|
245 |
if (iconIcon != null) { |
|
246 |
iconButton.setIcon(iconIcon); |
|
247 |
} |
|
248 |
if (iconButtonToolTip != null && iconButtonToolTip.length() != 0) { |
|
249 |
iconButton.setToolTipText(iconButtonToolTip); |
|
250 |
} |
|
251 |
if (maxIcon != null) { |
|
252 |
maxButton.setIcon(maxIcon); |
|
253 |
} |
|
254 |
if (maxButtonToolTip != null && maxButtonToolTip.length() != 0) { |
|
255 |
maxButton.setToolTipText(maxButtonToolTip); |
|
256 |
} |
|
257 |
} |
|
258 |
if (closeIcon != null) { |
|
259 |
closeButton.setIcon(closeIcon); |
|
260 |
} |
|
261 |
} |
|
262 |
||
263 |
protected void assembleSystemMenu() { |
|
264 |
menuBar = createSystemMenuBar(); |
|
265 |
windowMenu = createSystemMenu(); |
|
266 |
menuBar.add(windowMenu); |
|
267 |
addSystemMenuItems(windowMenu); |
|
268 |
enableActions(); |
|
269 |
} |
|
270 |
||
271 |
protected void addSystemMenuItems(JMenu systemMenu) { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
1285
diff
changeset
|
272 |
JMenuItem mi = systemMenu.add(restoreAction); |
21259
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
273 |
mi.setMnemonic(getButtonMnemonic("restore")); |
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
1285
diff
changeset
|
274 |
mi = systemMenu.add(moveAction); |
21259
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
275 |
mi.setMnemonic(getButtonMnemonic("move")); |
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
1285
diff
changeset
|
276 |
mi = systemMenu.add(sizeAction); |
21259
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
277 |
mi.setMnemonic(getButtonMnemonic("size")); |
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
1285
diff
changeset
|
278 |
mi = systemMenu.add(iconifyAction); |
21259
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
279 |
mi.setMnemonic(getButtonMnemonic("minimize")); |
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
1285
diff
changeset
|
280 |
mi = systemMenu.add(maximizeAction); |
21259
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
281 |
mi.setMnemonic(getButtonMnemonic("maximize")); |
2 | 282 |
systemMenu.add(new JSeparator()); |
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
1285
diff
changeset
|
283 |
mi = systemMenu.add(closeAction); |
21259
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
284 |
mi.setMnemonic(getButtonMnemonic("close")); |
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
285 |
} |
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
286 |
|
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
287 |
private static int getButtonMnemonic(String button) { |
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
288 |
try { |
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
289 |
return Integer.parseInt(UIManager.getString( |
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
290 |
"InternalFrameTitlePane." + button + "Button.mnemonic")); |
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
291 |
} catch (NumberFormatException e) { |
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
292 |
return -1; |
4780cf380d96
8020708: NLS mnemonics missing in SwingSet2/JInternalFrame demo
alexsch
parents:
20458
diff
changeset
|
293 |
} |
2 | 294 |
} |
295 |
||
296 |
protected JMenu createSystemMenu() { |
|
297 |
return new JMenu(" "); |
|
298 |
} |
|
299 |
||
300 |
protected JMenuBar createSystemMenuBar() { |
|
301 |
menuBar = new SystemMenuBar(); |
|
302 |
menuBar.setBorderPainted(false); |
|
303 |
return menuBar; |
|
304 |
} |
|
305 |
||
306 |
protected void showSystemMenu(){ |
|
307 |
// windowMenu.setPopupMenuVisible(true); |
|
308 |
// windowMenu.setVisible(true); |
|
309 |
windowMenu.doClick(); |
|
310 |
} |
|
311 |
||
312 |
public void paintComponent(Graphics g) { |
|
313 |
paintTitleBackground(g); |
|
314 |
||
315 |
if(frame.getTitle() != null) { |
|
316 |
boolean isSelected = frame.isSelected(); |
|
317 |
Font f = g.getFont(); |
|
318 |
g.setFont(getFont()); |
|
319 |
if(isSelected) |
|
320 |
g.setColor(selectedTextColor); |
|
321 |
else |
|
322 |
g.setColor(notSelectedTextColor); |
|
323 |
||
324 |
// Center text vertically. |
|
325 |
FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g); |
|
326 |
int baseline = (getHeight() + fm.getAscent() - fm.getLeading() - |
|
327 |
fm.getDescent()) / 2; |
|
328 |
||
329 |
int titleX; |
|
330 |
Rectangle r = new Rectangle(0, 0, 0, 0); |
|
331 |
if (frame.isIconifiable()) r = iconButton.getBounds(); |
|
332 |
else if (frame.isMaximizable()) r = maxButton.getBounds(); |
|
333 |
else if (frame.isClosable()) r = closeButton.getBounds(); |
|
334 |
int titleW; |
|
335 |
||
336 |
String title = frame.getTitle(); |
|
337 |
if( BasicGraphicsUtils.isLeftToRight(frame) ) { |
|
338 |
if (r.x == 0) r.x = frame.getWidth()-frame.getInsets().right; |
|
339 |
titleX = menuBar.getX() + menuBar.getWidth() + 2; |
|
340 |
titleW = r.x - titleX - 3; |
|
341 |
title = getTitle(frame.getTitle(), fm, titleW); |
|
342 |
} else { |
|
343 |
titleX = menuBar.getX() - 2 |
|
344 |
- SwingUtilities2.stringWidth(frame,fm,title); |
|
345 |
} |
|
346 |
||
347 |
SwingUtilities2.drawString(frame, g, title, titleX, baseline); |
|
348 |
g.setFont(f); |
|
349 |
} |
|
350 |
} |
|
351 |
||
352 |
/** |
|
353 |
* Invoked from paintComponent. |
|
354 |
* Paints the background of the titlepane. All text and icons will |
|
355 |
* then be rendered on top of this background. |
|
356 |
* @param g the graphics to use to render the background |
|
357 |
* @since 1.4 |
|
358 |
*/ |
|
359 |
protected void paintTitleBackground(Graphics g) { |
|
360 |
boolean isSelected = frame.isSelected(); |
|
361 |
||
362 |
if(isSelected) |
|
363 |
g.setColor(selectedTitleColor); |
|
364 |
else |
|
365 |
g.setColor(notSelectedTitleColor); |
|
366 |
g.fillRect(0, 0, getWidth(), getHeight()); |
|
367 |
} |
|
368 |
||
369 |
protected String getTitle(String text, FontMetrics fm, int availTextWidth) { |
|
370 |
return SwingUtilities2.clipStringIfNecessary( |
|
371 |
frame, fm, text, availTextWidth); |
|
372 |
} |
|
373 |
||
374 |
/** |
|
375 |
* Post a WINDOW_CLOSING-like event to the frame, so that it can |
|
376 |
* be treated like a regular Frame. |
|
377 |
*/ |
|
378 |
protected void postClosingEvent(JInternalFrame frame) { |
|
379 |
InternalFrameEvent e = new InternalFrameEvent( |
|
380 |
frame, InternalFrameEvent.INTERNAL_FRAME_CLOSING); |
|
381 |
// Try posting event, unless there's a SecurityManager. |
|
382 |
if (JInternalFrame.class.getClassLoader() == null) { |
|
383 |
try { |
|
384 |
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e); |
|
385 |
return; |
|
386 |
} catch (SecurityException se) { |
|
387 |
// Use dispatchEvent instead. |
|
388 |
} |
|
389 |
} |
|
390 |
frame.dispatchEvent(e); |
|
391 |
} |
|
392 |
||
393 |
||
394 |
protected void enableActions() { |
|
395 |
restoreAction.setEnabled(frame.isMaximum() || frame.isIcon()); |
|
396 |
maximizeAction.setEnabled( |
|
397 |
(frame.isMaximizable() && !frame.isMaximum() && !frame.isIcon()) || |
|
398 |
(frame.isMaximizable() && frame.isIcon())); |
|
399 |
iconifyAction.setEnabled(frame.isIconifiable() && !frame.isIcon()); |
|
400 |
closeAction.setEnabled(frame.isClosable()); |
|
401 |
sizeAction.setEnabled(false); |
|
402 |
moveAction.setEnabled(false); |
|
403 |
} |
|
404 |
||
405 |
private Handler getHandler() { |
|
406 |
if (handler == null) { |
|
407 |
handler = new Handler(); |
|
408 |
} |
|
409 |
return handler; |
|
410 |
} |
|
411 |
||
412 |
protected PropertyChangeListener createPropertyChangeListener() { |
|
413 |
return getHandler(); |
|
414 |
} |
|
415 |
||
416 |
protected LayoutManager createLayout() { |
|
417 |
return getHandler(); |
|
418 |
} |
|
419 |
||
420 |
||
421 |
private class Handler implements LayoutManager, PropertyChangeListener { |
|
422 |
// |
|
423 |
// PropertyChangeListener |
|
424 |
// |
|
425 |
public void propertyChange(PropertyChangeEvent evt) { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
1285
diff
changeset
|
426 |
String prop = evt.getPropertyName(); |
2 | 427 |
|
428 |
if (prop == JInternalFrame.IS_SELECTED_PROPERTY) { |
|
429 |
repaint(); |
|
430 |
return; |
|
431 |
} |
|
432 |
||
433 |
if (prop == JInternalFrame.IS_ICON_PROPERTY || |
|
434 |
prop == JInternalFrame.IS_MAXIMUM_PROPERTY) { |
|
435 |
setButtonIcons(); |
|
436 |
enableActions(); |
|
437 |
return; |
|
438 |
} |
|
439 |
||
440 |
if ("closable" == prop) { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
1285
diff
changeset
|
441 |
if (evt.getNewValue() == Boolean.TRUE) { |
2 | 442 |
add(closeButton); |
443 |
} else { |
|
444 |
remove(closeButton); |
|
445 |
} |
|
446 |
} else if ("maximizable" == prop) { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
1285
diff
changeset
|
447 |
if (evt.getNewValue() == Boolean.TRUE) { |
2 | 448 |
add(maxButton); |
449 |
} else { |
|
450 |
remove(maxButton); |
|
451 |
} |
|
452 |
} else if ("iconable" == prop) { |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
1285
diff
changeset
|
453 |
if (evt.getNewValue() == Boolean.TRUE) { |
2 | 454 |
add(iconButton); |
455 |
} else { |
|
456 |
remove(iconButton); |
|
457 |
} |
|
458 |
} |
|
459 |
enableActions(); |
|
460 |
||
461 |
revalidate(); |
|
462 |
repaint(); |
|
463 |
} |
|
464 |
||
465 |
||
466 |
// |
|
467 |
// LayoutManager |
|
468 |
// |
|
469 |
public void addLayoutComponent(String name, Component c) {} |
|
470 |
public void removeLayoutComponent(Component c) {} |
|
471 |
public Dimension preferredLayoutSize(Container c) { |
|
472 |
return minimumLayoutSize(c); |
|
473 |
} |
|
474 |
||
475 |
public Dimension minimumLayoutSize(Container c) { |
|
476 |
// Calculate width. |
|
477 |
int width = 22; |
|
478 |
||
479 |
if (frame.isClosable()) { |
|
480 |
width += 19; |
|
481 |
} |
|
482 |
if (frame.isMaximizable()) { |
|
483 |
width += 19; |
|
484 |
} |
|
485 |
if (frame.isIconifiable()) { |
|
486 |
width += 19; |
|
487 |
} |
|
488 |
||
489 |
FontMetrics fm = frame.getFontMetrics(getFont()); |
|
490 |
String frameTitle = frame.getTitle(); |
|
491 |
int title_w = frameTitle != null ? SwingUtilities2.stringWidth( |
|
492 |
frame, fm, frameTitle) : 0; |
|
493 |
int title_length = frameTitle != null ? frameTitle.length() : 0; |
|
494 |
||
495 |
// Leave room for three characters in the title. |
|
496 |
if (title_length > 3) { |
|
497 |
int subtitle_w = SwingUtilities2.stringWidth( |
|
498 |
frame, fm, frameTitle.substring(0, 3) + "..."); |
|
499 |
width += (title_w < subtitle_w) ? title_w : subtitle_w; |
|
500 |
} else { |
|
501 |
width += title_w; |
|
502 |
} |
|
503 |
||
504 |
// Calculate height. |
|
505 |
Icon icon = frame.getFrameIcon(); |
|
506 |
int fontHeight = fm.getHeight(); |
|
507 |
fontHeight += 2; |
|
508 |
int iconHeight = 0; |
|
509 |
if (icon != null) { |
|
510 |
// SystemMenuBar forces the icon to be 16x16 or less. |
|
511 |
iconHeight = Math.min(icon.getIconHeight(), 16); |
|
512 |
} |
|
513 |
iconHeight += 2; |
|
514 |
||
515 |
int height = Math.max( fontHeight, iconHeight ); |
|
516 |
||
517 |
Dimension dim = new Dimension(width, height); |
|
518 |
||
519 |
// Take into account the border insets if any. |
|
520 |
if (getBorder() != null) { |
|
521 |
Insets insets = getBorder().getBorderInsets(c); |
|
522 |
dim.height += insets.top + insets.bottom; |
|
523 |
dim.width += insets.left + insets.right; |
|
524 |
} |
|
525 |
return dim; |
|
526 |
} |
|
527 |
||
528 |
public void layoutContainer(Container c) { |
|
529 |
boolean leftToRight = BasicGraphicsUtils.isLeftToRight(frame); |
|
530 |
||
531 |
int w = getWidth(); |
|
532 |
int h = getHeight(); |
|
533 |
int x; |
|
534 |
||
535 |
int buttonHeight = closeButton.getIcon().getIconHeight(); |
|
536 |
||
537 |
Icon icon = frame.getFrameIcon(); |
|
538 |
int iconHeight = 0; |
|
539 |
if (icon != null) { |
|
540 |
iconHeight = icon.getIconHeight(); |
|
541 |
} |
|
542 |
x = (leftToRight) ? 2 : w - 16 - 2; |
|
543 |
menuBar.setBounds(x, (h - iconHeight) / 2, 16, 16); |
|
544 |
||
545 |
x = (leftToRight) ? w - 16 - 2 : 2; |
|
546 |
||
547 |
if (frame.isClosable()) { |
|
548 |
closeButton.setBounds(x, (h - buttonHeight) / 2, 16, 14); |
|
549 |
x += (leftToRight) ? -(16 + 2) : 16 + 2; |
|
550 |
} |
|
551 |
||
552 |
if (frame.isMaximizable()) { |
|
553 |
maxButton.setBounds(x, (h - buttonHeight) / 2, 16, 14); |
|
554 |
x += (leftToRight) ? -(16 + 2) : 16 + 2; |
|
555 |
} |
|
556 |
||
557 |
if (frame.isIconifiable()) { |
|
558 |
iconButton.setBounds(x, (h - buttonHeight) / 2, 16, 14); |
|
559 |
} |
|
560 |
} |
|
561 |
} |
|
562 |
||
563 |
/** |
|
564 |
* This class should be treated as a "protected" inner class. |
|
20169 | 565 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 566 |
*/ |
567 |
public class PropertyChangeHandler implements PropertyChangeListener { |
|
21278 | 568 |
// NOTE: This class exists only for backward compatibility. All |
2 | 569 |
// its functionality has been moved into Handler. If you need to add |
570 |
// new functionality add it to the Handler, but make sure this |
|
571 |
// class calls into the Handler. |
|
572 |
public void propertyChange(PropertyChangeEvent evt) { |
|
573 |
getHandler().propertyChange(evt); |
|
574 |
} |
|
575 |
} |
|
576 |
||
577 |
/** |
|
578 |
* This class should be treated as a "protected" inner class. |
|
20169 | 579 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 580 |
*/ |
581 |
public class TitlePaneLayout implements LayoutManager { |
|
21278 | 582 |
// NOTE: This class exists only for backward compatibility. All |
2 | 583 |
// its functionality has been moved into Handler. If you need to add |
584 |
// new functionality add it to the Handler, but make sure this |
|
585 |
// class calls into the Handler. |
|
586 |
public void addLayoutComponent(String name, Component c) { |
|
587 |
getHandler().addLayoutComponent(name, c); |
|
588 |
} |
|
589 |
||
590 |
public void removeLayoutComponent(Component c) { |
|
591 |
getHandler().removeLayoutComponent(c); |
|
592 |
} |
|
593 |
||
594 |
public Dimension preferredLayoutSize(Container c) { |
|
595 |
return getHandler().preferredLayoutSize(c); |
|
596 |
} |
|
597 |
||
598 |
public Dimension minimumLayoutSize(Container c) { |
|
599 |
return getHandler().minimumLayoutSize(c); |
|
600 |
} |
|
601 |
||
602 |
public void layoutContainer(Container c) { |
|
603 |
getHandler().layoutContainer(c); |
|
604 |
} |
|
605 |
} |
|
606 |
||
607 |
/** |
|
608 |
* This class should be treated as a "protected" inner class. |
|
20169 | 609 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 610 |
*/ |
611 |
public class CloseAction extends AbstractAction { |
|
612 |
public CloseAction() { |
|
1285
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
613 |
super(UIManager.getString( |
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
614 |
"InternalFrameTitlePane.closeButtonText")); |
2 | 615 |
} |
616 |
||
617 |
public void actionPerformed(ActionEvent e) { |
|
618 |
if(frame.isClosable()) { |
|
619 |
frame.doDefaultCloseAction(); |
|
620 |
} |
|
621 |
} |
|
622 |
} // end CloseAction |
|
623 |
||
624 |
/** |
|
625 |
* This class should be treated as a "protected" inner class. |
|
20169 | 626 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 627 |
*/ |
628 |
public class MaximizeAction extends AbstractAction { |
|
629 |
public MaximizeAction() { |
|
1285
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
630 |
super(UIManager.getString( |
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
631 |
"InternalFrameTitlePane.maximizeButtonText")); |
2 | 632 |
} |
633 |
||
634 |
public void actionPerformed(ActionEvent evt) { |
|
635 |
if (frame.isMaximizable()) { |
|
636 |
if (frame.isMaximum() && frame.isIcon()) { |
|
637 |
try { |
|
638 |
frame.setIcon(false); |
|
639 |
} catch (PropertyVetoException e) { } |
|
640 |
} else if (!frame.isMaximum()) { |
|
641 |
try { |
|
642 |
frame.setMaximum(true); |
|
643 |
} catch (PropertyVetoException e) { } |
|
644 |
} else { |
|
645 |
try { |
|
646 |
frame.setMaximum(false); |
|
647 |
} catch (PropertyVetoException e) { } |
|
648 |
} |
|
649 |
} |
|
650 |
} |
|
651 |
} |
|
652 |
||
653 |
/** |
|
654 |
* This class should be treated as a "protected" inner class. |
|
20169 | 655 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 656 |
*/ |
657 |
public class IconifyAction extends AbstractAction { |
|
658 |
public IconifyAction() { |
|
1285
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
659 |
super(UIManager.getString( |
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
660 |
"InternalFrameTitlePane.minimizeButtonText")); |
2 | 661 |
} |
662 |
||
663 |
public void actionPerformed(ActionEvent e) { |
|
664 |
if(frame.isIconifiable()) { |
|
665 |
if(!frame.isIcon()) { |
|
666 |
try { frame.setIcon(true); } catch (PropertyVetoException e1) { } |
|
667 |
} else{ |
|
668 |
try { frame.setIcon(false); } catch (PropertyVetoException e1) { } |
|
669 |
} |
|
670 |
} |
|
671 |
} |
|
672 |
} // end IconifyAction |
|
673 |
||
674 |
/** |
|
675 |
* This class should be treated as a "protected" inner class. |
|
20169 | 676 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 677 |
*/ |
678 |
public class RestoreAction extends AbstractAction { |
|
679 |
public RestoreAction() { |
|
1285
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
680 |
super(UIManager.getString( |
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
681 |
"InternalFrameTitlePane.restoreButtonText")); |
2 | 682 |
} |
683 |
||
684 |
public void actionPerformed(ActionEvent evt) { |
|
685 |
if (frame.isMaximizable() && frame.isMaximum() && frame.isIcon()) { |
|
686 |
try { |
|
687 |
frame.setIcon(false); |
|
688 |
} catch (PropertyVetoException e) { } |
|
689 |
} else if (frame.isMaximizable() && frame.isMaximum()) { |
|
690 |
try { |
|
691 |
frame.setMaximum(false); |
|
692 |
} catch (PropertyVetoException e) { } |
|
693 |
} else if (frame.isIconifiable() && frame.isIcon()) { |
|
694 |
try { |
|
695 |
frame.setIcon(false); |
|
696 |
} catch (PropertyVetoException e) { } |
|
697 |
} |
|
698 |
} |
|
699 |
} |
|
700 |
||
701 |
/** |
|
702 |
* This class should be treated as a "protected" inner class. |
|
20169 | 703 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 704 |
*/ |
705 |
public class MoveAction extends AbstractAction { |
|
706 |
public MoveAction() { |
|
1285
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
707 |
super(UIManager.getString( |
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
708 |
"InternalFrameTitlePane.moveButtonText")); |
2 | 709 |
} |
710 |
||
711 |
public void actionPerformed(ActionEvent e) { |
|
712 |
// This action is currently undefined |
|
713 |
} |
|
714 |
} // end MoveAction |
|
715 |
||
716 |
/* |
|
717 |
* Handles showing and hiding the system menu. |
|
718 |
*/ |
|
719 |
private class ShowSystemMenuAction extends AbstractAction { |
|
720 |
private boolean show; // whether to show the menu |
|
721 |
||
722 |
public ShowSystemMenuAction(boolean show) { |
|
723 |
this.show = show; |
|
724 |
} |
|
725 |
||
726 |
public void actionPerformed(ActionEvent e) { |
|
727 |
if (show) { |
|
728 |
windowMenu.doClick(); |
|
729 |
} else { |
|
730 |
windowMenu.setVisible(false); |
|
731 |
} |
|
732 |
} |
|
733 |
} |
|
734 |
||
735 |
/** |
|
736 |
* This class should be treated as a "protected" inner class. |
|
20169 | 737 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 738 |
*/ |
739 |
public class SizeAction extends AbstractAction { |
|
740 |
public SizeAction() { |
|
1285
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
741 |
super(UIManager.getString( |
d2d433263986
6725409: Unable to localize JInternalFrame system menu during run-time
mlapshin
parents:
2
diff
changeset
|
742 |
"InternalFrameTitlePane.sizeButtonText")); |
2 | 743 |
} |
744 |
||
745 |
public void actionPerformed(ActionEvent e) { |
|
746 |
// This action is currently undefined |
|
747 |
} |
|
748 |
} // end SizeAction |
|
749 |
||
750 |
||
751 |
/** |
|
752 |
* This class should be treated as a "protected" inner class. |
|
20169 | 753 |
* Instantiate it only within subclasses of <code>Foo</code>. |
2 | 754 |
*/ |
755 |
public class SystemMenuBar extends JMenuBar { |
|
756 |
public boolean isFocusTraversable() { return false; } |
|
757 |
public void requestFocus() {} |
|
758 |
public void paint(Graphics g) { |
|
759 |
Icon icon = frame.getFrameIcon(); |
|
760 |
if (icon == null) { |
|
761 |
icon = (Icon)DefaultLookup.get(frame, frame.getUI(), |
|
762 |
"InternalFrame.icon"); |
|
763 |
} |
|
764 |
if (icon != null) { |
|
765 |
// Resize to 16x16 if necessary. |
|
766 |
if (icon instanceof ImageIcon && (icon.getIconWidth() > 16 || icon.getIconHeight() > 16)) { |
|
767 |
Image img = ((ImageIcon)icon).getImage(); |
|
768 |
((ImageIcon)icon).setImage(img.getScaledInstance(16, 16, Image.SCALE_SMOOTH)); |
|
769 |
} |
|
770 |
icon.paintIcon(this, g, 0, 0); |
|
771 |
} |
|
772 |
} |
|
773 |
||
774 |
public boolean isOpaque() { |
|
775 |
return true; |
|
776 |
} |
|
777 |
} // end SystemMenuBar |
|
778 |
||
779 |
||
780 |
private class NoFocusButton extends JButton { |
|
781 |
private String uiKey; |
|
782 |
public NoFocusButton(String uiKey, String opacityKey) { |
|
783 |
setFocusPainted(false); |
|
784 |
setMargin(new Insets(0,0,0,0)); |
|
785 |
this.uiKey = uiKey; |
|
786 |
||
787 |
Object opacity = UIManager.get(opacityKey); |
|
788 |
if (opacity instanceof Boolean) { |
|
789 |
setOpaque(((Boolean)opacity).booleanValue()); |
|
790 |
} |
|
791 |
} |
|
792 |
public boolean isFocusTraversable() { return false; } |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
1285
diff
changeset
|
793 |
public void requestFocus() {} |
2 | 794 |
public AccessibleContext getAccessibleContext() { |
795 |
AccessibleContext ac = super.getAccessibleContext(); |
|
796 |
if (uiKey != null) { |
|
797 |
ac.setAccessibleName(UIManager.getString(uiKey)); |
|
798 |
uiKey = null; |
|
799 |
} |
|
800 |
return ac; |
|
801 |
} |
|
1290
da8902cd496c
6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents:
1285
diff
changeset
|
802 |
} // end NoFocusButton |
2 | 803 |
|
804 |
} // End Title Pane Class |