2
|
1 |
/*
|
|
2 |
* Copyright 2002-2003 Sun Microsystems, Inc. All Rights Reserved.
|
|
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
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
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 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package javax.swing.plaf.synth;
|
|
27 |
|
|
28 |
import java.awt.*;
|
|
29 |
import java.awt.event.*;
|
|
30 |
import javax.swing.*;
|
|
31 |
import javax.swing.plaf.*;
|
|
32 |
import javax.swing.plaf.basic.BasicDesktopIconUI;
|
|
33 |
import java.beans.*;
|
|
34 |
|
|
35 |
|
|
36 |
/**
|
4394
|
37 |
* Provides the Synth L&F UI delegate for a minimized internal frame on a desktop.
|
2
|
38 |
*
|
|
39 |
* @author Joshua Outwater
|
4394
|
40 |
* @since 1.7
|
2
|
41 |
*/
|
4394
|
42 |
public class SynthDesktopIconUI extends BasicDesktopIconUI
|
|
43 |
implements SynthUI, PropertyChangeListener {
|
2
|
44 |
private SynthStyle style;
|
4394
|
45 |
private Handler handler = new Handler();
|
2
|
46 |
|
4394
|
47 |
/**
|
|
48 |
* Creates a new UI object for the given component.
|
|
49 |
*
|
|
50 |
* @param c component to create UI object for
|
|
51 |
* @return the UI object
|
|
52 |
*/
|
2
|
53 |
public static ComponentUI createUI(JComponent c) {
|
|
54 |
return new SynthDesktopIconUI();
|
|
55 |
}
|
|
56 |
|
4394
|
57 |
/**
|
|
58 |
* @inheritDoc
|
|
59 |
*/
|
|
60 |
@Override
|
2
|
61 |
protected void installComponents() {
|
|
62 |
if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
|
|
63 |
iconPane = new JToggleButton(frame.getTitle(), frame.getFrameIcon()) {
|
4394
|
64 |
@Override public String getToolTipText() {
|
2
|
65 |
return getText();
|
|
66 |
}
|
|
67 |
|
4394
|
68 |
@Override public JPopupMenu getComponentPopupMenu() {
|
2
|
69 |
return frame.getComponentPopupMenu();
|
|
70 |
}
|
|
71 |
};
|
|
72 |
ToolTipManager.sharedInstance().registerComponent(iconPane);
|
|
73 |
iconPane.setFont(desktopIcon.getFont());
|
|
74 |
iconPane.setBackground(desktopIcon.getBackground());
|
|
75 |
iconPane.setForeground(desktopIcon.getForeground());
|
|
76 |
} else {
|
|
77 |
iconPane = new SynthInternalFrameTitlePane(frame);
|
|
78 |
iconPane.setName("InternalFrame.northPane");
|
|
79 |
}
|
|
80 |
desktopIcon.setLayout(new BorderLayout());
|
|
81 |
desktopIcon.add(iconPane, BorderLayout.CENTER);
|
|
82 |
}
|
|
83 |
|
4394
|
84 |
/**
|
|
85 |
* @inheritDoc
|
|
86 |
*/
|
|
87 |
@Override
|
2
|
88 |
protected void installListeners() {
|
|
89 |
super.installListeners();
|
|
90 |
desktopIcon.addPropertyChangeListener(this);
|
|
91 |
|
|
92 |
if (iconPane instanceof JToggleButton) {
|
|
93 |
frame.addPropertyChangeListener(this);
|
4394
|
94 |
((JToggleButton)iconPane).addActionListener(handler);
|
2
|
95 |
}
|
|
96 |
}
|
|
97 |
|
4394
|
98 |
/**
|
|
99 |
* @inheritDoc
|
|
100 |
*/
|
|
101 |
@Override
|
2
|
102 |
protected void uninstallListeners() {
|
|
103 |
if (iconPane instanceof JToggleButton) {
|
4394
|
104 |
((JToggleButton)iconPane).removeActionListener(handler);
|
2
|
105 |
frame.removePropertyChangeListener(this);
|
|
106 |
}
|
|
107 |
desktopIcon.removePropertyChangeListener(this);
|
|
108 |
super.uninstallListeners();
|
|
109 |
}
|
|
110 |
|
4394
|
111 |
/**
|
|
112 |
* @inheritDoc
|
|
113 |
*/
|
|
114 |
@Override
|
2
|
115 |
protected void installDefaults() {
|
|
116 |
updateStyle(desktopIcon);
|
|
117 |
}
|
|
118 |
|
|
119 |
private void updateStyle(JComponent c) {
|
|
120 |
SynthContext context = getContext(c, ENABLED);
|
|
121 |
style = SynthLookAndFeel.updateStyle(context, this);
|
|
122 |
context.dispose();
|
|
123 |
}
|
|
124 |
|
4394
|
125 |
/**
|
|
126 |
* @inheritDoc
|
|
127 |
*/
|
|
128 |
@Override
|
2
|
129 |
protected void uninstallDefaults() {
|
|
130 |
SynthContext context = getContext(desktopIcon, ENABLED);
|
|
131 |
style.uninstallDefaults(context);
|
|
132 |
context.dispose();
|
|
133 |
style = null;
|
|
134 |
}
|
|
135 |
|
4394
|
136 |
/**
|
|
137 |
* @inheritDoc
|
|
138 |
*/
|
|
139 |
@Override
|
2
|
140 |
public SynthContext getContext(JComponent c) {
|
|
141 |
return getContext(c, getComponentState(c));
|
|
142 |
}
|
|
143 |
|
|
144 |
private SynthContext getContext(JComponent c, int state) {
|
4394
|
145 |
Region region = SynthLookAndFeel.getRegion(c);
|
2
|
146 |
return SynthContext.getContext(SynthContext.class, c, region,
|
|
147 |
style, state);
|
|
148 |
}
|
|
149 |
|
|
150 |
private int getComponentState(JComponent c) {
|
|
151 |
return SynthLookAndFeel.getComponentState(c);
|
|
152 |
}
|
|
153 |
|
4394
|
154 |
/**
|
|
155 |
* @inheritDoc
|
|
156 |
*/
|
|
157 |
@Override
|
2
|
158 |
public void update(Graphics g, JComponent c) {
|
|
159 |
SynthContext context = getContext(c);
|
|
160 |
|
|
161 |
SynthLookAndFeel.update(context, g);
|
|
162 |
context.getPainter().paintDesktopIconBackground(context, g, 0, 0,
|
|
163 |
c.getWidth(), c.getHeight());
|
|
164 |
paint(context, g);
|
|
165 |
context.dispose();
|
|
166 |
}
|
|
167 |
|
4394
|
168 |
/**
|
|
169 |
* @inheritDoc
|
|
170 |
*/
|
|
171 |
@Override
|
2
|
172 |
public void paint(Graphics g, JComponent c) {
|
|
173 |
SynthContext context = getContext(c);
|
|
174 |
|
|
175 |
paint(context, g);
|
|
176 |
context.dispose();
|
|
177 |
}
|
|
178 |
|
4394
|
179 |
/**
|
|
180 |
* Paints the specified component. This implementation does nothing.
|
|
181 |
*
|
|
182 |
* @param context context for the component being painted
|
|
183 |
* @param g {@code Graphics} object used for painting
|
|
184 |
*/
|
2
|
185 |
protected void paint(SynthContext context, Graphics g) {
|
|
186 |
}
|
|
187 |
|
4394
|
188 |
/**
|
|
189 |
* @inheritDoc
|
|
190 |
*/
|
|
191 |
@Override
|
2
|
192 |
public void paintBorder(SynthContext context, Graphics g, int x,
|
|
193 |
int y, int w, int h) {
|
|
194 |
context.getPainter().paintDesktopIconBorder(context, g, x, y, w, h);
|
|
195 |
}
|
|
196 |
|
|
197 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
198 |
if (evt.getSource() instanceof JInternalFrame.JDesktopIcon) {
|
|
199 |
if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
|
|
200 |
updateStyle((JInternalFrame.JDesktopIcon)evt.getSource());
|
|
201 |
}
|
|
202 |
} else if (evt.getSource() instanceof JInternalFrame) {
|
|
203 |
JInternalFrame frame = (JInternalFrame)evt.getSource();
|
|
204 |
if (iconPane instanceof JToggleButton) {
|
|
205 |
JToggleButton button = (JToggleButton)iconPane;
|
|
206 |
String prop = evt.getPropertyName();
|
|
207 |
if (prop == "title") {
|
|
208 |
button.setText((String)evt.getNewValue());
|
|
209 |
} else if (prop == "frameIcon") {
|
|
210 |
button.setIcon((Icon)evt.getNewValue());
|
|
211 |
} else if (prop == JInternalFrame.IS_ICON_PROPERTY ||
|
|
212 |
prop == JInternalFrame.IS_SELECTED_PROPERTY) {
|
|
213 |
button.setSelected(!frame.isIcon() && frame.isSelected());
|
|
214 |
}
|
|
215 |
}
|
|
216 |
}
|
|
217 |
}
|
4394
|
218 |
|
|
219 |
private final class Handler implements ActionListener {
|
|
220 |
public void actionPerformed(ActionEvent evt) {
|
|
221 |
if (evt.getSource() instanceof JToggleButton) {
|
|
222 |
// Either iconify the frame or deiconify and activate it.
|
|
223 |
JToggleButton button = (JToggleButton)evt.getSource();
|
|
224 |
try {
|
|
225 |
boolean selected = button.isSelected();
|
|
226 |
if (!selected && !frame.isIconifiable()) {
|
|
227 |
button.setSelected(true);
|
|
228 |
} else {
|
|
229 |
frame.setIcon(!selected);
|
|
230 |
if (selected) {
|
|
231 |
frame.setSelected(true);
|
|
232 |
}
|
|
233 |
}
|
|
234 |
} catch (PropertyVetoException e2) {
|
|
235 |
}
|
|
236 |
}
|
|
237 |
}
|
|
238 |
}
|
2
|
239 |
}
|