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