author | darcy |
Sun, 23 Mar 2014 13:49:48 -0700 (2014-03-23) | |
changeset 23697 | e556a715949f |
parent 23010 | 6dadb192ad81 |
child 25100 | d527cc827d7d |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23697 | 2 |
* Copyright (c) 2002, 2014, 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.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 |
/** |
|
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
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 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
58 |
* {@inheritDoc} |
4394 | 59 |
*/ |
60 |
@Override |
|
2 | 61 |
protected void installComponents() { |
62 |
if (UIManager.getBoolean("InternalFrame.useTaskBar")) { |
|
23697 | 63 |
@SuppressWarnings("serial") // anonymous class |
64 |
JToggleButton tmp = new JToggleButton(frame.getTitle(), frame.getFrameIcon()) { |
|
4394 | 65 |
@Override public String getToolTipText() { |
2 | 66 |
return getText(); |
67 |
} |
|
68 |
||
4394 | 69 |
@Override public JPopupMenu getComponentPopupMenu() { |
2 | 70 |
return frame.getComponentPopupMenu(); |
71 |
} |
|
72 |
}; |
|
23697 | 73 |
iconPane = tmp; |
2 | 74 |
ToolTipManager.sharedInstance().registerComponent(iconPane); |
75 |
iconPane.setFont(desktopIcon.getFont()); |
|
76 |
iconPane.setBackground(desktopIcon.getBackground()); |
|
77 |
iconPane.setForeground(desktopIcon.getForeground()); |
|
78 |
} else { |
|
79 |
iconPane = new SynthInternalFrameTitlePane(frame); |
|
80 |
iconPane.setName("InternalFrame.northPane"); |
|
81 |
} |
|
82 |
desktopIcon.setLayout(new BorderLayout()); |
|
83 |
desktopIcon.add(iconPane, BorderLayout.CENTER); |
|
84 |
} |
|
85 |
||
4394 | 86 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
87 |
* {@inheritDoc} |
4394 | 88 |
*/ |
89 |
@Override |
|
2 | 90 |
protected void installListeners() { |
91 |
super.installListeners(); |
|
92 |
desktopIcon.addPropertyChangeListener(this); |
|
93 |
||
94 |
if (iconPane instanceof JToggleButton) { |
|
95 |
frame.addPropertyChangeListener(this); |
|
4394 | 96 |
((JToggleButton)iconPane).addActionListener(handler); |
2 | 97 |
} |
98 |
} |
|
99 |
||
4394 | 100 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
101 |
* {@inheritDoc} |
4394 | 102 |
*/ |
103 |
@Override |
|
2 | 104 |
protected void uninstallListeners() { |
105 |
if (iconPane instanceof JToggleButton) { |
|
4394 | 106 |
((JToggleButton)iconPane).removeActionListener(handler); |
2 | 107 |
frame.removePropertyChangeListener(this); |
108 |
} |
|
109 |
desktopIcon.removePropertyChangeListener(this); |
|
110 |
super.uninstallListeners(); |
|
111 |
} |
|
112 |
||
4394 | 113 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
114 |
* {@inheritDoc} |
4394 | 115 |
*/ |
116 |
@Override |
|
2 | 117 |
protected void installDefaults() { |
118 |
updateStyle(desktopIcon); |
|
119 |
} |
|
120 |
||
121 |
private void updateStyle(JComponent c) { |
|
122 |
SynthContext context = getContext(c, ENABLED); |
|
123 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
124 |
context.dispose(); |
|
125 |
} |
|
126 |
||
4394 | 127 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
128 |
* {@inheritDoc} |
4394 | 129 |
*/ |
130 |
@Override |
|
2 | 131 |
protected void uninstallDefaults() { |
132 |
SynthContext context = getContext(desktopIcon, ENABLED); |
|
133 |
style.uninstallDefaults(context); |
|
134 |
context.dispose(); |
|
135 |
style = null; |
|
136 |
} |
|
137 |
||
4394 | 138 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
139 |
* {@inheritDoc} |
4394 | 140 |
*/ |
141 |
@Override |
|
2 | 142 |
public SynthContext getContext(JComponent c) { |
143 |
return getContext(c, getComponentState(c)); |
|
144 |
} |
|
145 |
||
146 |
private SynthContext getContext(JComponent c, int state) { |
|
4394 | 147 |
Region region = SynthLookAndFeel.getRegion(c); |
2 | 148 |
return SynthContext.getContext(SynthContext.class, c, region, |
149 |
style, state); |
|
150 |
} |
|
151 |
||
152 |
private int getComponentState(JComponent c) { |
|
153 |
return SynthLookAndFeel.getComponentState(c); |
|
154 |
} |
|
155 |
||
4394 | 156 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
157 |
* Notifies this UI delegate to repaint the specified component. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
158 |
* This method paints the component background, then calls |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
159 |
* the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
160 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
161 |
* <p>In general, this method does not need to be overridden by subclasses. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
162 |
* All Look and Feel rendering code should reside in the {@code paint} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
163 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
164 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
165 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
166 |
* @see #paint(SynthContext,Graphics) |
4394 | 167 |
*/ |
168 |
@Override |
|
2 | 169 |
public void update(Graphics g, JComponent c) { |
170 |
SynthContext context = getContext(c); |
|
171 |
||
172 |
SynthLookAndFeel.update(context, g); |
|
173 |
context.getPainter().paintDesktopIconBackground(context, g, 0, 0, |
|
174 |
c.getWidth(), c.getHeight()); |
|
175 |
paint(context, g); |
|
176 |
context.dispose(); |
|
177 |
} |
|
178 |
||
4394 | 179 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
180 |
* Paints the specified component according to the Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
181 |
* <p>This method is not used by Synth Look and Feel. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
182 |
* Painting is handled by the {@link #paint(SynthContext,Graphics)} method. |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
183 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
184 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
185 |
* @param c the component being painted |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
186 |
* @see #paint(SynthContext,Graphics) |
4394 | 187 |
*/ |
188 |
@Override |
|
2 | 189 |
public void paint(Graphics g, JComponent c) { |
190 |
SynthContext context = getContext(c); |
|
191 |
||
192 |
paint(context, g); |
|
193 |
context.dispose(); |
|
194 |
} |
|
195 |
||
4394 | 196 |
/** |
197 |
* Paints the specified component. This implementation does nothing. |
|
198 |
* |
|
199 |
* @param context context for the component being painted |
|
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
200 |
* @param g the {@code Graphics} object used for painting |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
201 |
* @see #update(Graphics,JComponent) |
4394 | 202 |
*/ |
2 | 203 |
protected void paint(SynthContext context, Graphics g) { |
204 |
} |
|
205 |
||
4394 | 206 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
207 |
* {@inheritDoc} |
4394 | 208 |
*/ |
209 |
@Override |
|
2 | 210 |
public void paintBorder(SynthContext context, Graphics g, int x, |
211 |
int y, int w, int h) { |
|
212 |
context.getPainter().paintDesktopIconBorder(context, g, x, y, w, h); |
|
213 |
} |
|
214 |
||
215 |
public void propertyChange(PropertyChangeEvent evt) { |
|
216 |
if (evt.getSource() instanceof JInternalFrame.JDesktopIcon) { |
|
217 |
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { |
|
218 |
updateStyle((JInternalFrame.JDesktopIcon)evt.getSource()); |
|
219 |
} |
|
220 |
} else if (evt.getSource() instanceof JInternalFrame) { |
|
221 |
JInternalFrame frame = (JInternalFrame)evt.getSource(); |
|
222 |
if (iconPane instanceof JToggleButton) { |
|
223 |
JToggleButton button = (JToggleButton)iconPane; |
|
224 |
String prop = evt.getPropertyName(); |
|
225 |
if (prop == "title") { |
|
226 |
button.setText((String)evt.getNewValue()); |
|
227 |
} else if (prop == "frameIcon") { |
|
228 |
button.setIcon((Icon)evt.getNewValue()); |
|
229 |
} else if (prop == JInternalFrame.IS_ICON_PROPERTY || |
|
230 |
prop == JInternalFrame.IS_SELECTED_PROPERTY) { |
|
231 |
button.setSelected(!frame.isIcon() && frame.isSelected()); |
|
232 |
} |
|
233 |
} |
|
234 |
} |
|
235 |
} |
|
4394 | 236 |
|
237 |
private final class Handler implements ActionListener { |
|
238 |
public void actionPerformed(ActionEvent evt) { |
|
239 |
if (evt.getSource() instanceof JToggleButton) { |
|
240 |
// Either iconify the frame or deiconify and activate it. |
|
241 |
JToggleButton button = (JToggleButton)evt.getSource(); |
|
242 |
try { |
|
243 |
boolean selected = button.isSelected(); |
|
244 |
if (!selected && !frame.isIconifiable()) { |
|
245 |
button.setSelected(true); |
|
246 |
} else { |
|
247 |
frame.setIcon(!selected); |
|
248 |
if (selected) { |
|
249 |
frame.setSelected(true); |
|
250 |
} |
|
251 |
} |
|
252 |
} catch (PropertyVetoException e2) { |
|
253 |
} |
|
254 |
} |
|
255 |
} |
|
256 |
} |
|
2 | 257 |
} |