Java Code Examples for java.awt.event.InputEvent.ALT_MASK

The following are Jave code examples for showing how to use ALT_MASK of the java.awt.event.InputEvent 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: incubator-netbeans   File: WheelPanAction.java   View Source Code Vote up 6 votes
public State mouseWheelMoved (Widget widget, WidgetMouseWheelEvent event) {
    JComponent view = widget.getScene ().getView ();
    Rectangle visibleRect = view.getVisibleRect ();
    int amount = event.getWheelRotation () * 64;

    switch (event.getModifiers () & (InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK | InputEvent.ALT_MASK)) {
        case InputEvent.SHIFT_MASK:
            visibleRect.x += amount;
            break;
        case 0:
            visibleRect.y += amount;
            break;
        default:
            return State.REJECTED;
    }

    view.scrollRectToVisible (visibleRect);
    return State.CONSUMED;
}
 
Example 2
Project: openjdk-jdk10   File: KeyMaskTest.java   View Source Code Vote up 6 votes
@Override
public void keyPressed(KeyEvent e) {

    keyPressReceived = true;

    int code = e.getKeyCode();

    assertEQ(code, keyCode, "wrong key code");

    int mask = 0;

    if (code == KeyEvent.VK_SHIFT) {
        mask = InputEvent.SHIFT_MASK;
    } else if (code == KeyEvent.VK_CONTROL) {
        mask = InputEvent.CTRL_MASK;
    } else if (code == KeyEvent.VK_ALT) {
        mask = InputEvent.ALT_MASK;
    } else if (code == KeyEvent.VK_META) {
        mask = InputEvent.META_MASK;
    }

    int mod = e.getModifiers() & mask;
    assertEQ(mod, mask, "invalid key mask");

    synchronized (lock) { lock.notifyAll(); }
}
 
Example 3
Project: OpenJSharp   File: AWTKeyStroke.java   View Source Code Vote up 6 votes
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 4
Project: Tarski   File: OurUtil.java   View Source Code Vote up 6 votes
/** Construct a new JMenuItem then add it to an existing JMenu.
 * @param parent - the JMenu to add this JMenuItem into (or null if you don't want to add it to any JMenu yet)
 * @param label - the text to show on the menu
 * @param attrs - a list of attributes to apply onto the new JMenuItem
 * <p> If one positive number  a is supplied, we call setMnemonic(a)
 * <p> If two positive numbers a and b are supplied, and a!=VK_ALT, and a!=VK_SHIFT, we call setMnemoic(a) and setAccelerator(b)
 * <p> If two positive numbers a and b are supplied, and a==VK_ALT or a==VK_SHIFT, we call setAccelerator(a | b)
 * <p> If an ActionListener is supplied, we call addActionListener(x)
 * <p> If an Boolean x      is supplied, we call setEnabled(x)
 * <p> If an Icon x         is supplied, we call setIcon(x)
 */
public static JMenuItem menuItem (JMenu parent, String label, Object... attrs) {
   JMenuItem m = new JMenuItem(label, null);
   int accelMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
   boolean hasMnemonic = false;
   for(Object x: attrs) {
      if (x instanceof Character || x instanceof Integer) {
         int k = (x instanceof Character) ? ((int)((Character)x)) : ((Integer)x).intValue();
         if (k < 0) continue;
         if (k==KeyEvent.VK_ALT)   { hasMnemonic = true; accelMask = accelMask | InputEvent.ALT_MASK;   continue; }
         if (k==KeyEvent.VK_SHIFT) { hasMnemonic = true; accelMask = accelMask | InputEvent.SHIFT_MASK; continue; }
         if (!hasMnemonic) { m.setMnemonic(k); hasMnemonic=true; } else m.setAccelerator(KeyStroke.getKeyStroke(k, accelMask));
      }
      if (x instanceof ActionListener) m.addActionListener((ActionListener)x);
      if (x instanceof Icon) m.setIcon((Icon)x);
      if (x instanceof Boolean) m.setEnabled((Boolean)x);
   }
   if (parent!=null) parent.add(m);
   return m;
}
 
Example 5
Project: openjdk-jdk10   File: EventDispatcher.java   View Source Code Vote up 6 votes
/**
 * Get a string representation for key modifiers. Used to print trace.
 *
 * @param modifiers Bit mask of keyboard event modifiers.
 * @return a string representation for the keyboard event modifiers.
 */
public static String getModifiersString(int modifiers) {
    String result = "";
    if ((modifiers & InputEvent.CTRL_MASK) != 0) {
        result = result + "CTRL_MASK | ";
    }
    if ((modifiers & InputEvent.META_MASK) != 0) {
        result = result + "META_MASK | ";
    }
    if ((modifiers & InputEvent.ALT_MASK) != 0) {
        result = result + "ALT_MASK | ";
    }
    if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        result = result + "ALT_GRAPH_MASK | ";
    }
    if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
        result = result + "SHIFT_MASK | ";
    }
    if (result.length() > 0) {
        return result.substring(0, result.length() - 3);
    }
    return result;
}
 
Example 6
Project: openjdk-jdk10   File: EventDispatcher.java   View Source Code Vote up 5 votes
private void robotPressModifiers(int modifiers) {
    if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
        robotPressKey(KeyEvent.VK_SHIFT, modifiers & ~InputEvent.SHIFT_MASK);
    } else if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        robotPressKey(KeyEvent.VK_ALT_GRAPH, modifiers & ~InputEvent.ALT_GRAPH_MASK);
    } else if ((modifiers & InputEvent.ALT_MASK) != 0) {
        robotPressKey(KeyEvent.VK_ALT, modifiers & ~InputEvent.ALT_MASK);
    } else if ((modifiers & InputEvent.META_MASK) != 0) {
        robotPressKey(KeyEvent.VK_META, modifiers & ~InputEvent.META_MASK);
    } else if ((modifiers & InputEvent.CTRL_MASK) != 0) {
        robotPressKey(KeyEvent.VK_CONTROL, modifiers & ~InputEvent.CTRL_MASK);
    }
}
 
Example 7
Project: openjdk-jdk10   File: ModifierRobotEnhancedKeyTest.java   View Source Code Vote up 5 votes
public ModifierRobotEnhancedKeyTest() throws Exception {
    modifierKeys =  new int[4];
    modifierKeys[0] = KeyEvent.VK_SHIFT;
    modifierKeys[1] = KeyEvent.VK_CONTROL;
    modifierKeys[2] = KeyEvent.VK_ALT;
    modifierKeys[3] = KeyEvent.VK_ALT_GRAPH;

    inputMasks = new int[4];
    inputMasks[0] =  InputEvent.SHIFT_MASK;
    inputMasks[1] =  InputEvent.CTRL_MASK;
    inputMasks[2] =  InputEvent.ALT_MASK;
    inputMasks[3] =  InputEvent.ALT_GRAPH_MASK;

    modifierStatus = new boolean[modifierKeys.length];

    textKeys = new int[6];
    textKeys[0] = KeyEvent.VK_A;
    textKeys[1] = KeyEvent.VK_S;
    textKeys[2] = KeyEvent.VK_DELETE;
    textKeys[3] = KeyEvent.VK_HOME;
    textKeys[4] = KeyEvent.VK_F12;
    textKeys[5] = KeyEvent.VK_LEFT;

    textStatus = new boolean[textKeys.length];

    EventQueue.invokeAndWait( () -> { initializeGUI(); });
}
 
Example 8
Project: openjdk-jdk10   File: ModifierRobotKeyTest.java   View Source Code Vote up 5 votes
public ModifierRobotKeyTest() throws Exception {
    modifierKeys =  new int[4];
    modifierKeys[0] = KeyEvent.VK_SHIFT;
    modifierKeys[1] = KeyEvent.VK_CONTROL;
    modifierKeys[2] = KeyEvent.VK_ALT;
    modifierKeys[3] = KeyEvent.VK_ALT_GRAPH;

    inputMasks = new int[4];
    inputMasks[0] =  InputEvent.SHIFT_MASK;
    inputMasks[1] =  InputEvent.CTRL_MASK;
    inputMasks[2] =  InputEvent.ALT_MASK;
    inputMasks[3] =  InputEvent.ALT_GRAPH_MASK;

    modifierStatus = new boolean[modifierKeys.length];

    textKeys = new int[2];
    textKeys[0] = KeyEvent.VK_A;

    String os = System.getProperty("os.name").toLowerCase();

    if (os.contains("solaris") || os.contains("sunos"))
        textKeys[1] = KeyEvent.VK_S;
    else if (os.contains("os x"))
        textKeys[1] = KeyEvent.VK_K;
    else
        textKeys[1] = KeyEvent.VK_I;

    textStatus = new boolean[textKeys.length];

    EventQueue.invokeAndWait( () -> { initializeGUI(); });
}
 
Example 9
Project: org.alloytools.alloy   File: OurUtil.java   View Source Code Vote up 5 votes
/**
 * Construct a new JMenuItem then add it to an existing JMenu.
 * 
 * @param parent - the JMenu to add this JMenuItem into (or null if you
 *            don't want to add it to any JMenu yet)
 * @param label - the text to show on the menu
 * @param attrs - a list of attributes to apply onto the new JMenuItem
 *            <p>
 *            If one positive number a is supplied, we call setMnemonic(a)
 *            <p>
 *            If two positive numbers a and b are supplied, and a!=VK_ALT,
 *            and a!=VK_SHIFT, we call setMnemoic(a) and setAccelerator(b)
 *            <p>
 *            If two positive numbers a and b are supplied, and a==VK_ALT or
 *            a==VK_SHIFT, we call setAccelerator(a | b)
 *            <p>
 *            If an ActionListener is supplied, we call addActionListener(x)
 *            <p>
 *            If an Boolean x is supplied, we call setEnabled(x)
 *            <p>
 *            If an Icon x is supplied, we call setIcon(x)
 */
public static JMenuItem menuItem(JMenu parent, String label, Object... attrs) {
	JMenuItem m = new JMenuItem(label, null);
	int accelMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
	boolean hasMnemonic = false;
	for (Object x : attrs) {
		if (x instanceof Character || x instanceof Integer) {
			int k = (x instanceof Character) ? ((int) ((Character) x)) : ((Integer) x).intValue();
			if (k < 0)
				continue;
			if (k == KeyEvent.VK_ALT) {
				hasMnemonic = true;
				accelMask = accelMask | InputEvent.ALT_MASK;
				continue;
			}
			if (k == KeyEvent.VK_SHIFT) {
				hasMnemonic = true;
				accelMask = accelMask | InputEvent.SHIFT_MASK;
				continue;
			}
			if (!hasMnemonic) {
				m.setMnemonic(k);
				hasMnemonic = true;
			} else
				m.setAccelerator(KeyStroke.getKeyStroke(k, accelMask));
		}
		if (x instanceof ActionListener)
			m.addActionListener((ActionListener) x);
		if (x instanceof Icon)
			m.setIcon((Icon) x);
		if (x instanceof Boolean)
			m.setEnabled((Boolean) x);
	}
	if (parent != null)
		parent.add(m);
	return m;
}
 
Example 10
Project: openjdk-jdk10   File: RobotDriver.java   View Source Code Vote up 5 votes
/**
 * Presses modifiers keys by robot.
 *
 * @param modifiers a combination of {@code InputEvent.*_MASK} fields.
 */
protected void pressModifiers(int modifiers) {
    if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
        pressKey(KeyEvent.VK_SHIFT, modifiers & ~InputEvent.SHIFT_MASK);
    } else if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        pressKey(KeyEvent.VK_ALT_GRAPH, modifiers & ~InputEvent.ALT_GRAPH_MASK);
    } else if ((modifiers & InputEvent.ALT_MASK) != 0) {
        pressKey(KeyEvent.VK_ALT, modifiers & ~InputEvent.ALT_MASK);
    } else if ((modifiers & InputEvent.META_MASK) != 0) {
        pressKey(KeyEvent.VK_META, modifiers & ~InputEvent.META_MASK);
    } else if ((modifiers & InputEvent.CTRL_MASK) != 0) {
        pressKey(KeyEvent.VK_CONTROL, modifiers & ~InputEvent.CTRL_MASK);
    }
}
 
Example 11
Project: openjdk-jdk10   File: RobotDriver.java   View Source Code Vote up 5 votes
/**
 * Releases modifiers keys by robot.
 *
 * @param modifiers a combination of {@code InputEvent.*_MASK} fields.
 */
protected void releaseModifiers(int modifiers) {
    if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
        releaseKey(KeyEvent.VK_SHIFT, modifiers & ~InputEvent.SHIFT_MASK);
    } else if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        releaseKey(KeyEvent.VK_ALT_GRAPH, modifiers & ~InputEvent.ALT_GRAPH_MASK);
    } else if ((modifiers & InputEvent.ALT_MASK) != 0) {
        releaseKey(KeyEvent.VK_ALT, modifiers & ~InputEvent.ALT_MASK);
    } else if ((modifiers & InputEvent.META_MASK) != 0) {
        releaseKey(KeyEvent.VK_META, modifiers & ~InputEvent.META_MASK);
    } else if ((modifiers & InputEvent.CTRL_MASK) != 0) {
        releaseKey(KeyEvent.VK_CONTROL, modifiers & ~InputEvent.CTRL_MASK);
    }
}
 
Example 12
Project: JuggleMasterPro   File: PatternsFileJCheckBoxMenuItem.java   View Source Code Vote up 5 votes
@Override final public void menuKeyReleased(MenuKeyEvent objPmenuKeyEvent) {
	int intLkeysModifiers = objPmenuKeyEvent.getModifiers();
	final int intLaltMask = InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK | InputEvent.ALT_GRAPH_MASK | InputEvent.ALT_GRAPH_DOWN_MASK;
	if (Tools.intersects(intLkeysModifiers, intLaltMask)) {
		Tools.debug("Yep !");
		intLkeysModifiers ^= intLaltMask;
		PatternsFileJCheckBoxMenuItem.setKeysModifiers(intLkeysModifiers);
		return;
	}
	PatternsFileJCheckBoxMenuItem.setKeysModifiers(objPmenuKeyEvent.getModifiers());
}
 
Example 13
Project: jdk8u-jdk   File: AWTKeyStroke.java   View Source Code Vote up 5 votes
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 14
Project: openjdk-jdk10   File: AWTKeyStroke.java   View Source Code Vote up 5 votes
@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
Project: incubator-netbeans   File: BaseCaret.java   View Source Code Vote up 4 votes
private boolean isLeftMouseButtonExt(MouseEvent evt) {
    return (SwingUtilities.isLeftMouseButton(evt)
            && !(evt.isPopupTrigger())
            && (evt.getModifiers() & (InputEvent.META_MASK | InputEvent.ALT_MASK)) == 0);
}
 
Example 16
Project: incubator-netbeans   File: RecentViewListAction.java   View Source Code Vote up 4 votes
@Override
public void actionPerformed(ActionEvent evt) {
    boolean editors = true;
    boolean views = !documentsOnly;
    if( "immediately".equals( evt.getActionCommand() ) ) {
        TopComponent activeTc = TopComponent.getRegistry().getActivated();
        if( null != activeTc ) {
            if( TopComponentTracker.getDefault().isEditorTopComponent( activeTc ) ) {
                //switching in a document, go to some other document
                views = false;
            } else {
                //switching in a view, go to some other view
                editors = false;
                views = true;
            }
        }
    }
    
    TopComponent[] documents = getRecentWindows(editors, views);
    
    if (documents.length < 2) {
        return;
    }
    
    if(!"immediately".equals(evt.getActionCommand()) && // NOI18N
            !(evt.getSource() instanceof javax.swing.JMenuItem)) {
        // #46800: fetch key directly from action command
        KeyStroke keyStroke = Utilities.stringToKey(evt.getActionCommand());
        
        if(keyStroke != null) {
            int triggerKey = keyStroke.getKeyCode();
            int reverseKey = KeyEvent.VK_SHIFT;
            int releaseKey = 0;
            
            int modifiers = keyStroke.getModifiers();
            if((InputEvent.CTRL_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_CONTROL;
            } else if((InputEvent.ALT_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_ALT;
            } else if((InputEvent.META_MASK & modifiers) != 0) {
                releaseKey = KeyEvent.VK_META;
            }
            
            if(releaseKey != 0) {
                if (!KeyboardPopupSwitcher.isShown()) {
                    KeyboardPopupSwitcher.showPopup(documentsOnly, releaseKey, triggerKey, (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0);
                }
                return;
            }
        }
    }

    int documentIndex = (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0 ? 1 : documents.length-1;
    TopComponent tc = documents[documentIndex];
    // #37226 Unmaximized the other mode if needed.
    WindowManagerImpl wm = WindowManagerImpl.getInstance();
    ModeImpl mode = (ModeImpl) wm.findMode(tc);
    if(mode != null && mode != wm.getCurrentMaximizedMode()) {
        wm.switchMaximizedMode(null);
    }
    
    tc.requestActive();
}
 
Example 17
Project: jdk8u-jdk   File: LWCToolkit.java   View Source Code Vote up 4 votes
/**
 * Returns key modifiers used by Swing to set up a focus accelerator key
 * stroke.
 */
@Override
public int getFocusAcceleratorKeyMask() {
    return InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
}
 
Example 18
Project: openjdk-jdk10   File: bug6596966.java   View Source Code Vote up 4 votes
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            button = new JButton("Button");
            comboBox = new JComboBox();

            label = new JLabel("Label");
            label.setDisplayedMnemonic('L');
            label.setLabelFor(comboBox);

            JPanel pnContent = new JPanel();

            pnContent.add(button);
            pnContent.add(label);
            pnContent.add(comboBox);

            frame = new JFrame();

            frame.add(pnContent);
            frame.pack();
            frame.setVisible(true);
        }
    });

    robot.waitForIdle();


    int keyMask = InputEvent.ALT_MASK;
    if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
        keyMask = InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
    }
    ArrayList<Integer> keys = Util.getKeyCodesFromKeyMask(keyMask);
    for (int i = 0; i < keys.size(); ++i) {
        robot.keyPress(keys.get(i));
    }

    robot.keyPress(KeyEvent.VK_L);

    robot.waitForIdle();
    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new KeyEvent(label, KeyEvent.KEY_RELEASED,
            EventQueue.getMostRecentEventTime(), 0, KeyEvent.VK_L, 'L'));

    robot.waitForIdle();

    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                if (!comboBox.isFocusOwner()) {
                    throw new RuntimeException("comboBox isn't focus owner");
                }
            }
        });
    } finally {
        robot.keyRelease(KeyEvent.VK_L);
        for (int i = 0; i < keys.size(); ++i) {
            robot.keyRelease(keys.get(i));
        }
        robot.waitForIdle();
    }
}
 
Example 19
Project: openjdk-jdk10   File: LWCToolkit.java   View Source Code Vote up 4 votes
/**
 * Returns key modifiers used by Swing to set up a focus accelerator key
 * stroke.
 */
@Override
@SuppressWarnings("deprecation")
public int getFocusAcceleratorKeyMask() {
    return InputEvent.CTRL_MASK | InputEvent.ALT_MASK;
}
 
Example 20
Project: OpenJSharp   File: SunToolkit.java   View Source Code Vote up 2 votes
/**
 * Tests whether specified key modifiers mask can be used to enter a printable
 * character. This is a default implementation of this method, which reflects
 * the way things work on Windows: here, pressing ctrl + alt allows user to enter
 * characters from the extended character set (like euro sign or math symbols)
 */
public boolean isPrintableCharacterModifiersMask(int mods) {
    return ((mods & InputEvent.ALT_MASK) == (mods & InputEvent.CTRL_MASK));
}