Package org.jdesktop.swingx.rollover
Class RolloverProducer
java.lang.Object
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.
- Author:
- Jeanette Winzenburg
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
void
void
void
install
(JComponent component) Installs all listeners, as required.protected boolean
isClick
(MouseEvent e, Point oldRollover, boolean wasDragging) Returns a boolean indicating whether or not the given mouse event should be interpreted as a click.protected boolean
void
Implemented to do nothing.void
Implemented to set a dragging flag to true.void
Implemented to map to client property rollover and fire only if client coordinate changed.void
Implemented to remove client properties rollover and clicked. if the source is a JComponent.void
Implemented to map to client property rollover and fire only if client coordinate changed.void
Implemented to do nothing.void
Implemented to map to Rollover properties as needed.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.
-
Field Details
-
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:
-
ROLLOVER_KEY
Key for client property mapped from rollover events- See Also:
-
rollover
Current mouse location in client coordinates.
-
-
Constructor Details
-
RolloverProducer
public RolloverProducer()
-
-
Method Details
-
isDragging
protected boolean isDragging() -
install
Installs all listeners, as required.- Parameters:
component
- target to install required listeners on, must not be null.
-
release
Removes all listeners.- Parameters:
component
- target component to uninstall required listeners from, must not be null
-
mouseReleased
Implemented to map to Rollover properties as needed. This implemenation calls updateRollover with both ROLLOVER_KEY and CLICKED_KEY properties.- Specified by:
mouseReleased
in interfaceMouseListener
-
isClick
Returns a boolean indicating whether or not the given mouse event should be interpreted as a click. This method is called from mouseReleased after the cell coordiates were updated. While the ID of mouse event is not formally enforced, it is assumed to be a MOUSE_RELEASED. Calling for other types might or might not work as expected.This implementation returns true if the current rollover point is the same cell as the given oldRollover, that is ending a drag inside the same cell triggers the action while ending a drag somewhere does not.
PENDING JW: open to more complex logic in case it clashes with existing code, see Issue #1387.
- Parameters:
e
- the mouseEvent which triggered calling this, assumed to be a mouseReleased, must not be nulloldRollover
- the cell before the mouseEvent was mapped, must not be nullwasDragging
- true if the release happened- Returns:
- a boolean indicating whether or not the given mouseEvent should be interpreted as a click.
-
mouseEntered
Implemented to map to client property rollover and fire only if client coordinate changed.- Specified by:
mouseEntered
in interfaceMouseListener
-
mouseExited
Implemented to remove client properties rollover and clicked. if the source is a JComponent. Does nothing otherwise.- Specified by:
mouseExited
in interfaceMouseListener
-
mouseClicked
Implemented to do nothing.- Specified by:
mouseClicked
in interfaceMouseListener
-
mousePressed
Implemented to do nothing.- Specified by:
mousePressed
in interfaceMouseListener
-
mouseDragged
Implemented to set a dragging flag to true.- Specified by:
mouseDragged
in interfaceMouseMotionListener
-
mouseMoved
Implemented to map to client property rollover and fire only if client coordinate changed.- Specified by:
mouseMoved
in interfaceMouseMotionListener
-
componentShown
- Specified by:
componentShown
in interfaceComponentListener
-
componentResized
- Specified by:
componentResized
in interfaceComponentListener
-
componentMoved
- Specified by:
componentMoved
in interfaceComponentListener
-
componentHidden
- Specified by:
componentHidden
in interfaceComponentListener
-
updateRollover
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 coordinatesproperty
- the client property to map tofireAlways
- a flag indicating whether a client event should be fired if unchanged.- See Also:
-
updateClientProperty
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 componentproperty
- the client property to setfireAlways
- a flag indicating whether a client property should be forced to fire an event.
-
updateRolloverPoint
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 eventmousePoint
- the mouse position of the event, coordinates are component pixels
-