jdk/src/share/classes/javax/swing/DefaultDesktopManager.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8524 f2fac94f2434
child 22567 5816a47fa4dd
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8524
diff changeset
     2
 * Copyright (c) 1997, 2011, 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);
8524
f2fac94f2434 6826074: JScrollPane does not revalidate the component hierarchy after scrolling
alexp
parents: 7762
diff changeset
   177
            // 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
   178
            desktopIcon.revalidate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            setWasIcon(f, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (c == null || d == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (c instanceof JLayeredPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            JLayeredPane lp = (JLayeredPane)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            int layer = lp.getLayer(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            lp.putLayer(desktopIcon, layer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        // If we are maximized we already have the normal bounds recorded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        // don't try to re-record them, otherwise we incorrectly set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        // normal bounds to maximized state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (!f.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            f.setNormalBounds(f.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        d.setComponentOrderCheckingEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        c.remove(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        c.add(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        d.setComponentOrderCheckingEnabled(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (findNext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            if (d.selectFrame(true) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                // The icon is the last frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                f.restoreSubcomponentFocus();
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Removes the desktopIcon from its parent and adds its frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * to the parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param f the <code>JInternalFrame</code> to be de-iconified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public void deiconifyFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Container c = desktopIcon.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        JDesktopPane d = f.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (c != null && d != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            c.add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            // If the frame is to be restored to a maximized state make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            // sure it still fills the whole desktop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            if (f.isMaximum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                Rectangle desktopBounds = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                if (f.getWidth() != desktopBounds.width ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                        f.getHeight() != desktopBounds.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    setBoundsForFrame(f, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                        desktopBounds.width, desktopBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            removeIconFor(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            if (f.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                f.moveToFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                f.restoreSubcomponentFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                    f.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                } catch (PropertyVetoException e2) {}
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
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /** This will activate <b>f</b> moving it to the front. It will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
      * set the current active frame's (if any)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
      * <code>IS_SELECTED_PROPERTY</code> to <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
      * There can be only one active frame across all Layers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
      * @param f the <code>JInternalFrame</code> to be activated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public void activateFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        Container p = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        Component[] c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        JDesktopPane d = f.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        JInternalFrame currentlyActiveFrame =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
          (d == null) ? null : d.getSelectedFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        // fix for bug: 4162443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if(p == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            // If the frame is not in parent, its icon maybe, check it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            p = f.getDesktopIcon().getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            if(p == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // we only need to keep track of the currentActive InternalFrame, if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (currentlyActiveFrame == null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
          if (d != null) { d.setSelectedFrame(f);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        } else if (currentlyActiveFrame != f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
          // if not the same frame as the current active
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
          // we deactivate the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
          if (currentlyActiveFrame.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
              currentlyActiveFrame.setSelected(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            catch(PropertyVetoException e2) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
          if (d != null) { d.setSelectedFrame(f);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        f.moveToFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    // implements javax.swing.DesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public void deactivateFrame(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
      JDesktopPane d = f.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
      JInternalFrame currentlyActiveFrame =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
          (d == null) ? null : d.getSelectedFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
      if (currentlyActiveFrame == f)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        d.setSelectedFrame(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    // implements javax.swing.DesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public void beginDraggingFrame(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        setupDragMode(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (dragMode == FASTER_DRAG_MODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
          Component desktop = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
          floatingItems = findFloatingItems(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
          currentBounds = f.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
          if (desktop instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
              desktopBounds = ((JComponent)desktop).getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
          else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
              desktopBounds = desktop.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
              desktopBounds.x = desktopBounds.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
          desktopGraphics = JComponent.safelyGetGraphics(desktop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
          ((JInternalFrame)f).isDragging = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
          didDrag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    private void setupDragMode(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        JDesktopPane p = getDesktopPane(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        Container parent = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        dragMode = DEFAULT_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            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
   319
            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
   320
            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
   321
                dragMode = DEFAULT_DRAG_MODE;
72871be64138 6786238: api/javax_swing/DefaultDesktopManager/descriptions.html#xxxFrame Fails with NPE since 6u12 b02
alexp
parents: 3288
diff changeset
   322
            } else if (mode != null && mode.equals("outline")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                dragMode = OUTLINE_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            } else if (mode != null && mode.equals("faster")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    && f instanceof JInternalFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                    && ((JInternalFrame)f).isOpaque() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                       (parent == null || parent.isOpaque())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                dragMode = FASTER_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                if (p.getDragMode() == JDesktopPane.OUTLINE_DRAG_MODE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    dragMode = OUTLINE_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                } else if ( p.getDragMode() == JDesktopPane.LIVE_DRAG_MODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                        && f instanceof JInternalFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                        && ((JInternalFrame)f).isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    dragMode = FASTER_DRAG_MODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    dragMode = DEFAULT_DRAG_MODE;
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
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    private transient Point currentLoc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
      * Moves the visible location of the frame being dragged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
      * to the location specified.  The means by which this occurs can vary depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
      * on the dragging algorithm being used.  The actual logical location of the frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
      * might not change until <code>endDraggingFrame</code> is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public void dragFrame(JComponent f, int newX, int newY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        if (dragMode == OUTLINE_DRAG_MODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            JDesktopPane desktopPane = getDesktopPane(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            if (desktopPane != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
              Graphics g = JComponent.safelyGetGraphics(desktopPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
              g.setXORMode(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
              if (currentLoc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                g.drawRect(currentLoc.x, currentLoc.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                        f.getWidth()-1, f.getHeight()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
              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
   364
              /* 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
   365
              * Swing doesn't expect that its XOR drawRect did
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   366
              * not complete, so believes that on re-entering at
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   367
              * the next update location, that there is an XOR rect
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   368
              * to draw out at "currentLoc". But in fact
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   369
              * its now got a new clean surface without that rect,
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   370
              * 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
   371
              * So only update/set currentLoc if the draw completed.
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   372
              */
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   373
              sun.java2d.SurfaceData sData =
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   374
                  ((sun.java2d.SunGraphics2D)g).getSurfaceData();
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   375
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   376
              if (!sData.isSurfaceLost()) {
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   377
                  currentLoc = new Point (newX, newY);
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   378
              }
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   379
;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
              g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        } 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
   383
            dragFrameFaster(f, newX, newY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    // implements javax.swing.DesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public void endDraggingFrame(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        if ( dragMode == OUTLINE_DRAG_MODE && currentLoc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            setBoundsForFrame(f, currentLoc.x, currentLoc.y, f.getWidth(), f.getHeight() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            currentLoc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        } else if (dragMode == FASTER_DRAG_MODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            currentBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            if (desktopGraphics != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                desktopGraphics.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                desktopGraphics = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            desktopBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            ((JInternalFrame)f).isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    // implements javax.swing.DesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public void beginResizingFrame(JComponent f, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        setupDragMode(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Calls <code>setBoundsForFrame</code> with the new values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @param f the component to be resized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @param newX the new x-coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @param newY the new y-coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @param newWidth the new width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @param newHeight the new height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    public void resizeFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if ( dragMode == DEFAULT_DRAG_MODE || dragMode == FASTER_DRAG_MODE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            setBoundsForFrame(f, newX, newY, newWidth, newHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            JDesktopPane desktopPane = getDesktopPane(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if (desktopPane != null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
              Graphics g = JComponent.safelyGetGraphics(desktopPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
              g.setXORMode(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
              if (currentBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                g.drawRect( currentBounds.x, currentBounds.y, currentBounds.width-1, currentBounds.height-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
              g.drawRect( newX, newY, newWidth-1, newHeight-1);
7748
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   432
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   433
              // Work around for 6635462, see comment in dragFrame()
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   434
              sun.java2d.SurfaceData sData =
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   435
                  ((sun.java2d.SunGraphics2D)g).getSurfaceData();
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   436
              if (!sData.isSurfaceLost()) {
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   437
                  currentBounds = new Rectangle (newX, newY, newWidth, newHeight);
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   438
              }
26e6f5fc1bdb 6635462: D3D: REGRESSION: XOR rendering is extremly slow
jgodinez
parents: 5597
diff changeset
   439
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
              g.setPaintMode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
              g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
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
    // implements javax.swing.DesktopManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public void endResizingFrame(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if ( dragMode == OUTLINE_DRAG_MODE && currentBounds != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            setBoundsForFrame(f, currentBounds.x, currentBounds.y, currentBounds.width, currentBounds.height );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            currentBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /** This moves the <code>JComponent</code> and repaints the damaged areas. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        f.setBounds(newX, newY, newWidth, newHeight);
8524
f2fac94f2434 6826074: JScrollPane does not revalidate the component hierarchy after scrolling
alexp
parents: 7762
diff changeset
   459
        // 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
   460
        f.revalidate();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /** Convenience method to remove the desktopIcon of <b>f</b> is necessary. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    protected void removeIconFor(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        JInternalFrame.JDesktopIcon di = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        Container c = di.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        if(c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            c.remove(di);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            c.repaint(di.getX(), di.getY(), di.getWidth(), di.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /** The iconifyFrame() code calls this to determine the proper bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
      * for the desktopIcon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    protected Rectangle getBoundsForIconOf(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
      // Get the icon for this internal frame and its preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
      JInternalFrame.JDesktopIcon icon = f.getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
      Dimension prefSize = icon.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
      // Get the parent bounds and child components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
      Container c = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
      if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
          c = f.getDesktopIcon().getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
      if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        /* the frame has not yet been added to the parent; how about (0,0) ?*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        return new Rectangle(0, 0, prefSize.width, prefSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
      Rectangle parentBounds = c.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
      Component [] components = c.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
      // Iterate through valid default icon locations and return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
      // first one that does not intersect any other icons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
      Rectangle availableRectangle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
      JInternalFrame.JDesktopIcon currentIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
      int x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
      int y = parentBounds.height - prefSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
      int w = prefSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
      int h = prefSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
      boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
      while (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        availableRectangle = new Rectangle(x,y,w,h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        for ( int i=0; i<components.length; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
          //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
          // Get the icon for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
          //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
          if ( components[i] instanceof JInternalFrame ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            currentIcon = ((JInternalFrame)components[i]).getDesktopIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
          else if ( components[i] instanceof JInternalFrame.JDesktopIcon ){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            currentIcon = (JInternalFrame.JDesktopIcon)components[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
          } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            /* found a child that's neither an internal frame nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
               an icon. I don't believe this should happen, but at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
               present it does and causes a null pointer exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
               Even when that gets fixed, this code protects against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
               the npe. hania */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
          //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
          // If this icon intersects the current location, get next location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
          //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
          if ( !currentIcon.equals(icon) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            if ( availableRectangle.intersects(currentIcon.getBounds()) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
              found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        if (currentIcon == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
          /* didn't find any useful children above. This probably shouldn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
           happen, but this check protects against an npe if it ever does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
           (and it's happening now) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
          return availableRectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        x += currentIcon.getBounds().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        if ( x + w > parentBounds.width ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
          x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
          y -= h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
      return(availableRectangle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Stores the bounds of the component just before a maximize call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @param f the component about to be resized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @param r the normal bounds to be saved away
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    protected void setPreviousBounds(JInternalFrame f, Rectangle r)     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        f.setNormalBounds(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * Gets the normal bounds of the component prior to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * being maximized.
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 the normal bounds of the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    protected Rectangle getPreviousBounds(JInternalFrame f)     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        return f.getNormalBounds();
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
     * Sets that the component has been iconized and the bounds of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <code>desktopIcon</code> are valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    protected void setWasIcon(JInternalFrame f, Boolean value)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            f.putClientProperty(HAS_BEEN_ICONIFIED_PROPERTY, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
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
     * Returns <code>true</code> if the component has been iconized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * and the bounds of the <code>desktopIcon</code> are valid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * otherwise returns <code>false</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @param f the <code>JInternalFrame</code> of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @return <code>true</code> if the component has been iconized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     *    otherwise returns <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    protected boolean wasIcon(JInternalFrame f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        return (f.getClientProperty(HAS_BEEN_ICONIFIED_PROPERTY) == Boolean.TRUE);
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
    JDesktopPane getDesktopPane( JComponent frame ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        JDesktopPane pane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        Component c = frame.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        // Find the JDesktopPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        while ( pane == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            if ( c instanceof JDesktopPane ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                pane = (JDesktopPane)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            else if ( c == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                c = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        return pane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
  // =========== stuff for faster frame dragging ===================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
   private void dragFrameFaster(JComponent f, int newX, int newY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
      Rectangle previousBounds = new Rectangle(currentBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                                               currentBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                                               currentBounds.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                                               currentBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
   // move the frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
      currentBounds.x = newX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
      currentBounds.y = newY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
      if (didDrag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
          // Only initiate cleanup if we have actually done a drag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
          emergencyCleanup(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
      else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
          didDrag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
          // We reset the danger field as until now we haven't actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
          // moved the internal frame so we don't need to initiate repaint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
          ((JInternalFrame)f).danger = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
      boolean floaterCollision = isFloaterCollision(previousBounds, currentBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
      JComponent parent = (JComponent)f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
      Rectangle visBounds = previousBounds.intersection(desktopBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
      RepaintManager currentManager = RepaintManager.currentManager(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
      currentManager.beginPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
      try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
          if(!floaterCollision) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
              currentManager.copyArea(parent, desktopGraphics, visBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                                      visBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                                      visBounds.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                                      visBounds.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                                      newX - previousBounds.x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                                      newY - previousBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                                      true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
          f.setBounds(currentBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
          if(floaterCollision) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
              // since we couldn't blit we just redraw as fast as possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
              // the isDragging mucking is to avoid activating emergency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
              // cleanup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
              ((JInternalFrame)f).isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
              parent.paintImmediately(currentBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
              ((JInternalFrame)f).isDragging = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
          // fake out the repaint manager.  We'll take care of everything
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
          currentManager.markCompletelyClean(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
          currentManager.markCompletelyClean(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
          // compute the minimal newly exposed area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
          // if the rects intersect then we use computeDifference.  Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
          // we'll repaint the entire previous bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
          Rectangle[] dirtyRects = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
          if ( previousBounds.intersects(currentBounds) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
              dirtyRects = SwingUtilities.computeDifference(previousBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                                                            currentBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
              dirtyRects = new Rectangle[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
              dirtyRects[0] = previousBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
          };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
          // Fix the damage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
          for (int i = 0; i < dirtyRects.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
              parent.paintImmediately(dirtyRects[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
          // new areas of blit were exposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
          if ( !(visBounds.equals(previousBounds)) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
              dirtyRects = SwingUtilities.computeDifference(previousBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                                                            desktopBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
              for (int i = 0; i < dirtyRects.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                  dirtyRects[i].x += newX - previousBounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                  dirtyRects[i].y += newY - previousBounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                  ((JInternalFrame)f).isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                  parent.paintImmediately(dirtyRects[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                  ((JInternalFrame)f).isDragging = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
      } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
          currentManager.endPaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
      }
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   728
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   729
      // 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
   730
      Window topLevel = SwingUtilities.getWindowAncestor(f);
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   731
      Toolkit tk = Toolkit.getDefaultToolkit();
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 2808
diff changeset
   732
      if (!topLevel.isOpaque() &&
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   733
          (tk instanceof SunToolkit) &&
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   734
          ((SunToolkit)tk).needUpdateWindow())
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   735
      {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   736
          AWTAccessor.getWindowAccessor().updateWindow(topLevel);
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2
diff changeset
   737
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
   private boolean isFloaterCollision(Rectangle moveFrom, Rectangle moveTo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
      if (floatingItems.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        // System.out.println("no floaters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
      for (int i = 0; i < floatingItems.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
         boolean intersectsFrom = moveFrom.intersects(floatingItems[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
         if (intersectsFrom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
         boolean intersectsTo = moveTo.intersects(floatingItems[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
         if (intersectsTo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            return true;
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
      return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
   private Rectangle[] findFloatingItems(JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
      Container desktop = f.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
      Component[] children = desktop.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
      int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
      for (i = 0; i < children.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
         if (children[i] == f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
      // System.out.println(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
      Rectangle[] floaters = new Rectangle[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
      for (i = 0; i < floaters.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
         floaters[i] = children[i].getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
      return floaters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * This method is here to clean up problems associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * with a race condition which can occur when the full contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * of a copyArea's source argument is not available onscreen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * This uses brute force to clean up in case of possible damage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
   private void emergencyCleanup(final JComponent f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        if ( ((JInternalFrame)f).danger ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
           SwingUtilities.invokeLater( new Runnable(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                                       public void run(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                                       ((JInternalFrame)f).isDragging = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                                       f.paintImmediately(0,0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                                                          f.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                                                          f.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                                        //finalFrame.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                                        ((JInternalFrame)f).isDragging = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                                        // System.out.println("repair complete");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                                       }});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
             ((JInternalFrame)f).danger = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
}