author | yan |
Mon, 30 Jun 2014 16:32:36 +0400 | |
changeset 25178 | dbab904451e9 |
parent 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package javax.swing.plaf.metal; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.event.*; |
|
30 |
import javax.swing.*; |
|
31 |
import javax.swing.border.*; |
|
32 |
import javax.swing.plaf.*; |
|
33 |
import java.beans.*; |
|
34 |
import java.util.EventListener; |
|
35 |
import java.io.Serializable; |
|
36 |
import javax.swing.plaf.basic.BasicDesktopIconUI; |
|
37 |
||
38 |
/** |
|
39 |
* Metal desktop icon. |
|
40 |
* |
|
41 |
* @author Steve Wilson |
|
42 |
*/ |
|
43 |
public class MetalDesktopIconUI extends BasicDesktopIconUI |
|
44 |
{ |
|
45 |
||
46 |
JButton button; |
|
47 |
JLabel label; |
|
48 |
TitleListener titleListener; |
|
49 |
private int width; |
|
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 | 57 |
public static ComponentUI createUI(JComponent c) { |
58 |
return new MetalDesktopIconUI(); |
|
59 |
} |
|
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 | 64 |
public MetalDesktopIconUI() { |
65 |
} |
|
66 |
||
67 |
protected void installDefaults() { |
|
68 |
super.installDefaults(); |
|
69 |
LookAndFeel.installColorsAndFont(desktopIcon, "DesktopIcon.background", "DesktopIcon.foreground", "DesktopIcon.font"); |
|
70 |
width = UIManager.getInt("DesktopIcon.width"); |
|
71 |
} |
|
72 |
||
73 |
protected void installComponents() { |
|
74 |
frame = desktopIcon.getInternalFrame(); |
|
75 |
Icon icon = frame.getFrameIcon(); |
|
76 |
String title = frame.getTitle(); |
|
77 |
||
78 |
button = new JButton (title, icon); |
|
79 |
button.addActionListener( new ActionListener() { |
|
80 |
public void actionPerformed(ActionEvent e) { |
|
81 |
deiconize(); }} ); |
|
82 |
button.setFont(desktopIcon.getFont()); |
|
83 |
button.setBackground(desktopIcon.getBackground()); |
|
84 |
button.setForeground(desktopIcon.getForeground()); |
|
85 |
||
86 |
int buttonH = button.getPreferredSize().height; |
|
87 |
||
88 |
Icon drag = new MetalBumps((buttonH/3), buttonH, |
|
89 |
MetalLookAndFeel.getControlHighlight(), |
|
90 |
MetalLookAndFeel.getControlDarkShadow(), |
|
91 |
MetalLookAndFeel.getControl()); |
|
92 |
label = new JLabel(drag); |
|
93 |
||
94 |
label.setBorder( new MatteBorder( 0, 2, 0, 1, desktopIcon.getBackground()) ); |
|
95 |
desktopIcon.setLayout(new BorderLayout(2, 0)); |
|
96 |
desktopIcon.add(button, BorderLayout.CENTER); |
|
97 |
desktopIcon.add(label, BorderLayout.WEST); |
|
98 |
} |
|
99 |
||
100 |
protected void uninstallComponents() { |
|
101 |
desktopIcon.setLayout(null); |
|
102 |
desktopIcon.remove(label); |
|
103 |
desktopIcon.remove(button); |
|
104 |
button = null; |
|
105 |
frame = null; |
|
106 |
} |
|
107 |
||
108 |
protected void installListeners() { |
|
109 |
super.installListeners(); |
|
110 |
desktopIcon.getInternalFrame().addPropertyChangeListener( |
|
111 |
titleListener = new TitleListener()); |
|
112 |
} |
|
113 |
||
114 |
protected void uninstallListeners() { |
|
115 |
desktopIcon.getInternalFrame().removePropertyChangeListener( |
|
116 |
titleListener); |
|
117 |
titleListener = null; |
|
118 |
super.uninstallListeners(); |
|
119 |
} |
|
120 |
||
121 |
||
122 |
public Dimension getPreferredSize(JComponent c) { |
|
123 |
// Metal desktop icons can not be resized. Their dimensions should |
|
124 |
// always be the minimum size. See getMinimumSize(JComponent c). |
|
125 |
return getMinimumSize(c); |
|
126 |
} |
|
127 |
||
128 |
public Dimension getMinimumSize(JComponent c) { |
|
129 |
// For the metal desktop icon we will use the layout maanger to |
|
130 |
// determine the correct height of the component, but we want to keep |
|
131 |
// the width consistent according to the jlf spec. |
|
132 |
return new Dimension(width, |
|
133 |
desktopIcon.getLayout().minimumLayoutSize(desktopIcon).height); |
|
134 |
} |
|
135 |
||
136 |
public Dimension getMaximumSize(JComponent c) { |
|
137 |
// Metal desktop icons can not be resized. Their dimensions should |
|
138 |
// always be the minimum size. See getMinimumSize(JComponent c). |
|
139 |
return getMinimumSize(c); |
|
140 |
} |
|
141 |
||
142 |
class TitleListener implements PropertyChangeListener { |
|
143 |
public void propertyChange (PropertyChangeEvent e) { |
|
144 |
if (e.getPropertyName().equals("title")) { |
|
145 |
button.setText((String)e.getNewValue()); |
|
146 |
} |
|
147 |
||
148 |
if (e.getPropertyName().equals("frameIcon")) { |
|
149 |
button.setIcon((Icon)e.getNewValue()); |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
} |