jdk/src/java.desktop/share/classes/javax/swing/JDesktopPane.java
author aghaisas
Mon, 10 Jul 2017 14:55:29 +0530
changeset 47151 362dcbee0613
parent 35670 320e424b168c
permissions -rw-r--r--
6919529: NPE from MultiUIDefaults.getUIError Reviewed-by: aghaisas, psadhukhan, serb Contributed-by: shashidhara.veerabhadraiah@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
     2
 * Copyright (c) 1997, 2015, 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
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.ArrayList;
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
    29
import java.util.Collection;
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
    30
import java.util.Iterator;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Container;
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
    36
import java.beans.JavaBean;
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
    37
import java.beans.BeanProperty;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.beans.PropertyVetoException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.TreeSet;
26610
fbd0412506d3 8057184: JCK8's api/javax_swing/JDesktopPane/descriptions.html#getset failed with GTKLookAndFeel on Linux and Solaris
alexsch
parents: 25859
diff changeset
    43
import java.util.LinkedHashSet;
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
    44
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * A container used to create a multiple-document interface or a virtual desktop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * You create <code>JInternalFrame</code> objects and add them to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <code>JDesktopPane</code>. <code>JDesktopPane</code> extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <code>JLayeredPane</code> to manage the potentially overlapping internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * frames. It also maintains a reference to an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <code>DesktopManager</code> that is set by the UI
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17149
diff changeset
    52
 * class for the current look and feel (L&amp;F).  Note that <code>JDesktopPane</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * does not support borders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * This class is normally used as the parent of <code>JInternalFrames</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * to provide a pluggable <code>DesktopManager</code> object to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <code>JInternalFrames</code>. The <code>installUI</code> of the
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17149
diff changeset
    58
 * L&amp;F specific implementation is responsible for setting the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <code>desktopManager</code> variable appropriately.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * When the parent of a <code>JInternalFrame</code> is a <code>JDesktopPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * it should delegate most of its behavior to the <code>desktopManager</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * (closing, resizing, etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * 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
    65
 * <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
    66
 * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * 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
    78
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @see JInternalFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see JInternalFrame.JDesktopIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @see DesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @author David Kloba
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 22574
diff changeset
    87
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
    89
@JavaBean(defaultProperty = "UI")
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
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
   166
    @BeanProperty(hidden = true, visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
   167
            = "The UI object that implements the Component's LookAndFeel.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public void setUI(DesktopPaneUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Sets the "dragging style" used by the desktop pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * You may want to change to one mode or another for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * performance or aesthetic reasons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param dragMode the style of drag to use for items in the Desktop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @see #LIVE_DRAG_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @see #OUTLINE_DRAG_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
   184
    @BeanProperty(enumerationValues = {
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
   185
            "JDesktopPane.LIVE_DRAG_MODE",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
   186
            "JDesktopPane.OUTLINE_DRAG_MODE"}, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
   187
            = "Dragging style for internal frame children.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public void setDragMode(int dragMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        int oldDragMode = this.dragMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        this.dragMode = dragMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        firePropertyChange("dragMode", oldDragMode, this.dragMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        dragModeSet = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Gets the current "dragging style" used by the desktop pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @return either <code>Live_DRAG_MODE</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *   <code>OUTLINE_DRAG_MODE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @see #setDragMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     public int getDragMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
         return dragMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   207
     * Returns the {@code DesktopManger} that handles
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * desktop-specific UI actions.
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   209
     *
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   210
     * @return the {@code DesktopManger} that handles desktop-specific
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   211
     *         UI actions
2
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
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
   224
    @BeanProperty(description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
   225
            = "Desktop manager to handle the internal frames in the desktop pane.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public void setDesktopManager(DesktopManager d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        DesktopManager oldValue = desktopManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        desktopManager = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        firePropertyChange("desktopManager", oldValue, desktopManager);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17149
diff changeset
   233
     * Notification from the <code>UIManager</code> that the L&amp;F has changed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Replaces the current UI object with the latest version from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * <code>UIManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        setUI((DesktopPaneUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 17149
diff changeset
   245
     * Returns the name of the L&amp;F class that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @return the string "DesktopPaneUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
   251
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Returns all <code>JInternalFrames</code> currently displayed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * desktop. Returns iconified frames as well as expanded frames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @return an array of <code>JInternalFrame</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
   262
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public JInternalFrame[] getAllFrames() {
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   264
        return getAllFrames(this).toArray(new JInternalFrame[0]);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   265
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   267
    private static Collection<JInternalFrame> getAllFrames(Container parent) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   268
        int i, count;
26610
fbd0412506d3 8057184: JCK8's api/javax_swing/JDesktopPane/descriptions.html#getset failed with GTKLookAndFeel on Linux and Solaris
alexsch
parents: 25859
diff changeset
   269
        Collection<JInternalFrame> results = new LinkedHashSet<>();
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   270
        count = parent.getComponentCount();
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   271
        for (i = 0; i < count; i++) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   272
            Component next = parent.getComponent(i);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   273
            if (next instanceof JInternalFrame) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   274
                results.add((JInternalFrame) next);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   275
            } else if (next instanceof JInternalFrame.JDesktopIcon) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   276
                JInternalFrame tmp = ((JInternalFrame.JDesktopIcon) next).getInternalFrame();
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   277
                if (tmp != null) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   278
                    results.add(tmp);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   279
                }
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   280
            } else if (next instanceof Container) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   281
                results.addAll(getAllFrames((Container) next));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return results;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /** Returns the currently active <code>JInternalFrame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
      * in this <code>JDesktopPane</code>, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      * if no <code>JInternalFrame</code> is currently active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
      * @return the currently active <code>JInternalFrame</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      *   <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public JInternalFrame getSelectedFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
      return selectedFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /** Sets the currently active <code>JInternalFrame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *  in this <code>JDesktopPane</code>. This method is used to bridge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *  the package gap between JDesktopPane and the platform implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *  code and should not be called directly. To visually select the frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *  the client must call JInternalFrame.setSelected(true) to activate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *  the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *  @see JInternalFrame#setSelected(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @param f the internal frame that's currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public void setSelectedFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
      selectedFrame = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Returns all <code>JInternalFrames</code> currently displayed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * specified layer of the desktop. Returns iconified frames as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * expanded frames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @param layer  an int specifying the desktop layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @return an array of <code>JInternalFrame</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see JLayeredPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public JInternalFrame[] getAllFramesInLayer(int layer) {
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   326
        Collection<JInternalFrame> allFrames = getAllFrames(this);
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   327
        Iterator<JInternalFrame> iterator = allFrames.iterator();
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   328
        while (iterator.hasNext()) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   329
            if (iterator.next().getLayer() != layer) {
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   330
                iterator.remove();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
12532
dbf5d9a4b7bb 7124328: [macosx] javax.swing.JDesktopPane.getAllFramesInLayer returns unexpected value
alexp
parents: 7668
diff changeset
   333
        return allFrames.toArray(new JInternalFrame[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    private List<JInternalFrame> getFrames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        Component c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        Set<ComponentPosition> set = new TreeSet<ComponentPosition>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        for (int i = 0; i < getComponentCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            c = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if (c instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                set.add(new ComponentPosition((JInternalFrame)c, getLayer(c),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            else if (c instanceof JInternalFrame.JDesktopIcon)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                c = ((JInternalFrame.JDesktopIcon)c).getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                set.add(new ComponentPosition((JInternalFrame)c, getLayer(c),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        List<JInternalFrame> frames = new ArrayList<JInternalFrame>(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                set.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        for (ComponentPosition position : set) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            frames.add(position.component);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return frames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    private static class ComponentPosition implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        Comparable<ComponentPosition> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        private final JInternalFrame component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        private final int layer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        private final int zOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        ComponentPosition(JInternalFrame component, int layer, int zOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            this.component = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            this.layer = layer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            this.zOrder = zOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        public int compareTo(ComponentPosition o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            int delta = o.layer - layer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            if (delta == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                return zOrder - o.zOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            return delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    private JInternalFrame getNextFrame(JInternalFrame f, boolean forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        verifyFramesCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            return getTopInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        int i = framesCache.indexOf(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (i == -1 || framesCache.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            /* error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            // navigate to the next frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            if (++i == framesCache.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                /* wrap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            // navigate to the previous frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            if (--i == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                /* wrap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                i = framesCache.size() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return framesCache.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    JInternalFrame getNextFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        return getNextFrame(f, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    private JInternalFrame getTopInternalFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (framesCache.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return framesCache.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    private void updateFramesCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        framesCache = getFrames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    private void verifyFramesCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        // If framesCache is dirty, then recreate it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (componentOrderChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            componentOrderChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            updateFramesCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /**
17149
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   431
     * {@inheritDoc}
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   432
     */
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   433
    @Override
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   434
    public void remove(Component comp) {
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   435
        super.remove(comp);
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   436
        updateFramesCache();
adce5338e9b5 8012004: JInternalFrame not being finalized after closing
mcherkas
parents: 12532
diff changeset
   437
    }
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
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Selects the next <code>JInternalFrame</code> in this desktop pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @param forward a boolean indicating which direction to select in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *        <code>true</code> for forward, <code>false</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *        backward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @return the JInternalFrame that was selected or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *         if nothing was selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public JInternalFrame selectFrame(boolean forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        JInternalFrame selectedFrame = getSelectedFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        JInternalFrame frameToSelect = getNextFrame(selectedFrame, forward);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (frameToSelect == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        // Maintain navigation traversal order until an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        // external stack change, such as a click on a frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        setComponentOrderCheckingEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (forward && selectedFrame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            selectedFrame.moveToBack();  // For Windows MDI fidelity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        try { frameToSelect.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        } catch (PropertyVetoException pve) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        setComponentOrderCheckingEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return frameToSelect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * Sets whether component order checking is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @param enable a boolean value, where <code>true</code> means
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * a change in component order will cause a change in the keyboard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * navigation order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    void setComponentOrderCheckingEnabled(boolean enable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        componentOrderCheckingEnabled = enable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    protected void addImpl(Component comp, Object constraints, int index) {
35670
320e424b168c 4769772: JInternalFrame.setIcon(true) before JDesktopPane.add(JIF) causes wrong state
rchamyal
parents: 33253
diff changeset
   483
        checkComponentAttributes(comp);
2
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
35670
320e424b168c 4769772: JInternalFrame.setIcon(true) before JDesktopPane.add(JIF) causes wrong state
rchamyal
parents: 33253
diff changeset
   493
    private void checkComponentAttributes(Component comp) {
320e424b168c 4769772: JInternalFrame.setIcon(true) before JDesktopPane.add(JIF) causes wrong state
rchamyal
parents: 33253
diff changeset
   494
        if (comp instanceof JInternalFrame && ((JInternalFrame) comp).isIcon()) {
320e424b168c 4769772: JInternalFrame.setIcon(true) before JDesktopPane.add(JIF) causes wrong state
rchamyal
parents: 33253
diff changeset
   495
            ((JInternalFrame) comp).putClientProperty("wasIconOnce", Boolean.FALSE);
320e424b168c 4769772: JInternalFrame.setIcon(true) before JDesktopPane.add(JIF) causes wrong state
rchamyal
parents: 33253
diff changeset
   496
        }
320e424b168c 4769772: JInternalFrame.setIcon(true) before JDesktopPane.add(JIF) causes wrong state
rchamyal
parents: 33253
diff changeset
   497
    }
320e424b168c 4769772: JInternalFrame.setIcon(true) before JDesktopPane.add(JIF) causes wrong state
rchamyal
parents: 33253
diff changeset
   498
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    public void remove(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        if (componentOrderCheckingEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            Component comp = getComponent(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            if (comp instanceof JInternalFrame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                componentOrderChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        super.remove(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    public void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (componentOrderCheckingEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            int count = getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                Component comp = getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                if (comp instanceof JInternalFrame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    componentOrderChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        super.removeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public void setComponentZOrder(Component comp, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        super.setComponentZOrder(comp, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        if (componentOrderCheckingEnabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            if (comp instanceof JInternalFrame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                comp instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                componentOrderChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    void setUIProperty(String propertyName, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        if (propertyName == "dragMode") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            if (!dragModeSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                setDragMode(((Integer)value).intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                dragModeSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            super.setUIProperty(propertyName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * Returns a string representation of this <code>JDesktopPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * This method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @return  a string representation of this <code>JDesktopPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        String desktopManagerString = (desktopManager != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                       desktopManager.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        ",desktopManager=" + desktopManagerString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * <code>JDesktopPane</code>. For desktop panes, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * <code>AccessibleContext</code> takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * <code>AccessibleJDesktopPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * A new <code>AccessibleJDesktopPane</code> instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @return an <code>AccessibleJDesktopPane</code> that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *         <code>AccessibleContext</code> of this <code>JDesktopPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 26610
diff changeset
   604
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            accessibleContext = new AccessibleJDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * <code>JDesktopPane</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * Java Accessibility API appropriate to desktop pane user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * 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
   623
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
   627
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    protected class AccessibleJDesktopPane extends AccessibleJComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            return AccessibleRole.DESKTOP_PANE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
}