LayerUI.java revision 2334
1561N/A/*
1621N/A * Copyright 2009 Sun Microsystems, Inc. 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
1621N/A * published by the Free Software Foundation. Sun designates this
1621N/A * particular file as subject to the "Classpath" exception as provided
1621N/A * by Sun 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 *
1621N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1621N/A * CA 95054 USA or visit www.sun.com if you need additional information or
1621N/A * have any questions.
1561N/A */
1561N/A
1561N/Apackage javax.swing.plaf;
1561N/A
1561N/Aimport javax.accessibility.Accessible;
1561N/Aimport javax.swing.*;
1561N/Aimport javax.swing.plaf.ComponentUI;
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/>
1561N/A * {@link #paint(java.awt.Graphics, javax.swing.JComponent)} method performes 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 /**
1561N/A * Dispatches {@code AWTEvent}s for {@code JLayer}
1910N/A * and <b>all its subcomponents</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.
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)
1910N/A * @see #installUI(javax.swing.JComponent)
1910N/A * @see #uninstallUI(javax.swing.JComponent)
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 *
1910N/A * public void unistallUI(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 *
1910N/A * public void unistallUI(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 *
1910N/A * public void unistallUI(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 *
1910N/A * public void unistallUI(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 *
1910N/A * public void unistallUI(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 *
1910N/A * public void unistallUI(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 *
1910N/A * public void unistallUI(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 *
1910N/A * public void unistallUI(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 *
1910N/A * public void unistallUI(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.
1561N/A * The default implementation registers the {@code LayerUI}
1561N/A * as a property change listener for the passed {@code JLayer} component.
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.
1561N/A * The default implementation unregisters the property change listener
1561N/A * for the passed JLayer component.
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 * Returns the preferred size of the viewport for a view component.
1561N/A *
1636N/A * @param l the {@code JLayer} component where this UI delegate is being installed
1561N/A * @return the preferred size of the viewport for a view component
1561N/A * @see Scrollable#getPreferredScrollableViewportSize()
1561N/A */
1561N/A public Dimension getPreferredScrollableViewportSize(JLayer<? extends V> l) {
1561N/A if (l.getView() instanceof Scrollable) {
1561N/A return ((Scrollable)l.getView()).getPreferredScrollableViewportSize();
1561N/A }
1561N/A return l.getPreferredSize();
1561N/A }
1561N/A
1561N/A /**
1561N/A * Returns a scroll increment, which is required for components
1561N/A * that display logical rows or columns in order to completely expose
1561N/A * one block of rows or columns, depending on the value of orientation.
1561N/A *
1636N/A * @param l the {@code JLayer} component where this UI delegate is being installed
1636N/A * @param visibleRect The view area visible within the viewport
1636N/A * @param orientation Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
1636N/A * @param direction Less than zero to scroll up/left, greater than zero for down/right.
1561N/A * @return the "block" increment for scrolling in the specified direction
1561N/A * @see Scrollable#getScrollableBlockIncrement(Rectangle, int, int)
1561N/A */
1561N/A public int getScrollableBlockIncrement(JLayer<? extends V> l,
1561N/A Rectangle visibleRect,
1561N/A int orientation, int direction) {
1561N/A if (l.getView() instanceof Scrollable) {
1561N/A return ((Scrollable)l.getView()).getScrollableBlockIncrement(
1561N/A visibleRect,orientation, direction);
1561N/A }
1561N/A return (orientation == SwingConstants.VERTICAL) ? visibleRect.height :
1561N/A visibleRect.width;
1561N/A }
1561N/A
1561N/A /**
1561N/A * Returns {@code false} to indicate that the height of the viewport does not
1561N/A * determine the height of the layer, unless the preferred height
1561N/A * of the layer is smaller than the height of the viewport.
1561N/A *
1636N/A * @param l the {@code JLayer} component where this UI delegate is being installed
1561N/A * @return whether the layer should track the height of the viewport
1561N/A * @see Scrollable#getScrollableTracksViewportHeight()
1561N/A */
1561N/A public boolean getScrollableTracksViewportHeight(JLayer<? extends V> l) {
1561N/A if (l.getView() instanceof Scrollable) {
1561N/A return ((Scrollable)l.getView()).getScrollableTracksViewportHeight();
1561N/A }
1561N/A return false;
1561N/A }
1561N/A
1561N/A /**
1561N/A * Returns {@code false} to indicate that the width of the viewport does not
1561N/A * determine the width of the layer, unless the preferred width
1561N/A * of the layer is smaller than the width of the viewport.
1561N/A *
1636N/A * @param l the {@code JLayer} component where this UI delegate is being installed
1561N/A * @return whether the layer should track the width of the viewport
1561N/A * @see Scrollable
1561N/A * @see LayerUI#getScrollableTracksViewportWidth(JLayer)
1561N/A */
1561N/A public boolean getScrollableTracksViewportWidth(JLayer<? extends V> l) {
1561N/A if (l.getView() instanceof Scrollable) {
1561N/A return ((Scrollable)l.getView()).getScrollableTracksViewportWidth();
1561N/A }
1561N/A return false;
1561N/A }
1561N/A
1561N/A /**
1561N/A * Returns a scroll increment, which is required for components
1561N/A * that display logical rows or columns in order to completely expose
1561N/A * one new row or column, depending on the value of orientation.
1561N/A * Ideally, components should handle a partially exposed row or column
1561N/A * by returning the distance required to completely expose the item.
1561N/A * <p>
1561N/A * Scrolling containers, like JScrollPane, will use this method
1561N/A * each time the user requests a unit scroll.
1561N/A *
1636N/A * @param l the {@code JLayer} component where this UI delegate is being installed
1636N/A * @param visibleRect The view area visible within the viewport
1636N/A * @param orientation Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
1636N/A * @param direction Less than zero to scroll up/left, greater than zero for down/right.
1561N/A * @return The "unit" increment for scrolling in the specified direction.
1561N/A * This value should always be positive.
1561N/A * @see Scrollable#getScrollableUnitIncrement(Rectangle, int, int)
1561N/A */
1561N/A public int getScrollableUnitIncrement(JLayer<? extends V> l,
1561N/A Rectangle visibleRect,
1561N/A int orientation, int direction) {
1561N/A if (l.getView() instanceof Scrollable) {
1561N/A return ((Scrollable)l.getView()).getScrollableUnitIncrement(
1561N/A visibleRect, orientation, direction);
1561N/A }
1561N/A return 1;
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},
1561N/A * this calls 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 }
1621N/A}