001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.swing;
019:
020: import java.awt.Component;
021: import java.util.ArrayList;
022: import java.util.List;
023: import javax.accessibility.Accessible;
024: import javax.accessibility.AccessibleContext;
025: import javax.accessibility.AccessibleRole;
026: import javax.swing.plaf.DesktopPaneUI;
027:
028: /**
029: * <p>
030: * <i>JDesktopPane</i> is a container used to create a virtual desktop.
031: * </p>
032: * <h3>Implementation Notes:</h3>
033: * <ul>
034: * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
035: * optimization, not as a guarantee of serialization compatibility.</li>
036: * </ul>
037: */
038: public class JDesktopPane extends JLayeredPane implements Accessible {
039: private static final long serialVersionUID = -5428199090710889698L;
040:
041: /**
042: * Indicates that the entire content of the component should appear,
043: * when it is being dragged.
044: */
045: public static final int LIVE_DRAG_MODE = 0;
046:
047: /**
048: * Indicates that an outline should appear instead of the entire content
049: * of the component, when it is being dragged.
050: */
051: public static final int OUTLINE_DRAG_MODE = 1;
052:
053: protected class AccessibleJDesktopPane extends AccessibleJComponent {
054: private static final long serialVersionUID = -44586801937888192L;
055:
056: protected AccessibleJDesktopPane() {
057: super ();
058: }
059:
060: @Override
061: public AccessibleRole getAccessibleRole() {
062: return AccessibleRole.DESKTOP_PANE;
063: }
064: }
065:
066: // The style of dragging to use.
067: private int dragMode = LIVE_DRAG_MODE;
068:
069: // The desktop manager.
070: private DesktopManager desktopManager;
071:
072: // The currently active internal frame.
073: private JInternalFrame selectedFrame;
074:
075: public JDesktopPane() {
076: setFocusCycleRoot(true);
077: updateUI();
078: }
079:
080: /**
081: * Sets the UI object for this component.
082: *
083: * @param ui the UI object to set
084: */
085: public void setUI(final DesktopPaneUI ui) {
086: // setUI() from super (JComponent) should always be called
087: super .setUI(ui);
088: }
089:
090: /**
091: * Returns the UI object for this component.
092: *
093: * @return UI object for this component
094: */
095: public DesktopPaneUI getUI() {
096: return (DesktopPaneUI) ui;
097: }
098:
099: /**
100: * Resets UI object with the default object from <code>UIManager</code>
101: */
102: @Override
103: public void updateUI() {
104: setUI((DesktopPaneUI) UIManager.getUI(this ));
105: }
106:
107: /*
108: * Returns all internal frames in the array including iconified frames.
109: */
110: private JInternalFrame[] getAllFramesInArray(Component[] array) {
111: List<JInternalFrame> result = new ArrayList<JInternalFrame>(
112: array.length);
113: for (int i = 0; i < array.length; i++) {
114: if (array[i] instanceof JInternalFrame) {
115: // internal frame
116: result.add((JInternalFrame) array[i]);
117: } else if (array[i] instanceof JInternalFrame.JDesktopIcon) {
118: // iconified internal frame
119: result.add(((JInternalFrame.JDesktopIcon) array[i])
120: .getInternalFrame());
121: }
122: }
123: return result.toArray(new JInternalFrame[result.size()]);
124: }
125:
126: /**
127: * Returns all internal frames in the specified layer. Iconified frames
128: * are also taken into account.
129: *
130: * @param layer the layer to search for internal frames
131: *
132: * @return all internal frames in the specified layer
133: */
134: public JInternalFrame[] getAllFramesInLayer(final int layer) {
135: return getAllFramesInArray(getComponentsInLayer(layer));
136: }
137:
138: /**
139: * Returns all internal frames in the desktop pane including iconified
140: * frames.
141: *
142: * @return all internal frames in the desktop pane
143: */
144: public JInternalFrame[] getAllFrames() {
145: return getAllFramesInArray(getComponents());
146: }
147:
148: /**
149: * Sets the currently active internal frame.
150: *
151: * @param f the currently active internal frame
152: */
153: public void setSelectedFrame(final JInternalFrame f) {
154: selectedFrame = f;
155: }
156:
157: /**
158: * Returns the currently active internal frame or <code>null</code>,
159: * if there is no active frame.
160: *
161: * @return the currently active internal frame or <code>null</code>
162: */
163: public JInternalFrame getSelectedFrame() {
164: return selectedFrame;
165: }
166:
167: /**
168: * Sets the desktop manager.
169: *
170: * @param m the desktop manager
171: */
172: public void setDesktopManager(final DesktopManager m) {
173: DesktopManager oldValue = getDesktopManager();
174: desktopManager = m;
175: firePropertyChange("desktopManager", oldValue, m);
176: }
177:
178: /**
179: * Returns the desktop manager.
180: *
181: * @return the desktop manager
182: */
183: public DesktopManager getDesktopManager() {
184: return desktopManager;
185: }
186:
187: /**
188: * Returns the accessible context for the desktop pane.
189: *
190: * @return the accessible context for the desktop pane
191: */
192: @Override
193: public AccessibleContext getAccessibleContext() {
194: if (accessibleContext == null) {
195: accessibleContext = new AccessibleJDesktopPane();
196: }
197: return accessibleContext;
198: }
199:
200: /**
201: * Returns string representation of this desktop pane.
202: *
203: * @return string representation of this desktop pane
204: */
205: @Override
206: protected String paramString() {
207: return super .paramString();
208: }
209:
210: /**
211: * Returns the name of the L&F class that renders this component.
212: *
213: * @return the string "DesktopPaneUI"
214: */
215: @Override
216: public String getUIClassID() {
217: return "DesktopPaneUI";
218: }
219:
220: /**
221: * Always returns true.
222: *
223: * @return <code>true</code>
224: */
225: @Override
226: public boolean isOpaque() {
227: return true;
228: }
229:
230: /**
231: * Sets the style of dragging used by desktop pane.
232: *
233: * @param mode the style of dragging to use
234: */
235: public void setDragMode(final int mode) {
236: LookAndFeel.markPropertyNotInstallable(this , "dragMode");
237: dragMode = mode;
238: }
239:
240: /**
241: * Returns the style of dragging used by desktop pane.
242: *
243: * @return the used style of dragging
244: */
245: public int getDragMode() {
246: return dragMode;
247: }
248: }
|