Package swingtree
Class ComponentMouseEventDelegate<C extends JComponent>
java.lang.Object
swingtree.AbstractDelegate<C>
swingtree.ComponentDelegate<C,MouseEvent>
swingtree.ComponentMouseEventDelegate<C>
- Type Parameters:
C- The type ofJComponentthat thisComponentMouseEventDelegateis delegating to.
- Direct Known Subclasses:
ComponentDragEventDelegate,TabDelegate
public class ComponentMouseEventDelegate<C extends JComponent>
extends ComponentDelegate<C,MouseEvent>
A
This delegate is designed to provide clutter-free access to both the concrete
JComponent as well as MouseEvent delegate
providing useful context information to various Action listeners which are
typically registered through
UIForAnySwing.onMouseClick(sprouts.Action)},
UIForAnySwing.onMousePress(sprouts.Action) and
UIForAnySwing.onMouseRelease(sprouts.Action), among others.
This delegate is designed to provide clutter-free access to both the concrete
JComponent subtype C as well a the MouseEvent
which triggered the action.
Here is an example of how this delegate is typically exposed in your Action:
UI.panel()
.onMouseMove( it -> {
System.out.println("Moved on " + it.get());
System.out.println("Moved at " + it.mouseX() + ", " + it.mouseY());
})
.onMouseClick( it -> {
System.out.println("Clicked on " + it.get());
System.out.println("Click count: " + it.clickCount());
})
//...
For some more examples please take a look at the living swing-tree documentation.
-
Method Summary
Modifier and TypeMethodDescriptionfinal intReturns the number of mouse clicks associated with the event of this delegate.final booleanReturns whether the Alt modifier is down on the event of this delegate.final booleanReturns whether the Control modifier is down on the event of this delegate.final booleanReturns true if the mouse event of this delegate is the left mouse button.final booleanReturns whether the Meta modifier is down on the event of this delegate.final booleanReturns true if the mouse event of this delegate is the middle mouse button.final booleanReturns true if the mouse event of this delegate is the right mouse button.final booleanReturns whether the Shift modifier is down on the event of this delegate.final PositionReturns the position of the mouse event of this delegate in the form of an immutablePositionvalue object.final PositionReturns the absolute x and y position of the event of this delegate in the form of an immutablePositionvalue object.final intmouseX()Returns the x coordinate of the mouse event of this delegate.final intReturns the absolute horizontal x position of the event of this delegate.final intmouseY()Returns the y coordinate of the mouse event of this delegate.final intReturns the absolute vertical y position of the event of this delegate.Methods inherited from class swingtree.ComponentDelegate
forComponent, forSiblinghood, forSiblinghoodOfType, forSiblings, forSiblingsOfType, getComponent, getEvent, getSiblinghood, getSiblinghoodOfType, getSiblings, getSiblingsOfTypeMethods inherited from class swingtree.AbstractDelegate
_component, _isUndefinedColor, _isUndefinedFont, _siblingsSource, animateFor, animateFor, animateFor, animateFor, animateStyleFor, animateStyleFor, find, find, find, findAll, findAllByGroup, findAllByGroup, findAllByGroup, findAllByGroup, get, getBackground, getBorder, getBounds, getCursor, getFont, getForeground, getHeight, getLocation, getMaxSize, getMinSize, getParent, getPrefSize, getScale, getSize, getTooltip, getWidth, getX, getY, isEnabled, isOpaque, isVisible, paint, paint, paint, paint, parentDelegate, scale, scale, scale, scale, setBackground, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBorder, setBounds, setBounds, setBounds, setCursor, setCursor, setEnabled, setFont, setForeground, setForegroundColor, setForegroundColor, setForegroundColor, setForegroundColor, setHeight, setMaxHeight, setMaxSize, setMaxSize, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinSize, setMinSize, setMinWidth, setOpaque, setPrefHeight, setPrefSize, setPrefSize, setPrefSize, setPrefWidth, setSize, setSize, setSize, setTooltip, setVisible, setWidth, shapeOf, style
-
Method Details
-
isLeftMouseButton
public final boolean isLeftMouseButton()Returns true if the mouse event of this delegate is the left mouse button.- Returns:
- true if the left mouse button was active
-
isRightMouseButton
public final boolean isRightMouseButton()Returns true if the mouse event of this delegate is the right mouse button.- Returns:
- true if the right mouse button was active
-
isMiddleMouseButton
public final boolean isMiddleMouseButton()Returns true if the mouse event of this delegate is the middle mouse button.- Returns:
- true if the middle mouse button was active
-
isAltDown
public final boolean isAltDown()Returns whether the Alt modifier is down on the event of this delegate.- Returns:
- true if the alt modifier is down
-
isCtrlDown
public final boolean isCtrlDown()Returns whether the Control modifier is down on the event of this delegate.- Returns:
- true if the control modifier is down
-
isShiftDown
public final boolean isShiftDown()Returns whether the Shift modifier is down on the event of this delegate.- Returns:
- true if the shift modifier is down
-
isMetaDown
public final boolean isMetaDown()Returns whether the Meta modifier is down on the event of this delegate.- Returns:
- true if the meta modifier is down
-
clickCount
public final int clickCount()Returns the number of mouse clicks associated with the event of this delegate. You can use the returned number to distinguish between single-click and double-click events.- Returns:
- An integer indicating the number of mouse clicks associated with the mouse event.
-
mouseX
public final int mouseX()Returns the x coordinate of the mouse event of this delegate.- Returns:
- integer value for the x coordinate
-
mouseY
public final int mouseY()Returns the y coordinate of the mouse event of this delegate.- Returns:
- integer value for the y coordinate
-
mousePosition
Returns the position of the mouse event of this delegate in the form of an immutablePositionvalue object. So you may safely share this object without having to worry about side effects.- Returns:
- the position of the mouse event
-
mouseXOnScreen
public final int mouseXOnScreen()Returns the absolute horizontal x position of the event of this delegate. In a virtual device multi-screen environment in which the desktop area could span multiple physical screen devices, this coordinate is relative to the virtual coordinate system. Otherwise, this coordinate is relative to the coordinate system associated with the Component's GraphicsConfiguration.- Returns:
- x an integer indicating absolute horizontal position.
-
mouseYOnScreen
public final int mouseYOnScreen()Returns the absolute vertical y position of the event of this delegate. In a virtual device multiscreen environment in which the desktop area could span multiple physical screen devices, this coordinate is relative to the virtual coordinate system. Otherwise, this coordinate is relative to the coordinate system associated with the Component's GraphicsConfiguration.- Returns:
- y an integer indicating absolute vertical position.
-
mousePositionOnScreen
Returns the absolute x and y position of the event of this delegate in the form of an immutablePositionvalue object. So you may safely share this object without having to worry about side effects.- Returns:
- the absolute position of the mouse event
-