Java Code Examples for java.awt.event.InputEvent#CTRL_DOWN_MASK

The following examples show how to use java.awt.event.InputEvent#CTRL_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: OptionsDialogTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testRestoreDefaultsForFrontEndKeybindings() throws Exception {
	runSwing(() -> dialog.close());

	setUpDialog(env.getFrontEndTool());

	String actionName = "Archive Project";
	String pluginName = "ArchivePlugin";
	KeyStroke defaultKeyStroke = getKeyBinding(actionName);
	assertOptionsKeyStroke(actionName, pluginName, defaultKeyStroke);

	int keyCode = KeyEvent.VK_Q;
	int modifiers = InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK;
	KeyStroke newKeyStroke = setKeyBinding(actionName, modifiers, keyCode, 'Q');

	apply();
	assertOptionsKeyStroke(actionName, pluginName, newKeyStroke);

	restoreDefaults();

	KeyStroke currentBinding = getKeyBinding(actionName);
	assertEquals("Key binding not restored after a call to restore defautls", defaultKeyStroke,
		currentBinding);
	assertOptionsKeyStroke(actionName, pluginName, defaultKeyStroke);
}
 
Example 2
Source File: LineTool.java    From Logisim with GNU General Public License v3.0 6 votes vote down vote up
private void updateMouse(Canvas canvas, int mx, int my, int mods) {
	if (active) {
		boolean shift = (mods & InputEvent.SHIFT_DOWN_MASK) != 0;
		Location newEnd;
		if (shift) {
			newEnd = LineUtil.snapTo8Cardinals(mouseStart, mx, my);
		} else {
			newEnd = Location.create(mx, my);
		}

		if ((mods & InputEvent.CTRL_DOWN_MASK) == 0) {
			int x = newEnd.getX();
			int y = newEnd.getY();
			x = canvas.snapX(x);
			y = canvas.snapY(y);
			newEnd = Location.create(x, y);
		}

		if (!newEnd.equals(mouseEnd)) {
			mouseEnd = newEnd;
			repaintArea(canvas);
		}
	}
	lastMouseX = mx;
	lastMouseY = my;
}
 
Example 3
Source File: TabPagerMouseWheelListener.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
	TabPreviewPainter tpp = TabPreviewUtilities
			.getTabPreviewPainter(this.tabbedPane);
	if (tpp == null)
		return;

	if (((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0)
			&& e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
		int amount = e.getWheelRotation();
		TabPagerManager te = TabPagerManager.getPager();
		if (te.isVisible()) {
			if (amount > 0) {
				if (this.tabbedPane != null)
					te.page(this.tabbedPane, true);
				else
					te.page(true);
			} else {
				if (this.tabbedPane != null)
					te.page(this.tabbedPane, false);
				else
					te.page(false);
			}
		}
	}
}
 
Example 4
Source File: KeyMap.java    From SikuliX1 with MIT License 6 votes vote down vote up
public static int getModifier(KeyStroke keyStroke) {
    int modifiers = 0;
    if ((keyStroke.getModifiers() & InputEvent.SHIFT_DOWN_MASK) != 0) {
        modifiers |= shiftKey;
    }
    if ((keyStroke.getModifiers() & InputEvent.CTRL_DOWN_MASK) != 0) {
        modifiers |= controlKey;
    }
    if ((keyStroke.getModifiers() & InputEvent.META_DOWN_MASK) != 0) {
        modifiers |= cmdKey;
    }
    if ((keyStroke.getModifiers() & InputEvent.ALT_DOWN_MASK) != 0) {
        modifiers |= optionKey;
    }
    return modifiers;
}
 
Example 5
Source File: DragSourceDragEvent.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets new modifiers by the old ones.
 * The mouse modifiers have higher priority than overlaying key
 * modifiers.
 */
private void setNewModifiers() {
    if ((gestureModifiers & InputEvent.BUTTON1_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON1_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON2_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON2_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON3_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON3_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) {
        gestureModifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.CTRL_MASK) != 0) {
        gestureModifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        gestureModifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
    }
}
 
Example 6
Source File: SWTUtils.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an AWT <code>MouseEvent</code> from a swt event.
 * This method helps passing SWT mouse event to awt components.
 * @param event The swt event.
 * @return A AWT mouse event based on the given SWT event.
 */
public static MouseEvent toAwtMouseEvent(org.eclipse.swt.events.MouseEvent event) {
    int button = MouseEvent.NOBUTTON;
    switch (event.button) {
    case 1: button = MouseEvent.BUTTON1; break;
    case 2: button = MouseEvent.BUTTON2; break;
    case 3: button = MouseEvent.BUTTON3; break;
    }
    int modifiers = 0;
    if ((event.stateMask & SWT.CTRL) != 0) {
        modifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((event.stateMask & SWT.SHIFT) != 0) {
        modifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((event.stateMask & SWT.ALT) != 0) {
        modifiers |= InputEvent.ALT_DOWN_MASK;
    }
    MouseEvent awtMouseEvent = new MouseEvent(DUMMY_PANEL, event.hashCode(),
            event.time, modifiers, event.x, event.y, 1, false, button);
    return awtMouseEvent;
}
 
Example 7
Source File: AWTKeyStroke.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static int mapNewModifiers(int modifiers) {
    if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
        modifiers |= InputEvent.SHIFT_MASK;
    }
    if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
        modifiers |= InputEvent.ALT_MASK;
    }
    if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
        modifiers |= InputEvent.ALT_GRAPH_MASK;
    }
    if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
        modifiers |= InputEvent.CTRL_MASK;
    }
    if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
        modifiers |= InputEvent.META_MASK;
    }

    return modifiers;
}
 
Example 8
Source File: DragSourceDragEvent.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Sets old modifiers by the new ones.
 */
private void setOldModifiers() {
    if ((gestureModifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON1_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON2_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON3_MASK;
    }
    if ((gestureModifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.SHIFT_MASK;
    }
    if ((gestureModifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.CTRL_MASK;
    }
    if ((gestureModifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.ALT_GRAPH_MASK;
    }
}
 
Example 9
Source File: ChatCommandsConfig.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@ConfigItem(
	position = 13,
	keyName = "clearEntireChatBox",
	name = "Clear Chat Box",
	description = "Enable hotkey to clear entire chat box"
)
default Keybind clearChatBox()
{
	return new Keybind(KeyEvent.VK_BACK_SPACE, InputEvent.CTRL_DOWN_MASK);
}
 
Example 10
Source File: PolyTool.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
private void updateMouse(Canvas canvas, int mx, int my, int mods) {
	lastMouseX = mx;
	lastMouseY = my;
	if (active) {
		int index = locations.size() - 1;
		Location last = locations.get(index);
		Location newLast;
		if ((mods & InputEvent.SHIFT_DOWN_MASK) != 0 && index > 0) {
			Location nextLast = locations.get(index - 1);
			newLast = LineUtil.snapTo8Cardinals(nextLast, mx, my);
		} else {
			newLast = Location.create(mx, my);
		}
		if ((mods & InputEvent.CTRL_DOWN_MASK) == 0) {
			int lastX = newLast.getX();
			int lastY = newLast.getY();
			lastX = canvas.snapX(lastX);
			lastY = canvas.snapY(lastY);
			newLast = Location.create(lastX, lastY);
		}

		if (!newLast.equals(last)) {
			locations.set(index, newLast);
			repaintArea(canvas);
		}
	}
}
 
Example 11
Source File: AWTKeyStroke.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static int mapOldModifiers(int modifiers) {
    if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
        modifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((modifiers & InputEvent.ALT_MASK) != 0) {
        modifiers |= InputEvent.ALT_DOWN_MASK;
    }
    if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
    }
    if ((modifiers & InputEvent.CTRL_MASK) != 0) {
        modifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((modifiers & InputEvent.META_MASK) != 0) {
        modifiers |= InputEvent.META_DOWN_MASK;
    }

    modifiers &= InputEvent.SHIFT_DOWN_MASK
        | InputEvent.ALT_DOWN_MASK
        | InputEvent.ALT_GRAPH_DOWN_MASK
        | InputEvent.CTRL_DOWN_MASK
        | InputEvent.META_DOWN_MASK
        | InputEvent.BUTTON1_DOWN_MASK
        | InputEvent.BUTTON2_DOWN_MASK
        | InputEvent.BUTTON3_DOWN_MASK;

    return modifiers;
}
 
Example 12
Source File: AWTKeyStroke.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static String getModifiersText(int modifiers) {
    StringBuilder buf = new StringBuilder();

    if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0 ) {
        buf.append("shift ");
    }
    if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0 ) {
        buf.append("ctrl ");
    }
    if ((modifiers & InputEvent.META_DOWN_MASK) != 0 ) {
        buf.append("meta ");
    }
    if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0 ) {
        buf.append("alt ");
    }
    if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0 ) {
        buf.append("altGraph ");
    }
    if ((modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0 ) {
        buf.append("button1 ");
    }
    if ((modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0 ) {
        buf.append("button2 ");
    }
    if ((modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0 ) {
        buf.append("button3 ");
    }

    return buf.toString();
}
 
Example 13
Source File: AWTKeyStroke.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
static String getModifiersText(int modifiers) {
    StringBuilder buf = new StringBuilder();

    if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0 ) {
        buf.append("shift ");
    }
    if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0 ) {
        buf.append("ctrl ");
    }
    if ((modifiers & InputEvent.META_DOWN_MASK) != 0 ) {
        buf.append("meta ");
    }
    if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0 ) {
        buf.append("alt ");
    }
    if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0 ) {
        buf.append("altGraph ");
    }
    if ((modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0 ) {
        buf.append("button1 ");
    }
    if ((modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0 ) {
        buf.append("button2 ");
    }
    if ((modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0 ) {
        buf.append("button3 ");
    }

    return buf.toString();
}
 
Example 14
Source File: AWTKeyStroke.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static int mapOldModifiers(int modifiers) {
    if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
        modifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((modifiers & InputEvent.ALT_MASK) != 0) {
        modifiers |= InputEvent.ALT_DOWN_MASK;
    }
    if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
    }
    if ((modifiers & InputEvent.CTRL_MASK) != 0) {
        modifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((modifiers & InputEvent.META_MASK) != 0) {
        modifiers |= InputEvent.META_DOWN_MASK;
    }

    modifiers &= InputEvent.SHIFT_DOWN_MASK
        | InputEvent.ALT_DOWN_MASK
        | InputEvent.ALT_GRAPH_DOWN_MASK
        | InputEvent.CTRL_DOWN_MASK
        | InputEvent.META_DOWN_MASK
        | InputEvent.BUTTON1_DOWN_MASK
        | InputEvent.BUTTON2_DOWN_MASK
        | InputEvent.BUTTON3_DOWN_MASK;

    return modifiers;
}
 
Example 15
Source File: ConfigurationValueShortcut.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * @return Combination of InputEvent modifiers.
 */
public int getModifiers() {
  int modifiers = 0;
  if (alt) {
    modifiers = modifiers | InputEvent.ALT_DOWN_MASK;
  }
  if (ctrl) {
    modifiers = modifiers | InputEvent.CTRL_DOWN_MASK;
  }
  if (shift) {
    modifiers = modifiers | InputEvent.SHIFT_DOWN_MASK;
  }
  return modifiers;
}
 
Example 16
Source File: PointSelectionBehavior.java    From SNT with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void doProcess(final MouseEvent me) {
	if (me.isConsumed() || Toolbar.getToolId() != Toolbar.WAND)
		return;
	final int mouseEventID = me.getID();
	/*
	 * It's nice to still be able to zoom with the mouse wheel, so don't
	 * consume this event.
	 */
	if (mouseEventID == MouseEvent.MOUSE_WHEEL)
		return;
	me.consume();
	if (mouseEventID != MouseEvent.MOUSE_CLICKED)
		return;
	final Picker picker = univ.getPicker();
	final Content c = picker.getPickedContent(me.getX(), me.getY());
	if (null == c)
		return;

	final Point3d point = picker.getPickPointGeometry(c, me.getX(), me.getY());

	final boolean mac = IJ.isMacintosh();

	final boolean shift_key_down = (me.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0;
	final boolean joiner_modifier_down = mac ? ((me.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0)
			: ((me.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0);

	SwingUtilities.invokeLater(new Runnable() {
		@Override
		public void run() {
			tracerPlugin.clickForTrace(point, joiner_modifier_down);
		}
	});
}
 
Example 17
Source File: RuneLiteConfig.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@ConfigItem(
	keyName = "sidebarToggleKey",
	name = "Sidebar Toggle Key",
	description = "The key that will toggle the sidebar (accepts modifiers)",
	position = 45,
	section = windowSettings
)
default Keybind sidebarToggleKey()
{
	return new Keybind(KeyEvent.VK_F11, InputEvent.CTRL_DOWN_MASK);
}
 
Example 18
Source File: SunDragSourceContextPeer.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public static int convertModifiersToDropAction(final int modifiers,
                                               final int supportedActions) {
    int dropAction = DnDConstants.ACTION_NONE;

    /*
     * Fix for 4285634.
     * Calculate the drop action to match Motif DnD behavior.
     * If the user selects an operation (by pressing a modifier key),
     * return the selected operation or ACTION_NONE if the selected
     * operation is not supported by the drag source.
     * If the user doesn't select an operation search the set of operations
     * supported by the drag source for ACTION_MOVE, then for
     * ACTION_COPY, then for ACTION_LINK and return the first operation
     * found.
     */
    switch (modifiers & (InputEvent.SHIFT_DOWN_MASK |
                         InputEvent.CTRL_DOWN_MASK)) {
    case InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK:
        dropAction = DnDConstants.ACTION_LINK; break;
    case InputEvent.CTRL_DOWN_MASK:
        dropAction = DnDConstants.ACTION_COPY; break;
    case InputEvent.SHIFT_DOWN_MASK:
        dropAction = DnDConstants.ACTION_MOVE; break;
    default:
        if ((supportedActions & DnDConstants.ACTION_MOVE) != 0) {
            dropAction = DnDConstants.ACTION_MOVE;
        } else if ((supportedActions & DnDConstants.ACTION_COPY) != 0) {
            dropAction = DnDConstants.ACTION_COPY;
        } else if ((supportedActions & DnDConstants.ACTION_LINK) != 0) {
            dropAction = DnDConstants.ACTION_LINK;
        }
    }

    return dropAction & supportedActions;
}
 
Example 19
Source File: DarkUIUtil.java    From darklaf with MIT License 4 votes vote down vote up
public static boolean isMenuShortcutKeyDown(final InputEvent event) {
    return (event.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0;
}
 
Example 20
Source File: StringUtils.java    From Spark with Apache License 2.0 4 votes vote down vote up
public static String keyStroke2String(KeyStroke key) {
StringBuilder s = new StringBuilder(50);
int m = key.getModifiers();

if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
    s.append("shift ");
}
if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
    s.append("ctrl ");
}
if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
    s.append("meta ");
}
if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
    s.append("alt ");
}
if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
    s.append("button1 ");
}
if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
    s.append("button2 ");
}
if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
    s.append("button3 ");
}

switch (key.getKeyEventType()) {
case KeyEvent.KEY_TYPED:
    s.append("typed ");
    s.append(key.getKeyChar()).append(" ");
    break;
case KeyEvent.KEY_PRESSED:
    s.append("pressed ");
    s.append(getKeyText(key.getKeyCode())).append(" ");
    break;
case KeyEvent.KEY_RELEASED:
    s.append("released ");
    s.append(getKeyText(key.getKeyCode())).append(" ");
    break;
default:
    s.append("unknown-event-type ");
    break;
}

return s.toString();
   }