2015-05-05 Yvan Roux <yvan.roux@linaro.org>
[official-gcc.git] / libjava / classpath / javax / swing / JDesktopPane.java
blob6d8b212760eb48a4c2d85f50f0327fc7aef745a4
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 gnu.java.lang.CPStringBuilder;
43 import java.awt.Component;
44 import java.beans.PropertyVetoException;
46 import javax.accessibility.Accessible;
47 import javax.accessibility.AccessibleContext;
48 import javax.accessibility.AccessibleRole;
49 import javax.swing.plaf.DesktopPaneUI;
51 /**
52 * JDesktopPane is a container (usually for JInternalFrames) that simulates a
53 * desktop. Typically, the user will create JInternalFrames and place them in
54 * a JDesktopPane. The user can then interact with JInternalFrames like they
55 * usually would with JFrames. The actions (minimize, maximize, close, etc)
56 * are done by using a DesktopManager that is associated with the
57 * JDesktopPane.
59 public class JDesktopPane extends JLayeredPane implements Accessible
61 private static final long serialVersionUID = 766333777224038726L;
63 /**
64 * This specifies that when dragged, a JInternalFrame should be completely
65 * visible.
67 * @specnote final since 1.5.0.
69 public static final int LIVE_DRAG_MODE = 0;
71 /**
72 * This specifies that when dragged, a JInternalFrame should only be visible
73 * as an outline.
75 * @specnote final since 1.5.0.
77 public static final int OUTLINE_DRAG_MODE = 1;
79 /** The selected frame in the JDesktopPane. */
80 private transient JInternalFrame selectedFrame;
82 /** The JDesktopManager to use for acting on JInternalFrames. */
83 transient DesktopManager desktopManager;
85 /** The drag mode used by the JDesktopPane. */
86 private transient int dragMode = LIVE_DRAG_MODE;
88 /**
89 * Indicates if the dragMode property has been set by a client
90 * program or by the UI.
92 * @see #setUIProperty(String, Object)
93 * @see LookAndFeel#installProperty(JComponent, String, Object)
95 private boolean clientDragModeSet = false;
97 /**
98 * Provides the accessibility features for the <code>JDesktopPane</code>
99 * component.
101 protected class AccessibleJDesktopPane extends AccessibleJComponent
103 private static final long serialVersionUID = 6079388927946077570L;
106 * Creates a new <code>AccessibleJDesktopPane</code> instance.
108 protected AccessibleJDesktopPane()
110 // Nothing to do here.
114 * Returns the accessible role for the <code>JSlider</code> component.
116 * @return {@link AccessibleRole#DESKTOP_PANE}.
118 public AccessibleRole getAccessibleRole()
120 return AccessibleRole.DESKTOP_PANE;
125 * Creates a new JDesktopPane object.
127 public JDesktopPane()
129 setLayout(null);
130 updateUI();
134 * This method returns the UI used with the JDesktopPane.
136 * @return The UI used with the JDesktopPane.
138 public DesktopPaneUI getUI()
140 return (DesktopPaneUI) ui;
144 * This method sets the UI used with the JDesktopPane.
146 * @param ui The UI to use with the JDesktopPane.
148 public void setUI(DesktopPaneUI ui)
150 super.setUI(ui);
154 * This method sets the drag mode to use with the JDesktopPane.
156 * @param mode The drag mode to use.
158 * @throws IllegalArgumentException If the drag mode given is not
159 * LIVE_DRAG_MODE or OUTLINE_DRAG_MODE.
161 public void setDragMode(int mode)
163 if ((mode != LIVE_DRAG_MODE) && (mode != OUTLINE_DRAG_MODE))
164 throw new IllegalArgumentException("Drag mode not valid.");
166 clientDragModeSet = true;
168 // FIXME: Unsupported mode.
169 if (mode == OUTLINE_DRAG_MODE)
170 // throw new IllegalArgumentException("Outline drag modes are
171 // unsupported.");
172 mode = LIVE_DRAG_MODE;
174 dragMode = mode;
178 * This method returns the drag mode used with the JDesktopPane.
180 * @return The drag mode used with the JDesktopPane.
182 public int getDragMode()
184 return dragMode;
188 * This method returns the DesktopManager used with the JDesktopPane.
190 * @return The DesktopManager to use with the JDesktopPane.
192 public DesktopManager getDesktopManager()
194 return desktopManager;
198 * This method sets the DesktopManager to use with the JDesktopPane.
200 * @param manager The DesktopManager to use with the JDesktopPane.
202 public void setDesktopManager(DesktopManager manager)
204 desktopManager = manager;
208 * This method restores the UI used with the JDesktopPane to the default.
210 public void updateUI()
212 setUI((DesktopPaneUI) UIManager.getUI(this));
216 * This method returns a String identifier that allows the UIManager to know
217 * which class will act as JDesktopPane's UI.
219 * @return A String identifier for the UI class to use.
221 public String getUIClassID()
223 return "DesktopPaneUI";
227 * This method returns all JInternalFrames that are in the JDesktopPane.
229 * @return All JInternalFrames that are in the JDesktopPane.
231 public JInternalFrame[] getAllFrames()
233 return getFramesFromComponents(getComponents());
237 * This method returns the currently selected frame in the JDesktopPane.
239 * @return The currently selected frame in the JDesktopPane.
241 public JInternalFrame getSelectedFrame()
243 return selectedFrame;
247 * This method sets the selected frame in the JDesktopPane.
249 * @param frame The selected frame in the JDesktopPane.
251 public void setSelectedFrame(JInternalFrame frame)
253 if (selectedFrame != null)
257 selectedFrame.setSelected(false);
259 catch (PropertyVetoException e)
261 // We do nothing when the attempt is vetoed.
264 selectedFrame = null;
268 if (frame != null)
269 frame.setSelected(true);
271 selectedFrame = frame;
273 catch (PropertyVetoException e)
275 // We do nothing when the attempt is vetoed.
280 * This method returns all the JInternalFrames in the given layer.
282 * @param layer The layer to grab frames in.
284 * @return All JInternalFrames in the given layer.
286 public JInternalFrame[] getAllFramesInLayer(int layer)
288 return getFramesFromComponents(getComponentsInLayer(layer));
292 * This method always returns true to indicate that it is not transparent.
294 * @return true.
296 public boolean isOpaque()
298 return true;
302 * Returns an implementation-dependent string describing the attributes of
303 * this <code>JDesktopPane</code>.
305 * @return A string describing the attributes of this <code>JDesktopPane</code>
306 * (never <code>null</code>).
308 protected String paramString()
310 String superParamStr = super.paramString();
311 CPStringBuilder sb = new CPStringBuilder();
312 sb.append(",isOptimizedDrawingPossible=");
313 sb.append(isOptimizedDrawingEnabled());
314 sb.append(",desktopManager=");
315 if (desktopManager != null)
316 sb.append(desktopManager);
317 return superParamStr + sb.toString();
321 * This method returns all the JInternalFrames in the given Component array.
323 * @param components An array to search for JInternalFrames in.
325 * @return An array of JInternalFrames found in the Component array.
327 private static JInternalFrame[] getFramesFromComponents(Component[] components)
329 int count = 0;
331 for (int i = 0; i < components.length; i++)
332 if (components[i] instanceof JInternalFrame)
333 count++;
335 JInternalFrame[] value = new JInternalFrame[count];
336 for (int i = 0, j = 0; i < components.length && j != count; i++)
337 if (components[i] instanceof JInternalFrame)
338 value[j++] = (JInternalFrame) components[i];
339 return value;
343 * Returns the object that provides accessibility features for this
344 * <code>JDesktopPane</code> component.
346 * @return The accessible context (an instance of
347 * {@link AccessibleJDesktopPane}).
349 public AccessibleContext getAccessibleContext()
351 if (accessibleContext == null)
352 accessibleContext = new AccessibleJDesktopPane();
354 return accessibleContext;
358 * Helper method for
359 * {@link LookAndFeel#installProperty(JComponent, String, Object)}.
361 * @param propertyName the name of the property
362 * @param value the value of the property
364 * @throws IllegalArgumentException if the specified property cannot be set
365 * by this method
366 * @throws ClassCastException if the property value does not match the
367 * property type
368 * @throws NullPointerException if <code>c</code> or
369 * <code>propertyValue</code> is <code>null</code>
371 void setUIProperty(String propertyName, Object value)
373 if (propertyName.equals("dragMode"))
375 if (! clientDragModeSet)
377 setDragMode(((Integer) value).intValue());
378 clientDragModeSet = false;
381 else
383 super.setUIProperty(propertyName, value);