jdk/src/share/classes/javax/swing/JDesktopPane.java
author ant
Thu, 17 May 2012 21:48:57 +0400
changeset 12661 6cf8b7116579
parent 12532 dbf5d9a4b7bb
child 17149 adce5338e9b5
permissions -rw-r--r--
7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application. Summary: forward port from 7u4 Reviewed-by: art
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;
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
    30
import java.util.Collection;
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
    31
import java.util.Iterator;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.DefaultFocusTraversalPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.FocusTraversalPolicy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.beans.PropertyVetoException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.TreeSet;
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() {
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   264
        return getAllFrames(this).toArray(new JInternalFrame[0]);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   265
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   267
    private static Collection<JInternalFrame> getAllFrames(Container parent) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   268
        int i, count;
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   269
        Collection<JInternalFrame> results = new ArrayList<JInternalFrame>();
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   270
        count = parent.getComponentCount();
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   271
        for (i = 0; i < count; i++) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   272
            Component next = parent.getComponent(i);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   273
            if (next instanceof JInternalFrame) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   274
                results.add((JInternalFrame) next);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   275
            } else if (next instanceof JInternalFrame.JDesktopIcon) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   276
                JInternalFrame tmp = ((JInternalFrame.JDesktopIcon) next).getInternalFrame();
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   277
                if (tmp != null) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   278
                    results.add(tmp);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   279
                }
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   280
            } else if (next instanceof Container) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   281
                results.addAll(getAllFrames((Container) next));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return results;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /** Returns the currently active <code>JInternalFrame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
      * in this <code>JDesktopPane</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      * if no <code>JInternalFrame</code> is currently active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
      * @return the currently active <code>JInternalFrame</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      *   <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public JInternalFrame getSelectedFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
      return selectedFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /** Sets the currently active <code>JInternalFrame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *  in this <code>JDesktopPane</code>. This method is used to bridge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *  the package gap between JDesktopPane and the platform implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *  code and should not be called directly. To visually select the frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *  the client must call JInternalFrame.setSelected(true) to activate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *  the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *  @see JInternalFrame#setSelected(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @param f the internal frame that's currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public void setSelectedFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
      selectedFrame = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Returns all <code>JInternalFrames</code> currently displayed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * specified layer of the desktop. Returns iconified frames as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * expanded frames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @param layer  an int specifying the desktop layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @return an array of <code>JInternalFrame</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see JLayeredPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public JInternalFrame[] getAllFramesInLayer(int layer) {
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   326
        Collection<JInternalFrame> allFrames = getAllFrames(this);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   327
        Iterator<JInternalFrame> iterator = allFrames.iterator();
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   328
        while (iterator.hasNext()) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   329
            if (iterator.next().getLayer() != layer) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   330
                iterator.remove();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   333
        return allFrames.toArray(new JInternalFrame[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    private List<JInternalFrame> getFrames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        Component c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        Set<ComponentPosition> set = new TreeSet<ComponentPosition>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        for (int i = 0; i < getComponentCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            c = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if (c instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                set.add(new ComponentPosition((JInternalFrame)c, getLayer(c),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            else if (c instanceof JInternalFrame.JDesktopIcon)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                c = ((JInternalFrame.JDesktopIcon)c).getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                set.add(new ComponentPosition((JInternalFrame)c, getLayer(c),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        List<JInternalFrame> frames = new ArrayList<JInternalFrame>(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                set.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        for (ComponentPosition position : set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            frames.add(position.component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return frames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    private static class ComponentPosition implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        Comparable<ComponentPosition> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        private final JInternalFrame component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        private final int layer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        private final int zOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        ComponentPosition(JInternalFrame component, int layer, int zOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            this.component = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            this.layer = layer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            this.zOrder = zOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        public int compareTo(ComponentPosition o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            int delta = o.layer - layer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            if (delta == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                return zOrder - o.zOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            return delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    private JInternalFrame getNextFrame(JInternalFrame f, boolean forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        verifyFramesCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            return getTopInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        int i = framesCache.indexOf(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (i == -1 || framesCache.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            /* error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            // navigate to the next frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            if (++i == framesCache.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                /* wrap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            // navigate to the previous frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            if (--i == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                /* wrap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                i = framesCache.size() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return framesCache.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    JInternalFrame getNextFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        return getNextFrame(f, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    private JInternalFrame getTopInternalFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (framesCache.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return framesCache.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    private void updateFramesCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        framesCache = getFrames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    private void verifyFramesCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        // If framesCache is dirty, then recreate it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (componentOrderChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            componentOrderChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            updateFramesCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * Selects the next <code>JInternalFrame</code> in this desktop pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @param forward a boolean indicating which direction to select in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *        <code>true</code> for forward, <code>false</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *        backward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @return the JInternalFrame that was selected or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *         if nothing was selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public JInternalFrame selectFrame(boolean forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        JInternalFrame selectedFrame = getSelectedFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        JInternalFrame frameToSelect = getNextFrame(selectedFrame, forward);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        if (frameToSelect == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        // Maintain navigation traversal order until an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        // external stack change, such as a click on a frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        setComponentOrderCheckingEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if (forward && selectedFrame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            selectedFrame.moveToBack();  // For Windows MDI fidelity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        try { frameToSelect.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        } catch (PropertyVetoException pve) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        setComponentOrderCheckingEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        return frameToSelect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * Sets whether component order checking is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @param enable a boolean value, where <code>true</code> means
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * a change in component order will cause a change in the keyboard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * navigation order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    void setComponentOrderCheckingEnabled(boolean enable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        componentOrderCheckingEnabled = enable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    protected void addImpl(Component comp, Object constraints, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        super.addImpl(comp, constraints, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        if (componentOrderCheckingEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            if (comp instanceof JInternalFrame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                componentOrderChanged = true;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    public void remove(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (componentOrderCheckingEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            Component comp = getComponent(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            if (comp instanceof JInternalFrame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                componentOrderChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        super.remove(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    public void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if (componentOrderCheckingEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            int count = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                Component comp = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                if (comp instanceof JInternalFrame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                    componentOrderChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        super.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    public void setComponentZOrder(Component comp, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        super.setComponentZOrder(comp, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        if (componentOrderCheckingEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            if (comp instanceof JInternalFrame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                componentOrderChanged = true;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    void setUIProperty(String propertyName, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        if (propertyName == "dragMode") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            if (!dragModeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                setDragMode(((Integer)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                dragModeSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            super.setUIProperty(propertyName, value);
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
     * Returns a string representation of this <code>JDesktopPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * This method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @return  a string representation of this <code>JDesktopPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        String desktopManagerString = (desktopManager != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                       desktopManager.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        ",desktopManager=" + desktopManagerString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * <code>JDesktopPane</code>. For desktop panes, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * <code>AccessibleContext</code> takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * <code>AccessibleJDesktopPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * A new <code>AccessibleJDesktopPane</code> instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @return an <code>AccessibleJDesktopPane</code> that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     *         <code>AccessibleContext</code> of this <code>JDesktopPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            accessibleContext = new AccessibleJDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * <code>JDesktopPane</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * Java Accessibility API appropriate to desktop pane user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    protected class AccessibleJDesktopPane extends AccessibleJComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            return AccessibleRole.DESKTOP_PANE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
}