Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / swing / JDesktopPane.java
blob43ab71e7e9ffca36c06f5a7dab44463a3be8ec80
1 /* JDesktopPane.java --
2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing;
41 import java.awt.Component;
42 import java.beans.PropertyVetoException;
44 import javax.accessibility.Accessible;
45 import javax.accessibility.AccessibleContext;
46 import javax.accessibility.AccessibleRole;
47 import javax.swing.plaf.DesktopPaneUI;
49 /**
50 * JDesktopPane is a container (usually for JInternalFrames) that simulates a
51 * desktop. Typically, the user will create JInternalFrames and place them in
52 * a JDesktopPane. The user can then interact with JInternalFrames like they
53 * usually would with JFrames. The actions (minimize, maximize, close, etc)
54 * are done by using a DesktopManager that is associated with the
55 * JDesktopPane.
57 public class JDesktopPane extends JLayeredPane implements Accessible
59 /** DOCUMENT ME! */
60 private static final long serialVersionUID = 766333777224038726L;
62 /**
63 * This specifies that when dragged, a JInternalFrame should be completely
64 * visible.
66 * @specnote final since 1.5.0.
68 public static final int LIVE_DRAG_MODE = 0;
70 /**
71 * This specifies that when dragged, a JInternalFrame should only be visible
72 * as an outline.
74 * @specnote final since 1.5.0.
76 public static final int OUTLINE_DRAG_MODE = 1;
78 /** The selected frame in the JDesktopPane. */
79 private transient JInternalFrame selectedFrame;
81 /** The JDesktopManager to use for acting on JInternalFrames. */
82 transient DesktopManager desktopManager;
84 /** The drag mode used by the JDesktopPane. */
85 private transient int dragMode = LIVE_DRAG_MODE;
87 /**
88 * AccessibleJDesktopPane
90 protected class AccessibleJDesktopPane extends AccessibleJComponent
92 /** DOCUMENT ME! */
93 private static final long serialVersionUID = 6079388927946077570L;
95 /**
96 * Constructor AccessibleJDesktopPane
98 protected AccessibleJDesktopPane()
100 // Nothing to do here.
104 * getAccessibleRole
106 * @return AccessibleRole
108 public AccessibleRole getAccessibleRole()
110 return AccessibleRole.DESKTOP_PANE;
115 * Creates a new JDesktopPane object.
117 public JDesktopPane()
119 setLayout(null);
120 updateUI();
124 * This method returns the UI used with the JDesktopPane.
126 * @return The UI used with the JDesktopPane.
128 public DesktopPaneUI getUI()
130 return (DesktopPaneUI) ui;
134 * This method sets the UI used with the JDesktopPane.
136 * @param ui The UI to use with the JDesktopPane.
138 public void setUI(DesktopPaneUI ui)
140 super.setUI(ui);
144 * This method sets the drag mode to use with the JDesktopPane.
146 * @param mode The drag mode to use.
148 * @throws IllegalArgumentException If the drag mode given is not
149 * LIVE_DRAG_MODE or OUTLINE_DRAG_MODE.
151 public void setDragMode(int mode)
153 if ((mode != LIVE_DRAG_MODE) && (mode != OUTLINE_DRAG_MODE))
154 throw new IllegalArgumentException("Drag mode not valid.");
156 // FIXME: Unsupported mode.
157 if (mode == OUTLINE_DRAG_MODE)
158 // throw new IllegalArgumentException("Outline drag modes are
159 // unsupported.");
160 mode = LIVE_DRAG_MODE;
162 dragMode = mode;
166 * This method returns the drag mode used with the JDesktopPane.
168 * @return The drag mode used with the JDesktopPane.
170 public int getDragMode()
172 return dragMode;
176 * This method returns the DesktopManager used with the JDesktopPane.
178 * @return The DesktopManager to use with the JDesktopPane.
180 public DesktopManager getDesktopManager()
182 return desktopManager;
186 * This method sets the DesktopManager to use with the JDesktopPane.
188 * @param manager The DesktopManager to use with the JDesktopPane.
190 public void setDesktopManager(DesktopManager manager)
192 desktopManager = manager;
196 * This method restores the UI used with the JDesktopPane to the default.
198 public void updateUI()
200 setUI((DesktopPaneUI) UIManager.getUI(this));
201 invalidate();
205 * This method returns a String identifier that allows the UIManager to know
206 * which class will act as JDesktopPane's UI.
208 * @return A String identifier for the UI class to use.
210 public String getUIClassID()
212 return "DesktopPaneUI";
216 * This method returns all JInternalFrames that are in the JDesktopPane.
218 * @return All JInternalFrames that are in the JDesktopPane.
220 public JInternalFrame[] getAllFrames()
222 return getFramesFromComponents(getComponents());
226 * This method returns the currently selected frame in the JDesktopPane.
228 * @return The currently selected frame in the JDesktopPane.
230 public JInternalFrame getSelectedFrame()
232 return selectedFrame;
236 * This method sets the selected frame in the JDesktopPane.
238 * @param frame The selected frame in the JDesktopPane.
240 public void setSelectedFrame(JInternalFrame frame)
242 if (selectedFrame != null)
246 selectedFrame.setSelected(false);
248 catch (PropertyVetoException e)
250 // We do nothing when the attempt is vetoed.
253 selectedFrame = null;
257 if (frame != null)
258 frame.setSelected(true);
260 selectedFrame = frame;
262 catch (PropertyVetoException e)
264 // We do nothing when the attempt is vetoed.
269 * This method returns all the JInternalFrames in the given layer.
271 * @param layer The layer to grab frames in.
273 * @return All JInternalFrames in the given layer.
275 public JInternalFrame[] getAllFramesInLayer(int layer)
277 return getFramesFromComponents(getComponentsInLayer(layer));
281 * This method always returns true to indicate that it is not transparent.
283 * @return true.
285 public boolean isOpaque()
287 return true;
291 * This method returns a String that describes the JDesktopPane.
293 * @return A String that describes the JDesktopPane.
295 protected String paramString()
297 return "JDesktopPane";
301 * This method returns all the JInternalFrames in the given Component array.
303 * @param components An array to search for JInternalFrames in.
305 * @return An array of JInternalFrames found in the Component array.
307 private static JInternalFrame[] getFramesFromComponents(Component[] components)
309 int count = 0;
311 for (int i = 0; i < components.length; i++)
312 if (components[i] instanceof JInternalFrame)
313 count++;
315 JInternalFrame[] value = new JInternalFrame[count];
316 for (int i = 0, j = 0; i < components.length && j != count; i++)
317 if (components[i] instanceof JInternalFrame)
318 value[j++] = (JInternalFrame) components[i];
319 return value;
323 * getAccessibleContext
325 * @return AccessibleContext
327 public AccessibleContext getAccessibleContext()
329 if (accessibleContext == null)
330 accessibleContext = new AccessibleJDesktopPane();
332 return accessibleContext;