Java Code Examples for java.awt.AWTKeyStroke

The following are top voted examples for showing how to use java.awt.AWTKeyStroke. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: ShortcutAndMenuKeyEventProcessor.java   View source code 6 votes vote down vote up
public static synchronized void install() {
    if(installed) {
        return;
    }
    
    ShortcutAndMenuKeyEventProcessor instance = getDefault();
    
    KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    keyboardFocusManager.addKeyEventDispatcher(instance);
    keyboardFocusManager.addKeyEventPostProcessor(instance);
    // #63252: Disable focus traversal functionality of Ctrl+Tab and Ctrl+Shift+Tab,
    // to allow our own document switching (RecentViewListAction)
    defaultForward = keyboardFocusManager.getDefaultFocusTraversalKeys(
                        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    defaultBackward = keyboardFocusManager.getDefaultFocusTraversalKeys(
                        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
    keyboardFocusManager.setDefaultFocusTraversalKeys(
        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
        Collections.singleton(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0))
    );                
    keyboardFocusManager.setDefaultFocusTraversalKeys(
        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
        Collections.singleton(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK))
    );                
}
 
Example 2
Project: incubator-netbeans   File: ShortcutEnterPanel.java   View source code 6 votes vote down vote up
/** Creates new form ShortcutCustomizerPanel */
public ShortcutEnterPanel() {
    initComponents();
    bTab = new JButton();
    bClear = new JButton();
    loc(bTab, "CTL_Tab");
    loc(bClear, "CTL_Clear");
    tfShortcut.setFocusTraversalKeys(
            KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
            Collections.<AWTKeyStroke>emptySet()
            );
    tfShortcut.setFocusTraversalKeys(
            KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS,
            Collections.<AWTKeyStroke>emptySet()
            );
    tfShortcut.setFocusTraversalKeys(
            KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS,
            Collections.<AWTKeyStroke>emptySet()
            );
    
    tfShortcut.addKeyListener(listener);        
}
 
Example 3
Project: OpenJSharp   File: XEmbedHelper.java   View source code 6 votes vote down vote up
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
Example 4
Project: jdk8u-jdk   File: XEmbedHelper.java   View source code 6 votes vote down vote up
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
Example 5
Project: openjdk-jdk10   File: XEmbedHelper.java   View source code 6 votes vote down vote up
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
Example 6
Project: openjdk-jdk10   File: TestAWTKeyStroke.java   View source code 6 votes vote down vote up
private static void checkAWTKeyStroke(int keyCode, int modifiers,
        boolean onKeyRelease) throws Exception {

    AWTKeyStroke awtKeyStroke1 = AWTKeyStroke.getAWTKeyStroke(
            keyCode, modifiers, onKeyRelease);

    checkAWTKeyStroke(awtKeyStroke1, keyCode, modifiers, onKeyRelease);

    AWTKeyStroke awtKeyStroke2 = AWTKeyStroke.getAWTKeyStroke(
            keyCode, modifiers, onKeyRelease);

    if (awtKeyStroke1 != awtKeyStroke2) {
        throw new RuntimeException("AWTKeyStroke is not cached!");
    }

    checkSerializedKeyStroke(awtKeyStroke1);
}
 
Example 7
Project: openjdk-jdk10   File: TestAWTKeyStroke.java   View source code 6 votes vote down vote up
private static void checkSerializedKeyStrokes(int keyCode, int modifiers,
        boolean onKeyRelease) throws Exception {

    AWTKeyStroke awtKeyStroke = AWTKeyStroke.getAWTKeyStroke(
            keyCode, modifiers, onKeyRelease);

    KeyStroke keyStroke = KeyStroke.getKeyStroke(
            keyCode, modifiers, onKeyRelease);

    if (awtKeyStroke != getSerializedAWTKeyStroke(awtKeyStroke)) {
        throw new RuntimeException("Serialized AWTKeyStroke is not cached!");
    }

    awtKeyStroke = AWTKeyStroke.getAWTKeyStroke(
            keyCode, modifiers, !onKeyRelease);

    if (!keyStroke.equals(getSerializedAWTKeyStroke(keyStroke))) {
        throw new RuntimeException("Serialized KeyStroke is not cached!");
    }
}
 
Example 8
Project: openjdk9   File: XEmbedHelper.java   View source code 6 votes vote down vote up
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
Example 9
Project: openjdk9   File: TestAWTKeyStroke.java   View source code 6 votes vote down vote up
private static void checkAWTKeyStroke(int keyCode, int modifiers,
        boolean onKeyRelease) throws Exception {

    AWTKeyStroke awtKeyStroke1 = AWTKeyStroke.getAWTKeyStroke(
            keyCode, modifiers, onKeyRelease);

    checkAWTKeyStroke(awtKeyStroke1, keyCode, modifiers, onKeyRelease);

    AWTKeyStroke awtKeyStroke2 = AWTKeyStroke.getAWTKeyStroke(
            keyCode, modifiers, onKeyRelease);

    if (awtKeyStroke1 != awtKeyStroke2) {
        throw new RuntimeException("AWTKeyStroke is not cached!");
    }

    checkSerializedKeyStroke(awtKeyStroke1);
}
 
Example 10
Project: openjdk9   File: TestAWTKeyStroke.java   View source code 6 votes vote down vote up
private static void checkSerializedKeyStrokes(int keyCode, int modifiers,
        boolean onKeyRelease) throws Exception {

    AWTKeyStroke awtKeyStroke = AWTKeyStroke.getAWTKeyStroke(
            keyCode, modifiers, onKeyRelease);

    KeyStroke keyStroke = KeyStroke.getKeyStroke(
            keyCode, modifiers, onKeyRelease);

    if (awtKeyStroke != getSerializedAWTKeyStroke(awtKeyStroke)) {
        throw new RuntimeException("Serialized AWTKeyStroke is not cached!");
    }

    awtKeyStroke = AWTKeyStroke.getAWTKeyStroke(
            keyCode, modifiers, !onKeyRelease);

    if (!keyStroke.equals(getSerializedAWTKeyStroke(keyStroke))) {
        throw new RuntimeException("Serialized KeyStroke is not cached!");
    }
}
 
Example 11
Project: jdk8u_jdk   File: XEmbedHelper.java   View source code 6 votes vote down vote up
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
Example 12
Project: lookaside_java-1.8.0-openjdk   File: XEmbedHelper.java   View source code 6 votes vote down vote up
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
Example 13
Project: pitanga-system   File: EnterComoTab.java   View source code 6 votes vote down vote up
/**
 * Este método faz com que o ENTER seja considerado como TAB, em componentes
 * como um JTextField. Além disso, permite a navegação com as setas para
 * cima e para baixo.
 *
 * @param comp O componente.
 */
public static void considerarEnterComoTab(Component comp) {
    Set<AWTKeyStroke> newKeystrokes;
    newKeystrokes = new HashSet<AWTKeyStroke>(
            comp.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, 0));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_DOWN, 0));
    comp.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
            newKeystrokes);
    newKeystrokes = new HashSet<AWTKeyStroke>(
            comp.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER,
            InputEvent.SHIFT_DOWN_MASK));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_UP, 0));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_UP, 0));
    comp.setFocusTraversalKeys(
            KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newKeystrokes);
}
 
Example 14
Project: pitanga-system   File: EnterComoTab.java   View source code 6 votes vote down vote up
/**
 * Este método faz com que as setas sejam consideradas como TAB, e deve ser
 * usado em um botão qualquer.
 *
 * @param comp O componente.
 */
public static void considerarSetaComoTab(JButton comp) {
    Set<AWTKeyStroke> newKeystrokes;
    newKeystrokes = new HashSet<AWTKeyStroke>(
            comp.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_DOWN, 0));
    comp.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
            newKeystrokes);
    newKeystrokes = new HashSet<AWTKeyStroke>(
            comp.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_UP, 0));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_UP, 0));
    comp.setFocusTraversalKeys(
            KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newKeystrokes);
}
 
Example 15
Project: pitanga-system   File: GUIUtils.java   View source code 6 votes vote down vote up
/**
 * Este método faz com que o ENTER seja considerado como TAB, em componentes
 * como um JTextField. Além disso, permite a navegação com as setas para
 * esquerda e para direita.
 *
 * @param comp O componente.
 */
public static void considerarEnterComoTab(Component comp) {
    Set<AWTKeyStroke> newKeystrokes;
    newKeystrokes = new HashSet<AWTKeyStroke>(
            comp.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER, 0));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_RIGHT, 0));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_RIGHT, 0));
    comp.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
            newKeystrokes);
    newKeystrokes = new HashSet<AWTKeyStroke>(
            comp.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_ENTER,
            InputEvent.SHIFT_DOWN_MASK));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_LEFT, 0));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_LEFT, 0));
    comp.setFocusTraversalKeys(
            KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newKeystrokes);
}
 
Example 16
Project: pitanga-system   File: GUIUtils.java   View source code 6 votes vote down vote up
/**
 * Este método faz com que as setas sejam consideradas como TAB, e deve ser
 * usado em um botão qualquer.
 *
 * @param comp O componente.
 */
public static void considerarSetaComoTab(JButton comp) {
    Set<AWTKeyStroke> newKeystrokes;
    newKeystrokes = new HashSet<AWTKeyStroke>(
            comp.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_RIGHT, 0));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_RIGHT, 0));
    comp.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
            newKeystrokes);
    newKeystrokes = new HashSet<AWTKeyStroke>(
            comp.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_LEFT, 0));
    newKeystrokes.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_KP_LEFT, 0));
    comp.setFocusTraversalKeys(
            KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newKeystrokes);
}
 
Example 17
Project: infobip-open-jdk-8   File: XEmbedHelper.java   View source code 6 votes vote down vote up
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
Example 18
Project: jdk8u-dev-jdk   File: XEmbedHelper.java   View source code 6 votes vote down vote up
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
Example 19
Project: jdk7-jdk   File: XEmbedHelper.java   View source code 6 votes vote down vote up
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
Example 20
Project: cac-agent   File: SwingIdentityKeyChooser.java   View source code 6 votes vote down vote up
private void bindArrowKeys(JDialog dialog) {
	{
		Set<AWTKeyStroke> forwardKeys = dialog.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
		Set<AWTKeyStroke> newForwardKeys = new HashSet<>(forwardKeys);
		newForwardKeys.add(KeyStroke.getKeyStroke("DOWN"));
		newForwardKeys.add(KeyStroke.getKeyStroke("RIGHT"));
		dialog.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newForwardKeys);
	}

	{
		Set<AWTKeyStroke> backwardKeys = dialog.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
		Set<AWTKeyStroke> newBackwardKeys = new HashSet<>(backwardKeys);
		newBackwardKeys.add(KeyStroke.getKeyStroke("UP"));
		newBackwardKeys.add(KeyStroke.getKeyStroke("LEFT"));
		dialog.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, newBackwardKeys);
	}
}
 
Example 21
Project: openjdk-source-code-learn   File: XEmbedHelper.java   View source code 6 votes vote down vote up
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
Example 22
Project: OLD-OpenJDK8   File: XEmbedHelper.java   View source code 6 votes vote down vote up
AWTKeyStroke getKeyStrokeForKeySym(long keysym, long state) {
    XBaseWindow.checkSecurity();

    int keycode;

    XToolkit.awtLock();
    try {
        XKeysym.Keysym2JavaKeycode kc = XKeysym.getJavaKeycode( keysym );
        if(kc == null) {
            keycode = java.awt.event.KeyEvent.VK_UNDEFINED;
        }else{
            keycode = kc.getJavaKeycode();
        }
    } finally {
        XToolkit.awtUnlock();
    }

    int modifiers = getModifiers((int)state);
    return AWTKeyStroke.getAWTKeyStroke(keycode, modifiers);
}
 
Example 23
Project: cn1   File: BasicTextUI.java   View source code 6 votes vote down vote up
final Set<AWTKeyStroke> getDefaultFocusTraversalKeys(final int mode) {
    Set<AWTKeyStroke> result = component.getFocusTraversalKeys(mode);
    
    if (result == null) {
        result = new LinkedHashSet<AWTKeyStroke>();
        if (mode == KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS) {
            result.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB,
                                        InputEvent.CTRL_DOWN_MASK));
        } else {
            result.add(KeyStroke
                       .getKeyStroke(KeyEvent.VK_TAB,
                               InputEvent.CTRL_DOWN_MASK
                                     | InputEvent.SHIFT_DOWN_MASK));
        }
   } else {
       result = new LinkedHashSet<AWTKeyStroke>(result);
   }
    
   return result;
}
 
Example 24
Project: wandora   File: SimpleField.java   View source code 6 votes vote down vote up
public void initialize() {
    this.addMouseListener(this);
    // this.setFocusTraversalKeysEnabled(false);
    this.addKeyListener(this);
    this.setFocusable(true);
    this.addFocusListener(this);
    this.setFocusTraversalKeysEnabled(true);
    this.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,new HashSet(new EasyVector(new Object[]{AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,0)})));
    this.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,new HashSet(new EasyVector(new Object[]{AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,InputEvent.SHIFT_DOWN_MASK)})));
    this.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    
    // undoManager = new UndoManager();
    // Document document = this.getDocument();
    // document.addUndoableEditListener(undoManager);
 
    this.setMargin(defaultMargins);
    
    this.setDragEnabled(true);
    dt = new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
    
    setPopupMenu();
}
 
Example 25
Project: incubator-netbeans   File: ShortcutsDialog.java   View source code 5 votes vote down vote up
void init(ShortcutsFinder f) {
        this.f = f;
        loc (lShortcut, "Shortcut"); //NOI18N
        lConflict.setForeground (Color.red);
        loc (bTab, "CTL_Tab"); //NOI18N
        bTab.getAccessibleContext().setAccessibleName(loc("AN_Tab")); //NOI18N
        bTab.getAccessibleContext().setAccessibleDescription(loc("AD_Tab")); //NOI18N
        loc (bClear, "CTL_Clear"); //NOI18N
        bClear.getAccessibleContext().setAccessibleName(loc("AN_Clear")); //NOI18N
        bClear.getAccessibleContext().setAccessibleDescription(loc("AD_Clear")); //NOI18N
        tfShortcut.setFocusTraversalKeys (
            KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, 
            Collections.<AWTKeyStroke>emptySet()
        );
        tfShortcut.setFocusTraversalKeys (
            KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS, 
            Collections.<AWTKeyStroke>emptySet()
        );
        tfShortcut.getAccessibleContext().setAccessibleName(loc("AN_Shortcut")); //NOI18N
        tfShortcut.getAccessibleContext().setAccessibleDescription(loc("AD_Shortcut")); //NOI18N
        lShortcut.setDisplayedMnemonic(loc("CTL_Shortcut_Mnemonic").charAt(0));
//        tfShortcut.setFocusTraversalKeys (
//            KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, 
//            Collections.EMPTY_SET
//        );
        tfShortcut.setFocusTraversalKeys (
            KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, 
            Collections.<AWTKeyStroke>emptySet()
        );
        listener = new Listener ();
        tfShortcut.addKeyListener(listener);
    }
 
Example 26
Project: incubator-netbeans   File: FileSelectorField.java   View source code 5 votes vote down vote up
private void setTabTraversalEnabled(boolean enabled) {
    Set<AWTKeyStroke> tKeys = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    Set<AWTKeyStroke> newTKeys = new HashSet<>(tKeys);
    if (enabled) {
        newTKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0));
    } else {
        newTKeys.remove(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0));
    }
    setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newTKeys);
}
 
Example 27
Project: OpenJSharp   File: MetaData.java   View source code 5 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    AWTKeyStroke key = (AWTKeyStroke) oldInstance;

    char ch = key.getKeyChar();
    int code = key.getKeyCode();
    int mask = key.getModifiers();
    boolean onKeyRelease = key.isOnKeyRelease();

    Object[] args = null;
    if (ch == KeyEvent.CHAR_UNDEFINED) {
        args = !onKeyRelease
                ? new Object[]{code, mask}
                : new Object[]{code, mask, onKeyRelease};
    } else if (code == KeyEvent.VK_UNDEFINED) {
        if (!onKeyRelease) {
            args = (mask == 0)
                    ? new Object[]{ch}
                    : new Object[]{ch, mask};
        } else if (mask == 0) {
            args = new Object[]{ch, onKeyRelease};
        }
    }
    if (args == null) {
        throw new IllegalStateException("Unsupported KeyStroke: " + key);
    }
    Class<?> type = key.getClass();
    String name = type.getName();
    // get short name of the class
    int index = name.lastIndexOf('.') + 1;
    if (index > 0) {
        name = name.substring(index);
    }
    return new Expression( key, type, "get" + name, args );
}
 
Example 28
Project: OpenJSharp   File: InputContext.java   View source code 5 votes vote down vote up
/**
 * Checks the key event is the input method selection key or not.
 */
private boolean checkInputMethodSelectionKey(KeyEvent event) {
    if (inputMethodSelectionKey != null) {
        AWTKeyStroke aKeyStroke = AWTKeyStroke.getAWTKeyStrokeForEvent(event);
        return inputMethodSelectionKey.equals(aKeyStroke);
    } else {
        return false;
    }
}
 
Example 29
Project: OpenJSharp   File: InputContext.java   View source code 5 votes vote down vote up
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
Example 30
Project: OpenJSharp   File: XEmbedClientHelper.java   View source code 5 votes vote down vote up
void registerAccelerator(AWTKeyStroke stroke, int id) {
    if (active) {
        long sym = getX11KeySym(stroke);
        long mods = getX11Mods(stroke);
        sendMessage(server, XEMBED_REGISTER_ACCELERATOR, id, sym, mods);
    }
}
 
Example 31
Project: OpenJSharp   File: XEmbedClientHelper.java   View source code 5 votes vote down vote up
long getX11KeySym(AWTKeyStroke stroke) {
    XToolkit.awtLock();
    try {
        return XWindow.getKeySymForAWTKeyCode(stroke.getKeyCode());
    } finally {
        XToolkit.awtUnlock();
    }
}
 
Example 32
Project: jdk8u-jdk   File: MetaData.java   View source code 5 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    AWTKeyStroke key = (AWTKeyStroke) oldInstance;

    char ch = key.getKeyChar();
    int code = key.getKeyCode();
    int mask = key.getModifiers();
    boolean onKeyRelease = key.isOnKeyRelease();

    Object[] args = null;
    if (ch == KeyEvent.CHAR_UNDEFINED) {
        args = !onKeyRelease
                ? new Object[]{code, mask}
                : new Object[]{code, mask, onKeyRelease};
    } else if (code == KeyEvent.VK_UNDEFINED) {
        if (!onKeyRelease) {
            args = (mask == 0)
                    ? new Object[]{ch}
                    : new Object[]{ch, mask};
        } else if (mask == 0) {
            args = new Object[]{ch, onKeyRelease};
        }
    }
    if (args == null) {
        throw new IllegalStateException("Unsupported KeyStroke: " + key);
    }
    Class<?> type = key.getClass();
    String name = type.getName();
    // get short name of the class
    int index = name.lastIndexOf('.') + 1;
    if (index > 0) {
        name = name.substring(index);
    }
    return new Expression( key, type, "get" + name, args );
}
 
Example 33
Project: jdk8u-jdk   File: InputContext.java   View source code 5 votes vote down vote up
/**
 * Checks the key event is the input method selection key or not.
 */
private boolean checkInputMethodSelectionKey(KeyEvent event) {
    if (inputMethodSelectionKey != null) {
        AWTKeyStroke aKeyStroke = AWTKeyStroke.getAWTKeyStrokeForEvent(event);
        return inputMethodSelectionKey.equals(aKeyStroke);
    } else {
        return false;
    }
}
 
Example 34
Project: jdk8u-jdk   File: InputContext.java   View source code 5 votes vote down vote up
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
Example 35
Project: jdk8u-jdk   File: XEmbedClientHelper.java   View source code 5 votes vote down vote up
void registerAccelerator(AWTKeyStroke stroke, int id) {
    if (active) {
        long sym = getX11KeySym(stroke);
        long mods = getX11Mods(stroke);
        sendMessage(server, XEMBED_REGISTER_ACCELERATOR, id, sym, mods);
    }
}
 
Example 36
Project: jdk8u-jdk   File: XEmbedClientHelper.java   View source code 5 votes vote down vote up
long getX11KeySym(AWTKeyStroke stroke) {
    XToolkit.awtLock();
    try {
        return XWindow.getKeySymForAWTKeyCode(stroke.getKeyCode());
    } finally {
        XToolkit.awtUnlock();
    }
}
 
Example 37
Project: openjdk-jdk10   File: MetaData.java   View source code 5 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    AWTKeyStroke key = (AWTKeyStroke) oldInstance;

    char ch = key.getKeyChar();
    int code = key.getKeyCode();
    int mask = key.getModifiers();
    boolean onKeyRelease = key.isOnKeyRelease();

    Object[] args = null;
    if (ch == KeyEvent.CHAR_UNDEFINED) {
        args = !onKeyRelease
                ? new Object[]{code, mask}
                : new Object[]{code, mask, onKeyRelease};
    } else if (code == KeyEvent.VK_UNDEFINED) {
        if (!onKeyRelease) {
            args = (mask == 0)
                    ? new Object[]{ch}
                    : new Object[]{ch, mask};
        } else if (mask == 0) {
            args = new Object[]{ch, onKeyRelease};
        }
    }
    if (args == null) {
        throw new IllegalStateException("Unsupported KeyStroke: " + key);
    }
    Class<?> type = key.getClass();
    String name = type.getName();
    // get short name of the class
    int index = name.lastIndexOf('.') + 1;
    if (index > 0) {
        name = name.substring(index);
    }
    return new Expression( key, type, "get" + name, args );
}
 
Example 38
Project: openjdk-jdk10   File: InputContext.java   View source code 5 votes vote down vote up
/**
 * Checks the key event is the input method selection key or not.
 */
private boolean checkInputMethodSelectionKey(KeyEvent event) {
    if (inputMethodSelectionKey != null) {
        AWTKeyStroke aKeyStroke = AWTKeyStroke.getAWTKeyStrokeForEvent(event);
        return inputMethodSelectionKey.equals(aKeyStroke);
    } else {
        return false;
    }
}
 
Example 39
Project: openjdk-jdk10   File: InputContext.java   View source code 5 votes vote down vote up
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
Example 40
Project: openjdk-jdk10   File: XEmbeddedFrame.java   View source code 5 votes vote down vote up
public void registerAccelerator(AWTKeyStroke stroke) {
    XEmbeddedFramePeer xefp = AWTAccessor.getComponentAccessor()
                                         .getPeer(this);
    if (xefp != null) {
        xefp.registerAccelerator(stroke);
    }
}