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

The following examples show how to use java.awt.event.MouseEvent#BUTTON1_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: ScreenSelector.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public void mousePressed( MouseEvent mouseEvent ) {
    if (mouseEvent == null) // Ignore null events.
        return;

    if (MouseEvent.BUTTON1_DOWN_MASK != mouseEvent.getModifiersEx()) // Respond
                                                                     // to
                                                                     // button
                                                                     // 1
                                                                     // down
                                                                     // w/o
                                                                     // modifiers.
        return;

    this.armed = true;
    this.selectionStarted(mouseEvent);
    mouseEvent.consume(); // Consume the mouse event to prevent the view
                          // from responding to it.
}
 
Example 2
Source File: NBodyVisualizer.java    From gpu-nbody with MIT License 6 votes vote down vote up
@Override
public void mouseDragged(final MouseEvent e) {
	final int dx = e.getX() - previousMousePosition.x;
	final int dy = e.getY() - previousMousePosition.y;

	// If the left button is held down, move the object
	if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK) {
		translationX += dx / 100.0f;
		translationY -= dy / 100.0f;
	}

	// If the right button is held down, rotate the object
	else if ((e.getModifiersEx() & MouseEvent.BUTTON3_DOWN_MASK) == MouseEvent.BUTTON3_DOWN_MASK) {
		rotationX += dy;
		rotationY += dx;
	}
	previousMousePosition = e.getPoint();
	updateModelviewMatrix();
}
 
Example 3
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 4
Source File: SimpleInteraction.java    From jcuda-samples with MIT License 6 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e)
{
    int dx = e.getX() - previousMousePosition.x;
    int dy = e.getY() - previousMousePosition.y;

    // If the left button is held down, move the object
    if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 
        MouseEvent.BUTTON1_DOWN_MASK)
    {
        translationX += dx / 100.0f;
        translationY -= dy / 100.0f;
    }

    // If the right button is held down, rotate the object
    else if ((e.getModifiersEx() & MouseEvent.BUTTON3_DOWN_MASK) == 
        MouseEvent.BUTTON3_DOWN_MASK)
    {
        rotationDegX += dy;
        rotationDegY += dx;
    }
    previousMousePosition = e.getPoint();
    updateModelviewMatrix();
}
 
Example 5
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 6
Source File: SlideGestureRecognizer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Activates automatic slide in system */
@Override
public void mouseEntered(MouseEvent e) {
    if (!slideBar.isHoveringAllowed()) {
        // don't even try to trigger automatic sliding when focused slide is active
        return;
    }
    mouseInButton = (Component)e.getSource();
    curMouseLocX = e.getX();
    curMouseLocY = e.getY();
    pressingButton =false;
    // #54764 - start
    if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK) {
        pressingButton = true;
        return;
    }
    // #54764 - end
    autoSlideTrigger.activateAutoSlideInGesture();
}
 
Example 7
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 8
Source File: SlideGestureRecognizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Tracks mouse pointer location */
@Override
public void mouseMoved(MouseEvent e) {
    if (autoSlideTrigger.isEnabled()) {
        curMouseLocX = e.getX();
        curMouseLocY = e.getY();
    }
    // #54764 - start
    if (pressingButton && (e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) {
        pressingButton = false;
        autoSlideTrigger.activateAutoSlideInGesture(); 
    }
    // #54764 - end
}
 
Example 9
Source File: ConsoleProxyRdpClient.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public int mapMouseDownModifier(int code, int modifiers) {
    int mod = mapModifier(modifiers);
    switch (code) {
    case 0:
        mod = mod | MouseEvent.BUTTON1_DOWN_MASK;
        break;
    case 2:
        mod = mod | MouseEvent.BUTTON3_DOWN_MASK;
        break;
    default:
    }
    return mod;
}
 
Example 10
Source File: SectorSelector.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void mouseDragged(MouseEvent mouseEvent) {
    if (MouseEvent.BUTTON1_DOWN_MASK != mouseEvent.getModifiersEx())
        return;

    if (this.getShape().isResizeable())
        mouseEvent.consume(); // prevent view operations
}
 
Example 11
Source File: DtdSelectionTool.java    From workcraft with MIT License 5 votes vote down vote up
@Override
public void startDrag(GraphEditorMouseEvent e) {
    GraphEditor editor = e.getEditor();
    VisualModel model = editor.getModel();
    if (e.getButtonModifiers() == MouseEvent.BUTTON1_DOWN_MASK) {
        Node hitNode = HitMan.hitFirstInCurrentLevel(e.getStartPosition(), model);
        if ((swappingSignal == null) && e.isExtendKeyDown() &&
                (hitNode instanceof VisualSignal) && (model instanceof VisualDtd)) {
            swappingSignal = (VisualSignal) hitNode;
        }
    }
    super.startDrag(e);
}
 
Example 12
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 13
Source File: Ruler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
    if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
        setLocation(e.getXOnScreen() - x, e.getYOnScreen() - y);
    }
}
 
Example 14
Source File: Ruler.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
    if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
        setLocation(e.getXOnScreen() - x, e.getYOnScreen() - y);
    }
}
 
Example 15
Source File: Ruler.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
    if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
        setLocation(e.getXOnScreen() - x, e.getYOnScreen() - y);
    }
}
 
Example 16
Source File: Ruler.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
    if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
        setLocation(e.getXOnScreen() - x, e.getYOnScreen() - y);
    }
}
 
Example 17
Source File: Ruler.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
    if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
        setLocation(e.getXOnScreen() - x, e.getYOnScreen() - y);
    }
}
 
Example 18
Source File: GraphEditorMouseEvent.java    From workcraft with MIT License 4 votes vote down vote up
public int getButtonModifiers() {
    // BUTTON2 is ignored as it is reserved for panning
    return event.getModifiersEx() & (MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON3_DOWN_MASK);
}
 
Example 19
Source File: SelectionTool.java    From workcraft with MIT License 4 votes vote down vote up
@Override
public void startDrag(GraphEditorMouseEvent e) {
    GraphEditor editor = e.getEditor();
    VisualModel model = editor.getModel();
    if (e.getButtonModifiers() == MouseEvent.BUTTON1_DOWN_MASK) {
        Point2D startPos = e.getStartPosition();
        Node hitNode = HitMan.hitFirstInCurrentLevel(startPos, model);

        if (hitNode == null) {
            // If hit nothing then start region selection
            if (e.isShiftKeyDown()) {
                selectionMode = SelectionMode.ADD;
            } else if (e.isMenuKeyDown()) {
                selectionMode = SelectionMode.REMOVE;
            } else {
                selectionMode = SelectionMode.REPLACE;
            }
            // Selection will not actually be changed until drag completes
            dragState = DrugState.SELECT;
            selected.clear();
            if (selectionMode == SelectionMode.REPLACE) {
                model.selectNone();
            } else {
                selected.addAll(model.getSelection());
            }
        } else if (((e.getKeyModifiers() == 0) || e.isShiftKeyDown()) && (hitNode instanceof VisualNode)) {
            // If mouse down either without modifiers or with Ctrl/Menu being pressed and hit something then begin move-drag
            dragState = DrugState.MOVE;
            VisualNode node = (VisualNode) hitNode;
            if ((node != null) && !model.getSelection().contains(node)) {
                model.select(node);
            }
            AffineTransform localToRootTransform = TransformHelper.getTransformToRoot(node);
            moveOffset = new Point2D.Double(0.0, 0.0);
            startPos = TransformHelper.transform(node, localToRootTransform).getCenter();
            snaps = editor.getSnaps(node);
            Point2D snapPos = editor.snap(startPos, snaps);
            snapOffset = new Point2D.Double(snapPos.getX() - startPos.getX(), snapPos.getY() - startPos.getY());
            // Initial move of the selection - beforeSelectionModification is needed
            beforeSelectionModification(editor);
            VisualModelTransformer.translateSelection(model, snapOffset.getX(), snapOffset.getY());
        } else {
            // Do nothing if pressed on a node with modifiers
        }
    }
}
 
Example 20
Source File: Ruler.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void mouseDragged(MouseEvent e) {
    if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
        setLocation(e.getXOnScreen() - x, e.getYOnScreen() - y);
    }
}