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