author | ant |
Thu, 17 May 2012 21:48:57 +0400 | |
changeset 12661 | 6cf8b7116579 |
parent 12532 | dbf5d9a4b7bb |
child 17149 | adce5338e9b5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 1997, 2010, 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; |
|
27 |
||
28 |
import java.util.List; |
|
29 |
import java.util.ArrayList; |
|
12532
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
30 |
import java.util.Collection; |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
31 |
import java.util.Iterator; |
2 | 32 |
import javax.swing.plaf.*; |
33 |
import javax.accessibility.*; |
|
34 |
||
35 |
import java.awt.Component; |
|
36 |
import java.awt.Container; |
|
37 |
import java.awt.DefaultFocusTraversalPolicy; |
|
38 |
import java.awt.FocusTraversalPolicy; |
|
39 |
import java.awt.Window; |
|
40 |
import java.io.ObjectOutputStream; |
|
41 |
import java.io.ObjectInputStream; |
|
42 |
import java.io.IOException; |
|
43 |
import java.beans.PropertyVetoException; |
|
44 |
import java.util.Set; |
|
45 |
import java.util.TreeSet; |
|
46 |
/** |
|
47 |
* A container used to create a multiple-document interface or a virtual desktop. |
|
48 |
* You create <code>JInternalFrame</code> objects and add them to the |
|
49 |
* <code>JDesktopPane</code>. <code>JDesktopPane</code> extends |
|
50 |
* <code>JLayeredPane</code> to manage the potentially overlapping internal |
|
51 |
* frames. It also maintains a reference to an instance of |
|
52 |
* <code>DesktopManager</code> that is set by the UI |
|
53 |
* class for the current look and feel (L&F). Note that <code>JDesktopPane</code> |
|
54 |
* does not support borders. |
|
55 |
* <p> |
|
56 |
* This class is normally used as the parent of <code>JInternalFrames</code> |
|
57 |
* to provide a pluggable <code>DesktopManager</code> object to the |
|
58 |
* <code>JInternalFrames</code>. The <code>installUI</code> of the |
|
59 |
* L&F specific implementation is responsible for setting the |
|
60 |
* <code>desktopManager</code> variable appropriately. |
|
61 |
* When the parent of a <code>JInternalFrame</code> is a <code>JDesktopPane</code>, |
|
62 |
* it should delegate most of its behavior to the <code>desktopManager</code> |
|
63 |
* (closing, resizing, etc). |
|
64 |
* <p> |
|
65 |
* For further documentation and examples see |
|
66 |
* <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/internalframe.html">How to Use Internal Frames</a>, |
|
67 |
* a section in <em>The Java Tutorial</em>. |
|
68 |
* <p> |
|
69 |
* <strong>Warning:</strong> Swing is not thread safe. For more |
|
70 |
* information see <a |
|
71 |
* href="package-summary.html#threading">Swing's Threading |
|
72 |
* Policy</a>. |
|
73 |
* <p> |
|
74 |
* <strong>Warning:</strong> |
|
75 |
* Serialized objects of this class will not be compatible with |
|
76 |
* future Swing releases. The current serialization support is |
|
77 |
* appropriate for short term storage or RMI between applications running |
|
78 |
* the same version of Swing. As of 1.4, support for long term storage |
|
79 |
* of all JavaBeans<sup><font size="-2">TM</font></sup> |
|
80 |
* has been added to the <code>java.beans</code> package. |
|
81 |
* Please see {@link java.beans.XMLEncoder}. |
|
82 |
* |
|
83 |
* @see JInternalFrame |
|
84 |
* @see JInternalFrame.JDesktopIcon |
|
85 |
* @see DesktopManager |
|
86 |
* |
|
87 |
* @author David Kloba |
|
88 |
*/ |
|
89 |
public class JDesktopPane extends JLayeredPane implements Accessible |
|
90 |
{ |
|
91 |
/** |
|
92 |
* @see #getUIClassID |
|
93 |
* @see #readObject |
|
94 |
*/ |
|
95 |
private static final String uiClassID = "DesktopPaneUI"; |
|
96 |
||
97 |
transient DesktopManager desktopManager; |
|
98 |
||
99 |
private transient JInternalFrame selectedFrame = null; |
|
100 |
||
101 |
/** |
|
102 |
* Indicates that the entire contents of the item being dragged |
|
103 |
* should appear inside the desktop pane. |
|
104 |
* |
|
105 |
* @see #OUTLINE_DRAG_MODE |
|
106 |
* @see #setDragMode |
|
107 |
*/ |
|
108 |
public static final int LIVE_DRAG_MODE = 0; |
|
109 |
||
110 |
/** |
|
111 |
* Indicates that an outline only of the item being dragged |
|
112 |
* should appear inside the desktop pane. |
|
113 |
* |
|
114 |
* @see #LIVE_DRAG_MODE |
|
115 |
* @see #setDragMode |
|
116 |
*/ |
|
117 |
public static final int OUTLINE_DRAG_MODE = 1; |
|
118 |
||
119 |
private int dragMode = LIVE_DRAG_MODE; |
|
120 |
private boolean dragModeSet = false; |
|
121 |
private transient List<JInternalFrame> framesCache; |
|
122 |
private boolean componentOrderCheckingEnabled = true; |
|
123 |
private boolean componentOrderChanged = false; |
|
124 |
||
125 |
/** |
|
126 |
* Creates a new <code>JDesktopPane</code>. |
|
127 |
*/ |
|
128 |
public JDesktopPane() { |
|
129 |
setUIProperty("opaque", Boolean.TRUE); |
|
130 |
setFocusCycleRoot(true); |
|
131 |
||
132 |
setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() { |
|
133 |
public Component getDefaultComponent(Container c) { |
|
134 |
JInternalFrame jifArray[] = getAllFrames(); |
|
135 |
Component comp = null; |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
136 |
for (JInternalFrame jif : jifArray) { |
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
2
diff
changeset
|
137 |
comp = jif.getFocusTraversalPolicy().getDefaultComponent(jif); |
2 | 138 |
if (comp != null) { |
139 |
break; |
|
140 |
} |
|
141 |
} |
|
142 |
return comp; |
|
143 |
} |
|
144 |
}); |
|
145 |
updateUI(); |
|
146 |
} |
|
147 |
||
148 |
/** |
|
149 |
* Returns the L&F object that renders this component. |
|
150 |
* |
|
151 |
* @return the <code>DesktopPaneUI</code> object that |
|
152 |
* renders this component |
|
153 |
*/ |
|
154 |
public DesktopPaneUI getUI() { |
|
155 |
return (DesktopPaneUI)ui; |
|
156 |
} |
|
157 |
||
158 |
/** |
|
159 |
* Sets the L&F object that renders this component. |
|
160 |
* |
|
161 |
* @param ui the DesktopPaneUI L&F object |
|
162 |
* @see UIDefaults#getUI |
|
163 |
* @beaninfo |
|
164 |
* bound: true |
|
165 |
* hidden: true |
|
166 |
* attribute: visualUpdate true |
|
167 |
* description: The UI object that implements the Component's LookAndFeel. |
|
168 |
*/ |
|
169 |
public void setUI(DesktopPaneUI ui) { |
|
170 |
super.setUI(ui); |
|
171 |
} |
|
172 |
||
173 |
/** |
|
174 |
* Sets the "dragging style" used by the desktop pane. |
|
175 |
* You may want to change to one mode or another for |
|
176 |
* performance or aesthetic reasons. |
|
177 |
* |
|
178 |
* @param dragMode the style of drag to use for items in the Desktop |
|
179 |
* |
|
180 |
* @see #LIVE_DRAG_MODE |
|
181 |
* @see #OUTLINE_DRAG_MODE |
|
182 |
* |
|
183 |
* @beaninfo |
|
184 |
* bound: true |
|
185 |
* description: Dragging style for internal frame children. |
|
186 |
* enum: LIVE_DRAG_MODE JDesktopPane.LIVE_DRAG_MODE |
|
187 |
* OUTLINE_DRAG_MODE JDesktopPane.OUTLINE_DRAG_MODE |
|
188 |
* @since 1.3 |
|
189 |
*/ |
|
190 |
public void setDragMode(int dragMode) { |
|
191 |
int oldDragMode = this.dragMode; |
|
192 |
this.dragMode = dragMode; |
|
193 |
firePropertyChange("dragMode", oldDragMode, this.dragMode); |
|
194 |
dragModeSet = true; |
|
195 |
} |
|
196 |
||
197 |
/** |
|
198 |
* Gets the current "dragging style" used by the desktop pane. |
|
199 |
* @return either <code>Live_DRAG_MODE</code> or |
|
200 |
* <code>OUTLINE_DRAG_MODE</code> |
|
201 |
* @see #setDragMode |
|
202 |
* @since 1.3 |
|
203 |
*/ |
|
204 |
public int getDragMode() { |
|
205 |
return dragMode; |
|
206 |
} |
|
207 |
||
208 |
/** |
|
209 |
* Returns the <code>DesktopManger</code> that handles |
|
210 |
* desktop-specific UI actions. |
|
211 |
*/ |
|
212 |
public DesktopManager getDesktopManager() { |
|
213 |
return desktopManager; |
|
214 |
} |
|
215 |
||
216 |
/** |
|
217 |
* Sets the <code>DesktopManger</code> that will handle |
|
6653
a5de0f1919f9
6960126: With GTK L&F JDesktopPane substitutes set desktop manager
peterz
parents:
5506
diff
changeset
|
218 |
* desktop-specific UI actions. This may be overridden by |
a5de0f1919f9
6960126: With GTK L&F JDesktopPane substitutes set desktop manager
peterz
parents:
5506
diff
changeset
|
219 |
* {@code LookAndFeel}. |
2 | 220 |
* |
221 |
* @param d the <code>DesktopManager</code> to use |
|
222 |
* |
|
223 |
* @beaninfo |
|
224 |
* bound: true |
|
225 |
* description: Desktop manager to handle the internal frames in the |
|
226 |
* desktop pane. |
|
227 |
*/ |
|
228 |
public void setDesktopManager(DesktopManager d) { |
|
229 |
DesktopManager oldValue = desktopManager; |
|
230 |
desktopManager = d; |
|
231 |
firePropertyChange("desktopManager", oldValue, desktopManager); |
|
232 |
} |
|
233 |
||
234 |
/** |
|
235 |
* Notification from the <code>UIManager</code> that the L&F has changed. |
|
236 |
* Replaces the current UI object with the latest version from the |
|
237 |
* <code>UIManager</code>. |
|
238 |
* |
|
239 |
* @see JComponent#updateUI |
|
240 |
*/ |
|
241 |
public void updateUI() { |
|
242 |
setUI((DesktopPaneUI)UIManager.getUI(this)); |
|
243 |
} |
|
244 |
||
245 |
||
246 |
/** |
|
247 |
* Returns the name of the L&F class that renders this component. |
|
248 |
* |
|
249 |
* @return the string "DesktopPaneUI" |
|
250 |
* @see JComponent#getUIClassID |
|
251 |
* @see UIDefaults#getUI |
|
252 |
*/ |
|
253 |
public String getUIClassID() { |
|
254 |
return uiClassID; |
|
255 |
} |
|
256 |
||
257 |
/** |
|
258 |
* Returns all <code>JInternalFrames</code> currently displayed in the |
|
259 |
* desktop. Returns iconified frames as well as expanded frames. |
|
260 |
* |
|
261 |
* @return an array of <code>JInternalFrame</code> objects |
|
262 |
*/ |
|
263 |
public JInternalFrame[] getAllFrames() { |
|
12532
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
264 |
return getAllFrames(this).toArray(new JInternalFrame[0]); |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
265 |
} |
2 | 266 |
|
12532
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
267 |
private static Collection<JInternalFrame> getAllFrames(Container parent) { |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
268 |
int i, count; |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
269 |
Collection<JInternalFrame> results = new ArrayList<JInternalFrame>(); |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
270 |
count = parent.getComponentCount(); |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
271 |
for (i = 0; i < count; i++) { |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
272 |
Component next = parent.getComponent(i); |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
273 |
if (next instanceof JInternalFrame) { |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
274 |
results.add((JInternalFrame) next); |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
275 |
} else if (next instanceof JInternalFrame.JDesktopIcon) { |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
276 |
JInternalFrame tmp = ((JInternalFrame.JDesktopIcon) next).getInternalFrame(); |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
277 |
if (tmp != null) { |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
278 |
results.add(tmp); |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
279 |
} |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
280 |
} else if (next instanceof Container) { |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
281 |
results.addAll(getAllFrames((Container) next)); |
2 | 282 |
} |
283 |
} |
|
284 |
return results; |
|
285 |
} |
|
286 |
||
287 |
/** Returns the currently active <code>JInternalFrame</code> |
|
288 |
* in this <code>JDesktopPane</code>, or <code>null</code> |
|
289 |
* if no <code>JInternalFrame</code> is currently active. |
|
290 |
* |
|
291 |
* @return the currently active <code>JInternalFrame</code> or |
|
292 |
* <code>null</code> |
|
293 |
* @since 1.3 |
|
294 |
*/ |
|
295 |
||
296 |
public JInternalFrame getSelectedFrame() { |
|
297 |
return selectedFrame; |
|
298 |
} |
|
299 |
||
300 |
/** Sets the currently active <code>JInternalFrame</code> |
|
301 |
* in this <code>JDesktopPane</code>. This method is used to bridge |
|
302 |
* the package gap between JDesktopPane and the platform implementation |
|
303 |
* code and should not be called directly. To visually select the frame |
|
304 |
* the client must call JInternalFrame.setSelected(true) to activate |
|
305 |
* the frame. |
|
306 |
* @see JInternalFrame#setSelected(boolean) |
|
307 |
* |
|
308 |
* @param f the internal frame that's currently selected |
|
309 |
* @since 1.3 |
|
310 |
*/ |
|
311 |
||
312 |
public void setSelectedFrame(JInternalFrame f) { |
|
313 |
selectedFrame = f; |
|
314 |
} |
|
315 |
||
316 |
/** |
|
317 |
* Returns all <code>JInternalFrames</code> currently displayed in the |
|
318 |
* specified layer of the desktop. Returns iconified frames as well |
|
319 |
* expanded frames. |
|
320 |
* |
|
321 |
* @param layer an int specifying the desktop layer |
|
322 |
* @return an array of <code>JInternalFrame</code> objects |
|
323 |
* @see JLayeredPane |
|
324 |
*/ |
|
325 |
public JInternalFrame[] getAllFramesInLayer(int layer) { |
|
12532
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
326 |
Collection<JInternalFrame> allFrames = getAllFrames(this); |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
327 |
Iterator<JInternalFrame> iterator = allFrames.iterator(); |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
328 |
while (iterator.hasNext()) { |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
329 |
if (iterator.next().getLayer() != layer) { |
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
330 |
iterator.remove(); |
2 | 331 |
} |
332 |
} |
|
12532
dbf5d9a4b7bb
7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents:
7668
diff
changeset
|
333 |
return allFrames.toArray(new JInternalFrame[0]); |
2 | 334 |
} |
335 |
||
336 |
private List<JInternalFrame> getFrames() { |
|
337 |
Component c; |
|
338 |
Set<ComponentPosition> set = new TreeSet<ComponentPosition>(); |
|
339 |
for (int i = 0; i < getComponentCount(); i++) { |
|
340 |
c = getComponent(i); |
|
341 |
if (c instanceof JInternalFrame) { |
|
342 |
set.add(new ComponentPosition((JInternalFrame)c, getLayer(c), |
|
343 |
i)); |
|
344 |
} |
|
345 |
else if (c instanceof JInternalFrame.JDesktopIcon) { |
|
346 |
c = ((JInternalFrame.JDesktopIcon)c).getInternalFrame(); |
|
347 |
set.add(new ComponentPosition((JInternalFrame)c, getLayer(c), |
|
348 |
i)); |
|
349 |
} |
|
350 |
} |
|
351 |
List<JInternalFrame> frames = new ArrayList<JInternalFrame>( |
|
352 |
set.size()); |
|
353 |
for (ComponentPosition position : set) { |
|
354 |
frames.add(position.component); |
|
355 |
} |
|
356 |
return frames; |
|
357 |
} |
|
358 |
||
359 |
private static class ComponentPosition implements |
|
360 |
Comparable<ComponentPosition> { |
|
361 |
private final JInternalFrame component; |
|
362 |
private final int layer; |
|
363 |
private final int zOrder; |
|
364 |
||
365 |
ComponentPosition(JInternalFrame component, int layer, int zOrder) { |
|
366 |
this.component = component; |
|
367 |
this.layer = layer; |
|
368 |
this.zOrder = zOrder; |
|
369 |
} |
|
370 |
||
371 |
public int compareTo(ComponentPosition o) { |
|
372 |
int delta = o.layer - layer; |
|
373 |
if (delta == 0) { |
|
374 |
return zOrder - o.zOrder; |
|
375 |
} |
|
376 |
return delta; |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
private JInternalFrame getNextFrame(JInternalFrame f, boolean forward) { |
|
381 |
verifyFramesCache(); |
|
382 |
if (f == null) { |
|
383 |
return getTopInternalFrame(); |
|
384 |
} |
|
385 |
int i = framesCache.indexOf(f); |
|
386 |
if (i == -1 || framesCache.size() == 1) { |
|
387 |
/* error */ |
|
388 |
return null; |
|
389 |
} |
|
390 |
if (forward) { |
|
391 |
// navigate to the next frame |
|
392 |
if (++i == framesCache.size()) { |
|
393 |
/* wrap */ |
|
394 |
i = 0; |
|
395 |
} |
|
396 |
} |
|
397 |
else { |
|
398 |
// navigate to the previous frame |
|
399 |
if (--i == -1) { |
|
400 |
/* wrap */ |
|
401 |
i = framesCache.size() - 1; |
|
402 |
} |
|
403 |
} |
|
404 |
return framesCache.get(i); |
|
405 |
} |
|
406 |
||
407 |
JInternalFrame getNextFrame(JInternalFrame f) { |
|
408 |
return getNextFrame(f, true); |
|
409 |
} |
|
410 |
||
411 |
private JInternalFrame getTopInternalFrame() { |
|
412 |
if (framesCache.size() == 0) { |
|
413 |
return null; |
|
414 |
} |
|
415 |
return framesCache.get(0); |
|
416 |
} |
|
417 |
||
418 |
private void updateFramesCache() { |
|
419 |
framesCache = getFrames(); |
|
420 |
} |
|
421 |
||
422 |
private void verifyFramesCache() { |
|
423 |
// If framesCache is dirty, then recreate it. |
|
424 |
if (componentOrderChanged) { |
|
425 |
componentOrderChanged = false; |
|
426 |
updateFramesCache(); |
|
427 |
} |
|
428 |
} |
|
429 |
||
430 |
/** |
|
431 |
* Selects the next <code>JInternalFrame</code> in this desktop pane. |
|
432 |
* |
|
433 |
* @param forward a boolean indicating which direction to select in; |
|
434 |
* <code>true</code> for forward, <code>false</code> for |
|
435 |
* backward |
|
436 |
* @return the JInternalFrame that was selected or <code>null</code> |
|
437 |
* if nothing was selected |
|
438 |
* @since 1.6 |
|
439 |
*/ |
|
440 |
public JInternalFrame selectFrame(boolean forward) { |
|
441 |
JInternalFrame selectedFrame = getSelectedFrame(); |
|
442 |
JInternalFrame frameToSelect = getNextFrame(selectedFrame, forward); |
|
443 |
if (frameToSelect == null) { |
|
444 |
return null; |
|
445 |
} |
|
446 |
// Maintain navigation traversal order until an |
|
447 |
// external stack change, such as a click on a frame. |
|
448 |
setComponentOrderCheckingEnabled(false); |
|
449 |
if (forward && selectedFrame != null) { |
|
450 |
selectedFrame.moveToBack(); // For Windows MDI fidelity. |
|
451 |
} |
|
452 |
try { frameToSelect.setSelected(true); |
|
453 |
} catch (PropertyVetoException pve) {} |
|
454 |
setComponentOrderCheckingEnabled(true); |
|
455 |
return frameToSelect; |
|
456 |
} |
|
457 |
||
458 |
/* |
|
459 |
* Sets whether component order checking is enabled. |
|
460 |
* @param enable a boolean value, where <code>true</code> means |
|
461 |
* a change in component order will cause a change in the keyboard |
|
462 |
* navigation order. |
|
463 |
* @since 1.6 |
|
464 |
*/ |
|
465 |
void setComponentOrderCheckingEnabled(boolean enable) { |
|
466 |
componentOrderCheckingEnabled = enable; |
|
467 |
} |
|
468 |
||
469 |
/** |
|
470 |
* {@inheritDoc} |
|
471 |
* @since 1.6 |
|
472 |
*/ |
|
473 |
protected void addImpl(Component comp, Object constraints, int index) { |
|
474 |
super.addImpl(comp, constraints, index); |
|
475 |
if (componentOrderCheckingEnabled) { |
|
476 |
if (comp instanceof JInternalFrame || |
|
477 |
comp instanceof JInternalFrame.JDesktopIcon) { |
|
478 |
componentOrderChanged = true; |
|
479 |
} |
|
480 |
} |
|
481 |
} |
|
482 |
||
483 |
/** |
|
484 |
* {@inheritDoc} |
|
485 |
* @since 1.6 |
|
486 |
*/ |
|
487 |
public void remove(int index) { |
|
488 |
if (componentOrderCheckingEnabled) { |
|
489 |
Component comp = getComponent(index); |
|
490 |
if (comp instanceof JInternalFrame || |
|
491 |
comp instanceof JInternalFrame.JDesktopIcon) { |
|
492 |
componentOrderChanged = true; |
|
493 |
} |
|
494 |
} |
|
495 |
super.remove(index); |
|
496 |
} |
|
497 |
||
498 |
/** |
|
499 |
* {@inheritDoc} |
|
500 |
* @since 1.6 |
|
501 |
*/ |
|
502 |
public void removeAll() { |
|
503 |
if (componentOrderCheckingEnabled) { |
|
504 |
int count = getComponentCount(); |
|
505 |
for (int i = 0; i < count; i++) { |
|
506 |
Component comp = getComponent(i); |
|
507 |
if (comp instanceof JInternalFrame || |
|
508 |
comp instanceof JInternalFrame.JDesktopIcon) { |
|
509 |
componentOrderChanged = true; |
|
510 |
break; |
|
511 |
} |
|
512 |
} |
|
513 |
} |
|
514 |
super.removeAll(); |
|
515 |
} |
|
516 |
||
517 |
/** |
|
518 |
* {@inheritDoc} |
|
519 |
* @since 1.6 |
|
520 |
*/ |
|
521 |
public void setComponentZOrder(Component comp, int index) { |
|
522 |
super.setComponentZOrder(comp, index); |
|
523 |
if (componentOrderCheckingEnabled) { |
|
524 |
if (comp instanceof JInternalFrame || |
|
525 |
comp instanceof JInternalFrame.JDesktopIcon) { |
|
526 |
componentOrderChanged = true; |
|
527 |
} |
|
528 |
} |
|
529 |
} |
|
530 |
||
531 |
/** |
|
532 |
* See readObject() and writeObject() in JComponent for more |
|
533 |
* information about serialization in Swing. |
|
534 |
*/ |
|
535 |
private void writeObject(ObjectOutputStream s) throws IOException { |
|
536 |
s.defaultWriteObject(); |
|
537 |
if (getUIClassID().equals(uiClassID)) { |
|
538 |
byte count = JComponent.getWriteObjCounter(this); |
|
539 |
JComponent.setWriteObjCounter(this, --count); |
|
540 |
if (count == 0 && ui != null) { |
|
541 |
ui.installUI(this); |
|
542 |
} |
|
543 |
} |
|
544 |
} |
|
545 |
||
546 |
void setUIProperty(String propertyName, Object value) { |
|
547 |
if (propertyName == "dragMode") { |
|
548 |
if (!dragModeSet) { |
|
549 |
setDragMode(((Integer)value).intValue()); |
|
550 |
dragModeSet = false; |
|
551 |
} |
|
552 |
} else { |
|
553 |
super.setUIProperty(propertyName, value); |
|
554 |
} |
|
555 |
} |
|
556 |
||
557 |
/** |
|
558 |
* Returns a string representation of this <code>JDesktopPane</code>. |
|
559 |
* This method is intended to be used only for debugging purposes, and the |
|
560 |
* content and format of the returned string may vary between |
|
561 |
* implementations. The returned string may be empty but may not |
|
562 |
* be <code>null</code>. |
|
563 |
* |
|
564 |
* @return a string representation of this <code>JDesktopPane</code> |
|
565 |
*/ |
|
566 |
protected String paramString() { |
|
567 |
String desktopManagerString = (desktopManager != null ? |
|
568 |
desktopManager.toString() : ""); |
|
569 |
||
570 |
return super.paramString() + |
|
571 |
",desktopManager=" + desktopManagerString; |
|
572 |
} |
|
573 |
||
574 |
///////////////// |
|
575 |
// Accessibility support |
|
576 |
//////////////// |
|
577 |
||
578 |
/** |
|
579 |
* Gets the <code>AccessibleContext</code> associated with this |
|
580 |
* <code>JDesktopPane</code>. For desktop panes, the |
|
581 |
* <code>AccessibleContext</code> takes the form of an |
|
582 |
* <code>AccessibleJDesktopPane</code>. |
|
583 |
* A new <code>AccessibleJDesktopPane</code> instance is created if necessary. |
|
584 |
* |
|
585 |
* @return an <code>AccessibleJDesktopPane</code> that serves as the |
|
586 |
* <code>AccessibleContext</code> of this <code>JDesktopPane</code> |
|
587 |
*/ |
|
588 |
public AccessibleContext getAccessibleContext() { |
|
589 |
if (accessibleContext == null) { |
|
590 |
accessibleContext = new AccessibleJDesktopPane(); |
|
591 |
} |
|
592 |
return accessibleContext; |
|
593 |
} |
|
594 |
||
595 |
/** |
|
596 |
* This class implements accessibility support for the |
|
597 |
* <code>JDesktopPane</code> class. It provides an implementation of the |
|
598 |
* Java Accessibility API appropriate to desktop pane user-interface |
|
599 |
* elements. |
|
600 |
* <p> |
|
601 |
* <strong>Warning:</strong> |
|
602 |
* Serialized objects of this class will not be compatible with |
|
603 |
* future Swing releases. The current serialization support is |
|
604 |
* appropriate for short term storage or RMI between applications running |
|
605 |
* the same version of Swing. As of 1.4, support for long term storage |
|
606 |
* of all JavaBeans<sup><font size="-2">TM</font></sup> |
|
607 |
* has been added to the <code>java.beans</code> package. |
|
608 |
* Please see {@link java.beans.XMLEncoder}. |
|
609 |
*/ |
|
610 |
protected class AccessibleJDesktopPane extends AccessibleJComponent { |
|
611 |
||
612 |
/** |
|
613 |
* Get the role of this object. |
|
614 |
* |
|
615 |
* @return an instance of AccessibleRole describing the role of the |
|
616 |
* object |
|
617 |
* @see AccessibleRole |
|
618 |
*/ |
|
619 |
public AccessibleRole getAccessibleRole() { |
|
620 |
return AccessibleRole.DESKTOP_PANE; |
|
621 |
} |
|
622 |
} |
|
623 |
} |