author | alexp |
Thu, 24 Mar 2011 17:01:43 +0300 | |
changeset 8955 | 37ab7cd5890a |
parent 8372 | 786e091594a0 |
child 9050 | 26c2c1de1631 |
permissions | -rw-r--r-- |
3508 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. |
3733 | 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 |
3733 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
3733 | 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. |
|
3508 | 24 |
*/ |
25 |
||
26 |
package javax.swing.plaf; |
|
27 |
||
28 |
import javax.swing.*; |
|
29 |
import java.awt.*; |
|
30 |
import java.awt.event.*; |
|
31 |
import java.beans.PropertyChangeEvent; |
|
32 |
import java.beans.PropertyChangeSupport; |
|
33 |
import java.beans.PropertyChangeListener; |
|
34 |
import java.io.Serializable; |
|
35 |
||
36 |
/** |
|
37 |
* The base class for all {@link javax.swing.JLayer}'s UI delegates. |
|
38 |
* <p/> |
|
8955 | 39 |
* {@link #paint(java.awt.Graphics, javax.swing.JComponent)} method performs the |
3508 | 40 |
* painting of the {@code JLayer} |
41 |
* and {@link #eventDispatched(AWTEvent, JLayer)} method is notified |
|
42 |
* about any {@code AWTEvent}s which have been generated by a {@code JLayer} |
|
43 |
* or any of its subcomponents. |
|
44 |
* <p/> |
|
45 |
* The {@code LayerUI} differs from the UI delegates of the other components, |
|
46 |
* because it is LookAndFeel independent and is not updated by default when |
|
47 |
* the system LookAndFeel is changed. |
|
48 |
* <p/> |
|
49 |
* The subclasses of {@code LayerUI} can either be stateless and shareable |
|
50 |
* by multiple {@code JLayer}s or not shareable. |
|
51 |
* |
|
52 |
* @param <V> one of the super types of {@code JLayer}'s view component |
|
53 |
* |
|
54 |
* @see JLayer#setUI(LayerUI) |
|
55 |
* @see JLayer#setView(Component) |
|
56 |
* @see JLayer#getView() |
|
57 |
* @since 1.7 |
|
58 |
* |
|
59 |
* @author Alexander Potochkin |
|
60 |
*/ |
|
61 |
public class LayerUI<V extends Component> |
|
62 |
extends ComponentUI implements Serializable { |
|
63 |
||
64 |
private final PropertyChangeSupport propertyChangeSupport = |
|
65 |
new PropertyChangeSupport(this); |
|
66 |
||
67 |
/** |
|
68 |
* Paints the specified component. |
|
69 |
* Subclasses should override this method and use |
|
70 |
* the specified {@code Graphics} object to |
|
71 |
* render the content of the component. |
|
4276 | 72 |
* <p/> |
5450 | 73 |
* The default implementation paints the passed component as is. |
3508 | 74 |
* |
5450 | 75 |
* @param g the {@code Graphics} context in which to paint |
76 |
* @param c the component being painted |
|
3508 | 77 |
*/ |
78 |
public void paint(Graphics g, JComponent c) { |
|
5450 | 79 |
c.paint(g); |
3508 | 80 |
} |
81 |
||
82 |
/** |
|
5451
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
5450
diff
changeset
|
83 |
* Processes {@code AWTEvent}s for {@code JLayer} |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
5450
diff
changeset
|
84 |
* and <b>all its descendants</b> to this {@code LayerUI} instance. |
4276 | 85 |
* <p/> |
86 |
* To enable the {@code AWTEvent}s of a particular type, |
|
87 |
* you call {@link JLayer#setLayerEventMask} |
|
3508 | 88 |
* in {@link #installUI(javax.swing.JComponent)} |
89 |
* and set the layer event mask to {@code 0} |
|
4276 | 90 |
* in {@link #uninstallUI(javax.swing.JComponent)} after that. |
91 |
* By default this method calls the appropriate |
|
92 |
* {@code process<event type>Event} |
|
93 |
* method for the given class of event. |
|
5451
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
5450
diff
changeset
|
94 |
* <p/> |
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
5450
diff
changeset
|
95 |
* <b>Note:</b> Events are processed only for displayable {@code JLayer}s. |
3508 | 96 |
* |
97 |
* @param e the event to be dispatched |
|
98 |
* @param l the layer this LayerUI is set to |
|
99 |
* |
|
100 |
* @see JLayer#setLayerEventMask(long) |
|
5451
82e4cf75e5b4
6899405: Specification for JLayer.setLayerEventMask() should mention that eventDispatch() might not be called
alexp
parents:
5450
diff
changeset
|
101 |
* @see Component#isDisplayable() |
4276 | 102 |
* @see #processComponentEvent |
103 |
* @see #processFocusEvent |
|
104 |
* @see #processKeyEvent |
|
105 |
* @see #processMouseEvent |
|
106 |
* @see #processMouseMotionEvent |
|
107 |
* @see #processInputMethodEvent |
|
108 |
* @see #processHierarchyEvent |
|
109 |
* @see #processMouseWheelEvent |
|
3508 | 110 |
*/ |
111 |
public void eventDispatched(AWTEvent e, JLayer<? extends V> l){ |
|
4276 | 112 |
if (e instanceof FocusEvent) { |
113 |
processFocusEvent((FocusEvent)e, l); |
|
114 |
||
115 |
} else if (e instanceof MouseEvent) { |
|
116 |
switch(e.getID()) { |
|
117 |
case MouseEvent.MOUSE_PRESSED: |
|
118 |
case MouseEvent.MOUSE_RELEASED: |
|
119 |
case MouseEvent.MOUSE_CLICKED: |
|
120 |
case MouseEvent.MOUSE_ENTERED: |
|
121 |
case MouseEvent.MOUSE_EXITED: |
|
122 |
processMouseEvent((MouseEvent)e, l); |
|
123 |
break; |
|
124 |
case MouseEvent.MOUSE_MOVED: |
|
125 |
case MouseEvent.MOUSE_DRAGGED: |
|
126 |
processMouseMotionEvent((MouseEvent)e, l); |
|
127 |
break; |
|
128 |
case MouseEvent.MOUSE_WHEEL: |
|
129 |
processMouseWheelEvent((MouseWheelEvent)e, l); |
|
130 |
break; |
|
131 |
} |
|
132 |
} else if (e instanceof KeyEvent) { |
|
133 |
processKeyEvent((KeyEvent)e, l); |
|
134 |
} else if (e instanceof ComponentEvent) { |
|
135 |
processComponentEvent((ComponentEvent)e, l); |
|
136 |
} else if (e instanceof InputMethodEvent) { |
|
137 |
processInputMethodEvent((InputMethodEvent)e, l); |
|
138 |
} else if (e instanceof HierarchyEvent) { |
|
139 |
switch (e.getID()) { |
|
140 |
case HierarchyEvent.HIERARCHY_CHANGED: |
|
141 |
processHierarchyEvent((HierarchyEvent)e, l); |
|
142 |
break; |
|
143 |
case HierarchyEvent.ANCESTOR_MOVED: |
|
144 |
case HierarchyEvent.ANCESTOR_RESIZED: |
|
145 |
processHierarchyBoundsEvent((HierarchyEvent)e, l); |
|
146 |
break; |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
||
151 |
/** |
|
152 |
* Processes component events occurring on the {@link JLayer} |
|
153 |
* or any of its subcomponents. |
|
154 |
* <p/> |
|
155 |
* This method is not called unless component events are |
|
156 |
* enabled for the {@code JLayer} objects, this {@code LayerUI} is set to. |
|
157 |
* Component events are enabled in the overridden {@link #installUI} method |
|
158 |
* and should be disabled in the {@link #uninstallUI} method after that. |
|
159 |
* <pre> |
|
160 |
* public void installUI(JComponent c) { |
|
161 |
* super.installUI(c); |
|
162 |
* JLayer l = (JLayer) c; |
|
163 |
* l.setLayerEventMask(AWTEvent.COMPONENT_EVENT_MASK); |
|
164 |
* } |
|
165 |
* |
|
8955 | 166 |
* public void uninstallUI(JComponent c) { |
4276 | 167 |
* super.uninstallUI(c); |
168 |
* JLayer l = (JLayer) c; |
|
169 |
* l.setLayerEventMask(0); |
|
170 |
* } |
|
171 |
* </pre> |
|
172 |
* |
|
173 |
* @param e the {@code ComponentEvent} to be processed |
|
174 |
* @param l the layer this {@code LayerUI} instance is set to |
|
175 |
* |
|
176 |
* @see JLayer#setLayerEventMask(long) |
|
177 |
* @see #installUI(javax.swing.JComponent) |
|
178 |
* @see #uninstallUI(javax.swing.JComponent) |
|
179 |
*/ |
|
180 |
protected void processComponentEvent(ComponentEvent e, JLayer<? extends V> l) { |
|
181 |
} |
|
182 |
||
183 |
/** |
|
184 |
* Processes focus events occurring on the {@link JLayer} |
|
185 |
* or any of its subcomponents. |
|
186 |
* <p/> |
|
187 |
* This method is not called unless focus events are |
|
188 |
* enabled for the {@code JLayer} objects, this {@code LayerUI} is set to. |
|
189 |
* Focus events are enabled in the overridden {@link #installUI} method |
|
190 |
* and should be disabled in the {@link #uninstallUI} method after that. |
|
191 |
* <pre> |
|
192 |
* public void installUI(JComponent c) { |
|
193 |
* super.installUI(c); |
|
194 |
* JLayer l = (JLayer) c; |
|
195 |
* l.setLayerEventMask(AWTEvent.FOCUS_EVENT_MASK); |
|
196 |
* } |
|
197 |
* |
|
8955 | 198 |
* public void uninstallUI(JComponent c) { |
4276 | 199 |
* super.uninstallUI(c); |
200 |
* JLayer l = (JLayer) c; |
|
201 |
* l.setLayerEventMask(0); |
|
202 |
* } |
|
203 |
* </pre> |
|
204 |
* |
|
205 |
* @param e the {@code FocusEvent} to be processed |
|
206 |
* @param l the layer this {@code LayerUI} instance is set to |
|
207 |
* |
|
208 |
* @see JLayer#setLayerEventMask(long) |
|
209 |
* @see #installUI(javax.swing.JComponent) |
|
210 |
* @see #uninstallUI(javax.swing.JComponent) |
|
211 |
*/ |
|
212 |
protected void processFocusEvent(FocusEvent e, JLayer<? extends V> l) { |
|
213 |
} |
|
214 |
||
215 |
/** |
|
216 |
* Processes key events occurring on the {@link JLayer} |
|
217 |
* or any of its subcomponents. |
|
218 |
* <p/> |
|
219 |
* This method is not called unless key events are |
|
220 |
* enabled for the {@code JLayer} objects, this {@code LayerUI} is set to. |
|
221 |
* Key events are enabled in the overridden {@link #installUI} method |
|
222 |
* and should be disabled in the {@link #uninstallUI} method after that. |
|
223 |
* <pre> |
|
224 |
* public void installUI(JComponent c) { |
|
225 |
* super.installUI(c); |
|
226 |
* JLayer l = (JLayer) c; |
|
227 |
* l.setLayerEventMask(AWTEvent.KEY_EVENT_MASK); |
|
228 |
* } |
|
229 |
* |
|
8955 | 230 |
* public void uninstallUI(JComponent c) { |
4276 | 231 |
* super.uninstallUI(c); |
232 |
* JLayer l = (JLayer) c; |
|
233 |
* l.setLayerEventMask(0); |
|
234 |
* } |
|
235 |
* </pre> |
|
236 |
* |
|
237 |
* @param e the {@code KeyEvent} to be processed |
|
238 |
* @param l the layer this {@code LayerUI} instance is set to |
|
239 |
* |
|
240 |
* @see JLayer#setLayerEventMask(long) |
|
241 |
* @see #installUI(javax.swing.JComponent) |
|
242 |
* @see #uninstallUI(javax.swing.JComponent) |
|
243 |
*/ |
|
244 |
protected void processKeyEvent(KeyEvent e, JLayer<? extends V> l) { |
|
245 |
} |
|
246 |
||
247 |
/** |
|
248 |
* Processes mouse events occurring on the {@link JLayer} |
|
249 |
* or any of its subcomponents. |
|
250 |
* <p/> |
|
251 |
* This method is not called unless mouse events are |
|
252 |
* enabled for the {@code JLayer} objects, this {@code LayerUI} is set to. |
|
253 |
* Mouse events are enabled in the overridden {@link #installUI} method |
|
254 |
* and should be disabled in the {@link #uninstallUI} method after that. |
|
255 |
* <pre> |
|
256 |
* public void installUI(JComponent c) { |
|
257 |
* super.installUI(c); |
|
258 |
* JLayer l = (JLayer) c; |
|
259 |
* l.setLayerEventMask(AWTEvent.MOUSE_EVENT_MASK); |
|
260 |
* } |
|
261 |
* |
|
8955 | 262 |
* public void uninstallUI(JComponent c) { |
4276 | 263 |
* super.uninstallUI(c); |
264 |
* JLayer l = (JLayer) c; |
|
265 |
* l.setLayerEventMask(0); |
|
266 |
* } |
|
267 |
* </pre> |
|
268 |
* |
|
269 |
* @param e the {@code MouseEvent} to be processed |
|
270 |
* @param l the layer this {@code LayerUI} instance is set to |
|
271 |
* |
|
272 |
* @see JLayer#setLayerEventMask(long) |
|
273 |
* @see #installUI(javax.swing.JComponent) |
|
274 |
* @see #uninstallUI(javax.swing.JComponent) |
|
275 |
*/ |
|
276 |
protected void processMouseEvent(MouseEvent e, JLayer<? extends V> l) { |
|
277 |
} |
|
278 |
||
279 |
/** |
|
280 |
* Processes mouse motion event occurring on the {@link JLayer} |
|
281 |
* or any of its subcomponents. |
|
282 |
* <p/> |
|
283 |
* This method is not called unless mouse motion events are |
|
284 |
* enabled for the {@code JLayer} objects, this {@code LayerUI} is set to. |
|
285 |
* Mouse motion events are enabled in the overridden {@link #installUI} method |
|
286 |
* and should be disabled in the {@link #uninstallUI} method after that. |
|
287 |
* <pre> |
|
288 |
* public void installUI(JComponent c) { |
|
289 |
* super.installUI(c); |
|
290 |
* JLayer l = (JLayer) c; |
|
291 |
* l.setLayerEventMask(AWTEvent.MOUSE_MOTION_EVENT_MASK); |
|
292 |
* } |
|
293 |
* |
|
8955 | 294 |
* public void uninstallUI(JComponent c) { |
4276 | 295 |
* super.uninstallUI(c); |
296 |
* JLayer l = (JLayer) c; |
|
297 |
* l.setLayerEventMask(0); |
|
298 |
* } |
|
299 |
* </pre> |
|
300 |
* |
|
301 |
* @param e the {@code MouseEvent} to be processed |
|
302 |
* @param l the layer this {@code LayerUI} instance is set to |
|
303 |
* |
|
304 |
* @see JLayer#setLayerEventMask(long) |
|
305 |
* @see #installUI(javax.swing.JComponent) |
|
306 |
* @see #uninstallUI(javax.swing.JComponent) |
|
307 |
*/ |
|
308 |
protected void processMouseMotionEvent(MouseEvent e, JLayer<? extends V> l) { |
|
309 |
} |
|
310 |
||
311 |
/** |
|
312 |
* Processes mouse wheel event occurring on the {@link JLayer} |
|
313 |
* or any of its subcomponents. |
|
314 |
* <p/> |
|
315 |
* This method is not called unless mouse wheel events are |
|
316 |
* enabled for the {@code JLayer} objects, this {@code LayerUI} is set to. |
|
317 |
* Mouse wheel events are enabled in the overridden {@link #installUI} method |
|
318 |
* and should be disabled in the {@link #uninstallUI} method after that. |
|
319 |
* <pre> |
|
320 |
* public void installUI(JComponent c) { |
|
321 |
* super.installUI(c); |
|
322 |
* JLayer l = (JLayer) c; |
|
323 |
* l.setLayerEventMask(AWTEvent.MOUSE_WHEEL_EVENT_MASK); |
|
324 |
* } |
|
325 |
* |
|
8955 | 326 |
* public void uninstallUI(JComponent c) { |
4276 | 327 |
* super.uninstallUI(c); |
328 |
* JLayer l = (JLayer) c; |
|
329 |
* l.setLayerEventMask(0); |
|
330 |
* } |
|
331 |
* </pre> |
|
332 |
* |
|
333 |
* @param e the {@code MouseEvent} to be processed |
|
334 |
* @param l the layer this {@code LayerUI} instance is set to |
|
335 |
* |
|
336 |
* @see JLayer#setLayerEventMask(long) |
|
337 |
* @see #installUI(javax.swing.JComponent) |
|
338 |
* @see #uninstallUI(javax.swing.JComponent) |
|
339 |
*/ |
|
340 |
protected void processMouseWheelEvent(MouseWheelEvent e, JLayer<? extends V> l) { |
|
341 |
} |
|
342 |
||
343 |
/** |
|
344 |
* Processes input event occurring on the {@link JLayer} |
|
345 |
* or any of its subcomponents. |
|
346 |
* <p/> |
|
347 |
* This method is not called unless input events are |
|
348 |
* enabled for the {@code JLayer} objects, this {@code LayerUI} is set to. |
|
349 |
* Input events are enabled in the overridden {@link #installUI} method |
|
350 |
* and should be disabled in the {@link #uninstallUI} method after that. |
|
351 |
* <pre> |
|
352 |
* public void installUI(JComponent c) { |
|
353 |
* super.installUI(c); |
|
354 |
* JLayer l = (JLayer) c; |
|
355 |
* l.setLayerEventMask(AWTEvent.INPUT_METHOD_EVENT_MASK); |
|
356 |
* } |
|
357 |
* |
|
8955 | 358 |
* public void uninstallUI(JComponent c) { |
4276 | 359 |
* super.uninstallUI(c); |
360 |
* JLayer l = (JLayer) c; |
|
361 |
* l.setLayerEventMask(0); |
|
362 |
* } |
|
363 |
* </pre> |
|
364 |
* |
|
365 |
* @param e the {@code InputMethodEvent} to be processed |
|
366 |
* @param l the layer this {@code LayerUI} instance is set to |
|
367 |
* |
|
368 |
* @see JLayer#setLayerEventMask(long) |
|
369 |
* @see #installUI(javax.swing.JComponent) |
|
370 |
* @see #uninstallUI(javax.swing.JComponent) |
|
371 |
*/ |
|
372 |
protected void processInputMethodEvent(InputMethodEvent e, JLayer<? extends V> l) { |
|
373 |
} |
|
374 |
||
375 |
/** |
|
376 |
* Processes hierarchy event occurring on the {@link JLayer} |
|
377 |
* or any of its subcomponents. |
|
378 |
* <p/> |
|
379 |
* This method is not called unless hierarchy events are |
|
380 |
* enabled for the {@code JLayer} objects, this {@code LayerUI} is set to. |
|
381 |
* Hierarchy events are enabled in the overridden {@link #installUI} method |
|
382 |
* and should be disabled in the {@link #uninstallUI} method after that. |
|
383 |
* <pre> |
|
384 |
* public void installUI(JComponent c) { |
|
385 |
* super.installUI(c); |
|
386 |
* JLayer l = (JLayer) c; |
|
387 |
* l.setLayerEventMask(AWTEvent.HIERARCHY_EVENT_MASK); |
|
388 |
* } |
|
389 |
* |
|
8955 | 390 |
* public void uninstallUI(JComponent c) { |
4276 | 391 |
* super.uninstallUI(c); |
392 |
* JLayer l = (JLayer) c; |
|
393 |
* l.setLayerEventMask(0); |
|
394 |
* } |
|
395 |
* </pre> |
|
396 |
* |
|
397 |
* @param e the {@code HierarchyEvent} to be processed |
|
398 |
* @param l the layer this {@code LayerUI} instance is set to |
|
399 |
* |
|
400 |
* @see JLayer#setLayerEventMask(long) |
|
401 |
* @see #installUI(javax.swing.JComponent) |
|
402 |
* @see #uninstallUI(javax.swing.JComponent) |
|
403 |
*/ |
|
404 |
protected void processHierarchyEvent(HierarchyEvent e, JLayer<? extends V> l) { |
|
405 |
} |
|
406 |
||
407 |
/** |
|
408 |
* Processes hierarchy bounds event occurring on the {@link JLayer} |
|
409 |
* or any of its subcomponents. |
|
410 |
* <p/> |
|
411 |
* This method is not called unless hierarchy bounds events are |
|
412 |
* enabled for the {@code JLayer} objects, this {@code LayerUI} is set to. |
|
413 |
* Hierarchy bounds events are enabled in the overridden {@link #installUI} |
|
414 |
* method and should be disabled in the {@link #uninstallUI} method after that. |
|
415 |
* <pre> |
|
416 |
* public void installUI(JComponent c) { |
|
417 |
* super.installUI(c); |
|
418 |
* JLayer l = (JLayer) c; |
|
419 |
* l.setLayerEventMask(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK); |
|
420 |
* } |
|
421 |
* |
|
8955 | 422 |
* public void uninstallUI(JComponent c) { |
4276 | 423 |
* super.uninstallUI(c); |
424 |
* JLayer l = (JLayer) c; |
|
425 |
* l.setLayerEventMask(0); |
|
426 |
* } |
|
427 |
* </pre> |
|
428 |
* |
|
429 |
* @param e the {@code HierarchyEvent} to be processed |
|
430 |
* @param l the layer this {@code LayerUI} instance is set to |
|
431 |
* |
|
432 |
* @see JLayer#setLayerEventMask(long) |
|
433 |
* @see #installUI(javax.swing.JComponent) |
|
434 |
* @see #uninstallUI(javax.swing.JComponent) |
|
435 |
*/ |
|
436 |
protected void processHierarchyBoundsEvent(HierarchyEvent e, JLayer<? extends V> l) { |
|
3508 | 437 |
} |
438 |
||
439 |
/** |
|
440 |
* Invoked when {@link javax.swing.JLayer#updateUI()} is called |
|
441 |
* by the {@code JLayer} this {@code LayerUI} is set to. |
|
442 |
* |
|
443 |
* @param l the {@code JLayer} which UI is updated |
|
444 |
*/ |
|
445 |
public void updateUI(JLayer<? extends V> l){ |
|
446 |
} |
|
447 |
||
448 |
/** |
|
449 |
* Configures the {@code JLayer} this {@code LayerUI} is set to. |
|
7251
bfbe5cb5fbb2
6997170: Spec for javax.swing.plaf.LayerUI.installUI/uninstallUI() methods contradict behavior of the RI
alexp
parents:
6647
diff
changeset
|
450 |
* The default implementation registers the passed {@code JLayer} component |
bfbe5cb5fbb2
6997170: Spec for javax.swing.plaf.LayerUI.installUI/uninstallUI() methods contradict behavior of the RI
alexp
parents:
6647
diff
changeset
|
451 |
* as a {@code PropertyChangeListener} for the property changes of this {@code LayerUI}. |
3508 | 452 |
* |
453 |
* @param c the {@code JLayer} component where this UI delegate is being installed |
|
454 |
*/ |
|
455 |
public void installUI(JComponent c) { |
|
456 |
addPropertyChangeListener((JLayer) c); |
|
457 |
} |
|
458 |
||
459 |
/** |
|
460 |
* Reverses the configuration which was previously set |
|
461 |
* in the {@link #installUI(JComponent)} method. |
|
7251
bfbe5cb5fbb2
6997170: Spec for javax.swing.plaf.LayerUI.installUI/uninstallUI() methods contradict behavior of the RI
alexp
parents:
6647
diff
changeset
|
462 |
* The default implementation unregisters the passed {@code JLayer} component |
bfbe5cb5fbb2
6997170: Spec for javax.swing.plaf.LayerUI.installUI/uninstallUI() methods contradict behavior of the RI
alexp
parents:
6647
diff
changeset
|
463 |
* as a {@code PropertyChangeListener} for the property changes of this {@code LayerUI}. |
3508 | 464 |
* |
465 |
* @param c the component from which this UI delegate is being removed. |
|
466 |
*/ |
|
467 |
public void uninstallUI(JComponent c) { |
|
468 |
removePropertyChangeListener((JLayer) c); |
|
469 |
} |
|
470 |
||
471 |
/** |
|
472 |
* Adds a PropertyChangeListener to the listener list. The listener is |
|
473 |
* registered for all bound properties of this class. |
|
474 |
* <p/> |
|
475 |
* If {@code listener} is {@code null}, |
|
476 |
* no exception is thrown and no action is performed. |
|
477 |
* |
|
478 |
* @param listener the property change listener to be added |
|
479 |
* @see #removePropertyChangeListener |
|
480 |
* @see #getPropertyChangeListeners |
|
481 |
* @see #addPropertyChangeListener(String, java.beans.PropertyChangeListener) |
|
482 |
*/ |
|
483 |
public void addPropertyChangeListener(PropertyChangeListener listener) { |
|
484 |
propertyChangeSupport.addPropertyChangeListener(listener); |
|
485 |
} |
|
486 |
||
487 |
/** |
|
488 |
* Removes a PropertyChangeListener from the listener list. This method |
|
489 |
* should be used to remove PropertyChangeListeners that were registered |
|
490 |
* for all bound properties of this class. |
|
491 |
* <p/> |
|
492 |
* If {@code listener} is {@code null}, |
|
493 |
* no exception is thrown and no action is performed. |
|
494 |
* |
|
495 |
* @param listener the PropertyChangeListener to be removed |
|
496 |
* @see #addPropertyChangeListener |
|
497 |
* @see #getPropertyChangeListeners |
|
498 |
* @see #removePropertyChangeListener(String, PropertyChangeListener) |
|
499 |
*/ |
|
500 |
public void removePropertyChangeListener(PropertyChangeListener listener) { |
|
501 |
propertyChangeSupport.removePropertyChangeListener(listener); |
|
502 |
} |
|
503 |
||
504 |
/** |
|
505 |
* Returns an array of all the property change listeners |
|
506 |
* registered on this component. |
|
507 |
* |
|
508 |
* @return all of this ui's {@code PropertyChangeListener}s |
|
509 |
* or an empty array if no property change |
|
510 |
* listeners are currently registered |
|
511 |
* @see #addPropertyChangeListener |
|
512 |
* @see #removePropertyChangeListener |
|
513 |
* @see #getPropertyChangeListeners(String) |
|
514 |
*/ |
|
515 |
public PropertyChangeListener[] getPropertyChangeListeners() { |
|
516 |
return propertyChangeSupport.getPropertyChangeListeners(); |
|
517 |
} |
|
518 |
||
519 |
/** |
|
520 |
* Adds a PropertyChangeListener to the listener list for a specific |
|
521 |
* property. |
|
522 |
* <p/> |
|
523 |
* If {@code propertyName} or {@code listener} is {@code null}, |
|
524 |
* no exception is thrown and no action is taken. |
|
525 |
* |
|
526 |
* @param propertyName one of the property names listed above |
|
527 |
* @param listener the property change listener to be added |
|
528 |
* @see #removePropertyChangeListener(String, PropertyChangeListener) |
|
529 |
* @see #getPropertyChangeListeners(String) |
|
530 |
* @see #addPropertyChangeListener(String, PropertyChangeListener) |
|
531 |
*/ |
|
532 |
public void addPropertyChangeListener(String propertyName, |
|
533 |
PropertyChangeListener listener) { |
|
534 |
propertyChangeSupport.addPropertyChangeListener(propertyName, listener); |
|
535 |
} |
|
536 |
||
537 |
/** |
|
538 |
* Removes a {@code PropertyChangeListener} from the listener |
|
539 |
* list for a specific property. This method should be used to remove |
|
540 |
* {@code PropertyChangeListener}s |
|
541 |
* that were registered for a specific bound property. |
|
542 |
* <p/> |
|
543 |
* If {@code propertyName} or {@code listener} is {@code null}, |
|
544 |
* no exception is thrown and no action is taken. |
|
545 |
* |
|
546 |
* @param propertyName a valid property name |
|
547 |
* @param listener the PropertyChangeListener to be removed |
|
548 |
* @see #addPropertyChangeListener(String, PropertyChangeListener) |
|
549 |
* @see #getPropertyChangeListeners(String) |
|
550 |
* @see #removePropertyChangeListener(PropertyChangeListener) |
|
551 |
*/ |
|
552 |
public void removePropertyChangeListener(String propertyName, |
|
553 |
PropertyChangeListener listener) { |
|
554 |
propertyChangeSupport.removePropertyChangeListener(propertyName, listener); |
|
555 |
} |
|
556 |
||
557 |
/** |
|
558 |
* Returns an array of all the listeners which have been associated |
|
559 |
* with the named property. |
|
560 |
* |
|
3748
b88af44d77a8
6875153: JLayer.isOptimizedDrawingEnabled() throws NPE for null glass pane set
alexp
parents:
3737
diff
changeset
|
561 |
* @param propertyName The name of the property being listened to |
3508 | 562 |
* @return all of the {@code PropertyChangeListener}s associated with |
563 |
* the named property; if no such listeners have been added or |
|
564 |
* if {@code propertyName} is {@code null}, an empty |
|
565 |
* array is returned |
|
566 |
* @see #addPropertyChangeListener(String, PropertyChangeListener) |
|
567 |
* @see #removePropertyChangeListener(String, PropertyChangeListener) |
|
568 |
* @see #getPropertyChangeListeners |
|
569 |
*/ |
|
570 |
public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) { |
|
571 |
return propertyChangeSupport.getPropertyChangeListeners(propertyName); |
|
572 |
} |
|
573 |
||
574 |
/** |
|
575 |
* Support for reporting bound property changes for Object properties. |
|
576 |
* This method can be called when a bound property has changed and it will |
|
577 |
* send the appropriate PropertyChangeEvent to any registered |
|
578 |
* PropertyChangeListeners. |
|
579 |
* |
|
580 |
* @param propertyName the property whose value has changed |
|
581 |
* @param oldValue the property's previous value |
|
582 |
* @param newValue the property's new value |
|
583 |
*/ |
|
584 |
protected void firePropertyChange(String propertyName, |
|
585 |
Object oldValue, Object newValue) { |
|
586 |
propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue); |
|
587 |
} |
|
588 |
||
589 |
/** |
|
590 |
* Notifies the {@code LayerUI} when any of its property are changed |
|
4276 | 591 |
* and enables updating every {@code JLayer} |
592 |
* this {@code LayerUI} instance is set to. |
|
3508 | 593 |
* |
594 |
* @param evt the PropertyChangeEvent generated by this {@code LayerUI} |
|
595 |
* @param l the {@code JLayer} this LayerUI is set to |
|
596 |
*/ |
|
597 |
public void applyPropertyChange(PropertyChangeEvent evt, JLayer<? extends V> l) { |
|
598 |
} |
|
599 |
||
600 |
/** |
|
601 |
* If the {@code JLayer}'s view component is not {@code null}, |
|
602 |
* this calls the view's {@code getBaseline()} method. |
|
603 |
* Otherwise, the default implementation is called. |
|
604 |
* |
|
605 |
* @param c {@code JLayer} to return baseline resize behavior for |
|
606 |
* @param width the width to get the baseline for |
|
607 |
* @param height the height to get the baseline for |
|
608 |
* @return baseline or a value < 0 indicating there is no reasonable |
|
609 |
* baseline |
|
610 |
*/ |
|
611 |
public int getBaseline(JComponent c, int width, int height) { |
|
612 |
JLayer l = (JLayer) c; |
|
613 |
if (l.getView() != null) { |
|
614 |
return l.getView().getBaseline(width, height); |
|
615 |
} |
|
616 |
return super.getBaseline(c, width, height); |
|
617 |
} |
|
618 |
||
619 |
/** |
|
620 |
* If the {@code JLayer}'s view component is not {@code null}, |
|
6647 | 621 |
* this returns the result of the view's {@code getBaselineResizeBehavior()} method. |
3508 | 622 |
* Otherwise, the default implementation is called. |
623 |
* |
|
624 |
* @param c {@code JLayer} to return baseline resize behavior for |
|
625 |
* @return an enum indicating how the baseline changes as the component |
|
626 |
* size changes |
|
627 |
*/ |
|
628 |
public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) { |
|
629 |
JLayer l = (JLayer) c; |
|
630 |
if (l.getView() != null) { |
|
631 |
return l.getView().getBaselineResizeBehavior(); |
|
632 |
} |
|
633 |
return super.getBaselineResizeBehavior(c); |
|
634 |
} |
|
6647 | 635 |
|
636 |
/** |
|
637 |
* Causes the passed instance of {@code JLayer} to lay out its components. |
|
638 |
* |
|
639 |
* @param l the {@code JLayer} component where this UI delegate is being installed |
|
640 |
*/ |
|
641 |
public void doLayout(JLayer<? extends V> l) { |
|
642 |
Component view = l.getView(); |
|
643 |
if (view != null) { |
|
644 |
view.setBounds(0, 0, l.getWidth(), l.getHeight()); |
|
645 |
} |
|
646 |
Component glassPane = l.getGlassPane(); |
|
647 |
if (glassPane != null) { |
|
648 |
glassPane.setBounds(0, 0, l.getWidth(), l.getHeight()); |
|
649 |
} |
|
650 |
} |
|
651 |
||
652 |
/** |
|
653 |
* If the {@code JLayer}'s view component is not {@code null}, |
|
654 |
* this returns the result of the view's {@code getPreferredSize()} method. |
|
655 |
* Otherwise, the default implementation is used. |
|
656 |
* |
|
657 |
* @param c {@code JLayer} to return preferred size for |
|
658 |
* @return preferred size for the passed {@code JLayer} |
|
659 |
*/ |
|
660 |
public Dimension getPreferredSize(JComponent c) { |
|
661 |
JLayer l = (JLayer) c; |
|
662 |
Component view = l.getView(); |
|
663 |
if (view != null) { |
|
664 |
return view.getPreferredSize(); |
|
665 |
} |
|
666 |
return super.getPreferredSize(c); |
|
667 |
} |
|
668 |
||
669 |
/** |
|
670 |
* If the {@code JLayer}'s view component is not {@code null}, |
|
671 |
* this returns the result of the view's {@code getMinimalSize()} method. |
|
672 |
* Otherwise, the default implementation is used. |
|
673 |
* |
|
674 |
* @param c {@code JLayer} to return preferred size for |
|
675 |
* @return minimal size for the passed {@code JLayer} |
|
676 |
*/ |
|
677 |
public Dimension getMinimumSize(JComponent c) { |
|
678 |
JLayer l = (JLayer) c; |
|
679 |
Component view = l.getView(); |
|
680 |
if (view != null) { |
|
681 |
return view.getMinimumSize(); |
|
682 |
} |
|
683 |
return super.getMinimumSize(c); |
|
684 |
} |
|
685 |
||
686 |
/** |
|
687 |
* If the {@code JLayer}'s view component is not {@code null}, |
|
688 |
* this returns the result of the view's {@code getMaximumSize()} method. |
|
689 |
* Otherwise, the default implementation is used. |
|
690 |
* |
|
691 |
* @param c {@code JLayer} to return preferred size for |
|
8955 | 692 |
* @return maximum size for the passed {@code JLayer} |
6647 | 693 |
*/ |
694 |
public Dimension getMaximumSize(JComponent c) { |
|
695 |
JLayer l = (JLayer) c; |
|
696 |
Component view = l.getView(); |
|
697 |
if (view != null) { |
|
698 |
return view.getMaximumSize(); |
|
699 |
} |
|
700 |
return super.getMaximumSize(c); |
|
701 |
} |
|
702 |
||
703 |
/** |
|
8372
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
704 |
* Paints the specified region in the {@code JLayer} this {@code LayerUI} is set to, immediately. |
6647 | 705 |
* <p/> |
706 |
* This method is to be overridden when the dirty region needs to be changed. |
|
8372
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
707 |
* The default implementation delegates its functionality to {@link JComponent#paintImmediately(int, int, int, int)}. |
6647 | 708 |
* |
8372
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
709 |
* @param x the x value of the region to be painted |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
710 |
* @param y the y value of the region to be painted |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
711 |
* @param w the width of the region to be painted |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
712 |
* @param h the height of the region to be painted |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
713 |
* |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
714 |
* @see JComponent#paintImmediately(int, int, int, int) |
6647 | 715 |
*/ |
8372
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
716 |
public void paintImmediately(int x, int y, int width, int height, JLayer<? extends V> l) { |
786e091594a0
6993171: JavaTest/JDK7b114 - no help text is shown for interview questions, JavaTest HANGS UP
alexp
parents:
7668
diff
changeset
|
717 |
l.paintImmediately(x, y, width, height); |
6647 | 718 |
} |
3733 | 719 |
} |