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