Package org.jline.terminal
Class MouseEvent
- java.lang.Object
-
- org.jline.terminal.MouseEvent
-
public class MouseEvent extends java.lang.Object
Represents a mouse event in a terminal that supports mouse tracking.The MouseEvent class encapsulates information about mouse actions in a terminal, including the type of event (press, release, move, etc.), which button was involved, any modifier keys that were pressed, and the coordinates where the event occurred.
Mouse events are only available in terminals that support mouse tracking, which can be enabled using
Terminal.trackMouse(Terminal.MouseTracking)
. Once mouse tracking is enabled, mouse events can be read usingTerminal.readMouseEvent()
.Mouse events include:
- Pressed - A mouse button was pressed
- Released - A mouse button was released
- Moved - The mouse was moved without any buttons pressed
- Dragged - The mouse was moved with a button pressed
- Wheel - The mouse wheel was scrolled
Example usage:
Terminal terminal = TerminalBuilder.terminal(); // Enable mouse tracking if (terminal.hasMouseSupport()) { terminal.trackMouse(Terminal.MouseTracking.Normal); // Read mouse events MouseEvent event = terminal.readMouseEvent(); System.out.println("Mouse event: type=" + event.getType() + ", button=" + event.getButton() + ", position=" + event.getX() + "," + event.getY()); }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MouseEvent.Button
Defines the mouse buttons that can be involved in a mouse event.static class
MouseEvent.Modifier
Defines the modifier keys that can be pressed during a mouse event.static class
MouseEvent.Type
Defines the types of mouse events that can occur.
-
Constructor Summary
Constructors Constructor Description MouseEvent(MouseEvent.Type type, MouseEvent.Button button, java.util.EnumSet<MouseEvent.Modifier> modifiers, int x, int y)
Creates a new MouseEvent with the specified parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MouseEvent.Button
getButton()
Returns the button involved in this mouse event.java.util.EnumSet<MouseEvent.Modifier>
getModifiers()
Returns the set of modifier keys pressed during this mouse event.MouseEvent.Type
getType()
Returns the type of this mouse event.int
getX()
Returns the column (horizontal) position of this mouse event.int
getY()
Returns the row (vertical) position of this mouse event.java.lang.String
toString()
Returns a string representation of this MouseEvent object.
-
-
-
Constructor Detail
-
MouseEvent
public MouseEvent(MouseEvent.Type type, MouseEvent.Button button, java.util.EnumSet<MouseEvent.Modifier> modifiers, int x, int y)
Creates a new MouseEvent with the specified parameters.- Parameters:
type
- the type of mouse event (press, release, etc.)button
- the button involved in the eventmodifiers
- the modifier keys pressed during the eventx
- the column (horizontal) position of the eventy
- the row (vertical) position of the event
-
-
Method Detail
-
getType
public MouseEvent.Type getType()
Returns the type of this mouse event.- Returns:
- the event type (press, release, move, etc.)
-
getButton
public MouseEvent.Button getButton()
Returns the button involved in this mouse event.- Returns:
- the mouse button
-
getModifiers
public java.util.EnumSet<MouseEvent.Modifier> getModifiers()
Returns the set of modifier keys pressed during this mouse event.- Returns:
- the set of modifier keys (Shift, Alt, Control)
-
getX
public int getX()
Returns the column (horizontal) position of this mouse event.- Returns:
- the X coordinate (column)
-
getY
public int getY()
Returns the row (vertical) position of this mouse event.- Returns:
- the Y coordinate (row)
-
toString
public java.lang.String toString()
Returns a string representation of this MouseEvent object.The string representation includes all properties of the mouse event: the event type, button, modifier keys, and coordinates.
Example output:
MouseEvent[type=Pressed, button=Button1, modifiers=[Shift], x=10, y=20]
- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of this object
-
-