jdk/src/share/classes/javax/swing/plaf/basic/BasicDesktopIconUI.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 3345 e095f8b1c3e8
child 9230 c5674561cb9e
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3345
diff changeset
     2
 * Copyright (c) 1997, 2009, 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: 3345
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: 3345
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: 3345
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3345
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3345
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
package javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Basic L&F for a minimized window on a desktop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author David Kloba
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author Steve Wilson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author Rich Schiavi
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class BasicDesktopIconUI extends DesktopIconUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    protected JInternalFrame.JDesktopIcon desktopIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    protected JInternalFrame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * The title pane component used in the desktop icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected JComponent iconPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    MouseInputListener mouseInputListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static ComponentUI createUI(JComponent c)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return new BasicDesktopIconUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public BasicDesktopIconUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public void installUI(JComponent c)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        desktopIcon = (JInternalFrame.JDesktopIcon)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        frame = desktopIcon.getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        installComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        // Update icon layout if frame is already iconified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        JInternalFrame f = desktopIcon.getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (f.isIcon() && f.getParent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            JDesktopPane desktop = desktopIcon.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            if (desktop != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                DesktopManager desktopManager = desktop.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                if (desktopManager instanceof DefaultDesktopManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                    desktopManager.iconifyFrame(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        JLayeredPane.putLayer(desktopIcon, JLayeredPane.getLayer(frame));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        uninstallComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        // Force future UI to relayout icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        JInternalFrame f = desktopIcon.getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (f.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            JDesktopPane desktop = desktopIcon.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            if (desktop != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                DesktopManager desktopManager = desktop.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                if (desktopManager instanceof DefaultDesktopManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    // This will cause DefaultDesktopManager to layout the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    f.putClientProperty("wasIconOnce", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    // Move aside to allow fresh layout of all icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    desktopIcon.setLocation(Integer.MIN_VALUE, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        frame = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        desktopIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    protected void installComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        iconPane = new BasicInternalFrameTitlePane(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        desktopIcon.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        desktopIcon.add(iconPane, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    protected void uninstallComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        desktopIcon.remove(iconPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        desktopIcon.setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        iconPane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        mouseInputListener = createMouseInputListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        desktopIcon.addMouseMotionListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        desktopIcon.addMouseListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        desktopIcon.removeMouseMotionListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        desktopIcon.removeMouseListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        mouseInputListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        LookAndFeel.installBorder(desktopIcon, "DesktopIcon.border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        LookAndFeel.installProperty(desktopIcon, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        LookAndFeel.uninstallBorder(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    protected MouseInputListener createMouseInputListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        return new MouseInputHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        return desktopIcon.getLayout().preferredLayoutSize(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        Dimension dim = new Dimension(iconPane.getMinimumSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        Border border = frame.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            dim.height += border.getBorderInsets(frame).bottom +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                          border.getBorderInsets(frame).top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return dim;
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
     * Desktop icons can not be resized.  Therefore, we should always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * return the minimum size of the desktop icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @see #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public Dimension getMaximumSize(JComponent c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return iconPane.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public Insets getInsets(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        JInternalFrame iframe = desktopIcon.getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        Border border = iframe.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if(border != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            return border.getBorderInsets(iframe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public void deiconize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        try { frame.setIcon(false); } catch (PropertyVetoException e2) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Listens for mouse movements and acts on them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * This inner class is marked "public" due to a compiler bug.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * This class should be treated as a "protected" inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Instantiate it only within subclasses of <Foo>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public class MouseInputHandler extends MouseInputAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        // _x & _y are the mousePressed location in absolute coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        int _x, _y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // __x & __y are the mousePressed location in source view's coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        int __x, __y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        Rectangle startingBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            _x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            _y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            __x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            __y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            startingBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            JDesktopPane d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            if((d = desktopIcon.getDesktopPane()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                DesktopManager dm = d.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                dm.endDraggingFrame(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            Point p = SwingUtilities.convertPoint((Component)e.getSource(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                        e.getX(), e.getY(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            __x = e.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            __y = e.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            _x = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            _y = p.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            startingBounds = desktopIcon.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            JDesktopPane d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            if((d = desktopIcon.getDesktopPane()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                DesktopManager dm = d.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                dm.beginDraggingFrame(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            try { frame.setSelected(true); } catch (PropertyVetoException e1) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            if(desktopIcon.getParent() instanceof JLayeredPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                ((JLayeredPane)desktopIcon.getParent()).moveToFront(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            if(e.getClickCount() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                if(frame.isIconifiable() && frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                    deiconize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
         public void mouseMoved(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
         public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            Point p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            int newX, newY, newW, newH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            int deltaX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            int deltaY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            Dimension min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            Dimension max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            p = SwingUtilities.convertPoint((Component)e.getSource(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                        e.getX(), e.getY(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                Insets i = desktopIcon.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                int pWidth, pHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                pWidth = ((JComponent)desktopIcon.getParent()).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                pHeight = ((JComponent)desktopIcon.getParent()).getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                if (startingBounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                  // (STEVE) Yucky work around for bug ID 4106552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                newX = startingBounds.x - (_x - p.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                newY = startingBounds.y - (_y - p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                // Make sure we stay in-bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                if(newX + i.left <= -__x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                    newX = -__x - i.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                if(newY + i.top <= -__y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    newY = -__y - i.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                if(newX + __x + i.right > pWidth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    newX = pWidth - __x - i.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                if(newY + __y + i.bottom > pHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    newY =  pHeight - __y - i.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                JDesktopPane d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                if((d = desktopIcon.getDesktopPane()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    DesktopManager dm = d.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    dm.dragFrame(desktopIcon, newX, newY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    moveAndRepaint(desktopIcon, newX, newY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                desktopIcon.getWidth(), desktopIcon.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        public void moveAndRepaint(JComponent f, int newX, int newY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                        int newWidth, int newHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            Rectangle r = f.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            f.setBounds(newX, newY, newWidth, newHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            SwingUtilities.computeUnion(newX, newY, newWidth, newHeight, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            f.getParent().repaint(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }; /// End MotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
}