public void mouseReleased(MouseEvent e) { lastInteractionTime = System.currentTimeMillis(); if (enabled && !readOnly && lastPressEvent != null && dragInProgress) { if (enableMouseDrags && !e.getPoint().equals(lastPressEvent.getPoint())) { dragInProgress = false; // Generate the command string String s = "Mouse " + MouseCommand.MOUSE_DRAG; // Insert the button identifier if other than left button was pressed if (e.getButton() != MouseEvent.BUTTON1) { s += " " + MouseCommand.PARAM_BUTTON_SHORT + "=" + parser.buttonToString(e.getButton()); } // Insert modifiers if there are any String modifiers = parser.modifiersToString(e.getModifiers()); if (modifiers.length() > 0) { s += " " + MouseCommand.PARAM_MODIFIER + "=" + modifiers; } // Generate coordinates s += " " + MouseCommand.PARAM_FROM + "=" + parser.pointToString(lastPressEvent.getPoint()); s += " " + MouseCommand.PARAM_TO + "=" + parser.pointToString(e.getPoint()); // Insert the command to the current editor insertLine(s, false, true, false); insertEvent(e); } } }
/** * Implementation of the ActionListener interface. It is only called by a timer which is * associated with mouse moves (see mouseMoved method). * * @param e an ActionEvent instance. */ public void actionPerformed(ActionEvent e) { timer.stop(); if (enabled && !readOnly && lastMouseMoveEvent != null) { String s = "Mouse " + MouseCommand.MOUSE_MOVE + " " + MouseCommand.PARAM_TO + "=" + parser.pointToString(lastMouseMoveEvent.getPoint()); insertLine(s, false, true, false); insertEvent(lastMouseMoveEvent); mouseMovesList.clear(); } }
/** * This method gets called when user performs a mouse click. It decodes whether it is a single * click or part of a multiple click (double click, triple click etc.) and inserts appropriate * command to the current editor. * * @param e a MouseEvent describing the mouse click. */ public void mouseClicked(MouseEvent e) { if (enabled && !readOnly) { if (timer != null && timer.isRunning()) { timer.stop(); } if (enableMouseClicks) { int count = 1; MouseEvent e2; long lastEventTime = e.getWhen(); // This cycle is to determine multiple clicks like double click, triple click etc. // We go through the vector of events and check whether there are events corresponding to // multiple clicks. for (int i = 0; i < events.size() && events.get(i) instanceof MouseEvent; i++) { e2 = (MouseEvent) events.get(i); // The events are considered to be a multiple click when: // 1. Coordinates are equal // 2. Modifiers are equal // 3. Button is equal // 4. Delay between two subsequent clicks is lower than given number of miliseconds if (e2.getX() == e.getX() && e2.getY() == e.getY() && e2.getModifiers() == e.getModifiers() && (lastEventTime - e2.getWhen() < mouseMultiDelay) && e.getButton() == e2.getButton() && e2.getID() == e.getID()) { count++; lastEventTime = e2.getWhen(); } else { break; } } // Generate the command string String s = "Mouse " + MouseCommand.MOUSE_CLICK; // Insert the button identifier if other than left button was pressed if (e.getButton() != MouseEvent.BUTTON1) { s += " " + MouseCommand.PARAM_BUTTON_SHORT + "=" + parser.buttonToString(e.getButton()); } // Insert modifiers if there are any String modifiers = parser.modifiersToString(e.getModifiers()); if (modifiers.length() > 0) { s += " " + MouseCommand.PARAM_MODIFIER + "=" + modifiers; } // Generate the count parameter if (count > 1) { s += " " + MouseCommand.PARAM_COUNT + "=" + count; } // This will determine whether this click is preceded by a mouse // move command with the same coordinates. // It will be replaced if yes. boolean replaceLastMove = false; // if (enableMouseMoves) { // if (events.size() > 0 && events.get(events.size() - 1) instanceof // MouseEvent) { // MouseEvent me = (MouseEvent) events.get(events.size() - 1); // if (me.getID() == MouseEvent.MOUSE_MOVED && e.getX() == me.getX() // && e.getY() == me.getY()) { // replaceLastMove = true; // } // } // } // Generate coordinates s += " " + MouseCommand.PARAM_TO + "=" + parser.pointToString(e.getPoint()); // Insert the command to the current editor insertLine(s, count > 1 || replaceLastMove, true, false); dragInProgress = false; } insertEvent(e); } }
public void mouseWheelMoved(MouseWheelEvent e) { if (enabled && !readOnly) { if (timer != null && timer.isRunning()) { timer.stop(); } if (enableMouseWheel) { int count = 1; MouseWheelEvent e2; long lastEventTime = e.getWhen(); int steps = 0; int r; // This cycle is to determine multiple clicks like double wheel, triple wheel event etc. // We go through the vector of events and check whether there are events corresponding to // multiple events. for (int i = 0; i < events.size() && events.get(i) instanceof MouseWheelEvent; i++) { e2 = (MouseWheelEvent) events.get(i); // The events are considered to be a multiple click when: // 1. Coordinates are equal // 2. Modifiers are equal // 3. Both events are wheel up or down // 4. Delay between two subsequent clicks is lower than given number of miliseconds r = e2.getWheelRotation(); if (e2.getX() == e.getX() && e2.getY() == e.getY() && e2.getModifiers() == e.getModifiers() && (lastEventTime - e2.getWhen() < mouseMultiDelay) && e2.getID() == e.getID() && ((r > 0 && e.getWheelRotation() > 0) || (r < 0 && e.getWheelRotation() < 0))) { count++; lastEventTime = e2.getWhen(); steps += Math.abs(r); } else { break; } } steps += Math.abs(e.getWheelRotation()); // Generate the command string String s = "Mouse " + (e.getWheelRotation() > 0 ? MouseCommand.MOUSE_WHEEL_DOWN : MouseCommand.MOUSE_WHEEL_UP); // Insert modifiers if there are any String modifiers = parser.modifiersToString(e.getModifiers()); if (modifiers.length() > 0) { s += " " + MouseCommand.PARAM_MODIFIER + "=" + modifiers; } // Generate the count parameter if (count > 1) { s += " " + MouseCommand.PARAM_COUNT + "=" + Math.abs(steps); } // This will determine whether this event is preceded by a mouse move command with the same // coordinates. // It will be replaced if yes. boolean replaceLastMove = false; if (enableMouseMoves) { if (events.size() > 0 && events.get(events.size() - 1) instanceof MouseEvent) { MouseEvent me = (MouseEvent) events.get(events.size() - 1); if (me.getID() == MouseEvent.MOUSE_MOVED && e.getX() == me.getX() && e.getY() == me.getY()) { replaceLastMove = true; } } } // Generate coordinates s += " " + MouseCommand.PARAM_TO + "=" + parser.pointToString(e.getPoint()); // Insert the command to the current editor insertLine(s, count > 1 || replaceLastMove, true, false); dragInProgress = false; } insertEvent(e); } }