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