Java Code Examples for java.awt.event.MouseEvent#BUTTON2_DOWN_MASK

The following examples show how to use java.awt.event.MouseEvent#BUTTON2_DOWN_MASK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultMapController.java    From amodeus with GNU General Public License v2.0 6 votes vote down vote up
/** Sets the mouse button that is used for moving the map. Possible values are:
 * <ul>
 * <li>{@link MouseEvent#BUTTON1} (left mouse button)</li>
 * <li>{@link MouseEvent#BUTTON2} (middle mouse button)</li>
 * <li>{@link MouseEvent#BUTTON3} (right mouse button)</li>
 * </ul>
 *
 * @param movementMouseButton the mouse button that is used for moving the map */
public void setMovementMouseButton(int movementMouseButton) {
    this.movementMouseButton = movementMouseButton;
    switch (movementMouseButton) {
    case MouseEvent.BUTTON1:
        movementMouseButtonMask = MouseEvent.BUTTON1_DOWN_MASK;
        break;
    case MouseEvent.BUTTON2:
        movementMouseButtonMask = MouseEvent.BUTTON2_DOWN_MASK;
        break;
    case MouseEvent.BUTTON3:
        movementMouseButtonMask = MouseEvent.BUTTON3_DOWN_MASK;
        break;
    default:
        throw new RuntimeException("Unsupported button");
    }
}
 
Example 2
Source File: DefaultMapController.java    From Course_Generator with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets the mouse button that is used for moving the map. Possible values are:
 * <ul>
 * <li>{@link MouseEvent#BUTTON1} (left mouse button)</li>
 * <li>{@link MouseEvent#BUTTON2} (middle mouse button)</li>
 * <li>{@link MouseEvent#BUTTON3} (right mouse button)</li>
 * </ul>
 *
 * @param movementMouseButton
 */
public void setMovementMouseButton(int movementMouseButton) {
	this.movementMouseButton = movementMouseButton;
	switch (movementMouseButton) {
	case MouseEvent.BUTTON1:
		movementMouseButtonMask = MouseEvent.BUTTON1_DOWN_MASK;
		break;
	case MouseEvent.BUTTON2:
		movementMouseButtonMask = MouseEvent.BUTTON2_DOWN_MASK;
		break;
	case MouseEvent.BUTTON3:
		movementMouseButtonMask = MouseEvent.BUTTON3_DOWN_MASK;
		break;
	default:
		throw new RuntimeException("Unsupported button");
	}
}
 
Example 3
Source File: CGMapController.java    From Course_Generator with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets the mouse button that is used for moving the map. Possible values are:
 * <ul>
 * <li>{@link MouseEvent#BUTTON1} (left mouse button)</li>
 * <li>{@link MouseEvent#BUTTON2} (middle mouse button)</li>
 * <li>{@link MouseEvent#BUTTON3} (right mouse button)</li>
 * </ul>
 *
 * @param movementMouseButton
 */
public void setMovementMouseButton(int movementMouseButton) {
	this.movementMouseButton = movementMouseButton;
	switch (movementMouseButton) {
	case MouseEvent.BUTTON1:
		movementMouseButtonMask = MouseEvent.BUTTON1_DOWN_MASK;
		break;
	case MouseEvent.BUTTON2:
		movementMouseButtonMask = MouseEvent.BUTTON2_DOWN_MASK;
		break;
	case MouseEvent.BUTTON3:
		movementMouseButtonMask = MouseEvent.BUTTON3_DOWN_MASK;
		break;
	default:
		throw new RuntimeException("Unsupported button");
	}
}
 
Example 4
Source File: MainFrame.java    From zxpoly with GNU General Public License v3.0 6 votes vote down vote up
private int extractButtons(final MouseEvent event) {
  int result = AbstractTool.BUTTON_NONE;
  if ((event.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0) {
    result |= AbstractTool.BUTTON_CTRL;
  }
  if ((event.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0) {
    result |= AbstractTool.BUTTON_ALT;
  }
  if ((event.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0) {
    result |= AbstractTool.BUTTON_SHIFT;
  }
  if ((event.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
    result |= AbstractTool.BUTTON_MOUSE_LEFT;
  }
  if ((event.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) != 0) {
    result |= AbstractTool.BUTTON_MOUSE_MIDDLE;
  }
  if ((event.getModifiersEx() & MouseEvent.BUTTON3_DOWN_MASK) != 0) {
    result |= AbstractTool.BUTTON_MOUSE_RIGHT;
  }
  return result;
}
 
Example 5
Source File: SwingTerminal.java    From jexer with MIT License 5 votes vote down vote up
/**
 * Pass mouse events into the event queue.
 *
 * @param mouse mouse event received
 */
public void mouseDragged(final MouseEvent mouse) {
    int modifiers = mouse.getModifiersEx();
    boolean eventMouse1 = false;
    boolean eventMouse2 = false;
    boolean eventMouse3 = false;
    if ((modifiers & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
        eventMouse1 = true;
    }
    if ((modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0) {
        eventMouse2 = true;
    }
    if ((modifiers & MouseEvent.BUTTON3_DOWN_MASK) != 0) {
        eventMouse3 = true;
    }
    mouse1 = eventMouse1;
    mouse2 = eventMouse2;
    mouse3 = eventMouse3;
    int x = textColumn(mouse.getX());
    int y = textRow(mouse.getY());

    TMouseEvent mouseEvent = new TMouseEvent(TMouseEvent.Type.MOUSE_MOTION,
        x, y, x, y, mouse1, mouse2, mouse3, false, false);

    synchronized (eventQueue) {
        eventQueue.add(mouseEvent);
        resetBlinkTimer();
    }
    if (listener != null) {
        synchronized (listener) {
            listener.notifyAll();
        }
    }
}
 
Example 6
Source File: SwingTerminal.java    From jexer with MIT License 5 votes vote down vote up
/**
 * Pass mouse events into the event queue.
 *
 * @param mouse mouse event received
 */
public void mousePressed(final MouseEvent mouse) {
    int modifiers = mouse.getModifiersEx();
    boolean eventMouse1 = false;
    boolean eventMouse2 = false;
    boolean eventMouse3 = false;
    if ((modifiers & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
        eventMouse1 = true;
    }
    if ((modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0) {
        eventMouse2 = true;
    }
    if ((modifiers & MouseEvent.BUTTON3_DOWN_MASK) != 0) {
        eventMouse3 = true;
    }
    mouse1 = eventMouse1;
    mouse2 = eventMouse2;
    mouse3 = eventMouse3;
    int x = textColumn(mouse.getX());
    int y = textRow(mouse.getY());

    TMouseEvent mouseEvent = new TMouseEvent(TMouseEvent.Type.MOUSE_DOWN,
        x, y, x, y, mouse1, mouse2, mouse3, false, false);

    synchronized (eventQueue) {
        eventQueue.add(mouseEvent);
        resetBlinkTimer();
    }
    if (listener != null) {
        synchronized (listener) {
            listener.notifyAll();
        }
    }
}
 
Example 7
Source File: SwingTerminal.java    From jexer with MIT License 4 votes vote down vote up
/**
 * Pass mouse events into the event queue.
 *
 * @param mouse mouse event received
 */
public void mouseReleased(final MouseEvent mouse) {
    int modifiers = mouse.getModifiersEx();
    boolean eventMouse1 = false;
    boolean eventMouse2 = false;
    boolean eventMouse3 = false;
    if ((modifiers & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
        eventMouse1 = true;
    }
    if ((modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0) {
        eventMouse2 = true;
    }
    if ((modifiers & MouseEvent.BUTTON3_DOWN_MASK) != 0) {
        eventMouse3 = true;
    }
    if (mouse1) {
        mouse1 = false;
        eventMouse1 = true;
    }
    if (mouse2) {
        mouse2 = false;
        eventMouse2 = true;
    }
    if (mouse3) {
        mouse3 = false;
        eventMouse3 = true;
    }
    int x = textColumn(mouse.getX());
    int y = textRow(mouse.getY());

    TMouseEvent mouseEvent = new TMouseEvent(TMouseEvent.Type.MOUSE_UP,
        x, y, x, y, eventMouse1, eventMouse2, eventMouse3, false, false);

    synchronized (eventQueue) {
        eventQueue.add(mouseEvent);
        resetBlinkTimer();
    }
    if (listener != null) {
        synchronized (listener) {
            listener.notifyAll();
        }
    }
}
 
Example 8
Source File: SwingTerminal.java    From jexer with MIT License 4 votes vote down vote up
/**
 * Pass mouse events into the event queue.
 *
 * @param mouse mouse event received
 */
public void mouseWheelMoved(final MouseWheelEvent mouse) {
    int modifiers = mouse.getModifiersEx();
    boolean eventMouse1 = false;
    boolean eventMouse2 = false;
    boolean eventMouse3 = false;
    boolean mouseWheelUp = false;
    boolean mouseWheelDown = false;
    if ((modifiers & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
        eventMouse1 = true;
    }
    if ((modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0) {
        eventMouse2 = true;
    }
    if ((modifiers & MouseEvent.BUTTON3_DOWN_MASK) != 0) {
        eventMouse3 = true;
    }
    mouse1 = eventMouse1;
    mouse2 = eventMouse2;
    mouse3 = eventMouse3;
    int x = textColumn(mouse.getX());
    int y = textRow(mouse.getY());
    if (mouse.getWheelRotation() > 0) {
        mouseWheelDown = true;
    }
    if (mouse.getWheelRotation() < 0) {
        mouseWheelUp = true;
    }

    TMouseEvent mouseEvent = new TMouseEvent(TMouseEvent.Type.MOUSE_DOWN,
        x, y, x, y, mouse1, mouse2, mouse3, mouseWheelUp, mouseWheelDown);

    synchronized (eventQueue) {
        eventQueue.add(mouseEvent);
        resetBlinkTimer();
    }
    if (listener != null) {
        synchronized (listener) {
            listener.notifyAll();
        }
    }
}
 
Example 9
Source File: PaintCanvas.java    From Spade with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e)
{
	if(document == null)
		return;
	// Don't use BUTTON2_MASK because it will trigger when ALT is pressed. Sometimes Java is stupid.
	int middleMouseMod = MouseEvent.BUTTON2_DOWN_MASK;
	int modifier = e.getModifiersEx();
	boolean middleMouseDown = (modifier & middleMouseMod) != 0;
	boolean returned = true;
	
	if(middleMouseDown && returned)
	{
		float dragX = e.getX() - this.mouseLastDragPosX;
		float dragY = e.getY() - this.mouseLastDragPosY;
		
		this.cam_positionX -= dragX / this.cam_zoom;
		this.cam_positionY -= dragY / this.cam_zoom;
		
		if(this.cam_positionX < 0)
		{
			this.cam_positionX = 0;
		}
		if(this.cam_positionY < 0)
		{
			this.cam_positionY = 0;
		}
		
		if(this.cam_positionX > this.image.getWidth())
		{
			this.cam_positionX = this.image.getWidth();
		}
		if(this.cam_positionY > this.image.getHeight())
		{
			this.cam_positionY = this.image.getHeight();
		}
		
		//this.updateBackground();
		this.repaint();
		returned = false;
	}
	
	if(returned && (lastButton == MouseEvent.BUTTON1 || lastButton == MouseEvent.BUTTON3))
	{
		Point2D p = this.transformCanvasPointToImagePoint(e.getPoint());
		short x = (short) p.getX();
		short y = (short) p.getY();
		mouseX = x;
		mouseY = y;
		Spade.main.gui.checkDynamicInfo();
		Spade.main.currentTool.whilePressed(document.getCurrent(), x, y, lastButton);
	}
	
	this.mouseLastDragPosX = e.getX();
	this.mouseLastDragPosY = e.getY();
}