jdk/src/share/classes/javax/swing/JDesktopPane.java
author henryjen
Wed, 18 Jun 2014 09:13:46 -0700
changeset 25201 4adc75e0c4e5
parent 22574 7f8ce0c8c20a
child 25760 7955db32d6b0
permissions -rw-r--r--
8046485: Add missing @since tag under javax.swing.* Reviewed-by: alexsch, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
     2
 * Copyright (c) 1997, 2014, 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
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17149
diff changeset
    53
 * class for the current look and feel (L&amp;F).  Note that <code>JDesktopPane</code>
2
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
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17149
diff changeset
    59
 * L&amp;F specific implementation is responsible for setting the
2
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
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20169
diff changeset
    66
 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html">How to Use Internal Frames</a>,
2
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
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    79
 * of all JavaBeans&trade;
2
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
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 22574
diff changeset
    88
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    90
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
public class JDesktopPane extends JLayeredPane implements Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static final String uiClassID = "DesktopPaneUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    transient DesktopManager desktopManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private transient JInternalFrame selectedFrame = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
      * Indicates that the entire contents of the item being dragged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      * should appear inside the desktop pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
      * @see #OUTLINE_DRAG_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      * @see #setDragMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public static final int LIVE_DRAG_MODE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      * Indicates that an outline only of the item being dragged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      * should appear inside the desktop pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
      * @see #LIVE_DRAG_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      * @see #setDragMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static final int OUTLINE_DRAG_MODE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private int dragMode = LIVE_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private boolean dragModeSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private transient List<JInternalFrame> framesCache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private boolean componentOrderCheckingEnabled = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private boolean componentOrderChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Creates a new <code>JDesktopPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public JDesktopPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        setUIProperty("opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        setFocusCycleRoot(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            public Component getDefaultComponent(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                JInternalFrame jifArray[] = getAllFrames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                Component comp = null;
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   138
                for (JInternalFrame jif : jifArray) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   139
                    comp = jif.getFocusTraversalPolicy().getDefaultComponent(jif);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    if (comp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                return comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17149
diff changeset
   151
     * Returns the L&amp;F object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return the <code>DesktopPaneUI</code> object that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *   renders this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public DesktopPaneUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return (DesktopPaneUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17149
diff changeset
   161
     * Sets the L&amp;F object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17149
diff changeset
   163
     * @param ui  the DesktopPaneUI L&amp;F object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *  description: The UI object that implements the Component's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public void setUI(DesktopPaneUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Sets the "dragging style" used by the desktop pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * You may want to change to one mode or another for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * performance or aesthetic reasons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param dragMode the style of drag to use for items in the Desktop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @see #LIVE_DRAG_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @see #OUTLINE_DRAG_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *  description: Dragging style for internal frame children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *         enum: LIVE_DRAG_MODE JDesktopPane.LIVE_DRAG_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *               OUTLINE_DRAG_MODE JDesktopPane.OUTLINE_DRAG_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public void setDragMode(int dragMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        int oldDragMode = this.dragMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        this.dragMode = dragMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        firePropertyChange("dragMode", oldDragMode, this.dragMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        dragModeSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Gets the current "dragging style" used by the desktop pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @return either <code>Live_DRAG_MODE</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *   <code>OUTLINE_DRAG_MODE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @see #setDragMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     public int getDragMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
         return dragMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Returns the <code>DesktopManger</code> that handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * desktop-specific UI actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public DesktopManager getDesktopManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return desktopManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * 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
   220
     * 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
   221
     * {@code LookAndFeel}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param d the <code>DesktopManager</code> to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *  description: Desktop manager to handle the internal frames in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *               desktop pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public void setDesktopManager(DesktopManager d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        DesktopManager oldValue = desktopManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        desktopManager = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        firePropertyChange("desktopManager", oldValue, desktopManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17149
diff changeset
   237
     * Notification from the <code>UIManager</code> that the L&amp;F has changed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Replaces the current UI object with the latest version from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * <code>UIManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        setUI((DesktopPaneUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17149
diff changeset
   249
     * Returns the name of the L&amp;F class that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @return the string "DesktopPaneUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Returns all <code>JInternalFrames</code> currently displayed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * desktop. Returns iconified frames as well as expanded frames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @return an array of <code>JInternalFrame</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public JInternalFrame[] getAllFrames() {
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   266
        return getAllFrames(this).toArray(new JInternalFrame[0]);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   267
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   269
    private static Collection<JInternalFrame> getAllFrames(Container parent) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   270
        int i, count;
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   271
        Collection<JInternalFrame> results = new ArrayList<JInternalFrame>();
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   272
        count = parent.getComponentCount();
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   273
        for (i = 0; i < count; i++) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   274
            Component next = parent.getComponent(i);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   275
            if (next instanceof JInternalFrame) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   276
                results.add((JInternalFrame) next);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   277
            } else if (next instanceof JInternalFrame.JDesktopIcon) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   278
                JInternalFrame tmp = ((JInternalFrame.JDesktopIcon) next).getInternalFrame();
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   279
                if (tmp != null) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   280
                    results.add(tmp);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   281
                }
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   282
            } else if (next instanceof Container) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   283
                results.addAll(getAllFrames((Container) next));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return results;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /** Returns the currently active <code>JInternalFrame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      * in this <code>JDesktopPane</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
      * if no <code>JInternalFrame</code> is currently active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      * @return the currently active <code>JInternalFrame</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      *   <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
      * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public JInternalFrame getSelectedFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
      return selectedFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /** Sets the currently active <code>JInternalFrame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *  in this <code>JDesktopPane</code>. This method is used to bridge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *  the package gap between JDesktopPane and the platform implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *  code and should not be called directly. To visually select the frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *  the client must call JInternalFrame.setSelected(true) to activate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *  the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *  @see JInternalFrame#setSelected(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @param f the internal frame that's currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public void setSelectedFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
      selectedFrame = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Returns all <code>JInternalFrames</code> currently displayed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * specified layer of the desktop. Returns iconified frames as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * expanded frames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @param layer  an int specifying the desktop layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @return an array of <code>JInternalFrame</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @see JLayeredPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    public JInternalFrame[] getAllFramesInLayer(int layer) {
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   328
        Collection<JInternalFrame> allFrames = getAllFrames(this);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   329
        Iterator<JInternalFrame> iterator = allFrames.iterator();
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   330
        while (iterator.hasNext()) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   331
            if (iterator.next().getLayer() != layer) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   332
                iterator.remove();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   335
        return allFrames.toArray(new JInternalFrame[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    private List<JInternalFrame> getFrames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        Component c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        Set<ComponentPosition> set = new TreeSet<ComponentPosition>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        for (int i = 0; i < getComponentCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            c = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            if (c instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                set.add(new ComponentPosition((JInternalFrame)c, getLayer(c),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            else if (c instanceof JInternalFrame.JDesktopIcon)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                c = ((JInternalFrame.JDesktopIcon)c).getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                set.add(new ComponentPosition((JInternalFrame)c, getLayer(c),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        List<JInternalFrame> frames = new ArrayList<JInternalFrame>(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                set.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        for (ComponentPosition position : set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            frames.add(position.component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return frames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    private static class ComponentPosition implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        Comparable<ComponentPosition> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        private final JInternalFrame component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        private final int layer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        private final int zOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        ComponentPosition(JInternalFrame component, int layer, int zOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            this.component = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            this.layer = layer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            this.zOrder = zOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        public int compareTo(ComponentPosition o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            int delta = o.layer - layer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            if (delta == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                return zOrder - o.zOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    private JInternalFrame getNextFrame(JInternalFrame f, boolean forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        verifyFramesCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            return getTopInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        int i = framesCache.indexOf(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        if (i == -1 || framesCache.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            /* error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            // navigate to the next frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (++i == framesCache.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                /* wrap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            // navigate to the previous frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            if (--i == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                /* wrap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                i = framesCache.size() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return framesCache.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    JInternalFrame getNextFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        return getNextFrame(f, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    private JInternalFrame getTopInternalFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (framesCache.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return framesCache.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    private void updateFramesCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        framesCache = getFrames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    private void verifyFramesCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        // If framesCache is dirty, then recreate it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (componentOrderChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            componentOrderChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            updateFramesCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
17149
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   433
     * {@inheritDoc}
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   434
     */
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   435
    @Override
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   436
    public void remove(Component comp) {
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   437
        super.remove(comp);
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   438
        updateFramesCache();
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   439
    }
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   440
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   441
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * Selects the next <code>JInternalFrame</code> in this desktop pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @param forward a boolean indicating which direction to select in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *        <code>true</code> for forward, <code>false</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *        backward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @return the JInternalFrame that was selected or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *         if nothing was selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public JInternalFrame selectFrame(boolean forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        JInternalFrame selectedFrame = getSelectedFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        JInternalFrame frameToSelect = getNextFrame(selectedFrame, forward);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        if (frameToSelect == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        // Maintain navigation traversal order until an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        // external stack change, such as a click on a frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        setComponentOrderCheckingEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (forward && selectedFrame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            selectedFrame.moveToBack();  // For Windows MDI fidelity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        try { frameToSelect.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        } catch (PropertyVetoException pve) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        setComponentOrderCheckingEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return frameToSelect;
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
     * Sets whether component order checking is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @param enable a boolean value, where <code>true</code> means
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * a change in component order will cause a change in the keyboard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * navigation order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    void setComponentOrderCheckingEnabled(boolean enable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        componentOrderCheckingEnabled = enable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    protected void addImpl(Component comp, Object constraints, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        super.addImpl(comp, constraints, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        if (componentOrderCheckingEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            if (comp instanceof JInternalFrame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                componentOrderChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            }
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
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public void remove(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        if (componentOrderCheckingEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            Component comp = getComponent(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            if (comp instanceof JInternalFrame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                componentOrderChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        super.remove(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        if (componentOrderCheckingEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            int count = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                Component comp = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                if (comp instanceof JInternalFrame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                    comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                    componentOrderChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        super.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    public void setComponentZOrder(Component comp, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        super.setComponentZOrder(comp, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        if (componentOrderCheckingEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            if (comp instanceof JInternalFrame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                componentOrderChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            }
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
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            }
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
    void setUIProperty(String propertyName, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        if (propertyName == "dragMode") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            if (!dragModeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                setDragMode(((Integer)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                dragModeSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            super.setUIProperty(propertyName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
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
     * Returns a string representation of this <code>JDesktopPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * This method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @return  a string representation of this <code>JDesktopPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        String desktopManagerString = (desktopManager != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                                       desktopManager.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        ",desktopManager=" + desktopManagerString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * <code>JDesktopPane</code>. For desktop panes, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <code>AccessibleContext</code> takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * <code>AccessibleJDesktopPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * A new <code>AccessibleJDesktopPane</code> instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @return an <code>AccessibleJDesktopPane</code> that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *         <code>AccessibleContext</code> of this <code>JDesktopPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            accessibleContext = new AccessibleJDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * <code>JDesktopPane</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * Java Accessibility API appropriate to desktop pane user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   617
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
   621
    @SuppressWarnings("serial") // Same-version serialization only
2
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
}