Example usage for java.awt.event KeyEvent getKeyLocation

List of usage examples for java.awt.event KeyEvent getKeyLocation

Introduction

In this page you can find the example usage for java.awt.event KeyEvent getKeyLocation.

Prototype

public int getKeyLocation() 

Source Link

Document

Returns the location of the key that originated this key event.

Usage

From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java

@Override
public void keyPressed(KeyEvent e) {
    if (e.getSource() != table) {
        return;/*from w ww.ja va2 s.c  om*/
    }

    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        // What's the current selection ?
        final List<File> selection = getSelection();

        if (selection.size() == 1) {
            final File selectedFile = selection.iterator().next();

            if (selectedFile.isDirectory()) {
                // Change to the selected directory
                setDirectory(selectedFile);
            }
        }
    } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
        // Return to the parent directory (if any)
        final File parentDir = getParentDirectory();

        if ((parentDir != null) && parentDir.exists()) {
            setDirectory(parentDir);
        }
    } else {
        // Propagate event to our listeners
        processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(),
                e.getKeyChar(), e.getKeyLocation()));
    }
}

From source file:tufts.vue.RichTextBox.java

private static boolean isFinishEditKeyPress(KeyEvent e) {
    // if we hit return key either on numpad ("enter" key), or
    // with any modifier down except a shift alone (in case of
    // caps lock) complete the edit.
    return e.getKeyCode() == KeyEvent.VK_ENTER && (e.getKeyLocation() == KeyEvent.KEY_LOCATION_NUMPAD
            || (e.getModifiersEx() != 0 && !e.isShiftDown())) == true;
    //== false; // reversed logic of below description
}