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