org.jdesktop.jxlayer.plaf
Class AbstractLayerUI<V extends javax.swing.JComponent>

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by org.jdesktop.jxlayer.plaf.LayerUI<V>
          extended by org.jdesktop.jxlayer.plaf.AbstractLayerUI<V>
All Implemented Interfaces:
LayerItem
Direct Known Subclasses:
AbstractBufferedLayerUI, ButtonPanelUI, MouseScrollableUI

public class AbstractLayerUI<V extends javax.swing.JComponent>
extends LayerUI<V>

The AbstractLayerUI provided default implementation for most of the abstract methods in the LayerUI class. It takes care of the management of LayerItemListeners and defines the hook method to configure the Graphics2D instance specified in the paint(Graphics,JComponent) method. It also provides convenient methods named process<eventType>Event to process the given class of event.

If state of the AbstractLayerUI is changed, call setDirty(boolean) with true as the parameter, it will repaint all JXLayers connected with this AbstractLayerUI

See Also:
JXLayer.setUI(LayerUI)

Constructor Summary
AbstractLayerUI()
           
 
Method Summary
 void addLayerItemListener(LayerItemListener l)
          Adds a LayerItemListener to the layer item.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list.
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list for a specific property.
protected  void configureGraphics(java.awt.Graphics2D g2, JXLayer<V> l)
          This method is called by the paint(java.awt.Graphics, javax.swing.JComponent) method prior to any drawing operations to configure the Graphics2D object.
 void eventDispatched(java.awt.AWTEvent e, JXLayer<V> l)
          Dispatches all input and focus events from the JXLayer and all it subcomponents to this LayerUI, when LayerItem.isEnabled() returns true.

This method calls the appropriate process<eventType>Event method for the given class of event.

protected  void fireLayerItemChanged()
          Notifies all LayerItemListeners that have been added to this object.
protected  void fireLayerItemChanged(LayerItemChangeEvent event)
          Notifies all LayerItemListeners that have been added to this object.
protected  void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Support for reporting bound property changes for Object properties.
protected  java.awt.Shape getClip(JXLayer<V> l)
          Returns the Shape to be used as the clip during painting of this JXLayer, the default implementation returns null.
protected  java.awt.Composite getComposite(JXLayer<V> l)
          Returns the Composite to be used during painting of this JXLayer, the default implementation returns null.
 long getLayerEventMask()
          Returns the bitmap of event mask to receive by this LayerUI and all its JXLayers

It means that LayerUI.eventDispatched(AWTEvent, JXLayer) method will only receive events that match the event mask.

By default only mouse, mouse motion, mouse wheel, keyboard and focus events are supported, all other events included in the eventMask will be ignored.

 LayerItemListener[] getLayerItemListeners()
          Returns an array of all the LayerItemListeners registered on this LayerItem.
 java.beans.PropertyChangeListener[] getPropertyChangeListeners()
          Returns an array of all the property change listeners registered on this component.
 java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
          Returns an array of all the listeners which have been associated with the named property.
protected  java.util.Map<java.awt.RenderingHints.Key,java.lang.Object> getRenderingHints(JXLayer<V> l)
          Returns the map of rendering hints to be used during painting of this JXLayer, the default implementation returns the empty unmodifiable map.
protected  java.awt.geom.AffineTransform getTransform(JXLayer<V> l)
          Returns the AffineTransform to be used during painting of this JXLayer, the default implementation returns null.
 void installUI(javax.swing.JComponent c)
          Configures the specified JXLayer appropriate for this AbstractLayerUI.
protected  boolean isAWTEventListenerEnabled()
          Returns true if this AbstractLayerUI catches AWT events with help of AWTEventListener, in this case registerAWTEventListener(JXLayer, long) will be called from installUI(JComponent) with getLayerEventMask() as the second parameter and unregisterAWTEventListener(JXLayer) will be called from uninstallUI(JComponent)

If this method is overridden to return true don't forget to override getAWTEventListenerEventMask()

The default implementation returns false

protected  boolean isDirty()
          Returns the "dirty bit".
 boolean isEnabled()
          Indicates if this LayerItem is in active state.

AbstractLayerUI is enabled initially by default.

 void paint(java.awt.Graphics g, javax.swing.JComponent c)
          Paints the specified component.

Note: It is rarely necessary to override this method, for custom painting override paintLayer(Graphics2D,JXLayer) instead

This method configures the passed Graphics with help of the configureGraphics(Graphics2D,JXLayer) method, then calls paintLayer(Graphics2D,JXLayer) and resets the "dirty bit" at the end.

protected  void paintLayer(java.awt.Graphics2D g2, JXLayer<V> l)
          Subclasses should implement this method and perform custom painting operations here.
protected  void processFocusEvent(java.awt.event.FocusEvent e, JXLayer<V> l)
          Processes FocusEvent occurring on the JXLayer or any of its subcomponents.
protected  void processKeyEvent(java.awt.event.KeyEvent e, JXLayer<V> l)
          Processes KeyEvent occurring on the JXLayer or any of its subcomponents.
protected  void processMouseEvent(java.awt.event.MouseEvent e, JXLayer<V> l)
          Processes MouseEvent occurring on the JXLayer or any of its subcomponents.
protected  void processMouseMotionEvent(java.awt.event.MouseEvent e, JXLayer<V> l)
          Processes mouse motion events occurring on the JXLayer or any of its subcomponents.
protected  void processMouseWheelEvent(java.awt.event.MouseWheelEvent e, JXLayer<V> l)
          Processes MouseWheelEvent occurring on the JXLayer or any of its subcomponents.
protected  void registerAWTEventListener(JXLayer<V> l, long eventMask)
          This is an alternative implementation of catching JXLayer's events.
 void removeLayerItemListener(LayerItemListener l)
          Removes a LayerItemListener from this LayerItem.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list.
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list for a specific property.
protected  void setDirty(boolean isDirty)
          Sets the "dirty bit".
 void setEnabled(boolean enabled)
          Enables or disables this component, depending on the value of the parameter enabled.
 void setLayerEventMask(long layerEventMask)
          Sets the eventMask for this AbstractLayerUI and all its JXLayers

It means that eventDispatched(AWTEvent, JXLayer) method will only receive events that match the event mask.

 void uninstallUI(javax.swing.JComponent c)
          Reverses configuration which was done on the specified component during installUI(JComponent).
protected  void unregisterAWTEventListener(JXLayer<V> l)
          Unregister an event listener which was previously set by registerAWTEventListener(JXLayer, long) and also enables back the proxy InputContext of the passed JXLayer.
 
Methods inherited from class org.jdesktop.jxlayer.plaf.LayerUI
getAccessibleChild, getAccessibleChildrenCount, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, isEventEnabled, update, updateUI
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, createUI, getMaximumSize, getMinimumSize, getPreferredSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractLayerUI

public AbstractLayerUI()
Method Detail

installUI

public void installUI(javax.swing.JComponent c)
Configures the specified JXLayer appropriate for this AbstractLayerUI.

This method is invoked when the LayerUI instance is being installed as the UI delegate on the specified JXLayer. Subclasses can install any listeners to the passed JXLayer, configure its glassPane or do any other setting up. The default implementation registers the passed JXLayer as a LayerItemListener for this AbstractLayerUI.

Note: Subclasses can safely cast the passed component to the JXLayer<V>

Overrides:
installUI in class javax.swing.plaf.ComponentUI
Parameters:
c - the JXLayer where this UI delegate is being installed
See Also:
uninstallUI(JComponent)

uninstallUI

public void uninstallUI(javax.swing.JComponent c)
Reverses configuration which was done on the specified component during installUI(JComponent). This method is invoked when this LayerUI instance is being removed as the UI delegate for the specified JXLayer.

uninstallUI(JComponent) should undo the configuration performed in installUI(JComponent), being careful to leave the JXLayer instance in a clean state (e.g. all previously set listeners must be removed in this method). The default implementation removes the passed JXLayer from the LayerItemListener's list of this AbstractLayerUI.

Note: Subclasses can safely cast the passed component to the JXLayer<V>

Overrides:
uninstallUI in class javax.swing.plaf.ComponentUI
Parameters:
c - the JXLayer where this UI delegate is being installed
See Also:
installUI(JComponent)

registerAWTEventListener

protected void registerAWTEventListener(JXLayer<V> l,
                                        long eventMask)
This is an alternative implementation of catching JXLayer's events. When this method is called, the proxy InputContext of the passed JXLayer is disabled and an AWTEventListener starts listen events for this JXLayer and all its subcomponents.

If there is a security manager, its checkPermission method is called with an AWTPermission("listenToAllAWTEvents") permission. This may result in a SecurityException.

eventMask is a bitmask of event types to receive. It is constructed by bitwise OR-ing together the event masks defined in AWTEvent.

For example, the following mask includes all mouse events:

 AWTEvent.MOUSE_EVENT_MASK |
           AWTEvent.MOUSE_MOTION_EVENT_MASK |
           AWTEvent.MOUSE_WHEEL_EVENT_MASK
 
It is guaranteed that this eventDispatched(AWTEvent, JXLayer) will be notified of any event inside layer's hierarchy that matched with the eventMask A specific AWTEventListener's implementation may also pass some events that don't match with the eventMask, but you shouldn't rely on it.

Note: It is unlikely that you will ever need to manually call this method, if you need to enable the AWTEventListener, just override isAWTEventListenerEnabled() together with getLayerEventMask().

For more informaiton please see JXLayer 3.0 - Event handling

Parameters:
l - the JXLayer to listen events for
eventMask - the bitmask of event types to receive
See Also:
isAWTEventListenerEnabled(), getLayerEventMask(), unregisterAWTEventListener(JXLayer)

unregisterAWTEventListener

protected void unregisterAWTEventListener(JXLayer<V> l)
Unregister an event listener which was previously set by registerAWTEventListener(JXLayer, long) and also enables back the proxy InputContext of the passed JXLayer.

Note: If you call (JXLayer, long) from the installUI(), you must call this method in the uninstallUI(JComponent) to release resources.

Note: It is unlikely that you will ever need to manually call this method, if you need to enable the AWTEventListener, just override isAWTEventListenerEnabled() together with getLayerEventMask().

Parameters:
l - the JXLayer to unregister the listener for
See Also:
registerAWTEventListener(JXLayer, long)

isAWTEventListenerEnabled

protected boolean isAWTEventListenerEnabled()
Returns true if this AbstractLayerUI catches AWT events with help of AWTEventListener, in this case registerAWTEventListener(JXLayer, long) will be called from installUI(JComponent) with getLayerEventMask() as the second parameter and unregisterAWTEventListener(JXLayer) will be called from uninstallUI(JComponent)

If this method is overridden to return true don't forget to override getAWTEventListenerEventMask()

The default implementation returns false

Returns:
true if this AbstractLayerUI catches AWT events with help of AWTEventListener
See Also:
(), registerAWTEventListener(JXLayer, long)

getLayerEventMask

public long getLayerEventMask()
Returns the bitmap of event mask to receive by this LayerUI and all its JXLayers

It means that LayerUI.eventDispatched(AWTEvent, JXLayer) method will only receive events that match the event mask. By default the mask includes mouse, mouse motion, mouse wheel, keyboard and focus events.

By default only mouse, mouse motion, mouse wheel, keyboard and focus events are supported, all other events included in the eventMask will be ignored. To enable the rest of the events, like HierarchyEvents you should override isAWTEventListenerEnabled() to return true.

Overrides:
getLayerEventMask in class LayerUI<V extends javax.swing.JComponent>
Returns:
the bitmask of event types to receive for this LayerUI
See Also:
setLayerEventMask(long), isAWTEventListenerEnabled()

setLayerEventMask

public void setLayerEventMask(long layerEventMask)
Sets the eventMask for this AbstractLayerUI and all its JXLayers

It means that eventDispatched(AWTEvent, JXLayer) method will only receive events that match the event mask.

    //Call from the ui's constructor to receive only keyboard and focus events:
    setLayerEventMask(AWTEvent.KEY_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK);
 

By default only mouse, mouse motion, mouse wheel, keyboard and focus events are supported, all other events included in the eventMask will be ignored. To enable the rest of the events, like HierarchyEvents you should override isAWTEventListenerEnabled() to return true.

Parameters:
layerEventMask - the bitmask of event types to receive
See Also:
getLayerEventMask()

addLayerItemListener

public void addLayerItemListener(LayerItemListener l)
Adds a LayerItemListener to the layer item.

Parameters:
l - the listener to add

getLayerItemListeners

public LayerItemListener[] getLayerItemListeners()
Returns an array of all the LayerItemListeners registered on this LayerItem.

Returns:
all of this item's LayerItemListeners or an empty array if no item listeners are currently registered

removeLayerItemListener

public void removeLayerItemListener(LayerItemListener l)
Removes a LayerItemListener from this LayerItem.

Parameters:
l - the listener to remove

fireLayerItemChanged

protected void fireLayerItemChanged()
Notifies all LayerItemListeners that have been added to this object.

See Also:
addLayerItemListener(LayerItemListener)

fireLayerItemChanged

protected void fireLayerItemChanged(LayerItemChangeEvent event)
Notifies all LayerItemListeners that have been added to this object.

Parameters:
event - the LayerItemChangeEvent
See Also:
addLayerItemListener(LayerItemListener)

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list. The listener is registered for all bound properties of this class.

If listener is null, no exception is thrown and no action is performed.

Parameters:
listener - the property change listener to be added
See Also:
removePropertyChangeListener(java.beans.PropertyChangeListener), getPropertyChangeListeners(), addPropertyChangeListener(String, PropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. This method should be used to remove PropertyChangeListeners that were registered for all bound properties of this class.

If listener is null, no exception is thrown and no action is performed.

Parameters:
listener - the PropertyChangeListener to be removed
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener), getPropertyChangeListeners(), removePropertyChangeListener(String, PropertyChangeListener)

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all the property change listeners registered on this component.

Returns:
all of this ui's PropertyChangeListeners or an empty array if no property change listeners are currently registered
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener), removePropertyChangeListener(java.beans.PropertyChangeListener), getPropertyChangeListeners(String)

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list for a specific property.

If propertyName or listener is null, no exception is thrown and no action is taken.

Parameters:
propertyName - one of the property names listed above
listener - the property change listener to be added
See Also:
removePropertyChangeListener(String, PropertyChangeListener), getPropertyChangeListeners(String), addPropertyChangeListener(String, PropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list for a specific property. This method should be used to remove PropertyChangeListeners that were registered for a specific bound property.

If propertyName or listener is null, no exception is thrown and no action is taken.

Parameters:
propertyName - a valid property name
listener - the PropertyChangeListener to be removed
See Also:
addPropertyChangeListener(String, PropertyChangeListener), getPropertyChangeListeners(String), removePropertyChangeListener(PropertyChangeListener)

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
Returns an array of all the listeners which have been associated with the named property.

Returns:
all of the PropertyChangeListeners associated with the named property; if no such listeners have been added or if propertyName is null, an empty array is returned
See Also:
addPropertyChangeListener(String, PropertyChangeListener), removePropertyChangeListener(String, PropertyChangeListener), getPropertyChangeListeners()

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
Support for reporting bound property changes for Object properties. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.

Parameters:
propertyName - the property whose value has changed
oldValue - the property's previous value
newValue - the property's new value

isEnabled

public boolean isEnabled()
Indicates if this LayerItem is in active state.

AbstractLayerUI is enabled initially by default.

Returns:
true if this LayerItem is in active state

setEnabled

public void setEnabled(boolean enabled)
Enables or disables this component, depending on the value of the parameter enabled. An enabled LayerUI paints the JXLayers components they are set to and receives their input and focuse events.

AbstractLayerUI is enabled initially by default.

Parameters:
enabled - If true, this AbstractLayerUI is enabled; otherwise this AbstractLayerUI is disabled

isDirty

protected boolean isDirty()
Returns the "dirty bit". If true, then the AbstractLayerUI is considered dirty and in need of being repainted.

Returns:
true if the AbstractLayerUI state has changed and the JXLayers it is set to need to be repainted.

setDirty

protected void setDirty(boolean isDirty)
Sets the "dirty bit". If isDirty is true, then the AbstractLayerUI is considered dirty and it triggers the repainting of the JXLayers this AbstractLayerUI it is set to.

Parameters:
isDirty - whether this AbstractLayerUI is dirty or not.

paint

public void paint(java.awt.Graphics g,
                  javax.swing.JComponent c)
Paints the specified component. Subclasses should override this method and use the specified Graphics object to render the content of the component.

Note: Subclasses can safely cast the passed component to the JXLayer<V>
and the passed Graphics to the Graphics2D instance.

Note: It is rarely necessary to override this method, for custom painting override paintLayer(Graphics2D,JXLayer) instead

This method configures the passed Graphics with help of the configureGraphics(Graphics2D,JXLayer) method, then calls paintLayer(Graphics2D,JXLayer) and resets the "dirty bit" at the end.

Overrides:
paint in class LayerUI<V extends javax.swing.JComponent>
Parameters:
g - the Graphics context in which to paint; this object can be safely cast to the Graphics2D instance.
c - the component being painted; it can be safely cast to the JXLayer<V>
See Also:
configureGraphics(Graphics2D,JXLayer), paintLayer(Graphics2D,JXLayer), setDirty(boolean)

paintLayer

protected void paintLayer(java.awt.Graphics2D g2,
                          JXLayer<V> l)
Subclasses should implement this method and perform custom painting operations here.

The default implementation paints the passed JXLayer as is.

Parameters:
g2 - the Graphics2D context in which to paint
l - the JXLayer being painted

configureGraphics

protected void configureGraphics(java.awt.Graphics2D g2,
                                 JXLayer<V> l)
This method is called by the paint(java.awt.Graphics, javax.swing.JComponent) method prior to any drawing operations to configure the Graphics2D object. The default implementation sets the Composite, the clip, AffineTransform and rendering hints obtained from the corresponding hook methods.

Parameters:
g2 - the Graphics2D object to configure
l - the JXLayer being painted
See Also:
getComposite(JXLayer), getClip(JXLayer), getTransform(JXLayer), getRenderingHints(JXLayer)

getComposite

protected java.awt.Composite getComposite(JXLayer<V> l)
Returns the Composite to be used during painting of this JXLayer, the default implementation returns null.

Parameters:
l - the JXLayer being painted
Returns:
the Composite to be used during painting for the JXLayer

getTransform

protected java.awt.geom.AffineTransform getTransform(JXLayer<V> l)
Returns the AffineTransform to be used during painting of this JXLayer, the default implementation returns null.

Parameters:
l - the JXLayer being painted
Returns:
the AffineTransform to be used during painting of the JXLayer

getClip

protected java.awt.Shape getClip(JXLayer<V> l)
Returns the Shape to be used as the clip during painting of this JXLayer, the default implementation returns null.

Parameters:
l - the JXLayer being painted
Returns:
the Shape to be used as the clip during painting of the JXLayer

getRenderingHints

protected java.util.Map<java.awt.RenderingHints.Key,java.lang.Object> getRenderingHints(JXLayer<V> l)
Returns the map of rendering hints to be used during painting of this JXLayer, the default implementation returns the empty unmodifiable map.

Parameters:
l - the JXLayer being painted
Returns:
the map of rendering hints to be used during painting of the JXLayer

eventDispatched

public void eventDispatched(java.awt.AWTEvent e,
                            JXLayer<V> l)
Dispatches all input and focus events from the JXLayer and all it subcomponents to this LayerUI, when LayerItem.isEnabled() returns true.

This method calls the appropriate process<eventType>Event method for the given class of event.

Overrides:
eventDispatched in class LayerUI<V extends javax.swing.JComponent>
Parameters:
e - the event to be dispatched
l - the layer this LayerUI is set to

processFocusEvent

protected void processFocusEvent(java.awt.event.FocusEvent e,
                                 JXLayer<V> l)
Processes FocusEvent occurring on the JXLayer or any of its subcomponents.

Parameters:
e - the FocusEvent to be processed
l - the layer this LayerUI is set to

processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent e,
                                 JXLayer<V> l)
Processes MouseEvent occurring on the JXLayer or any of its subcomponents.

Parameters:
e - the MouseEvent to be processed
l - the layer this LayerUI is set to

processMouseMotionEvent

protected void processMouseMotionEvent(java.awt.event.MouseEvent e,
                                       JXLayer<V> l)
Processes mouse motion events occurring on the JXLayer or any of its subcomponents.

Parameters:
e - the MouseEvent to be processed
l - the layer this LayerUI is set to

processMouseWheelEvent

protected void processMouseWheelEvent(java.awt.event.MouseWheelEvent e,
                                      JXLayer<V> l)
Processes MouseWheelEvent occurring on the JXLayer or any of its subcomponents.

Parameters:
e - the MouseWheelEvent to be processed
l - the layer this LayerUI is set to

processKeyEvent

protected void processKeyEvent(java.awt.event.KeyEvent e,
                               JXLayer<V> l)
Processes KeyEvent occurring on the JXLayer or any of its subcomponents.

Parameters:
e - the KeyEvent to be processed
l - the layer this LayerUI is set to