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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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.
24 */
25
26 package javax.swing;
27
28 import java.util.List;
29 import java.util.ArrayList;
30 import java.util.Collection;
31 import java.util.Iterator;
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
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™
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 * @since 1.2
89 */
90 @SuppressWarnings("serial") // Same-version serialization only
91 public class JDesktopPane extends JLayeredPane implements Accessible
92 {
93 /**
94 * @see #getUIClassID
95 * @see #readObject
96 */
97 private static final String uiClassID = "DesktopPaneUI";
98
99 transient DesktopManager desktopManager;
100
101 private transient JInternalFrame selectedFrame = null;
102
103 /**
104 * Indicates that the entire contents of the item being dragged
105 * should appear inside the desktop pane.
106 *
107 * @see #OUTLINE_DRAG_MODE
108 * @see #setDragMode
109 */
145 }
146 });
147 updateUI();
148 }
149
150 /**
151 * Returns the L&F object that renders this component.
152 *
153 * @return the <code>DesktopPaneUI</code> object that
154 * renders this component
155 */
156 public DesktopPaneUI getUI() {
157 return (DesktopPaneUI)ui;
158 }
159
160 /**
161 * Sets the L&F object that renders this component.
162 *
163 * @param ui the DesktopPaneUI L&F object
164 * @see UIDefaults#getUI
165 * @beaninfo
166 * bound: true
167 * hidden: true
168 * attribute: visualUpdate true
169 * description: The UI object that implements the Component's LookAndFeel.
170 */
171 public void setUI(DesktopPaneUI ui) {
172 super.setUI(ui);
173 }
174
175 /**
176 * Sets the "dragging style" used by the desktop pane.
177 * You may want to change to one mode or another for
178 * performance or aesthetic reasons.
179 *
180 * @param dragMode the style of drag to use for items in the Desktop
181 *
182 * @see #LIVE_DRAG_MODE
183 * @see #OUTLINE_DRAG_MODE
184 *
185 * @beaninfo
186 * bound: true
187 * description: Dragging style for internal frame children.
188 * enum: LIVE_DRAG_MODE JDesktopPane.LIVE_DRAG_MODE
189 * OUTLINE_DRAG_MODE JDesktopPane.OUTLINE_DRAG_MODE
190 * @since 1.3
191 */
192 public void setDragMode(int dragMode) {
193 int oldDragMode = this.dragMode;
194 this.dragMode = dragMode;
195 firePropertyChange("dragMode", oldDragMode, this.dragMode);
196 dragModeSet = true;
197 }
198
199 /**
200 * Gets the current "dragging style" used by the desktop pane.
201 * @return either <code>Live_DRAG_MODE</code> or
202 * <code>OUTLINE_DRAG_MODE</code>
203 * @see #setDragMode
204 * @since 1.3
205 */
206 public int getDragMode() {
207 return dragMode;
208 }
209
210 /**
211 * Returns the {@code DesktopManger} that handles
212 * desktop-specific UI actions.
213 *
214 * @return the {@code DesktopManger} that handles desktop-specific
215 * UI actions
216 */
217 public DesktopManager getDesktopManager() {
218 return desktopManager;
219 }
220
221 /**
222 * Sets the <code>DesktopManger</code> that will handle
223 * desktop-specific UI actions. This may be overridden by
224 * {@code LookAndFeel}.
225 *
226 * @param d the <code>DesktopManager</code> to use
227 *
228 * @beaninfo
229 * bound: true
230 * description: Desktop manager to handle the internal frames in the
231 * desktop pane.
232 */
233 public void setDesktopManager(DesktopManager d) {
234 DesktopManager oldValue = desktopManager;
235 desktopManager = d;
236 firePropertyChange("desktopManager", oldValue, desktopManager);
237 }
238
239 /**
240 * Notification from the <code>UIManager</code> that the L&F has changed.
241 * Replaces the current UI object with the latest version from the
242 * <code>UIManager</code>.
243 *
244 * @see JComponent#updateUI
245 */
246 public void updateUI() {
247 setUI((DesktopPaneUI)UIManager.getUI(this));
248 }
249
250
251 /**
252 * Returns the name of the L&F class that renders this component.
253 *
254 * @return the string "DesktopPaneUI"
255 * @see JComponent#getUIClassID
256 * @see UIDefaults#getUI
257 */
258 public String getUIClassID() {
259 return uiClassID;
260 }
261
262 /**
263 * Returns all <code>JInternalFrames</code> currently displayed in the
264 * desktop. Returns iconified frames as well as expanded frames.
265 *
266 * @return an array of <code>JInternalFrame</code> objects
267 */
268 public JInternalFrame[] getAllFrames() {
269 return getAllFrames(this).toArray(new JInternalFrame[0]);
270 }
271
272 private static Collection<JInternalFrame> getAllFrames(Container parent) {
273 int i, count;
274 Collection<JInternalFrame> results = new ArrayList<JInternalFrame>();
275 count = parent.getComponentCount();
276 for (i = 0; i < count; i++) {
277 Component next = parent.getComponent(i);
278 if (next instanceof JInternalFrame) {
279 results.add((JInternalFrame) next);
280 } else if (next instanceof JInternalFrame.JDesktopIcon) {
281 JInternalFrame tmp = ((JInternalFrame.JDesktopIcon) next).getInternalFrame();
282 if (tmp != null) {
283 results.add(tmp);
284 }
285 } else if (next instanceof Container) {
286 results.addAll(getAllFrames((Container) next));
287 }
582 desktopManager.toString() : "");
583
584 return super.paramString() +
585 ",desktopManager=" + desktopManagerString;
586 }
587
588 /////////////////
589 // Accessibility support
590 ////////////////
591
592 /**
593 * Gets the <code>AccessibleContext</code> associated with this
594 * <code>JDesktopPane</code>. For desktop panes, the
595 * <code>AccessibleContext</code> takes the form of an
596 * <code>AccessibleJDesktopPane</code>.
597 * A new <code>AccessibleJDesktopPane</code> instance is created if necessary.
598 *
599 * @return an <code>AccessibleJDesktopPane</code> that serves as the
600 * <code>AccessibleContext</code> of this <code>JDesktopPane</code>
601 */
602 public AccessibleContext getAccessibleContext() {
603 if (accessibleContext == null) {
604 accessibleContext = new AccessibleJDesktopPane();
605 }
606 return accessibleContext;
607 }
608
609 /**
610 * This class implements accessibility support for the
611 * <code>JDesktopPane</code> class. It provides an implementation of the
612 * Java Accessibility API appropriate to desktop pane user-interface
613 * elements.
614 * <p>
615 * <strong>Warning:</strong>
616 * Serialized objects of this class will not be compatible with
617 * future Swing releases. The current serialization support is
618 * appropriate for short term storage or RMI between applications running
619 * the same version of Swing. As of 1.4, support for long term storage
620 * of all JavaBeans™
621 * has been added to the <code>java.beans</code> package.
|
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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.
24 */
25 package javax.swing;
26
27 import java.util.List;
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.Iterator;
31 import javax.swing.plaf.*;
32 import javax.accessibility.*;
33
34 import java.awt.Component;
35 import java.awt.Container;
36 import java.beans.JavaBean;
37 import java.beans.BeanProperty;
38 import java.io.ObjectOutputStream;
39 import java.io.IOException;
40 import java.beans.PropertyVetoException;
41 import java.util.Set;
42 import java.util.TreeSet;
43
44 /**
45 * A container used to create a multiple-document interface or a virtual desktop.
46 * You create <code>JInternalFrame</code> objects and add them to the
47 * <code>JDesktopPane</code>. <code>JDesktopPane</code> extends
48 * <code>JLayeredPane</code> to manage the potentially overlapping internal
49 * frames. It also maintains a reference to an instance of
50 * <code>DesktopManager</code> that is set by the UI
51 * class for the current look and feel (L&F). Note that <code>JDesktopPane</code>
52 * does not support borders.
53 * <p>
54 * This class is normally used as the parent of <code>JInternalFrames</code>
55 * to provide a pluggable <code>DesktopManager</code> object to the
56 * <code>JInternalFrames</code>. The <code>installUI</code> of the
57 * L&F specific implementation is responsible for setting the
58 * <code>desktopManager</code> variable appropriately.
59 * When the parent of a <code>JInternalFrame</code> is a <code>JDesktopPane</code>,
60 * it should delegate most of its behavior to the <code>desktopManager</code>
61 * (closing, resizing, etc).
62 * <p>
63 * For further documentation and examples see
68 * information see <a
69 * href="package-summary.html#threading">Swing's Threading
70 * Policy</a>.
71 * <p>
72 * <strong>Warning:</strong>
73 * Serialized objects of this class will not be compatible with
74 * future Swing releases. The current serialization support is
75 * appropriate for short term storage or RMI between applications running
76 * the same version of Swing. As of 1.4, support for long term storage
77 * of all JavaBeans™
78 * has been added to the <code>java.beans</code> package.
79 * Please see {@link java.beans.XMLEncoder}.
80 *
81 * @see JInternalFrame
82 * @see JInternalFrame.JDesktopIcon
83 * @see DesktopManager
84 *
85 * @author David Kloba
86 * @since 1.2
87 */
88 @JavaBean(defaultProperty = "UI")
89 @SuppressWarnings("serial") // Same-version serialization only
90 public class JDesktopPane extends JLayeredPane implements Accessible
91 {
92 /**
93 * @see #getUIClassID
94 * @see #readObject
95 */
96 private static final String uiClassID = "DesktopPaneUI";
97
98 transient DesktopManager desktopManager;
99
100 private transient JInternalFrame selectedFrame = null;
101
102 /**
103 * Indicates that the entire contents of the item being dragged
104 * should appear inside the desktop pane.
105 *
106 * @see #OUTLINE_DRAG_MODE
107 * @see #setDragMode
108 */
144 }
145 });
146 updateUI();
147 }
148
149 /**
150 * Returns the L&F object that renders this component.
151 *
152 * @return the <code>DesktopPaneUI</code> object that
153 * renders this component
154 */
155 public DesktopPaneUI getUI() {
156 return (DesktopPaneUI)ui;
157 }
158
159 /**
160 * Sets the L&F object that renders this component.
161 *
162 * @param ui the DesktopPaneUI L&F object
163 * @see UIDefaults#getUI
164 */
165 @BeanProperty(hidden = true, visualUpdate = true, description
166 = "The UI object that implements the Component's LookAndFeel.")
167 public void setUI(DesktopPaneUI ui) {
168 super.setUI(ui);
169 }
170
171 /**
172 * Sets the "dragging style" used by the desktop pane.
173 * You may want to change to one mode or another for
174 * performance or aesthetic reasons.
175 *
176 * @param dragMode the style of drag to use for items in the Desktop
177 *
178 * @see #LIVE_DRAG_MODE
179 * @see #OUTLINE_DRAG_MODE
180 *
181 * @since 1.3
182 */
183 @BeanProperty(enumerationValues = {
184 "JDesktopPane.LIVE_DRAG_MODE",
185 "JDesktopPane.OUTLINE_DRAG_MODE"}, description
186 = "Dragging style for internal frame children.")
187 public void setDragMode(int dragMode) {
188 int oldDragMode = this.dragMode;
189 this.dragMode = dragMode;
190 firePropertyChange("dragMode", oldDragMode, this.dragMode);
191 dragModeSet = true;
192 }
193
194 /**
195 * Gets the current "dragging style" used by the desktop pane.
196 * @return either <code>Live_DRAG_MODE</code> or
197 * <code>OUTLINE_DRAG_MODE</code>
198 * @see #setDragMode
199 * @since 1.3
200 */
201 public int getDragMode() {
202 return dragMode;
203 }
204
205 /**
206 * Returns the {@code DesktopManger} that handles
207 * desktop-specific UI actions.
208 *
209 * @return the {@code DesktopManger} that handles desktop-specific
210 * UI actions
211 */
212 public DesktopManager getDesktopManager() {
213 return desktopManager;
214 }
215
216 /**
217 * Sets the <code>DesktopManger</code> that will handle
218 * desktop-specific UI actions. This may be overridden by
219 * {@code LookAndFeel}.
220 *
221 * @param d the <code>DesktopManager</code> to use
222 */
223 @BeanProperty(description
224 = "Desktop manager to handle the internal frames in the desktop pane.")
225 public void setDesktopManager(DesktopManager d) {
226 DesktopManager oldValue = desktopManager;
227 desktopManager = d;
228 firePropertyChange("desktopManager", oldValue, desktopManager);
229 }
230
231 /**
232 * Notification from the <code>UIManager</code> that the L&F has changed.
233 * Replaces the current UI object with the latest version from the
234 * <code>UIManager</code>.
235 *
236 * @see JComponent#updateUI
237 */
238 public void updateUI() {
239 setUI((DesktopPaneUI)UIManager.getUI(this));
240 }
241
242
243 /**
244 * Returns the name of the L&F class that renders this component.
245 *
246 * @return the string "DesktopPaneUI"
247 * @see JComponent#getUIClassID
248 * @see UIDefaults#getUI
249 */
250 @BeanProperty(bound = false)
251 public String getUIClassID() {
252 return uiClassID;
253 }
254
255 /**
256 * Returns all <code>JInternalFrames</code> currently displayed in the
257 * desktop. Returns iconified frames as well as expanded frames.
258 *
259 * @return an array of <code>JInternalFrame</code> objects
260 */
261 @BeanProperty(bound = false)
262 public JInternalFrame[] getAllFrames() {
263 return getAllFrames(this).toArray(new JInternalFrame[0]);
264 }
265
266 private static Collection<JInternalFrame> getAllFrames(Container parent) {
267 int i, count;
268 Collection<JInternalFrame> results = new ArrayList<JInternalFrame>();
269 count = parent.getComponentCount();
270 for (i = 0; i < count; i++) {
271 Component next = parent.getComponent(i);
272 if (next instanceof JInternalFrame) {
273 results.add((JInternalFrame) next);
274 } else if (next instanceof JInternalFrame.JDesktopIcon) {
275 JInternalFrame tmp = ((JInternalFrame.JDesktopIcon) next).getInternalFrame();
276 if (tmp != null) {
277 results.add(tmp);
278 }
279 } else if (next instanceof Container) {
280 results.addAll(getAllFrames((Container) next));
281 }
576 desktopManager.toString() : "");
577
578 return super.paramString() +
579 ",desktopManager=" + desktopManagerString;
580 }
581
582 /////////////////
583 // Accessibility support
584 ////////////////
585
586 /**
587 * Gets the <code>AccessibleContext</code> associated with this
588 * <code>JDesktopPane</code>. For desktop panes, the
589 * <code>AccessibleContext</code> takes the form of an
590 * <code>AccessibleJDesktopPane</code>.
591 * A new <code>AccessibleJDesktopPane</code> instance is created if necessary.
592 *
593 * @return an <code>AccessibleJDesktopPane</code> that serves as the
594 * <code>AccessibleContext</code> of this <code>JDesktopPane</code>
595 */
596 @BeanProperty(bound = false)
597 public AccessibleContext getAccessibleContext() {
598 if (accessibleContext == null) {
599 accessibleContext = new AccessibleJDesktopPane();
600 }
601 return accessibleContext;
602 }
603
604 /**
605 * This class implements accessibility support for the
606 * <code>JDesktopPane</code> class. It provides an implementation of the
607 * Java Accessibility API appropriate to desktop pane user-interface
608 * elements.
609 * <p>
610 * <strong>Warning:</strong>
611 * Serialized objects of this class will not be compatible with
612 * future Swing releases. The current serialization support is
613 * appropriate for short term storage or RMI between applications running
614 * the same version of Swing. As of 1.4, support for long term storage
615 * of all JavaBeans™
616 * has been added to the <code>java.beans</code> package.
|