org.jdesktop.jxlayer.plaf.ext
Class MouseScrollableUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by org.jdesktop.jxlayer.plaf.LayerUI<V>
          extended by org.jdesktop.jxlayer.plaf.AbstractLayerUI<javax.swing.JScrollPane>
              extended by org.jdesktop.jxlayer.plaf.ext.MouseScrollableUI
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, LayerItem

public class MouseScrollableUI
extends AbstractLayerUI<javax.swing.JScrollPane>
implements java.awt.event.ActionListener

The MouseScrollableUI provides the mouse auto-scrolling feature for your applications. Wrap your JScrollPane with a JXLayer, set an instance of MouseScrollableUI as the JXLayer's ui and after that, pressing the middle mouse button inside the JScrollPane will activate the auto-scrolling mode.

Here is an example of using MouseScrollableUI:

 // a JScrollPane to be enhanced with mouse auto-scrolling
 JScrollPane myScrollPane = getMyScrollPane();
 

JXLayer<JScrollPane> layer = new JXLayer<JScrollPane>(myScrollPane, new MouseScrollableUI());

// add the layer to a frame or a panel, like any other component frame.add(layer);

The MouseScrollableDemo is available


Constructor Summary
MouseScrollableUI()
          Creates a new instance of MouseScrollableUI.
MouseScrollableUI(boolean isAWTEventListenerEnabled)
          Creates a new instance of MouseScrollableUI.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 void eventDispatched(java.awt.AWTEvent e, JXLayer<javax.swing.JScrollPane> 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.

Preprocesses the AWTEvent to deactivate mouse scrolling when any key was pressed or focus left the JXLayer.

 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 AbstractLayerUI.registerAWTEventListener(JXLayer, long) will be called from installUI(JComponent) with AbstractLayerUI.getLayerEventMask() as the second parameter and AbstractLayerUI.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 isMouseScrollingTrigger(java.awt.event.MouseEvent mouseEvent)
          Returns true if mouseEvent is a mouse auto-scrolling trigger.
protected  void processMouseEvent(java.awt.event.MouseEvent e, JXLayer<javax.swing.JScrollPane> l)
          Processes MouseEvent occurring on the JXLayer or any of its subcomponents.

Activates the mouse auto-scrolling if e is a scrolling trigger.

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

Scrolls the JXLayer's view JScrollPane if mouse scrolling is activated

 void setEnabled(boolean enabled)
          Enables or disables this component, depending on the value of the parameter enabled.

Deactivates the mouse scrolling for disabled MouseScrollableUI

 void uninstallUI(javax.swing.JComponent c)
          Reverses configuration which was done on the specified component during installUI(JComponent).
 
Methods inherited from class org.jdesktop.jxlayer.plaf.AbstractLayerUI
addLayerItemListener, addPropertyChangeListener, addPropertyChangeListener, configureGraphics, fireLayerItemChanged, fireLayerItemChanged, firePropertyChange, getClip, getComposite, getLayerEventMask, getLayerItemListeners, getPropertyChangeListeners, getPropertyChangeListeners, getRenderingHints, getTransform, isDirty, isEnabled, paint, paintLayer, processFocusEvent, processKeyEvent, processMouseWheelEvent, registerAWTEventListener, removeLayerItemListener, removePropertyChangeListener, removePropertyChangeListener, setDirty, setLayerEventMask, unregisterAWTEventListener
 
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

MouseScrollableUI

public MouseScrollableUI()
Creates a new instance of MouseScrollableUI.


MouseScrollableUI

public MouseScrollableUI(boolean isAWTEventListenerEnabled)
Creates a new instance of MouseScrollableUI.

Parameters:
isAWTEventListenerEnabled - if true then the AWTEventListener will be used to catch the AWT events
Method Detail

installUI

public void installUI(javax.swing.JComponent c)
Description copied from class: AbstractLayerUI
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 AbstractLayerUI<javax.swing.JScrollPane>
Parameters:
c - the JXLayer where this UI delegate is being installed
See Also:
AbstractLayerUI.uninstallUI(JComponent)

uninstallUI

public void uninstallUI(javax.swing.JComponent c)
Description copied from class: AbstractLayerUI
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 AbstractLayerUI<javax.swing.JScrollPane>
Parameters:
c - the JXLayer where this UI delegate is being installed
See Also:
AbstractLayerUI.installUI(JComponent)

isAWTEventListenerEnabled

protected boolean isAWTEventListenerEnabled()
Returns true if this AbstractLayerUI catches AWT events with help of AWTEventListener, in this case AbstractLayerUI.registerAWTEventListener(JXLayer, long) will be called from installUI(JComponent) with AbstractLayerUI.getLayerEventMask() as the second parameter and AbstractLayerUI.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

Overrides:
isAWTEventListenerEnabled in class AbstractLayerUI<javax.swing.JScrollPane>
Returns:
true if this AbstractLayerUI catches AWT events with help of AWTEventListener
See Also:
(), AbstractLayerUI.registerAWTEventListener(JXLayer, long)

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.

Deactivates the mouse scrolling for disabled MouseScrollableUI

Overrides:
setEnabled in class AbstractLayerUI<javax.swing.JScrollPane>
Parameters:
enabled - If true, this AbstractLayerUI is enabled; otherwise this AbstractLayerUI is disabled

processMouseEvent

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

Activates the mouse auto-scrolling if e is a scrolling trigger.

Overrides:
processMouseEvent in class AbstractLayerUI<javax.swing.JScrollPane>
Parameters:
e - the MouseEvent to be processed
l - the layer this LayerUI is set to
See Also:
isMouseScrollingTrigger(MouseEvent)

isMouseScrollingTrigger

protected boolean isMouseScrollingTrigger(java.awt.event.MouseEvent mouseEvent)
Returns true if mouseEvent is a mouse auto-scrolling trigger.

Parameters:
mouseEvent - the mouseEvent to be tested
Returns:
true if mouseEvent is a mouse auto-scrolling trigger, otherwise returns false

processMouseMotionEvent

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

Scrolls the JXLayer's view JScrollPane if mouse scrolling is activated

Overrides:
processMouseMotionEvent in class AbstractLayerUI<javax.swing.JScrollPane>
Parameters:
e - the MouseEvent to be processed
l - the layer this LayerUI is set to

eventDispatched

public void eventDispatched(java.awt.AWTEvent e,
                            JXLayer<javax.swing.JScrollPane> 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.

Preprocesses the AWTEvent to deactivate mouse scrolling when any key was pressed or focus left the JXLayer.

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

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener