Class ComponentMouseEventDelegate<C extends JComponent>
- Type Parameters:
C- The type ofJComponentthat thisComponentMouseEventDelegateis delegating to.
- Direct Known Subclasses:
ComponentDragEventDelegate,TabDelegate
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 thePositionof the mouse event of this delegate without DPI scaling.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 without DPI scaling.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 without DPI scaling.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, getSize, getTooltip, getWidth, getX, getY, isEnabled, isOpaque, isVisible, paint, paint, paint, paint, parentDelegate, 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, 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 without DPI scaling. So the value is in "developer pixel" coordinate space relative to the underlying component. So a mouse position of (0,0) would be in the top left corner of the component.
For Context:
SwingTree supports high DPI scaling, but to achieve this it needs to scale the size of components for you depending on the currentUI.scale()factor.
This means that whatever dimensions you specify in methods likeUIForAnySwing.withSizeExactly(Size)are not necessarily going to be the equal to the actual size of the underlying component.
Therefore the component relative mouse position must be "unscaled" to be consistent from a developers point of view...- Returns:
- An integer value representing the x coordinate without DPI scaling (aka "developer pixel").
-
mouseY
public final int mouseY()Returns the y coordinate of the mouse event of this delegate without DPI scaling. So the value is in "developer pixel" coordinate space relative to the underlying component. So a mouse position of (0,0) would be in the top left corner of the component.
For Context:
SwingTree supports high DPI scaling, but to achieve this it needs to scale the size of components for you depending on the currentUI.scale()factor.
This means that whatever dimensions you specify in methods likeUIForAnySwing.withSizeExactly(Size)are not necessarily going to be the equal to the actual size of the underlying component.
Therefore the component relative mouse position must be "unscaled" to be consistent from a developers point of view...- Returns:
- An integer value representing the y coordinate without DPI scaling (aka "developer pixel").
-
mousePosition
Returns thePositionof the mouse event of this delegate without DPI scaling. So the x and y coordinates of the position is scaled to the "developer pixel" coordinate space relative to the underlying component. So a position of (0,0) is in the top left corner of the component.
For Context:
SwingTree supports high DPI scaling, but to achieve this it needs to scale the size of components for you depending on the currentUI.scale()factor.
This means that whatever dimensions you specify in methods likeUIForAnySwing.withSizeExactly(Size)are not necessarily going to be the equal to the actual size of the underlying component.
Therefore the component relative mouse position must be "unscaled" to be consistent from a developers point of view...- Returns:
- The component relative position of the mouse event in the developer pixel coordinate space (without DPI scaling applied).
-
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
-