1561N/A/*
3909N/A * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
1621N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1621N/A *
1621N/A * This code is free software; you can redistribute it and/or modify it
1621N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1621N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1621N/A *
1621N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1621N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1621N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1621N/A * version 2 for more details (a copy is included in the LICENSE file that
1621N/A * accompanied this code).
1621N/A *
1621N/A * You should have received a copy of the GNU General Public License version
1621N/A * 2 along with this work; if not, write to the Free Software Foundation,
1621N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1621N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1561N/A */
1561N/A
1561N/Apackage javax.swing.plaf;
1561N/A
1561N/Aimport javax.swing.*;
1561N/Aimport java.awt.*;
1561N/Aimport java.awt.event.*;
1561N/Aimport java.beans.PropertyChangeEvent;
1561N/Aimport java.beans.PropertyChangeSupport;
1561N/Aimport java.beans.PropertyChangeListener;
1561N/Aimport java.io.Serializable;
1561N/A
1561N/A/**
1561N/A * The base class for all {@link javax.swing.JLayer}'s UI delegates.
1561N/A * <p/>
3829N/A * {@link #paint(java.awt.Graphics, javax.swing.JComponent)} method performs the
1561N/A * painting of the {@code JLayer}
1561N/A * and {@link #eventDispatched(AWTEvent, JLayer)} method is notified
1561N/A * about any {@code AWTEvent}s which have been generated by a {@code JLayer}
1561N/A * or any of its subcomponents.
1561N/A * <p/>
1561N/A * The {@code LayerUI} differs from the UI delegates of the other components,
1561N/A * because it is LookAndFeel independent and is not updated by default when
1561N/A * the system LookAndFeel is changed.
1561N/A * <p/>
1561N/A * The subclasses of {@code LayerUI} can either be stateless and shareable
1561N/A * by multiple {@code JLayer}s or not shareable.
1561N/A *
1561N/A * @param <V> one of the super types of {@code JLayer}'s view component
1561N/A *
1561N/A * @see JLayer#setUI(LayerUI)
1561N/A * @see JLayer#setView(Component)
1561N/A * @see JLayer#getView()
1561N/A * @since 1.7
1561N/A *
1561N/A * @author Alexander Potochkin
1561N/A */
1561N/Apublic class LayerUI<V extends Component>
1561N/A extends ComponentUI implements Serializable {
1561N/A
1561N/A private final PropertyChangeSupport propertyChangeSupport =
1561N/A new PropertyChangeSupport(this);
1561N/A
1561N/A /**
1561N/A * Paints the specified component.
1561N/A * Subclasses should override this method and use
1561N/A * the specified {@code Graphics} object to
1561N/A * render the content of the component.
1910N/A * <p/>
2334N/A * The default implementation paints the passed component as is.
1561N/A *
2334N/A * @param g the {@code Graphics} context in which to paint
2334N/A * @param c the component being painted
1561N/A */
1561N/A public void paint(Graphics g, JComponent c) {
2334N/A c.paint(g);
1561N/A }
1561N/A
1561N/A /**
2335N/A * Processes {@code AWTEvent}s for {@code JLayer}
2335N/A * and <b>all its descendants</b> to this {@code LayerUI} instance.
1910N/A * <p/>
1910N/A * To enable the {@code AWTEvent}s of a particular type,
1910N/A * you call {@link JLayer#setLayerEventMask}
1561N/A * in {@link #installUI(javax.swing.JComponent)}
1561N/A * and set the layer event mask to {@code 0}
1910N/A * in {@link #uninstallUI(javax.swing.JComponent)} after that.
1910N/A * By default this method calls the appropriate
1910N/A * {@code process&lt;event&nbsp;type&gt;Event}
1910N/A * method for the given class of event.
2335N/A * <p/>
2335N/A * <b>Note:</b> Events are processed only for displayable {@code JLayer}s.
1561N/A *
1561N/A * @param e the event to be dispatched
1561N/A * @param l the layer this LayerUI is set to
1561N/A *
1561N/A * @see JLayer#setLayerEventMask(long)
2335N/A * @see Component#isDisplayable()
1910N/A * @see #processComponentEvent
1910N/A * @see #processFocusEvent
1910N/A * @see #processKeyEvent
1910N/A * @see #processMouseEvent
1910N/A * @see #processMouseMotionEvent
1910N/A * @see #processInputMethodEvent
1910N/A * @see #processHierarchyEvent
1910N/A * @see #processMouseWheelEvent
1561N/A */
1561N/A public void eventDispatched(AWTEvent e, JLayer<? extends V> l){
1910N/A if (e instanceof FocusEvent) {
1910N/A processFocusEvent((FocusEvent)e, l);
1910N/A
1910N/A } else if (e instanceof MouseEvent) {
1910N/A switch(e.getID()) {
1910N/A case MouseEvent.MOUSE_PRESSED:
1910N/A case MouseEvent.MOUSE_RELEASED:
1910N/A case MouseEvent.MOUSE_CLICKED:
1910N/A case MouseEvent.MOUSE_ENTERED:
1910N/A case MouseEvent.MOUSE_EXITED:
1910N/A processMouseEvent((MouseEvent)e, l);
1910N/A break;
1910N/A case MouseEvent.MOUSE_MOVED:
1910N/A case MouseEvent.MOUSE_DRAGGED:
1910N/A processMouseMotionEvent((MouseEvent)e, l);
1910N/A break;
1910N/A case MouseEvent.MOUSE_WHEEL:
1910N/A processMouseWheelEvent((MouseWheelEvent)e, l);
1910N/A break;
1910N/A }
1910N/A } else if (e instanceof KeyEvent) {
1910N/A processKeyEvent((KeyEvent)e, l);
1910N/A } else if (e instanceof ComponentEvent) {
1910N/A processComponentEvent((ComponentEvent)e, l);
1910N/A } else if (e instanceof InputMethodEvent) {
1910N/A processInputMethodEvent((InputMethodEvent)e, l);
1910N/A } else if (e instanceof HierarchyEvent) {
1910N/A switch (e.getID()) {
1910N/A case HierarchyEvent.HIERARCHY_CHANGED:
1910N/A processHierarchyEvent((HierarchyEvent)e, l);
1910N/A break;
1910N/A case HierarchyEvent.ANCESTOR_MOVED:
1910N/A case HierarchyEvent.ANCESTOR_RESIZED:
1910N/A processHierarchyBoundsEvent((HierarchyEvent)e, l);
1910N/A break;
1910N/A }
1910N/A }
1910N/A }
1910N/A
1910N/A /**
1910N/A * Processes component events occurring on the {@link JLayer}
1910N/A * or any of its subcomponents.
1910N/A * <p/>
1910N/A * This method is not called unless component events are
1910N/A * enabled for the {@code JLayer} objects, this {@code LayerUI} is set to.
1910N/A * Component events are enabled in the overridden {@link #installUI} method
1910N/A * and should be disabled in the {@link #uninstallUI} method after that.
1910N/A * <pre>
1910N/A * public void installUI(JComponent c) {
1910N/A * super.installUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(AWTEvent.COMPONENT_EVENT_MASK);
1910N/A * }
1910N/A *
3829N/A * public void uninstallUI(JComponent c) {
1910N/A * super.uninstallUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(0);
1910N/A * }
1910N/A * </pre>
1910N/A *
1910N/A * @param e the {@code ComponentEvent} to be processed
1910N/A * @param l the layer this {@code LayerUI} instance is set to
1910N/A *
1910N/A * @see JLayer#setLayerEventMask(long)
1910N/A * @see #installUI(javax.swing.JComponent)
1910N/A * @see #uninstallUI(javax.swing.JComponent)
1910N/A */
1910N/A protected void processComponentEvent(ComponentEvent e, JLayer<? extends V> l) {
1910N/A }
1910N/A
1910N/A /**
1910N/A * Processes focus events occurring on the {@link JLayer}
1910N/A * or any of its subcomponents.
1910N/A * <p/>
1910N/A * This method is not called unless focus events are
1910N/A * enabled for the {@code JLayer} objects, this {@code LayerUI} is set to.
1910N/A * Focus events are enabled in the overridden {@link #installUI} method
1910N/A * and should be disabled in the {@link #uninstallUI} method after that.
1910N/A * <pre>
1910N/A * public void installUI(JComponent c) {
1910N/A * super.installUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(AWTEvent.FOCUS_EVENT_MASK);
1910N/A * }
1910N/A *
3829N/A * public void uninstallUI(JComponent c) {
1910N/A * super.uninstallUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(0);
1910N/A * }
1910N/A * </pre>
1910N/A *
1910N/A * @param e the {@code FocusEvent} to be processed
1910N/A * @param l the layer this {@code LayerUI} instance is set to
1910N/A *
1910N/A * @see JLayer#setLayerEventMask(long)
1910N/A * @see #installUI(javax.swing.JComponent)
1910N/A * @see #uninstallUI(javax.swing.JComponent)
1910N/A */
1910N/A protected void processFocusEvent(FocusEvent e, JLayer<? extends V> l) {
1910N/A }
1910N/A
1910N/A /**
1910N/A * Processes key events occurring on the {@link JLayer}
1910N/A * or any of its subcomponents.
1910N/A * <p/>
1910N/A * This method is not called unless key events are
1910N/A * enabled for the {@code JLayer} objects, this {@code LayerUI} is set to.
1910N/A * Key events are enabled in the overridden {@link #installUI} method
1910N/A * and should be disabled in the {@link #uninstallUI} method after that.
1910N/A * <pre>
1910N/A * public void installUI(JComponent c) {
1910N/A * super.installUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(AWTEvent.KEY_EVENT_MASK);
1910N/A * }
1910N/A *
3829N/A * public void uninstallUI(JComponent c) {
1910N/A * super.uninstallUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(0);
1910N/A * }
1910N/A * </pre>
1910N/A *
1910N/A * @param e the {@code KeyEvent} to be processed
1910N/A * @param l the layer this {@code LayerUI} instance is set to
1910N/A *
1910N/A * @see JLayer#setLayerEventMask(long)
1910N/A * @see #installUI(javax.swing.JComponent)
1910N/A * @see #uninstallUI(javax.swing.JComponent)
1910N/A */
1910N/A protected void processKeyEvent(KeyEvent e, JLayer<? extends V> l) {
1910N/A }
1910N/A
1910N/A /**
1910N/A * Processes mouse events occurring on the {@link JLayer}
1910N/A * or any of its subcomponents.
1910N/A * <p/>
1910N/A * This method is not called unless mouse events are
1910N/A * enabled for the {@code JLayer} objects, this {@code LayerUI} is set to.
1910N/A * Mouse events are enabled in the overridden {@link #installUI} method
1910N/A * and should be disabled in the {@link #uninstallUI} method after that.
1910N/A * <pre>
1910N/A * public void installUI(JComponent c) {
1910N/A * super.installUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(AWTEvent.MOUSE_EVENT_MASK);
1910N/A * }
1910N/A *
3829N/A * public void uninstallUI(JComponent c) {
1910N/A * super.uninstallUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(0);
1910N/A * }
1910N/A * </pre>
1910N/A *
1910N/A * @param e the {@code MouseEvent} to be processed
1910N/A * @param l the layer this {@code LayerUI} instance is set to
1910N/A *
1910N/A * @see JLayer#setLayerEventMask(long)
1910N/A * @see #installUI(javax.swing.JComponent)
1910N/A * @see #uninstallUI(javax.swing.JComponent)
1910N/A */
1910N/A protected void processMouseEvent(MouseEvent e, JLayer<? extends V> l) {
1910N/A }
1910N/A
1910N/A /**
1910N/A * Processes mouse motion event occurring on the {@link JLayer}
1910N/A * or any of its subcomponents.
1910N/A * <p/>
1910N/A * This method is not called unless mouse motion events are
1910N/A * enabled for the {@code JLayer} objects, this {@code LayerUI} is set to.
1910N/A * Mouse motion events are enabled in the overridden {@link #installUI} method
1910N/A * and should be disabled in the {@link #uninstallUI} method after that.
1910N/A * <pre>
1910N/A * public void installUI(JComponent c) {
1910N/A * super.installUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(AWTEvent.MOUSE_MOTION_EVENT_MASK);
1910N/A * }
1910N/A *
3829N/A * public void uninstallUI(JComponent c) {
1910N/A * super.uninstallUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(0);
1910N/A * }
1910N/A * </pre>
1910N/A *
1910N/A * @param e the {@code MouseEvent} to be processed
1910N/A * @param l the layer this {@code LayerUI} instance is set to
1910N/A *
1910N/A * @see JLayer#setLayerEventMask(long)
1910N/A * @see #installUI(javax.swing.JComponent)
1910N/A * @see #uninstallUI(javax.swing.JComponent)
1910N/A */
1910N/A protected void processMouseMotionEvent(MouseEvent e, JLayer<? extends V> l) {
1910N/A }
1910N/A
1910N/A /**
1910N/A * Processes mouse wheel event occurring on the {@link JLayer}
1910N/A * or any of its subcomponents.
1910N/A * <p/>
1910N/A * This method is not called unless mouse wheel events are
1910N/A * enabled for the {@code JLayer} objects, this {@code LayerUI} is set to.
1910N/A * Mouse wheel events are enabled in the overridden {@link #installUI} method
1910N/A * and should be disabled in the {@link #uninstallUI} method after that.
1910N/A * <pre>
1910N/A * public void installUI(JComponent c) {
1910N/A * super.installUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(AWTEvent.MOUSE_WHEEL_EVENT_MASK);
1910N/A * }
1910N/A *
3829N/A * public void uninstallUI(JComponent c) {
1910N/A * super.uninstallUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(0);
1910N/A * }
1910N/A * </pre>
1910N/A *
1910N/A * @param e the {@code MouseEvent} to be processed
1910N/A * @param l the layer this {@code LayerUI} instance is set to
1910N/A *
1910N/A * @see JLayer#setLayerEventMask(long)
1910N/A * @see #installUI(javax.swing.JComponent)
1910N/A * @see #uninstallUI(javax.swing.JComponent)
1910N/A */
1910N/A protected void processMouseWheelEvent(MouseWheelEvent e, JLayer<? extends V> l) {
1910N/A }
1910N/A
1910N/A /**
1910N/A * Processes input event occurring on the {@link JLayer}
1910N/A * or any of its subcomponents.
1910N/A * <p/>
1910N/A * This method is not called unless input events are
1910N/A * enabled for the {@code JLayer} objects, this {@code LayerUI} is set to.
1910N/A * Input events are enabled in the overridden {@link #installUI} method
1910N/A * and should be disabled in the {@link #uninstallUI} method after that.
1910N/A * <pre>
1910N/A * public void installUI(JComponent c) {
1910N/A * super.installUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(AWTEvent.INPUT_METHOD_EVENT_MASK);
1910N/A * }
1910N/A *
3829N/A * public void uninstallUI(JComponent c) {
1910N/A * super.uninstallUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(0);
1910N/A * }
1910N/A * </pre>
1910N/A *
1910N/A * @param e the {@code InputMethodEvent} to be processed
1910N/A * @param l the layer this {@code LayerUI} instance is set to
1910N/A *
1910N/A * @see JLayer#setLayerEventMask(long)
1910N/A * @see #installUI(javax.swing.JComponent)
1910N/A * @see #uninstallUI(javax.swing.JComponent)
1910N/A */
1910N/A protected void processInputMethodEvent(InputMethodEvent e, JLayer<? extends V> l) {
1910N/A }
1910N/A
1910N/A /**
1910N/A * Processes hierarchy event occurring on the {@link JLayer}
1910N/A * or any of its subcomponents.
1910N/A * <p/>
1910N/A * This method is not called unless hierarchy events are
1910N/A * enabled for the {@code JLayer} objects, this {@code LayerUI} is set to.
1910N/A * Hierarchy events are enabled in the overridden {@link #installUI} method
1910N/A * and should be disabled in the {@link #uninstallUI} method after that.
1910N/A * <pre>
1910N/A * public void installUI(JComponent c) {
1910N/A * super.installUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(AWTEvent.HIERARCHY_EVENT_MASK);
1910N/A * }
1910N/A *
3829N/A * public void uninstallUI(JComponent c) {
1910N/A * super.uninstallUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(0);
1910N/A * }
1910N/A * </pre>
1910N/A *
1910N/A * @param e the {@code HierarchyEvent} to be processed
1910N/A * @param l the layer this {@code LayerUI} instance is set to
1910N/A *
1910N/A * @see JLayer#setLayerEventMask(long)
1910N/A * @see #installUI(javax.swing.JComponent)
1910N/A * @see #uninstallUI(javax.swing.JComponent)
1910N/A */
1910N/A protected void processHierarchyEvent(HierarchyEvent e, JLayer<? extends V> l) {
1910N/A }
1910N/A
1910N/A /**
1910N/A * Processes hierarchy bounds event occurring on the {@link JLayer}
1910N/A * or any of its subcomponents.
1910N/A * <p/>
1910N/A * This method is not called unless hierarchy bounds events are
1910N/A * enabled for the {@code JLayer} objects, this {@code LayerUI} is set to.
1910N/A * Hierarchy bounds events are enabled in the overridden {@link #installUI}
1910N/A * method and should be disabled in the {@link #uninstallUI} method after that.
1910N/A * <pre>
1910N/A * public void installUI(JComponent c) {
1910N/A * super.installUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK);
1910N/A * }
1910N/A *
3829N/A * public void uninstallUI(JComponent c) {
1910N/A * super.uninstallUI(c);
1910N/A * JLayer l = (JLayer) c;
1910N/A * l.setLayerEventMask(0);
1910N/A * }
1910N/A * </pre>
1910N/A *
1910N/A * @param e the {@code HierarchyEvent} to be processed
1910N/A * @param l the layer this {@code LayerUI} instance is set to
1910N/A *
1910N/A * @see JLayer#setLayerEventMask(long)
1910N/A * @see #installUI(javax.swing.JComponent)
1910N/A * @see #uninstallUI(javax.swing.JComponent)
1910N/A */
1910N/A protected void processHierarchyBoundsEvent(HierarchyEvent e, JLayer<? extends V> l) {
1561N/A }
1561N/A
1561N/A /**
1561N/A * Invoked when {@link javax.swing.JLayer#updateUI()} is called
1561N/A * by the {@code JLayer} this {@code LayerUI} is set to.
1561N/A *
1561N/A * @param l the {@code JLayer} which UI is updated
1561N/A */
1561N/A public void updateUI(JLayer<? extends V> l){
1561N/A }
1561N/A
1561N/A /**
1561N/A * Configures the {@code JLayer} this {@code LayerUI} is set to.
3085N/A * The default implementation registers the passed {@code JLayer} component
3085N/A * as a {@code PropertyChangeListener} for the property changes of this {@code LayerUI}.
1561N/A *
1561N/A * @param c the {@code JLayer} component where this UI delegate is being installed
1561N/A */
1561N/A public void installUI(JComponent c) {
1561N/A addPropertyChangeListener((JLayer) c);
1561N/A }
1561N/A
1561N/A /**
1561N/A * Reverses the configuration which was previously set
1561N/A * in the {@link #installUI(JComponent)} method.
3085N/A * The default implementation unregisters the passed {@code JLayer} component
3085N/A * as a {@code PropertyChangeListener} for the property changes of this {@code LayerUI}.
1561N/A *
1561N/A * @param c the component from which this UI delegate is being removed.
1561N/A */
1561N/A public void uninstallUI(JComponent c) {
1561N/A removePropertyChangeListener((JLayer) c);
1561N/A }
1561N/A
1561N/A /**
1561N/A * Adds a PropertyChangeListener to the listener list. The listener is
1561N/A * registered for all bound properties of this class.
1561N/A * <p/>
1561N/A * If {@code listener} is {@code null},
1561N/A * no exception is thrown and no action is performed.
1561N/A *
1561N/A * @param listener the property change listener to be added
1561N/A * @see #removePropertyChangeListener
1561N/A * @see #getPropertyChangeListeners
1561N/A * @see #addPropertyChangeListener(String, java.beans.PropertyChangeListener)
1561N/A */
1561N/A public void addPropertyChangeListener(PropertyChangeListener listener) {
1561N/A propertyChangeSupport.addPropertyChangeListener(listener);
1561N/A }
1561N/A
1561N/A /**
1561N/A * Removes a PropertyChangeListener from the listener list. This method
1561N/A * should be used to remove PropertyChangeListeners that were registered
1561N/A * for all bound properties of this class.
1561N/A * <p/>
1561N/A * If {@code listener} is {@code null},
1561N/A * no exception is thrown and no action is performed.
1561N/A *
1561N/A * @param listener the PropertyChangeListener to be removed
1561N/A * @see #addPropertyChangeListener
1561N/A * @see #getPropertyChangeListeners
1561N/A * @see #removePropertyChangeListener(String, PropertyChangeListener)
1561N/A */
1561N/A public void removePropertyChangeListener(PropertyChangeListener listener) {
1561N/A propertyChangeSupport.removePropertyChangeListener(listener);
1561N/A }
1561N/A
1561N/A /**
1561N/A * Returns an array of all the property change listeners
1561N/A * registered on this component.
1561N/A *
1561N/A * @return all of this ui's {@code PropertyChangeListener}s
1561N/A * or an empty array if no property change
1561N/A * listeners are currently registered
1561N/A * @see #addPropertyChangeListener
1561N/A * @see #removePropertyChangeListener
1561N/A * @see #getPropertyChangeListeners(String)
1561N/A */
1561N/A public PropertyChangeListener[] getPropertyChangeListeners() {
1561N/A return propertyChangeSupport.getPropertyChangeListeners();
1561N/A }
1561N/A
1561N/A /**
1561N/A * Adds a PropertyChangeListener to the listener list for a specific
1561N/A * property.
1561N/A * <p/>
1561N/A * If {@code propertyName} or {@code listener} is {@code null},
1561N/A * no exception is thrown and no action is taken.
1561N/A *
1561N/A * @param propertyName one of the property names listed above
1561N/A * @param listener the property change listener to be added
1561N/A * @see #removePropertyChangeListener(String, PropertyChangeListener)
1561N/A * @see #getPropertyChangeListeners(String)
1561N/A * @see #addPropertyChangeListener(String, PropertyChangeListener)
1561N/A */
1561N/A public void addPropertyChangeListener(String propertyName,
1561N/A PropertyChangeListener listener) {
1561N/A propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
1561N/A }
1561N/A
1561N/A /**
1561N/A * Removes a {@code PropertyChangeListener} from the listener
1561N/A * list for a specific property. This method should be used to remove
1561N/A * {@code PropertyChangeListener}s
1561N/A * that were registered for a specific bound property.
1561N/A * <p/>
1561N/A * If {@code propertyName} or {@code listener} is {@code null},
1561N/A * no exception is thrown and no action is taken.
1561N/A *
1561N/A * @param propertyName a valid property name
1561N/A * @param listener the PropertyChangeListener to be removed
1561N/A * @see #addPropertyChangeListener(String, PropertyChangeListener)
1561N/A * @see #getPropertyChangeListeners(String)
1561N/A * @see #removePropertyChangeListener(PropertyChangeListener)
1561N/A */
1561N/A public void removePropertyChangeListener(String propertyName,
1561N/A PropertyChangeListener listener) {
1561N/A propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
1561N/A }
1561N/A
1561N/A /**
1561N/A * Returns an array of all the listeners which have been associated
1561N/A * with the named property.
1561N/A *
1636N/A * @param propertyName The name of the property being listened to
1561N/A * @return all of the {@code PropertyChangeListener}s associated with
1561N/A * the named property; if no such listeners have been added or
1561N/A * if {@code propertyName} is {@code null}, an empty
1561N/A * array is returned
1561N/A * @see #addPropertyChangeListener(String, PropertyChangeListener)
1561N/A * @see #removePropertyChangeListener(String, PropertyChangeListener)
1561N/A * @see #getPropertyChangeListeners
1561N/A */
1561N/A public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
1561N/A return propertyChangeSupport.getPropertyChangeListeners(propertyName);
1561N/A }
1561N/A
1561N/A /**
1561N/A * Support for reporting bound property changes for Object properties.
1561N/A * This method can be called when a bound property has changed and it will
1561N/A * send the appropriate PropertyChangeEvent to any registered
1561N/A * PropertyChangeListeners.
1561N/A *
1561N/A * @param propertyName the property whose value has changed
1561N/A * @param oldValue the property's previous value
1561N/A * @param newValue the property's new value
1561N/A */
1561N/A protected void firePropertyChange(String propertyName,
1561N/A Object oldValue, Object newValue) {
1561N/A propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
1561N/A }
1561N/A
1561N/A /**
1561N/A * Notifies the {@code LayerUI} when any of its property are changed
1910N/A * and enables updating every {@code JLayer}
1910N/A * this {@code LayerUI} instance is set to.
1561N/A *
1561N/A * @param evt the PropertyChangeEvent generated by this {@code LayerUI}
1561N/A * @param l the {@code JLayer} this LayerUI is set to
1561N/A */
1561N/A public void applyPropertyChange(PropertyChangeEvent evt, JLayer<? extends V> l) {
1561N/A }
1561N/A
1561N/A /**
1561N/A * If the {@code JLayer}'s view component is not {@code null},
1561N/A * this calls the view's {@code getBaseline()} method.
1561N/A * Otherwise, the default implementation is called.
1561N/A *
1561N/A * @param c {@code JLayer} to return baseline resize behavior for
1561N/A * @param width the width to get the baseline for
1561N/A * @param height the height to get the baseline for
1561N/A * @return baseline or a value &lt; 0 indicating there is no reasonable
1561N/A * baseline
1561N/A */
1561N/A public int getBaseline(JComponent c, int width, int height) {
1561N/A JLayer l = (JLayer) c;
1561N/A if (l.getView() != null) {
1561N/A return l.getView().getBaseline(width, height);
1561N/A }
1561N/A return super.getBaseline(c, width, height);
1561N/A }
1561N/A
1561N/A /**
1561N/A * If the {@code JLayer}'s view component is not {@code null},
2778N/A * this returns the result of the view's {@code getBaselineResizeBehavior()} method.
1561N/A * Otherwise, the default implementation is called.
1561N/A *
1561N/A * @param c {@code JLayer} to return baseline resize behavior for
1561N/A * @return an enum indicating how the baseline changes as the component
1561N/A * size changes
1561N/A */
1561N/A public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) {
1561N/A JLayer l = (JLayer) c;
1561N/A if (l.getView() != null) {
1561N/A return l.getView().getBaselineResizeBehavior();
1561N/A }
1561N/A return super.getBaselineResizeBehavior(c);
1561N/A }
2778N/A
2778N/A /**
2778N/A * Causes the passed instance of {@code JLayer} to lay out its components.
2778N/A *
2778N/A * @param l the {@code JLayer} component where this UI delegate is being installed
2778N/A */
2778N/A public void doLayout(JLayer<? extends V> l) {
2778N/A Component view = l.getView();
2778N/A if (view != null) {
2778N/A view.setBounds(0, 0, l.getWidth(), l.getHeight());
2778N/A }
2778N/A Component glassPane = l.getGlassPane();
2778N/A if (glassPane != null) {
2778N/A glassPane.setBounds(0, 0, l.getWidth(), l.getHeight());
2778N/A }
2778N/A }
2778N/A
2778N/A /**
2778N/A * If the {@code JLayer}'s view component is not {@code null},
2778N/A * this returns the result of the view's {@code getPreferredSize()} method.
2778N/A * Otherwise, the default implementation is used.
2778N/A *
2778N/A * @param c {@code JLayer} to return preferred size for
2778N/A * @return preferred size for the passed {@code JLayer}
2778N/A */
2778N/A public Dimension getPreferredSize(JComponent c) {
2778N/A JLayer l = (JLayer) c;
2778N/A Component view = l.getView();
2778N/A if (view != null) {
2778N/A return view.getPreferredSize();
2778N/A }
2778N/A return super.getPreferredSize(c);
2778N/A }
2778N/A
2778N/A /**
2778N/A * If the {@code JLayer}'s view component is not {@code null},
2778N/A * this returns the result of the view's {@code getMinimalSize()} method.
2778N/A * Otherwise, the default implementation is used.
2778N/A *
2778N/A * @param c {@code JLayer} to return preferred size for
2778N/A * @return minimal size for the passed {@code JLayer}
2778N/A */
2778N/A public Dimension getMinimumSize(JComponent c) {
2778N/A JLayer l = (JLayer) c;
2778N/A Component view = l.getView();
2778N/A if (view != null) {
2778N/A return view.getMinimumSize();
2778N/A }
2778N/A return super.getMinimumSize(c);
2778N/A }
2778N/A
2778N/A /**
2778N/A * If the {@code JLayer}'s view component is not {@code null},
2778N/A * this returns the result of the view's {@code getMaximumSize()} method.
2778N/A * Otherwise, the default implementation is used.
2778N/A *
2778N/A * @param c {@code JLayer} to return preferred size for
3829N/A * @return maximum size for the passed {@code JLayer}
2778N/A */
2778N/A public Dimension getMaximumSize(JComponent c) {
2778N/A JLayer l = (JLayer) c;
2778N/A Component view = l.getView();
2778N/A if (view != null) {
2778N/A return view.getMaximumSize();
2778N/A }
2778N/A return super.getMaximumSize(c);
2778N/A }
2778N/A
2778N/A /**
3555N/A * Paints the specified region in the {@code JLayer} this {@code LayerUI} is set to, immediately.
2778N/A * <p/>
2778N/A * This method is to be overridden when the dirty region needs to be changed.
3555N/A * The default implementation delegates its functionality to {@link JComponent#paintImmediately(int, int, int, int)}.
2778N/A *
3555N/A * @param x the x value of the region to be painted
3555N/A * @param y the y value of the region to be painted
3995N/A * @param width the width of the region to be painted
3995N/A * @param height the height of the region to be painted
3555N/A *
3555N/A * @see JComponent#paintImmediately(int, int, int, int)
2778N/A */
3555N/A public void paintImmediately(int x, int y, int width, int height, JLayer<? extends V> l) {
3555N/A l.paintImmediately(x, y, width, height);
2778N/A }
1621N/A}