jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDesktopIconUI.java
author weijun
Thu, 11 Dec 2014 15:19:12 +0800
changeset 28228 be83f404724d
parent 25859 3317bb8137f4
permissions -rw-r--r--
8067207: Replace concat String to append in StringBuilder parameters (client) Reviewed-by: serb Contributed-by: Otavio Santana <otaviojava@java.net>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 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
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 9230
diff changeset
    37
 * Basic L&amp;F for a minimized window on a desktop.
2
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
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    45
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    46
     * The instance of {@code JInternalFrame.JDesktopIcon}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    47
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    protected JInternalFrame.JDesktopIcon desktopIcon;
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    49
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    50
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    51
     * The instance of {@code JInternalFrame}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    52
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected JInternalFrame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * The title pane component used in the desktop icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected JComponent iconPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    MouseInputListener mouseInputListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    63
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    64
     * Constructs a new instance of {@code BasicDesktopIconUI}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    65
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    66
     * @param c a component
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    67
     * @return a new instance of {@code BasicDesktopIconUI}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    68
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static ComponentUI createUI(JComponent c)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        return new BasicDesktopIconUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    73
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    74
     * Constructs a new instance of {@code BasicDesktopIconUI}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
    75
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public BasicDesktopIconUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public void installUI(JComponent c)   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        desktopIcon = (JInternalFrame.JDesktopIcon)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        frame = desktopIcon.getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        installComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // Update icon layout if frame is already iconified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        JInternalFrame f = desktopIcon.getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (f.isIcon() && f.getParent() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            JDesktopPane desktop = desktopIcon.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            if (desktop != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                DesktopManager desktopManager = desktop.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                if (desktopManager instanceof DefaultDesktopManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                    desktopManager.iconifyFrame(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        JLayeredPane.putLayer(desktopIcon, JLayeredPane.getLayer(frame));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public void uninstallUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        uninstallDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        uninstallComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // Force future UI to relayout icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        JInternalFrame f = desktopIcon.getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (f.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            JDesktopPane desktop = desktopIcon.getDesktopPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            if (desktop != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                DesktopManager desktopManager = desktop.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                if (desktopManager instanceof DefaultDesktopManager) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    // This will cause DefaultDesktopManager to layout the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    f.putClientProperty("wasIconOnce", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    // Move aside to allow fresh layout of all icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    desktopIcon.setLocation(Integer.MIN_VALUE, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        frame = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        desktopIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   125
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   126
     * Registers components.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   127
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    protected void installComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        iconPane = new BasicInternalFrameTitlePane(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        desktopIcon.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        desktopIcon.add(iconPane, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   134
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   135
     * Unregisters components.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   136
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    protected void uninstallComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        desktopIcon.remove(iconPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        desktopIcon.setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        iconPane = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   143
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   144
     * Registers listeners.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   145
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        mouseInputListener = createMouseInputListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        desktopIcon.addMouseMotionListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        desktopIcon.addMouseListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   152
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   153
     * Unregisters listeners.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   154
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        desktopIcon.removeMouseMotionListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        desktopIcon.removeMouseListener(mouseInputListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        mouseInputListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   161
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   162
     * Installs default properties.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   163
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        LookAndFeel.installBorder(desktopIcon, "DesktopIcon.border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        LookAndFeel.installProperty(desktopIcon, "opaque", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   169
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   170
     * Uninstalls default properties.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   171
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    protected void uninstallDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        LookAndFeel.uninstallBorder(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   176
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   177
     * Returns a new instance of {@code MouseInputListener}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   178
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   179
     * @return a new instance of {@code MouseInputListener}
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   180
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    protected MouseInputListener createMouseInputListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return new MouseInputHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return desktopIcon.getLayout().preferredLayoutSize(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        Dimension dim = new Dimension(iconPane.getMinimumSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        Border border = frame.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            dim.height += border.getBorderInsets(frame).bottom +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                          border.getBorderInsets(frame).top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return dim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Desktop icons can not be resized.  Therefore, we should always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * return the minimum size of the desktop icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @see #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public Dimension getMaximumSize(JComponent c){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return iconPane.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   210
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   211
     * Returns the insets.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   212
     *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   213
     * @param c a component
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   214
     * @return the insets
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   215
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public Insets getInsets(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        JInternalFrame iframe = desktopIcon.getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        Border border = iframe.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if(border != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            return border.getBorderInsets(iframe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   225
    /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   226
     * De-iconifies the internal frame.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   227
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public void deiconize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        try { frame.setIcon(false); } catch (PropertyVetoException e2) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Listens for mouse movements and acts on them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * This class should be treated as a &quot;protected&quot; inner class.
9230
c5674561cb9e 6985329: 9 classes in swing.plaf contains words inappropriate for public spec - about some compiler bug
alexp
parents: 5506
diff changeset
   236
     * Instantiate it only within subclasses of {@code BasicDesktopIconUI}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public class MouseInputHandler extends MouseInputAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        // _x & _y are the mousePressed location in absolute coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        int _x, _y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        // __x & __y are the mousePressed location in source view's coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int __x, __y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        Rectangle startingBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            _x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            _y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            __x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            __y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            startingBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            JDesktopPane d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if((d = desktopIcon.getDesktopPane()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                DesktopManager dm = d.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                dm.endDraggingFrame(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            Point p = SwingUtilities.convertPoint((Component)e.getSource(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        e.getX(), e.getY(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            __x = e.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            __y = e.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            _x = p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            _y = p.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            startingBounds = desktopIcon.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            JDesktopPane d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            if((d = desktopIcon.getDesktopPane()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                DesktopManager dm = d.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                dm.beginDraggingFrame(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            try { frame.setSelected(true); } catch (PropertyVetoException e1) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            if(desktopIcon.getParent() instanceof JLayeredPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                ((JLayeredPane)desktopIcon.getParent()).moveToFront(desktopIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            if(e.getClickCount() > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                if(frame.isIconifiable() && frame.isIcon()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    deiconize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
         public void mouseMoved(MouseEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
         public void mouseDragged(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            Point p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            int newX, newY, newW, newH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            int deltaX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            int deltaY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            Dimension min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            Dimension max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            p = SwingUtilities.convertPoint((Component)e.getSource(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                        e.getX(), e.getY(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                Insets i = desktopIcon.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                int pWidth, pHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                pWidth = ((JComponent)desktopIcon.getParent()).getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                pHeight = ((JComponent)desktopIcon.getParent()).getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                if (startingBounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                  // (STEVE) Yucky work around for bug ID 4106552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                newX = startingBounds.x - (_x - p.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                newY = startingBounds.y - (_y - p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                // Make sure we stay in-bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                if(newX + i.left <= -__x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    newX = -__x - i.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                if(newY + i.top <= -__y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    newY = -__y - i.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                if(newX + __x + i.right > pWidth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    newX = pWidth - __x - i.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                if(newY + __y + i.bottom > pHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    newY =  pHeight - __y - i.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                JDesktopPane d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                if((d = desktopIcon.getDesktopPane()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    DesktopManager dm = d.getDesktopManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    dm.dragFrame(desktopIcon, newX, newY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    moveAndRepaint(desktopIcon, newX, newY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                desktopIcon.getWidth(), desktopIcon.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
25763
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   333
        /**
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   334
         * Moves and repaints a component {@code f}.
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   335
         *
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   336
         * @param f a component
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   337
         * @param newX a new X coordinate
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   338
         * @param newY a new Y coordinate
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   339
         * @param newWidth a new width
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   340
         * @param newHeight a new height
51d1f910f68d 8049704: Fix doclint warnings from javax.swing.plaf.basic package, 2 of 7
aeremeev
parents: 23010
diff changeset
   341
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        public void moveAndRepaint(JComponent f, int newX, int newY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                                        int newWidth, int newHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            Rectangle r = f.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            f.setBounds(newX, newY, newWidth, newHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            SwingUtilities.computeUnion(newX, newY, newWidth, newHeight, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            f.getParent().repaint(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }; /// End MotionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
}