author | darcy |
Fri, 03 Apr 2015 10:41:34 -0700 | |
changeset 29894 | 3e16b51732f5 |
parent 25859 | 3317bb8137f4 |
child 37698 | 4d798c873df0 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
29894
3e16b51732f5
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2002, 2015, 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.BasicInternalFrameUI; |
|
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 |
4394 | 38 |
* {@link javax.swing.JInternalFrame}. |
2 | 39 |
* |
40 |
* @author David Kloba |
|
41 |
* @author Joshua Outwater |
|
42 |
* @author Rich Schiavi |
|
4394 | 43 |
* @since 1.7 |
2 | 44 |
*/ |
4394 | 45 |
public class SynthInternalFrameUI extends BasicInternalFrameUI |
46 |
implements SynthUI, PropertyChangeListener { |
|
2 | 47 |
private SynthStyle style; |
48 |
||
4394 | 49 |
/** |
50 |
* Creates a new UI object for the given component. |
|
51 |
* |
|
52 |
* @param b component to create UI object for |
|
53 |
* @return the UI object |
|
54 |
*/ |
|
2 | 55 |
public static ComponentUI createUI(JComponent b) { |
56 |
return new SynthInternalFrameUI((JInternalFrame)b); |
|
57 |
} |
|
58 |
||
29894
3e16b51732f5
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents:
25859
diff
changeset
|
59 |
/** |
3e16b51732f5
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents:
25859
diff
changeset
|
60 |
* Constructs a {@code SynthInternalFrameUI}. |
3e16b51732f5
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents:
25859
diff
changeset
|
61 |
* @param b an internal frame |
3e16b51732f5
8076520: Fix missing doclint warnings in javax.swing.{table, tree, undo, plaf.{metal, nimbus, synth}}
darcy
parents:
25859
diff
changeset
|
62 |
*/ |
4394 | 63 |
protected SynthInternalFrameUI(JInternalFrame b) { |
2 | 64 |
super(b); |
65 |
} |
|
66 |
||
4394 | 67 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
68 |
* {@inheritDoc} |
4394 | 69 |
*/ |
70 |
@Override |
|
2 | 71 |
public void installDefaults() { |
72 |
frame.setLayout(internalFrameLayout = createLayoutManager()); |
|
73 |
updateStyle(frame); |
|
74 |
} |
|
75 |
||
4394 | 76 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
77 |
* {@inheritDoc} |
4394 | 78 |
*/ |
79 |
@Override |
|
2 | 80 |
protected void installListeners() { |
81 |
super.installListeners(); |
|
82 |
frame.addPropertyChangeListener(this); |
|
83 |
} |
|
84 |
||
4394 | 85 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
86 |
* {@inheritDoc} |
4394 | 87 |
*/ |
88 |
@Override |
|
2 | 89 |
protected void uninstallComponents() { |
90 |
if (frame.getComponentPopupMenu() instanceof UIResource) { |
|
91 |
frame.setComponentPopupMenu(null); |
|
92 |
} |
|
93 |
super.uninstallComponents(); |
|
94 |
} |
|
95 |
||
4394 | 96 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
97 |
* {@inheritDoc} |
4394 | 98 |
*/ |
99 |
@Override |
|
2 | 100 |
protected void uninstallListeners() { |
101 |
frame.removePropertyChangeListener(this); |
|
102 |
super.uninstallListeners(); |
|
103 |
} |
|
104 |
||
105 |
private void updateStyle(JComponent c) { |
|
106 |
SynthContext context = getContext(c, ENABLED); |
|
107 |
SynthStyle oldStyle = style; |
|
108 |
||
109 |
style = SynthLookAndFeel.updateStyle(context, this); |
|
110 |
if (style != oldStyle) { |
|
111 |
Icon frameIcon = frame.getFrameIcon(); |
|
112 |
if (frameIcon == null || frameIcon instanceof UIResource) { |
|
113 |
frame.setFrameIcon(context.getStyle().getIcon( |
|
114 |
context, "InternalFrame.icon")); |
|
115 |
} |
|
116 |
if (oldStyle != null) { |
|
117 |
uninstallKeyboardActions(); |
|
118 |
installKeyboardActions(); |
|
119 |
} |
|
120 |
} |
|
121 |
context.dispose(); |
|
122 |
} |
|
123 |
||
4394 | 124 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
125 |
* {@inheritDoc} |
4394 | 126 |
*/ |
127 |
@Override |
|
2 | 128 |
protected void uninstallDefaults() { |
129 |
SynthContext context = getContext(frame, ENABLED); |
|
130 |
style.uninstallDefaults(context); |
|
131 |
context.dispose(); |
|
132 |
style = null; |
|
133 |
if(frame.getLayout() == internalFrameLayout) { |
|
134 |
frame.setLayout(null); |
|
135 |
} |
|
136 |
||
137 |
} |
|
138 |
||
4394 | 139 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
140 |
* {@inheritDoc} |
4394 | 141 |
*/ |
142 |
@Override |
|
2 | 143 |
public SynthContext getContext(JComponent c) { |
144 |
return getContext(c, getComponentState(c)); |
|
145 |
} |
|
146 |
||
147 |
private SynthContext getContext(JComponent c, int state) { |
|
25100 | 148 |
return SynthContext.getContext(c, style, state); |
2 | 149 |
} |
150 |
||
4394 | 151 |
private int getComponentState(JComponent c) { |
2 | 152 |
return SynthLookAndFeel.getComponentState(c); |
153 |
} |
|
154 |
||
4394 | 155 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
156 |
* {@inheritDoc} |
4394 | 157 |
*/ |
158 |
@Override |
|
2 | 159 |
protected JComponent createNorthPane(JInternalFrame w) { |
160 |
titlePane = new SynthInternalFrameTitlePane(w); |
|
161 |
titlePane.setName("InternalFrame.northPane"); |
|
162 |
return titlePane; |
|
163 |
} |
|
164 |
||
4394 | 165 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
166 |
* {@inheritDoc} |
4394 | 167 |
*/ |
168 |
@Override |
|
2 | 169 |
protected ComponentListener createComponentListener() { |
170 |
if (UIManager.getBoolean("InternalFrame.useTaskBar")) { |
|
171 |
return new ComponentHandler() { |
|
4394 | 172 |
@Override public void componentResized(ComponentEvent e) { |
2 | 173 |
if (frame != null && frame.isMaximum()) { |
174 |
JDesktopPane desktop = (JDesktopPane)e.getSource(); |
|
175 |
for (Component comp : desktop.getComponents()) { |
|
176 |
if (comp instanceof SynthDesktopPaneUI.TaskBar) { |
|
177 |
frame.setBounds(0, 0, |
|
178 |
desktop.getWidth(), |
|
179 |
desktop.getHeight() - comp.getHeight()); |
|
180 |
frame.revalidate(); |
|
181 |
break; |
|
182 |
} |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
// Update the new parent bounds for next resize, but don't |
|
187 |
// let the super method touch this frame |
|
188 |
JInternalFrame f = frame; |
|
189 |
frame = null; |
|
190 |
super.componentResized(e); |
|
191 |
frame = f; |
|
192 |
} |
|
193 |
}; |
|
194 |
} else { |
|
195 |
return super.createComponentListener(); |
|
196 |
} |
|
197 |
} |
|
198 |
||
4394 | 199 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
200 |
* 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
|
201 |
* 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
|
202 |
* 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
|
203 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
204 |
* <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
|
205 |
* 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
|
206 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
207 |
* @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
|
208 |
* @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
|
209 |
* @see #paint(SynthContext,Graphics) |
4394 | 210 |
*/ |
211 |
@Override |
|
2 | 212 |
public void update(Graphics g, JComponent c) { |
213 |
SynthContext context = getContext(c); |
|
214 |
||
215 |
SynthLookAndFeel.update(context, g); |
|
216 |
context.getPainter().paintInternalFrameBackground(context, |
|
217 |
g, 0, 0, c.getWidth(), c.getHeight()); |
|
218 |
paint(context, g); |
|
219 |
context.dispose(); |
|
220 |
} |
|
221 |
||
4394 | 222 |
/** |
4848
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
223 |
* 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
|
224 |
* <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
|
225 |
* 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
|
226 |
* |
ffcc849b9351
6912118: Incosistency in several SynthUI classes between inherited specs ofupdate() and paint() methods
peterz
parents:
4394
diff
changeset
|
227 |
* @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
|
228 |
* @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
|
229 |
* @see #paint(SynthContext,Graphics) |
4394 | 230 |
*/ |
231 |
@Override |
|
2 | 232 |
public void paint(Graphics g, JComponent c) { |
233 |
SynthContext context = getContext(c); |
|
234 |
||
235 |
paint(context, g); |
|
236 |
context.dispose(); |
|
237 |
} |
|
238 |
||
4394 | 239 |
/** |
240 |
* Paints the specified component. This implementation does nothing. |
|
241 |
* |
|
242 |
* @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
|
243 |
* @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
|
244 |
* @see #update(Graphics,JComponent) |
4394 | 245 |
*/ |
2 | 246 |
protected void paint(SynthContext context, Graphics g) { |
247 |
} |
|
248 |
||
4394 | 249 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
250 |
* {@inheritDoc} |
4394 | 251 |
*/ |
252 |
@Override |
|
2 | 253 |
public void paintBorder(SynthContext context, Graphics g, int x, |
254 |
int y, int w, int h) { |
|
255 |
context.getPainter().paintInternalFrameBorder(context, |
|
256 |
g, x, y, w, h); |
|
257 |
} |
|
258 |
||
4394 | 259 |
/** |
20168
137788883a22
8025070: [javadoc] fix some javadoc errors in javax/swing/plaf/synth
alexsch
parents:
7668
diff
changeset
|
260 |
* {@inheritDoc} |
4394 | 261 |
*/ |
262 |
@Override |
|
2 | 263 |
public void propertyChange(PropertyChangeEvent evt) { |
264 |
SynthStyle oldStyle = style; |
|
265 |
JInternalFrame f = (JInternalFrame)evt.getSource(); |
|
266 |
String prop = evt.getPropertyName(); |
|
267 |
||
268 |
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { |
|
269 |
updateStyle(f); |
|
270 |
} |
|
271 |
||
272 |
if (style == oldStyle && |
|
273 |
(prop == JInternalFrame.IS_MAXIMUM_PROPERTY || |
|
274 |
prop == JInternalFrame.IS_SELECTED_PROPERTY)) { |
|
275 |
// Border (and other defaults) may need to change |
|
276 |
SynthContext context = getContext(f, ENABLED); |
|
277 |
style.uninstallDefaults(context); |
|
278 |
style.installDefaults(context, this); |
|
279 |
} |
|
280 |
} |
|
281 |
} |