public abstract class RolloverProducer extends Object implements MouseListener, MouseMotionListener, ComponentListener
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.
Modifier and Type | Field and Description |
---|---|
static String |
CLICKED_KEY
Key for client property mapped from mouse-triggered action.
|
private boolean |
isDragging |
private static Logger |
LOG |
protected Point |
rollover
Current mouse location in client coordinates.
|
static String |
ROLLOVER_KEY
Key for client property mapped from rollover events
|
Constructor and Description |
---|
RolloverProducer() |
Modifier and Type | Method and Description |
---|---|
void |
componentHidden(ComponentEvent e) |
void |
componentMoved(ComponentEvent e) |
void |
componentResized(ComponentEvent e) |
void |
componentShown(ComponentEvent e) |
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.
|
void |
mouseClicked(MouseEvent e)
Implemented to do nothing.
|
void |
mouseDragged(MouseEvent e)
Implemented to set a dragging flag to true.
|
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. if the
source is a JComponent.
|
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 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.
|
private void |
updateRollover(ComponentEvent e) |
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.
|
public static final String CLICKED_KEY
public static final String ROLLOVER_KEY
private boolean isDragging
public RolloverProducer()
public void install(JComponent component)
component
- target to install required listeners on, must
not be null.public void release(JComponent component)
component
- target component to uninstall required listeners from,
must not be nullpublic void mouseReleased(MouseEvent e)
mouseReleased
in interface MouseListener
protected boolean isClick(MouseEvent e, Point oldRollover, boolean wasDragging)
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.
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 happenedpublic void mouseEntered(MouseEvent e)
mouseEntered
in interface MouseListener
public void mouseExited(MouseEvent e)
mouseExited
in interface MouseListener
public void mouseClicked(MouseEvent e)
mouseClicked
in interface MouseListener
public void mousePressed(MouseEvent e)
mousePressed
in interface MouseListener
public void mouseDragged(MouseEvent e)
mouseDragged
in interface MouseMotionListener
public void mouseMoved(MouseEvent e)
mouseMoved
in interface MouseMotionListener
public void componentShown(ComponentEvent e)
componentShown
in interface ComponentListener
public void componentResized(ComponentEvent e)
componentResized
in interface ComponentListener
public void componentMoved(ComponentEvent e)
componentMoved
in interface ComponentListener
private void updateRollover(ComponentEvent e)
e
- public void componentHidden(ComponentEvent e)
componentHidden
in interface ComponentListener
protected void updateRollover(MouseEvent e, String property, boolean fireAlways)
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.updateRolloverPoint(JComponent, Point)
,
updateClientProperty(JComponent, String, boolean)
protected void updateClientProperty(JComponent component, String property, boolean fireAlways)
component
- the target componentproperty
- the client property to setfireAlways
- a flag indicating whether a client property
should be forced to fire an event.protected abstract void updateRolloverPoint(JComponent component, Point mousePoint)
component
- the target component which received a mouse eventmousePoint
- the mouse position of the event, coordinates are
component pixelsWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses