Class JmriMouseEvent
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndicates mouse button #1; used bygetButton().static final intIndicates mouse button #2; used bygetButton().static final intIndicates mouse button #3; used bygetButton().static final intThe "mouse clicked" event.static final intThe "mouse dragged" event.static final intThe "mouse entered" event.static final intThe "mouse exited" event.static final intThe "mouse moved" event.static final intThe "mouse pressed" event.static final intThe "mouse released" event.static final intThe "mouse wheel" event.static final intIndicates no mouse buttons; used bygetButton(). -
Constructor Summary
ConstructorsConstructorDescriptionJmriMouseEvent(Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger) JmriMouseEvent(Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger, int button) JmriMouseEvent(MouseEvent event) -
Method Summary
Modifier and TypeMethodDescriptionvoidconsume()Consumes this event so that it will not be processed in the default manner by the source which originated it.intReturns which, if any, of the mouse buttons has changed state.intReturns the number of mouse clicks associated with this event.Returns the originator of the event.intgetID()Returns the event type.Returns the absolute x, y position of the event.intDeprecated.intReturns the extended modifier mask for this event.static StringgetMouseModifiersText(int modifiers) Returns aStringinstance describing the modifier keys and mouse buttons that were down during the event, such as "Shift", or "Ctrl+Shift".getPoint()Returns the x,y position of the event relative to the source component.The object on which the Event initially occurred.longgetWhen()Returns the difference in milliseconds between the timestamp of when this event occurred and midnight, January 1, 1970 UTC.intgetX()Returns the horizontal x position of the event relative to the source component.intReturns the absolute horizontal x position of the event.intgetY()Returns the vertical y position of the event relative to the source component.intReturns the absolute vertical y position of the event.booleanReturns whether or not the Alt modifier is down on this event.booleanReturns whether or not the AltGraph modifier is down on this event.booleanReturns whether or not the Control modifier is down on this event.booleanReturns whether or not the Meta modifier is down on this event.booleanReturns whether or not this mouse event is the popup menu trigger event for the platform.booleanReturns whether or not the Shift modifier is down on this event.Returns a parameter string identifying this event.voidtranslatePoint(int x, int y) Translates the event's coordinates to a new position by adding specifiedx(horizontal) andy(vertical) offsets.
-
Field Details
-
MOUSE_CLICKED
The "mouse clicked" event. ThisMouseEventoccurs when a mouse button is pressed and released.- See Also:
-
MOUSE_PRESSED
The "mouse pressed" event. ThisMouseEventoccurs when a mouse button is pushed down.- See Also:
-
MOUSE_RELEASED
The "mouse released" event. ThisMouseEventoccurs when a mouse button is let up.- See Also:
-
MOUSE_MOVED
The "mouse moved" event. ThisMouseEventoccurs when the mouse position changes.- See Also:
-
MOUSE_ENTERED
The "mouse entered" event. ThisMouseEventoccurs when the mouse cursor enters the unobscured part of component's geometry.- See Also:
-
MOUSE_EXITED
The "mouse exited" event. ThisMouseEventoccurs when the mouse cursor exits the unobscured part of component's geometry.- See Also:
-
MOUSE_DRAGGED
The "mouse dragged" event. ThisMouseEventoccurs when the mouse position changes while a mouse button is pressed.- See Also:
-
MOUSE_WHEEL
The "mouse wheel" event. This is the onlyMouseWheelEvent. It occurs when a mouse equipped with a wheel has its wheel rotated.- Since:
- 1.4
- See Also:
-
NOBUTTON
Indicates no mouse buttons; used bygetButton().- Since:
- 1.4
- See Also:
-
BUTTON1
Indicates mouse button #1; used bygetButton().- Since:
- 1.4
- See Also:
-
BUTTON2
Indicates mouse button #2; used bygetButton().- Since:
- 1.4
- See Also:
-
BUTTON3
Indicates mouse button #3; used bygetButton().- Since:
- 1.4
- See Also:
-
-
Constructor Details
-
JmriMouseEvent
-
JmriMouseEvent
public JmriMouseEvent(Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger) -
JmriMouseEvent
public JmriMouseEvent(Component source, int id, long when, int modifiers, int x, int y, int clickCount, boolean popupTrigger, int button)
-
-
Method Details
-
getID
Returns the event type.- Returns:
- the event's type id
-
getLocationOnScreen
Returns the absolute x, y position of the event. In a virtual device multi-screen environment in which the desktop area could span multiple physical screen devices, these coordinates are relative to the virtual coordinate system. Otherwise, these coordinates are relative to the coordinate system associated with the Component's GraphicsConfiguration.- Returns:
- a
Pointobject containing the absolute x and y coordinates. - Since:
- 1.6
- See Also:
-
getXOnScreen
Returns the absolute horizontal x position of the event. 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.
- Since:
- 1.6
- See Also:
-
getYOnScreen
Returns the absolute vertical y position of the event. 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:
- y an integer indicating absolute vertical position.
- Since:
- 1.6
- See Also:
-
getX
Returns the horizontal x position of the event relative to the source component.- Returns:
- x an integer indicating horizontal position relative to the component
-
getY
Returns the vertical y position of the event relative to the source component.- Returns:
- y an integer indicating vertical position relative to the component
-
getPoint
Returns the x,y position of the event relative to the source component.- Returns:
- a
Pointobject containing the x and y coordinates relative to the source component
-
translatePoint
Translates the event's coordinates to a new position by adding specifiedx(horizontal) andy(vertical) offsets.- Parameters:
x- the horizontal x value to add to the current x coordinate positiony- the vertical y value to add to the current y coordinate position
-
getClickCount
Returns the number of mouse clicks associated with this event.- Returns:
- integer value for the number of clicks
-
getButton
Returns which, if any, of the mouse buttons has changed state. The returned value is ranged from 0 to theMouseInfo.getNumberOfButtons()value. The returned value includes at least the following constants:-
NOBUTTON -
BUTTON1 -
BUTTON2 -
BUTTON3
if (anEvent.getButton() == JmriMouseEvent.BUTTON1) {In particular, for a mouse with one, two, or three buttons this method may return the following values:- 0 (
NOBUTTON) - 1 (
BUTTON1) - 2 (
BUTTON2) - 3 (
BUTTON3)
BUTTON3have no constant identifier. So if a mouse with five buttons is installed, this method may return the following values:- 0 (
NOBUTTON) - 1 (
BUTTON1) - 2 (
BUTTON2) - 3 (
BUTTON3) - 4
- 5
Note: If support for extended mouse buttons is
disabledby Java then the AWT event subsystem does not produce mouse events for the extended mouse buttons. So it is not expected that this method returns anything exceptNOBUTTON,BUTTON1,BUTTON2,BUTTON3.- Returns:
- one of the values from 0 to
MouseInfo.getNumberOfButtons()if support for the extended mouse buttons isenabledby Java. That range includesNOBUTTON,BUTTON1,BUTTON2,BUTTON3;
NOBUTTON,BUTTON1,BUTTON2orBUTTON3if support for the extended mouse buttons isdisabledby Java - Since:
- 1.4
- See Also:
-
-
isPopupTrigger
Returns whether or not this mouse event is the popup menu trigger event for the platform.Note: Popup menus are triggered differently on different systems. Therefore,
isPopupTriggershould be checked in bothmousePressedandmouseReleasedfor proper cross-platform functionality.- Returns:
- boolean, true if this event is the popup menu trigger for this platform
-
getMouseModifiersText
Returns aStringinstance describing the modifier keys and mouse buttons that were down during the event, such as "Shift", or "Ctrl+Shift". These strings can be localized by changing theawt.propertiesfile.Note that the
InputEvent.ALT_MASKandInputEvent.BUTTON2_MASKhave equal values, so the "Alt" string is returned for both modifiers. Likewise, theInputEvent.META_MASKandInputEvent.BUTTON3_MASKhave equal values, so the "Meta" string is returned for both modifiers.Note that passing negative parameter is incorrect, and will cause the returning an unspecified string. Zero parameter means that no modifiers were passed and will cause the returning an empty string.
- Parameters:
modifiers- A modifier mask describing the modifier keys and mouse buttons that were down during the event- Returns:
- string string text description of the combination of modifier keys and mouse buttons that were down during the event
- Since:
- 1.4
- See Also:
-
paramString
Returns a parameter string identifying this event. This method is useful for event-logging and for debugging.- Returns:
- a string identifying the event and its attributes
-
isShiftDown
Returns whether or not the Shift modifier is down on this event.- Returns:
- whether or not the Shift modifier is down on this event
-
isControlDown
Returns whether or not the Control modifier is down on this event.- Returns:
- whether or not the Control modifier is down on this event
-
isMetaDown
Returns whether or not the Meta modifier is down on this event. The meta key was until Java 8 the right mouse button on Windows. On Java 9 on Windows 10, there is no more meta key. Note that this method is called both on mouse button events and mouse move events, and therefore "event.getButton() == JmriMouseEvent.BUTTON3" doesn't work. As of Java 11, the meta key process has changed. The getModifiersEx() value will vary when button 3 is used, depending on the mouse event. mousePressed :: 4096 (button 3) mouseDragged :: 4096 mouseReleased :: 256 (meta) mouseClicked :: 256 The meta value is simulated by Java for Linux and Windows based on button 3 being active.- Returns:
- whether or not the Meta modifier is down on this event
-
isAltDown
Returns whether or not the Alt modifier is down on this event.- Returns:
- whether or not the Alt modifier is down on this event
-
isAltGraphDown
Returns whether or not the AltGraph modifier is down on this event.- Returns:
- whether or not the AltGraph modifier is down on this event
-
getWhen
Returns the difference in milliseconds between the timestamp of when this event occurred and midnight, January 1, 1970 UTC.- Returns:
- the difference in milliseconds between the timestamp and midnight, January 1, 1970 UTC
-
getModifiers
Deprecated.It is recommended that extended modifier keys andgetModifiersEx()be used insteadReturns the modifier mask for this event.- Returns:
- the modifier mask for this event
-
getModifiersEx
Returns the extended modifier mask for this event.Extended modifiers are the modifiers that ends with the _DOWN_MASK suffix, such as ALT_DOWN_MASK, BUTTON1_DOWN_MASK, and others.
Extended modifiers represent the state of all modal keys, such as ALT, CTRL, META, and the mouse buttons just after the event occurred.
For example, if the user presses button 1 followed by button 2, and then releases them in the same order, the following sequence of events is generated:
MOUSE_PRESSED:BUTTON1_DOWN_MASKMOUSE_PRESSED:BUTTON1_DOWN_MASK | BUTTON2_DOWN_MASKMOUSE_RELEASED:BUTTON2_DOWN_MASKMOUSE_CLICKED:BUTTON2_DOWN_MASKMOUSE_RELEASED:MOUSE_CLICKED:It is not recommended to compare the return value of this method using
==because new modifiers can be added in the future. For example, the appropriate way to check that SHIFT and BUTTON1 are down, but CTRL is up is demonstrated by the following code:int onmask = SHIFT_DOWN_MASK | BUTTON1_DOWN_MASK; int offmask = CTRL_DOWN_MASK; if ((event.getModifiersEx() & (onmask | offmask)) == onmask) { ... }The above code will work even if new modifiers are added.- Returns:
- the extended modifier mask for this event
- Since:
- 1.4
-
getComponent
Returns the originator of the event.- Returns:
- the
Componentobject that originated the event, ornullif the object is not aComponent.
-
getSource
The object on which the Event initially occurred.- Returns:
- the object on which the Event initially occurred
-
consume
Consumes this event so that it will not be processed in the default manner by the source which originated it.
-
getModifiersEx()be used instead