jdk/src/java.desktop/share/classes/javax/swing/DefaultDesktopManager.java
author prr
Sat, 19 Sep 2015 15:45:59 -0700
changeset 32865 f9cb6e427f9e
parent 25859 3317bb8137f4
child 35663 c118917086ed
permissions -rw-r--r--
8136783: Run blessed-modifier-order script on java.desktop Reviewed-by: martin, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 9035
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: 3288
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: 3288
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: 3288
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3288
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3288
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
5587
72871be64138 6786238: api/javax_swing/DefaultDesktopManager/descriptions.html#xxxFrame Fails with NPE since 6u12 b02
alexp
parents: 3288
diff changeset
    29
import com.sun.awt.AWTUtilities;
72871be64138 6786238: api/javax_swing/DefaultDesktopManager/descriptions.html#xxxFrame Fails with NPE since 6u12 b02
alexp
parents: 3288
diff changeset
    30
import sun.awt.AWTAccessor;
72871be64138 6786238: api/javax_swing/DefaultDesktopManager/descriptions.html#xxxFrame Fails with NPE since 6u12 b02
alexp
parents: 3288
diff changeset
    31
import sun.awt.SunToolkit;
72871be64138 6786238: api/javax_swing/DefaultDesktopManager/descriptions.html#xxxFrame Fails with NPE since 6u12 b02
alexp
parents: 3288
diff changeset
    32
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.PropertyVetoException;
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
    35
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/** This is an implementation of the <code>DesktopManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  * It currently implements the basic behaviors for managing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  * <code>JInternalFrame</code>s in an arbitrary parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  * <code>JInternalFrame</code>s that are not children of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  * <code>JDesktop</code> will use this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  * to handle their desktop-like actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  * <p>This class provides a policy for the various JInternalFrame methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  * it is not meant to be called directly rather the various JInternalFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  * methods will call into the DesktopManager.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  * @see JDesktopPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  * @see JInternalFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  * @author David Kloba
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  * @author Steve Wilson
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 23697
diff changeset
    49
  * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23280
diff changeset
    51
@SuppressWarnings("serial") // No Interesting Non-Transient State
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class DefaultDesktopManager implements DesktopManager, java.io.Serializable {
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    53
    static final String HAS_BEEN_ICONIFIED_PROPERTY = "wasIconOnce";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    55
    static final int DEFAULT_DRAG_MODE = 0;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    56
    static final int OUTLINE_DRAG_MODE = 1;
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    57
    static final int FASTER_DRAG_MODE = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    int dragMode = DEFAULT_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private transient Rectangle currentBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private transient Graphics desktopGraphics = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private transient Rectangle desktopBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private transient Rectangle[] floatingItems = {};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Set to true when the user actually drags a frame vs clicks on it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * to start the drag operation.  This is only used when dragging with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * FASTER_DRAG_MODE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private transient boolean didDrag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /** Normally this method will not be called. If it is, it
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25386
diff changeset
    74
      * tries to determine the appropriate parent from the desktopIcon of the frame.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
      * Will remove the desktopIcon from its parent if it successfully adds the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public void openFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if(f.getDesktopIcon().getParent() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            f.getDesktopIcon().getParent().add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            removeIconFor(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Removes the frame, and, if necessary, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * <code>desktopIcon</code>, from its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @param f the <code>JInternalFrame</code> to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public void closeFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        JDesktopPane d = f.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (d == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        boolean findNext = f.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        Container c = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        JInternalFrame nextFrame = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (findNext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            nextFrame = d.getNextFrame(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            try { f.setSelected(false); } catch (PropertyVetoException e2) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if(c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            c.remove(f); // Removes the focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        removeIconFor(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if(f.getNormalBounds() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            f.setNormalBounds(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if(wasIcon(f))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            setWasIcon(f, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (nextFrame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            try { nextFrame.setSelected(true); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            catch (PropertyVetoException e2) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        } else if (findNext && d.getComponentCount() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            // It was selected and was the last component on the desktop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            d.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Resizes the frame to fill its parents bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param f the frame to be resized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public void maximizeFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (f.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                // In turn calls deiconifyFrame in the desktop manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                // That method will handle the maximization of the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                f.setIcon(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            } catch (PropertyVetoException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            f.setNormalBounds(f.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            Rectangle desktopBounds = f.getParent().getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            setBoundsForFrame(f, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                desktopBounds.width, desktopBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // Set the maximized frame as selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            f.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        } catch (PropertyVetoException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Restores the frame back to its size and position prior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * to a <code>maximizeFrame</code> call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param f the <code>JInternalFrame</code> to be restored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public void minimizeFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // If the frame was an icon restore it back to an icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (f.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            iconifyFrame(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if ((f.getNormalBounds()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            Rectangle r = f.getNormalBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            f.setNormalBounds(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            try { f.setSelected(true); } catch (PropertyVetoException e2) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            setBoundsForFrame(f, r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Removes the frame from its parent and adds its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * <code>desktopIcon</code> to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @param f the <code>JInternalFrame</code> to be iconified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public void iconifyFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        JInternalFrame.JDesktopIcon desktopIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        Container c = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        JDesktopPane d = f.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        boolean findNext = f.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        desktopIcon = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if(!wasIcon(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            Rectangle r = getBoundsForIconOf(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            desktopIcon.setBounds(r.x, r.y, r.width, r.height);
8524
f2fac94f2434 6826074: JScrollPane does not revalidate the component hierarchy after scrolling
alexp
parents: 7762
diff changeset
   179
            // we must validate the hierarchy to not break the hw/lw mixing
f2fac94f2434 6826074: JScrollPane does not revalidate the component hierarchy after scrolling
alexp
parents: 7762
diff changeset
   180
            desktopIcon.revalidate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            setWasIcon(f, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (c == null || d == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (c instanceof JLayeredPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            JLayeredPane lp = (JLayeredPane)c;
22567
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 9035
diff changeset
   190
            int layer = JLayeredPane.getLayer(f);
5816a47fa4dd 8032047: Fix static lint warnings in client libraries
darcy
parents: 9035
diff changeset
   191
            JLayeredPane.putLayer(desktopIcon, layer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        // If we are maximized we already have the normal bounds recorded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        // don't try to re-record them, otherwise we incorrectly set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        // normal bounds to maximized state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (!f.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            f.setNormalBounds(f.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        d.setComponentOrderCheckingEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        c.remove(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        c.add(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        d.setComponentOrderCheckingEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (findNext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            if (d.selectFrame(true) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                // The icon is the last frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                f.restoreSubcomponentFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Removes the desktopIcon from its parent and adds its frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param f the <code>JInternalFrame</code> to be de-iconified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public void deiconifyFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        Container c = desktopIcon.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        JDesktopPane d = f.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (c != null && d != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            c.add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            // If the frame is to be restored to a maximized state make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            // sure it still fills the whole desktop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            if (f.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                Rectangle desktopBounds = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                if (f.getWidth() != desktopBounds.width ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                        f.getHeight() != desktopBounds.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    setBoundsForFrame(f, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                        desktopBounds.width, desktopBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            removeIconFor(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            if (f.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                f.moveToFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                f.restoreSubcomponentFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    f.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                } catch (PropertyVetoException e2) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /** This will activate <b>f</b> moving it to the front. It will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
      * set the current active frame's (if any)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
      * <code>IS_SELECTED_PROPERTY</code> to <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
      * There can be only one active frame across all Layers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      * @param f the <code>JInternalFrame</code> to be activated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public void activateFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        Container p = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        Component[] c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        JDesktopPane d = f.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        JInternalFrame currentlyActiveFrame =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
          (d == null) ? null : d.getSelectedFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        // fix for bug: 4162443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        if(p == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            // If the frame is not in parent, its icon maybe, check it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            p = f.getDesktopIcon().getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if(p == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // we only need to keep track of the currentActive InternalFrame, if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (currentlyActiveFrame == null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
          if (d != null) { d.setSelectedFrame(f);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        } else if (currentlyActiveFrame != f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
          // if not the same frame as the current active
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
          // we deactivate the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
          if (currentlyActiveFrame.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
              currentlyActiveFrame.setSelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            catch(PropertyVetoException e2) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
          if (d != null) { d.setSelectedFrame(f);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        f.moveToFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    // implements javax.swing.DesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public void deactivateFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      JDesktopPane d = f.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
      JInternalFrame currentlyActiveFrame =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
          (d == null) ? null : d.getSelectedFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      if (currentlyActiveFrame == f)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        d.setSelectedFrame(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    // implements javax.swing.DesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public void beginDraggingFrame(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        setupDragMode(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        if (dragMode == FASTER_DRAG_MODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
          Component desktop = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
          floatingItems = findFloatingItems(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
          currentBounds = f.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
          if (desktop instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
              desktopBounds = ((JComponent)desktop).getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
          else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
              desktopBounds = desktop.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
              desktopBounds.x = desktopBounds.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
          desktopGraphics = JComponent.safelyGetGraphics(desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
          ((JInternalFrame)f).isDragging = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
          didDrag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    private void setupDragMode(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        JDesktopPane p = getDesktopPane(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        Container parent = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        dragMode = DEFAULT_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            String mode = (String)p.getClientProperty("JDesktopPane.dragMode");
5587
72871be64138 6786238: api/javax_swing/DefaultDesktopManager/descriptions.html#xxxFrame Fails with NPE since 6u12 b02
alexp
parents: 3288
diff changeset
   321
            Window window = SwingUtilities.getWindowAncestor(f);
72871be64138 6786238: api/javax_swing/DefaultDesktopManager/descriptions.html#xxxFrame Fails with NPE since 6u12 b02
alexp
parents: 3288
diff changeset
   322
            if (window != null && !AWTUtilities.isWindowOpaque(window)) {
72871be64138 6786238: api/javax_swing/DefaultDesktopManager/descriptions.html#xxxFrame Fails with NPE since 6u12 b02
alexp
parents: 3288
diff changeset
   323
                dragMode = DEFAULT_DRAG_MODE;
72871be64138 6786238: api/javax_swing/DefaultDesktopManager/descriptions.html#xxxFrame Fails with NPE since 6u12 b02
alexp
parents: 3288
diff changeset
   324
            } else if (mode != null && mode.equals("outline")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                dragMode = OUTLINE_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            } else if (mode != null && mode.equals("faster")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    && f instanceof JInternalFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    && ((JInternalFrame)f).isOpaque() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                       (parent == null || parent.isOpaque())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                dragMode = FASTER_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                if (p.getDragMode() == JDesktopPane.OUTLINE_DRAG_MODE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    dragMode = OUTLINE_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                } else if ( p.getDragMode() == JDesktopPane.LIVE_DRAG_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                        && f instanceof JInternalFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                        && ((JInternalFrame)f).isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    dragMode = FASTER_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    dragMode = DEFAULT_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    private transient Point currentLoc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
      * Moves the visible location of the frame being dragged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
      * to the location specified.  The means by which this occurs can vary depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
      * on the dragging algorithm being used.  The actual logical location of the frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
      * might not change until <code>endDraggingFrame</code> is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public void dragFrame(JComponent f, int newX, int newY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        if (dragMode == OUTLINE_DRAG_MODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            JDesktopPane desktopPane = getDesktopPane(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (desktopPane != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
              Graphics g = JComponent.safelyGetGraphics(desktopPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
              g.setXORMode(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
              if (currentLoc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                g.drawRect(currentLoc.x, currentLoc.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                        f.getWidth()-1, f.getHeight()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
              g.drawRect( newX, newY, f.getWidth()-1, f.getHeight()-1);
7748
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   366
              /* Work around for 6635462: XOR mode may cause a SurfaceLost on first use.
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   367
              * Swing doesn't expect that its XOR drawRect did
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   368
              * not complete, so believes that on re-entering at
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   369
              * the next update location, that there is an XOR rect
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   370
              * to draw out at "currentLoc". But in fact
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   371
              * its now got a new clean surface without that rect,
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   372
              * so drawing it "out" in fact draws it on, leaving garbage.
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   373
              * So only update/set currentLoc if the draw completed.
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   374
              */
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   375
              sun.java2d.SurfaceData sData =
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   376
                  ((sun.java2d.SunGraphics2D)g).getSurfaceData();
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   377
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   378
              if (!sData.isSurfaceLost()) {
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   379
                  currentLoc = new Point (newX, newY);
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   380
              }
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   381
;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
              g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        } else if (dragMode == FASTER_DRAG_MODE) {
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   385
            dragFrameFaster(f, newX, newY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    // implements javax.swing.DesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public void endDraggingFrame(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        if ( dragMode == OUTLINE_DRAG_MODE && currentLoc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            setBoundsForFrame(f, currentLoc.x, currentLoc.y, f.getWidth(), f.getHeight() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            currentLoc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        } else if (dragMode == FASTER_DRAG_MODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            currentBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            if (desktopGraphics != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                desktopGraphics.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                desktopGraphics = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            desktopBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            ((JInternalFrame)f).isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    // implements javax.swing.DesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public void beginResizingFrame(JComponent f, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        setupDragMode(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Calls <code>setBoundsForFrame</code> with the new values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @param f the component to be resized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @param newX the new x-coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @param newY the new y-coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @param newWidth the new width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @param newHeight the new height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public void resizeFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if ( dragMode == DEFAULT_DRAG_MODE || dragMode == FASTER_DRAG_MODE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            setBoundsForFrame(f, newX, newY, newWidth, newHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            JDesktopPane desktopPane = getDesktopPane(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            if (desktopPane != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
              Graphics g = JComponent.safelyGetGraphics(desktopPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
              g.setXORMode(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
              if (currentBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                g.drawRect( currentBounds.x, currentBounds.y, currentBounds.width-1, currentBounds.height-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
              g.drawRect( newX, newY, newWidth-1, newHeight-1);
7748
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   434
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   435
              // Work around for 6635462, see comment in dragFrame()
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   436
              sun.java2d.SurfaceData sData =
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   437
                  ((sun.java2d.SunGraphics2D)g).getSurfaceData();
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   438
              if (!sData.isSurfaceLost()) {
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   439
                  currentBounds = new Rectangle (newX, newY, newWidth, newHeight);
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   440
              }
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   441
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
              g.setPaintMode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
              g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    // implements javax.swing.DesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public void endResizingFrame(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if ( dragMode == OUTLINE_DRAG_MODE && currentBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            setBoundsForFrame(f, currentBounds.x, currentBounds.y, currentBounds.width, currentBounds.height );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            currentBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /** This moves the <code>JComponent</code> and repaints the damaged areas. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        f.setBounds(newX, newY, newWidth, newHeight);
8524
f2fac94f2434 6826074: JScrollPane does not revalidate the component hierarchy after scrolling
alexp
parents: 7762
diff changeset
   461
        // we must validate the hierarchy to not break the hw/lw mixing
f2fac94f2434 6826074: JScrollPane does not revalidate the component hierarchy after scrolling
alexp
parents: 7762
diff changeset
   462
        f.revalidate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   465
    /**
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   466
     * Convenience method to remove the desktopIcon of <b>f</b> is necessary.
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   467
     *
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   468
     * @param f the {@code JInternalFrame} for which to remove the
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   469
     *          {@code desktopIcon}
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   470
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    protected void removeIconFor(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        JInternalFrame.JDesktopIcon di = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        Container c = di.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        if(c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            c.remove(di);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            c.repaint(di.getX(), di.getY(), di.getWidth(), di.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   480
    /**
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   481
     * The {@code iconifyFrame()} code calls this to determine the proper bounds
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   482
     * for the desktopIcon.
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   483
     *
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   484
     * @param f the {@code JInternalFrame} of interest
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   485
     * @return a {@code Rectangle} containing bounds for the {@code desktopIcon}
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   486
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    protected Rectangle getBoundsForIconOf(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
      // Get the icon for this internal frame and its preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
      JInternalFrame.JDesktopIcon icon = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
      Dimension prefSize = icon.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
      // Get the parent bounds and child components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
      Container c = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
      if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
          c = f.getDesktopIcon().getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
      if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        /* the frame has not yet been added to the parent; how about (0,0) ?*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        return new Rectangle(0, 0, prefSize.width, prefSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
      Rectangle parentBounds = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
      Component [] components = c.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
      // Iterate through valid default icon locations and return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
      // first one that does not intersect any other icons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
      Rectangle availableRectangle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
      JInternalFrame.JDesktopIcon currentIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
      int x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
      int y = parentBounds.height - prefSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
      int w = prefSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
      int h = prefSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
      boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
      while (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        availableRectangle = new Rectangle(x,y,w,h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        for ( int i=0; i<components.length; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
          //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
          // Get the icon for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
          //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
          if ( components[i] instanceof JInternalFrame ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            currentIcon = ((JInternalFrame)components[i]).getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
          else if ( components[i] instanceof JInternalFrame.JDesktopIcon ){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            currentIcon = (JInternalFrame.JDesktopIcon)components[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
          } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            /* found a child that's neither an internal frame nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
               an icon. I don't believe this should happen, but at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
               present it does and causes a null pointer exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
               Even when that gets fixed, this code protects against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
               the npe. hania */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
          //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
          // If this icon intersects the current location, get next location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
          //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
          if ( !currentIcon.equals(icon) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            if ( availableRectangle.intersects(currentIcon.getBounds()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
              found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        if (currentIcon == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
          /* didn't find any useful children above. This probably shouldn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
           happen, but this check protects against an npe if it ever does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
           (and it's happening now) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
          return availableRectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        x += currentIcon.getBounds().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        if ( x + w > parentBounds.width ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
          x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
          y -= h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
      return(availableRectangle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * Stores the bounds of the component just before a maximize call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @param f the component about to be resized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @param r the normal bounds to be saved away
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    protected void setPreviousBounds(JInternalFrame f, Rectangle r)     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        f.setNormalBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * Gets the normal bounds of the component prior to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * being maximized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @param f the <code>JInternalFrame</code> of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @return the normal bounds of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    protected Rectangle getPreviousBounds(JInternalFrame f)     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        return f.getNormalBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Sets that the component has been iconized and the bounds of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * <code>desktopIcon</code> are valid.
25386
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   603
     *
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   604
     * @param f     the {@code JInternalFrame} of interest
9ef80c24fd74 8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents: 25201
diff changeset
   605
     * @param value a {@code Boolean} signifying if component has been iconized
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    protected void setWasIcon(JInternalFrame f, Boolean value)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            f.putClientProperty(HAS_BEEN_ICONIFIED_PROPERTY, value);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * Returns <code>true</code> if the component has been iconized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * and the bounds of the <code>desktopIcon</code> are valid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * otherwise returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @param f the <code>JInternalFrame</code> of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * @return <code>true</code> if the component has been iconized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     *    otherwise returns <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    protected boolean wasIcon(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        return (f.getClientProperty(HAS_BEEN_ICONIFIED_PROPERTY) == Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    JDesktopPane getDesktopPane( JComponent frame ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        JDesktopPane pane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        Component c = frame.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        // Find the JDesktopPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        while ( pane == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            if ( c instanceof JDesktopPane ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                pane = (JDesktopPane)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            else if ( c == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                c = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        return pane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
  // =========== stuff for faster frame dragging ===================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
   private void dragFrameFaster(JComponent f, int newX, int newY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
      Rectangle previousBounds = new Rectangle(currentBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                                               currentBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                                               currentBounds.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                                               currentBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
   // move the frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
      currentBounds.x = newX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
      currentBounds.y = newY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
      if (didDrag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
          // Only initiate cleanup if we have actually done a drag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
          emergencyCleanup(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
      else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
          didDrag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
          // We reset the danger field as until now we haven't actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
          // moved the internal frame so we don't need to initiate repaint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
          ((JInternalFrame)f).danger = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
      boolean floaterCollision = isFloaterCollision(previousBounds, currentBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
      JComponent parent = (JComponent)f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
      Rectangle visBounds = previousBounds.intersection(desktopBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
      RepaintManager currentManager = RepaintManager.currentManager(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
      currentManager.beginPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
      try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
          if(!floaterCollision) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
              currentManager.copyArea(parent, desktopGraphics, visBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                                      visBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                                      visBounds.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                                      visBounds.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                                      newX - previousBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                                      newY - previousBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                                      true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
          f.setBounds(currentBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
23280
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 22567
diff changeset
   693
          if (!floaterCollision) {
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 22567
diff changeset
   694
              Rectangle r = currentBounds;
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 22567
diff changeset
   695
              currentManager.notifyRepaintPerformed(parent, r.x, r.y, r.width, r.height);
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 22567
diff changeset
   696
          }
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 22567
diff changeset
   697
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
          if(floaterCollision) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
              // since we couldn't blit we just redraw as fast as possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
              // the isDragging mucking is to avoid activating emergency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
              // cleanup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
              ((JInternalFrame)f).isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
              parent.paintImmediately(currentBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
              ((JInternalFrame)f).isDragging = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
          // fake out the repaint manager.  We'll take care of everything
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
          currentManager.markCompletelyClean(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
          currentManager.markCompletelyClean(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
          // compute the minimal newly exposed area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
          // if the rects intersect then we use computeDifference.  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
          // we'll repaint the entire previous bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
          Rectangle[] dirtyRects = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
          if ( previousBounds.intersects(currentBounds) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
              dirtyRects = SwingUtilities.computeDifference(previousBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                                                            currentBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
              dirtyRects = new Rectangle[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
              dirtyRects[0] = previousBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
          };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
          // Fix the damage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
          for (int i = 0; i < dirtyRects.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
              parent.paintImmediately(dirtyRects[i]);
23280
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 22567
diff changeset
   727
              Rectangle r = dirtyRects[i];
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 22567
diff changeset
   728
              currentManager.notifyRepaintPerformed(parent, r.x, r.y, r.width, r.height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
          // new areas of blit were exposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
          if ( !(visBounds.equals(previousBounds)) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
              dirtyRects = SwingUtilities.computeDifference(previousBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                                                            desktopBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
              for (int i = 0; i < dirtyRects.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                  dirtyRects[i].x += newX - previousBounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                  dirtyRects[i].y += newY - previousBounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                  ((JInternalFrame)f).isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                  parent.paintImmediately(dirtyRects[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                  ((JInternalFrame)f).isDragging = true;
23280
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 22567
diff changeset
   741
                  Rectangle r = dirtyRects[i];
df31f522531f 8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents: 22567
diff changeset
   742
                  currentManager.notifyRepaintPerformed(parent, r.x, r.y, r.width, r.height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
      } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
          currentManager.endPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
      }
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   749
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   750
      // update window if it's non-opaque
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   751
      Window topLevel = SwingUtilities.getWindowAncestor(f);
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   752
      Toolkit tk = Toolkit.getDefaultToolkit();
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 2808
diff changeset
   753
      if (!topLevel.isOpaque() &&
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   754
          (tk instanceof SunToolkit) &&
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   755
          ((SunToolkit)tk).needUpdateWindow())
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   756
      {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   757
          AWTAccessor.getWindowAccessor().updateWindow(topLevel);
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   758
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
   private boolean isFloaterCollision(Rectangle moveFrom, Rectangle moveTo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
      if (floatingItems.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        // System.out.println("no floaters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
         return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
      for (int i = 0; i < floatingItems.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
         boolean intersectsFrom = moveFrom.intersects(floatingItems[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
         if (intersectsFrom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
         boolean intersectsTo = moveTo.intersects(floatingItems[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
         if (intersectsTo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
      return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
   private Rectangle[] findFloatingItems(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
      Container desktop = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
      Component[] children = desktop.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
      int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
      for (i = 0; i < children.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
         if (children[i] == f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
      // System.out.println(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
      Rectangle[] floaters = new Rectangle[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
      for (i = 0; i < floaters.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
         floaters[i] = children[i].getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
      return floaters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * This method is here to clean up problems associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * with a race condition which can occur when the full contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * of a copyArea's source argument is not available onscreen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * This uses brute force to clean up in case of possible damage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
   private void emergencyCleanup(final JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        if ( ((JInternalFrame)f).danger ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
           SwingUtilities.invokeLater( new Runnable(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                                       public void run(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                                       ((JInternalFrame)f).isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                                       f.paintImmediately(0,0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                                                          f.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                                                          f.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                                        //finalFrame.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                                        ((JInternalFrame)f).isDragging = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                                        // System.out.println("repair complete");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                                       }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
             ((JInternalFrame)f).danger = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
}