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