jdk/src/share/classes/javax/swing/plaf/metal/MetalDesktopIconUI.java
author yan
Mon, 30 Jun 2014 16:32:36 +0400
changeset 25178 dbab904451e9
parent 5506 202f599c92aa
permissions -rw-r--r--
8046434: Fix doclint warnings from javax.swing.plaf.metal package Reviewed-by: alexsch Contributed-by: Andrei Eremeev <andrei.eremeev@oracle.com>
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: 2
diff changeset
     2
 * Copyright (c) 1998, 2003, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.metal;
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.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.plaf.basic.BasicDesktopIconUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Metal desktop icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author Steve Wilson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class MetalDesktopIconUI extends BasicDesktopIconUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    JButton button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    JLabel label;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    TitleListener titleListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 5506
diff changeset
    51
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 5506
diff changeset
    52
     * Constructs a new instance of {@code MetalDesktopIconUI}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 5506
diff changeset
    53
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 5506
diff changeset
    54
     * @param c a component
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 5506
diff changeset
    55
     * @return a new instance of {@code MetalDesktopIconUI}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 5506
diff changeset
    56
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static ComponentUI createUI(JComponent c)    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        return new MetalDesktopIconUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 5506
diff changeset
    61
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 5506
diff changeset
    62
     * Constructs a new instance of {@code MetalDesktopIconUI}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 5506
diff changeset
    63
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public MetalDesktopIconUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected void installDefaults() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        super.installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        LookAndFeel.installColorsAndFont(desktopIcon, "DesktopIcon.background", "DesktopIcon.foreground", "DesktopIcon.font");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        width = UIManager.getInt("DesktopIcon.width");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected void installComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        frame = desktopIcon.getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        Icon icon = frame.getFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        String title = frame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        button = new JButton (title, icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        button.addActionListener( new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                  public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
             deiconize(); }} );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        button.setFont(desktopIcon.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        button.setBackground(desktopIcon.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        button.setForeground(desktopIcon.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        int buttonH = button.getPreferredSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        Icon drag = new MetalBumps((buttonH/3), buttonH,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                   MetalLookAndFeel.getControlHighlight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                   MetalLookAndFeel.getControlDarkShadow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                   MetalLookAndFeel.getControl());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        label = new JLabel(drag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        label.setBorder( new MatteBorder( 0, 2, 0, 1, desktopIcon.getBackground()) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        desktopIcon.setLayout(new BorderLayout(2, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        desktopIcon.add(button, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        desktopIcon.add(label, BorderLayout.WEST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    protected void uninstallComponents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        desktopIcon.setLayout(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        desktopIcon.remove(label);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        desktopIcon.remove(button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        button = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        frame = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        desktopIcon.getInternalFrame().addPropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                titleListener = new TitleListener());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        desktopIcon.getInternalFrame().removePropertyChangeListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                titleListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        titleListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super.uninstallListeners();
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
    public Dimension getPreferredSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        // Metal desktop icons can not be resized.  Their dimensions should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // always be the minimum size.  See getMinimumSize(JComponent c).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return getMinimumSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public Dimension getMinimumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // For the metal desktop icon we will use the layout maanger to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // determine the correct height of the component, but we want to keep
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        // the width consistent according to the jlf spec.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return new Dimension(width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                desktopIcon.getLayout().minimumLayoutSize(desktopIcon).height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public Dimension getMaximumSize(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // Metal desktop icons can not be resized.  Their dimensions should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // always be the minimum size.  See getMinimumSize(JComponent c).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return getMinimumSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    class TitleListener implements PropertyChangeListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        public void propertyChange (PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
          if (e.getPropertyName().equals("title")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            button.setText((String)e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
          if (e.getPropertyName().equals("frameIcon")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            button.setIcon((Icon)e.getNewValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}