Java Code Examples for java.awt.event.MouseEvent.getModifiersEx()

The following are Jave code examples for showing how to use getModifiersEx() of the java.awt.event.MouseEvent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenJSharp   File: WMouseDragGestureRecognizer.java   View Source Code Vote up 6 votes
/**
 * determine the drop action from the event
 */

protected int mapDragOperationFromModifiers(MouseEvent e) {
    int mods = e.getModifiersEx();
    int btns = mods & ButtonMask;

    // Prohibit multi-button drags.
    if (!(btns == InputEvent.BUTTON1_DOWN_MASK ||
          btns == InputEvent.BUTTON2_DOWN_MASK ||
          btns == InputEvent.BUTTON3_DOWN_MASK)) {
        return DnDConstants.ACTION_NONE;
    }

    return
        SunDragSourceContextPeer.convertModifiersToDropAction(mods,
                                                              getSourceActions());
}
 
Example 2
Project: MapAnalyst   File: DefaultMapController.java   View Source Code Vote up 6 votes
@Override
public void mouseMoved(MouseEvent e) {
    // Mac OSX simulates with  ctrl + mouse 1  the second mouse button hence no dragging events get fired.
    //
    if (isPlatformOsx()) {
        if (!movementEnabled || !isMoving)
            return;
        // Is only the selected mouse button pressed?
        if (e.getModifiersEx() == MouseEvent.CTRL_DOWN_MASK) {
            Point p = e.getPoint();
            if (lastDragPoint != null) {
                int diffx = lastDragPoint.x - p.x;
                int diffy = lastDragPoint.y - p.y;
                map.moveMap(diffx, diffy);
            }
            lastDragPoint = p;
        }
    }
}
 
Example 3
Project: jdk8u-jdk   File: XMouseDragGestureRecognizer.java   View Source Code Vote up 6 votes
/**
 * determine the drop action from the event
 */

protected int mapDragOperationFromModifiers(MouseEvent e) {
    int mods = e.getModifiersEx();
    int btns = mods & ButtonMask;

    // Do not allow right mouse button drag since Motif DnD does not
    // terminate drag operation on right mouse button release.
    if (!(btns == InputEvent.BUTTON1_DOWN_MASK ||
          btns == InputEvent.BUTTON2_DOWN_MASK)) {
        return DnDConstants.ACTION_NONE;
    }

    return
        SunDragSourceContextPeer.convertModifiersToDropAction(mods,
                                                              getSourceActions());
}
 
Example 4
Project: jdk8u-jdk   File: XToolkit.java   View Source Code Vote up 6 votes
static boolean isRightMouseButton(MouseEvent me) {
    int numButtons = ((Integer)getDefaultToolkit().getDesktopProperty("awt.mouse.numButtons")).intValue();
    switch (me.getID()) {
      case MouseEvent.MOUSE_PRESSED:
      case MouseEvent.MOUSE_RELEASED:
          return ((numButtons == 2 && me.getButton() == MouseEvent.BUTTON2) ||
                   (numButtons > 2 && me.getButton() == MouseEvent.BUTTON3));
      case MouseEvent.MOUSE_ENTERED:
      case MouseEvent.MOUSE_EXITED:
      case MouseEvent.MOUSE_CLICKED:
      case MouseEvent.MOUSE_DRAGGED:
          return ((numButtons == 2 && (me.getModifiersEx() & InputEvent.BUTTON2_DOWN_MASK) != 0) ||
                  (numButtons > 2 && (me.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0));
    }
    return false;
}
 
Example 5
Project: Pogamut3   File: MapController.java   View Source Code Vote up 6 votes
private ModificationStatus updateMode(MouseEvent e) {
    boolean leftDown = (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) == InputEvent.BUTTON1_DOWN_MASK;
    boolean rightDown = (e.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) == InputEvent.BUTTON3_DOWN_MASK;

    if (leftDown && rightDown) {
        operationMode = ModificationStatus.MOVE_CENTER;
    } else if (leftDown && !rightDown) {
        operationMode = ModificationStatus.MOVE_AHEAD;
    } else if (!leftDown && rightDown) {
        operationMode = ModificationStatus.ROTATE_EYE;
    } else {
        operationMode = ModificationStatus.NONE;
    }
    System.out.println("ModificationMode: " + operationMode);
    return operationMode;
}
 
Example 6
Project: openjdk-jdk10   File: WMouseDragGestureRecognizer.java   View Source Code Vote up 6 votes
/**
 * determine the drop action from the event
 */

protected int mapDragOperationFromModifiers(MouseEvent e) {
    int mods = e.getModifiersEx();
    int btns = mods & ButtonMask;

    // Prohibit multi-button drags.
    if (!(btns == InputEvent.BUTTON1_DOWN_MASK ||
          btns == InputEvent.BUTTON2_DOWN_MASK ||
          btns == InputEvent.BUTTON3_DOWN_MASK)) {
        return DnDConstants.ACTION_NONE;
    }

    return
        SunDragSourceContextPeer.convertModifiersToDropAction(mods,
                                                              getSourceActions());
}
 
Example 7
Project: jermit   File: SwingTerminal.java   View Source Code Vote up 5 votes
/**
 * 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 = screen.textColumn(mouse.getX());
    int y = screen.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);
    }
    synchronized (listener) {
        listener.notifyAll();
    }
}
 
Example 8
Project: Logisim   File: PolyTool.java   View Source Code Vote up 5 votes
@Override
public void mousePressed(Canvas canvas, MouseEvent e) {
	int mx = e.getX();
	int my = e.getY();
	lastMouseX = mx;
	lastMouseY = my;
	int mods = e.getModifiersEx();
	if ((mods & InputEvent.CTRL_DOWN_MASK) == 0) {
		mx = canvas.snapX(mx);
		my = canvas.snapY(my);
	}

	if (active && e.getClickCount() > 1) {
		CanvasObject add = commit(canvas);
		canvas.toolGestureComplete(this, add);
		return;
	}

	Location loc = Location.create(mx, my);
	ArrayList<Location> locs = locations;
	if (!active) {
		locs.clear();
		locs.add(loc);
	}
	locs.add(loc);

	mouseDown = true;
	active = canvas.getModel() != null;
	repaintArea(canvas);
}
 
Example 9
Project: incubator-netbeans   File: BaseCaret.java   View Source Code Vote up 5 votes
protected int mapDragOperationFromModifiers(MouseEvent e) {
    int mods = e.getModifiersEx();
    
    if ((mods & InputEvent.BUTTON1_DOWN_MASK) == 0) {
        return TransferHandler.NONE;
    }
    
    return TransferHandler.COPY_OR_MOVE;
}
 
Example 10
Project: MapAnalyst   File: DefaultMapController.java   View Source Code Vote up 5 votes
@Override
public void mousePressed(MouseEvent e) {
    if (e.getButton() == movementMouseButton || (isPlatformOsx() && e.getModifiersEx() == MAC_MOUSE_BUTTON3_MASK)) {
        lastDragPoint = null;
        isMoving = true;
    }
}
 
Example 11
Project: jdk8u-jdk   File: XToolkit.java   View Source Code Vote up 5 votes
static boolean isLeftMouseButton(MouseEvent me) {
    switch (me.getID()) {
      case MouseEvent.MOUSE_PRESSED:
      case MouseEvent.MOUSE_RELEASED:
          return (me.getButton() == MouseEvent.BUTTON1);
      case MouseEvent.MOUSE_ENTERED:
      case MouseEvent.MOUSE_EXITED:
      case MouseEvent.MOUSE_CLICKED:
      case MouseEvent.MOUSE_DRAGGED:
          return ((me.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0);
    }
    return false;
}
 
Example 12
Project: jdk8u-jdk   File: bug7170657.java   View Source Code Vote up 5 votes
private static void test(final Frame frame, final MouseEvent me) {
    MouseEvent newme = SwingUtilities.convertMouseEvent(frame, me, frame);
    if (me.getModifiersEx() != newme.getModifiersEx()
            || me.getModifiers() != newme.getModifiers()) {
        fail(me, newme);
    }
}
 
Example 13
Project: letsmake-ledmatrix   File: ImageEditorPanel.java   View Source Code Vote up 5 votes
private void clickedAt(MouseEvent e) {
    if (!isEnabled()) return;

    if (!editable)
        return;

    int dx = DeviceImagePainter.getXSpacing(getWidth());
    int dy = DeviceImagePainter.getYSpacing(getHeight());
    int sx = DeviceImagePainter.getXSize(getWidth());
    int sy = DeviceImagePainter.getYSize(getHeight());

    int x = (e.getX() - dx) / (sx + dx);
    int y = (e.getY() - dy) / (sy + dy);

    boolean v = !deviceImage.getPixel(x, y);
    if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) {
        for (int i = 0; i < DeviceImage.MAX_Y; i++) {
            deviceImage.setPixel(x, i, v);
        }
    } else if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) {
        for (int i = 0; i < DeviceImage.MAX_X; i++) {
            deviceImage.setPixel(i, y, v);
        }
    } else {
        deviceImage.setPixel(x, y, v);
    }

    fireStateChanged();
    repaint();
}
 
Example 14
Project: Logisim   File: CanvasListener.java   View Source Code Vote up 4 votes
private boolean isButton1(MouseEvent e) {
	return (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) != 0;
}
 
Example 15
Project: incubator-netbeans   File: BaseCaret.java   View Source Code Vote up 4 votes
private static String logMouseEvent(MouseEvent evt) {
    return "x=" + evt.getX() + ", y=" + evt.getY() + ", clicks=" + evt.getClickCount() //NOI18N
        + ", component=" + s2s(evt.getComponent()) //NOI18N
        + ", source=" + s2s(evt.getSource()) + ", button=" + evt.getButton() + ", mods=" + evt.getModifiers() + ", modsEx=" + evt.getModifiersEx(); //NOI18N
}
 
Example 16
Project: incubator-netbeans   File: EditorCaret.java   View Source Code Vote up 4 votes
private boolean isMiddleMouseButtonExt(MouseEvent evt) {
    return (evt.getButton() == MouseEvent.BUTTON2) &&
            (evt.getModifiersEx() & (InputEvent.CTRL_DOWN_MASK | InputEvent.META_DOWN_MASK | /* cannot be tested bcs of bug in JDK InputEvent.ALT_DOWN_MASK | */ InputEvent.ALT_GRAPH_DOWN_MASK)) == 0;
}
 
Example 17
Project: incubator-netbeans   File: EditorCaret.java   View Source Code Vote up 4 votes
private static String logMouseEvent(MouseEvent evt) {
    return "x=" + evt.getX() + ", y=" + evt.getY() + ", clicks=" + evt.getClickCount() //NOI18N
        + ", component=" + s2s(evt.getComponent()) //NOI18N
        + ", source=" + s2s(evt.getSource()) + ", button=" + evt.getButton() + ", mods=" + evt.getModifiers() + ", modsEx=" + evt.getModifiersEx(); //NOI18N
}
 
Example 18
Project: incubator-netbeans   File: TreeTable.java   View Source Code Vote up 4 votes
/**
 * This is overridden to forward the event to the tree and start editor timer.
 */
@Override
public boolean isCellEditable(EventObject e) {
    if (lastRow != -1) {
        TreePath tp = tree.getPathForRow(lastRow);
        org.openide.nodes.Node n = tp != null ? Visualizer.findNode(tp.getLastPathComponent()) : null;

        if ((n == null) || !n.canRename()) {
            //return false;
            canEdit = false;
        }
    }

    if (canEdit && (e != null) && (e.getSource() instanceof Timer)) {
        return true;
    }

    if (canEdit && shouldStartEditingTimer(e)) {
        startEditingTimer();
    } else if (shouldStopEditingTimer(e)) {
        timer.stop();
    }

    if (e instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) e;
        int column = getTreeColumnIndex();

        if (SwingUtilities.isLeftMouseButton(me) && (me.getClickCount() == 2)) {
            TreePath path = tree.getPathForRow(TreeTable.this.rowAtPoint(me.getPoint()));
            Rectangle r = tree.getPathBounds(path);

            if ((me.getX() < (r.x - positionX)) || (me.getX() > (r.x - positionX + r.width))) {
                me.translatePoint(r.x - me.getX(), 0);
            }
        }

        MouseEvent newME = new MouseEvent(
                TreeTable.this.tree, me.getID(), me.getWhen(), me.getModifiers()+me.getModifiersEx(),
                me.getX() - getCellRect(0, column, true).x + positionX, me.getY(), me.getClickCount(),
                me.isPopupTrigger()
            );
        TreeTable.this.tree.dispatchEvent(newME);
    }

    return false;
}
 
Example 19
Project: openjdk-jdk10   File: Ruler.java   View Source Code Vote up 4 votes
@Override
public void mouseDragged(MouseEvent e) {
    if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
        setLocation(e.getXOnScreen() - x, e.getYOnScreen() - y);
    }
}
 
Example 20
Project: OpenJSharp   File: Ruler.java   View Source Code Vote up 4 votes
@Override
public void mouseDragged(MouseEvent e) {
    if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
        setLocation(e.getXOnScreen() - x, e.getYOnScreen() - y);
    }
}