Example usage for java.awt.event KeyEvent getWhen

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

Introduction

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

Prototype

public long getWhen() 

Source Link

Document

Returns the difference in milliseconds between the timestamp of when this event occurred and midnight, January 1, 1970 UTC.

Usage

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

@Override
public void keyReleased(KeyEvent e) {
    if (e.getSource() == getSelectedComponent()) {
        // Propagate the event to our listeners
        processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(),
                e.getKeyChar(), e.getKeyLocation()));
    }//www .  j a v  a  2s .c o  m
}

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

@Override
public void keyTyped(KeyEvent e) {
    if (e.getSource() == getSelectedComponent()) {
        // Propagate the event to our listeners
        processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(),
                e.getKeyChar(), e.getKeyLocation()));
    }/*w w  w.  ja va 2 s.com*/
}

From source file:Main.java

private void displayInfo(KeyEvent e, String keyStatus) {

    // You should only rely on the key char if the event
    // is a key typed event.
    int id = e.getID();
    String keyString;// w w  w.  ja  v a2 s.  co  m
    if (id == KeyEvent.KEY_TYPED) {
        char c = e.getKeyChar();
        keyString = "key character = '" + c + "'";
    } else {
        int keyCode = e.getKeyCode();
        keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")";
    }

    int modifiersEx = e.getModifiersEx();
    String modString = "extended modifiers = " + modifiersEx;
    String tmpString = KeyEvent.getModifiersExText(modifiersEx);
    System.out.println(e.getWhen());

    if (tmpString.length() > 0) {
        modString += " (" + tmpString + ")";
    } else {
        modString += " (no extended modifiers)";
    }

    String actionString = "action key? ";
    if (e.isActionKey()) {
        actionString += "YES";
    } else {
        actionString += "NO";
    }

    String locationString = "key location: ";
    int location = e.getKeyLocation();
    if (location == KeyEvent.KEY_LOCATION_STANDARD) {
        locationString += "standard";
    } else if (location == KeyEvent.KEY_LOCATION_LEFT) {
        locationString += "left";
    } else if (location == KeyEvent.KEY_LOCATION_RIGHT) {
        locationString += "right";
    } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) {
        locationString += "numpad";
    } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN)
        locationString += "unknown";
    }

    displayArea.append(keyStatus + newline + "    " + keyString + newline + "    " + modString + newline
            + "    " + actionString + newline + "    " + locationString + newline);
    displayArea.setCaretPosition(displayArea.getDocument().getLength());
}

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

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

    // Propagate event to our listeners
    processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(),
            e.getKeyLocation()));
}

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

@Override
public void keyTyped(KeyEvent e) {
    if (e.getSource() != table) {
        return;/*from   w w  w . j  a v  a2 s .c om*/
    }

    // Propagate event to our listeners
    processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(),
            e.getKeyLocation()));
}

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

@Override
public void keyPressed(KeyEvent e) {
    if (e.getSource() == getSelectedComponent()) {
        final boolean metaDown = (e.getModifiersEx() | KeyEvent.META_DOWN_MASK) == KeyEvent.META_DOWN_MASK;

        if ((e.getKeyCode() == KeyEvent.VK_T) && metaDown) {
            // Create a new tab and set to focus on it
            setSelectedComponent(addBrowserTab(getActiveBrowser().getDirectory()));
        } else if ((e.getKeyCode() == KeyEvent.VK_W) && metaDown) {
            if (getTabCount() > 1) {
                // Close the current tab (only if not the last one)
                closeActiveBrowserTab();
            }/*from   www.j av  a 2  s.  c  om*/
        } else if ((e.getKeyCode() >= KeyEvent.VK_1) && (e.getKeyCode() <= KeyEvent.VK_9) && metaDown) {
            final int index = e.getKeyCode() - KeyEvent.VK_1;

            if (index <= getTabCount() - 1) {
                setSelectedIndex(index);
            }
        } 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:com.github.fritaly.dualcommander.DirectoryBrowser.java

@Override
public void keyPressed(KeyEvent e) {
    if (e.getSource() != table) {
        return;/*ww w  .ja  v a  2  s.com*/
    }

    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()));
    }
}