org.jdesktop.swingx.rollover
Class RolloverProducer

java.lang.Object
  extended by org.jdesktop.swingx.rollover.RolloverProducer
All Implemented Interfaces:
ComponentListener, MouseListener, MouseMotionListener, EventListener
Direct Known Subclasses:
ListRolloverProducer, TableRolloverProducer, TreeRolloverProducer

public abstract class RolloverProducer
extends Object
implements MouseListener, MouseMotionListener, ComponentListener

Mouse/Motion/Listener which maps mouse coordinates to client coordinates and stores these as client properties in the target JComponent. The exact mapping process is left to subclasses. Typically, they will map to "cell" coordinates.

Note: this class assumes that the target component is of type JComponent.

Note: this implementation is stateful, it can't be shared across different instances of a target component.


Field Summary
static String CLICKED_KEY
          Key for client property mapped from mouse-triggered action.
protected  Point rollover
          Current mouse location in client coordinates.
static String ROLLOVER_KEY
          Key for client property mapped from rollover events
 
Constructor Summary
RolloverProducer()
           
 
Method Summary
 void componentHidden(ComponentEvent e)
          Invoked when the component has been made invisible.
 void componentMoved(ComponentEvent e)
          Invoked when the component's position changes.
 void componentResized(ComponentEvent e)
          Invoked when the component's size changes.
 void componentShown(ComponentEvent e)
          Invoked when the component has been made visible.
 void install(JComponent component)
          Installs all listeners, as required.
 void mouseClicked(MouseEvent e)
          Implemented to do nothing.
 void mouseDragged(MouseEvent e)
          Implemented to do nothing.
 void mouseEntered(MouseEvent e)
          Implemented to map to client property rollover and fire only if client coordinate changed.
 void mouseExited(MouseEvent e)
          Implemented to remove client properties rollover and clicked.
 void mouseMoved(MouseEvent e)
          Implemented to map to client property rollover and fire only if client coordinate changed.
 void mousePressed(MouseEvent e)
          Implemented to do nothing.
 void mouseReleased(MouseEvent e)
          Implemented to map to client property clicked and fire always.
 void release(JComponent component)
          Removes all listeners.
protected  void updateClientProperty(JComponent component, String property, boolean fireAlways)
          Sets the given client property to the value of current mouse location in client coordinates.
protected  void updateRollover(MouseEvent e, String property, boolean fireAlways)
          Controls the mapping of the given mouse event to a client property.
protected abstract  void updateRolloverPoint(JComponent component, Point mousePoint)
          Subclasses must implement to map the given mouse coordinates into appropriate client coordinates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLICKED_KEY

public static final String CLICKED_KEY
Key for client property mapped from mouse-triggered action. Note that the actual mouse-event which results in setting the property depends on the implementation of the concrete RolloverProducer.

See Also:
Constant Field Values

ROLLOVER_KEY

public static final String ROLLOVER_KEY
Key for client property mapped from rollover events

See Also:
Constant Field Values

rollover

protected Point rollover
Current mouse location in client coordinates.

Constructor Detail

RolloverProducer

public RolloverProducer()
Method Detail

install

public void install(JComponent component)
Installs all listeners, as required.

Parameters:
component - target to install required listeners on, must not be null.

release

public void release(JComponent component)
Removes all listeners.

Parameters:
component - target component to uninstall required listeners from, must not be null

mouseReleased

public void mouseReleased(MouseEvent e)
Implemented to map to client property clicked and fire always.

Specified by:
mouseReleased in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Implemented to map to client property rollover and fire only if client coordinate changed.

Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Implemented to remove client properties rollover and clicked. if the source is a JComponent. Does nothing otherwise.

Specified by:
mouseExited in interface MouseListener

mouseClicked

public void mouseClicked(MouseEvent e)
Implemented to do nothing.

Specified by:
mouseClicked in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Implemented to do nothing.

Specified by:
mousePressed in interface MouseListener

mouseDragged

public void mouseDragged(MouseEvent e)
Implemented to do nothing. PENDING JW: probably should do something? Mapped coordinates will be out of synch after a drag.

Specified by:
mouseDragged in interface MouseMotionListener

mouseMoved

public void mouseMoved(MouseEvent e)
Implemented to map to client property rollover and fire only if client coordinate changed.

Specified by:
mouseMoved in interface MouseMotionListener

componentShown

public void componentShown(ComponentEvent e)
Description copied from interface: java.awt.event.ComponentListener
Invoked when the component has been made visible.

Specified by:
componentShown in interface ComponentListener

componentResized

public void componentResized(ComponentEvent e)
Description copied from interface: java.awt.event.ComponentListener
Invoked when the component's size changes.

Specified by:
componentResized in interface ComponentListener

componentMoved

public void componentMoved(ComponentEvent e)
Description copied from interface: java.awt.event.ComponentListener
Invoked when the component's position changes.

Specified by:
componentMoved in interface ComponentListener

componentHidden

public void componentHidden(ComponentEvent e)
Description copied from interface: java.awt.event.ComponentListener
Invoked when the component has been made invisible.

Specified by:
componentHidden in interface ComponentListener

updateRollover

protected void updateRollover(MouseEvent e,
                              String property,
                              boolean fireAlways)
Controls the mapping of the given mouse event to a client property. This implementation first calls updateRolloverPoint to convert the mouse coordinates. Then calls updateClientProperty to actually set the client property in the

Parameters:
e - the MouseEvent to map to client coordinates
property - the client property to map to
fireAlways - a flag indicating whether a client event should be fired if unchanged.
See Also:
updateRolloverPoint(JComponent, Point), updateClientProperty(JComponent, String, boolean)

updateClientProperty

protected void updateClientProperty(JComponent component,
                                    String property,
                                    boolean fireAlways)
Sets the given client property to the value of current mouse location in client coordinates. If fireAlways, the property is force to fire a change.

Parameters:
component - the target component
property - the client property to set
fireAlways - a flag indicating whether a client property should be forced to fire an event.

updateRolloverPoint

protected abstract void updateRolloverPoint(JComponent component,
                                            Point mousePoint)
Subclasses must implement to map the given mouse coordinates into appropriate client coordinates. The result must be stored in the rollover field.

Parameters:
component - the target component which received a mouse event
mousePoint - the mouse position of the event, coordinates are component pixels