Example usage for java.awt.event KeyEvent getID

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

Introduction

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

Prototype

public int getID() 

Source Link

Document

Returns the event type.

Usage

From source file:KeyEventDemo.java

protected void displayInfo(KeyEvent e, String s) {
    String keyString, modString, tmpString, actionString, locationString;

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

    int modifiers = e.getModifiersEx();
    modString = "modifiers = " + modifiers;
    tmpString = KeyEvent.getModifiersExText(modifiers);
    if (tmpString.length() > 0) {
        modString += " (" + tmpString + ")";
    } else {
        modString += " (no modifiers)";
    }

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

    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(s + 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  w w w  .j  av  a 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. ja v a  2  s.  c  o  m
    }

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

From source file:AvatarTest.java

/**
 * Process a keyboard event//from ww w.j ava 2 s. c o  m
 */
private void processAWTEvent(AWTEvent[] events) {
    for (int n = 0; n < events.length; n++) {
        if (events[n] instanceof KeyEvent) {
            KeyEvent eventKey = (KeyEvent) events[n];

            if (eventKey.getID() == KeyEvent.KEY_PRESSED) {
                int keyCode = eventKey.getKeyCode();
                int keyChar = eventKey.getKeyChar();

                Vector3f translate = new Vector3f();

                Transform3D t3d = new Transform3D();
                m_TransformGroup.getTransform(t3d);
                t3d.get(translate);

                switch (keyCode) {
                case KeyEvent.VK_LEFT:
                    translate.x += TRANSLATE_LEFT;
                    break;

                case KeyEvent.VK_RIGHT:
                    translate.x += TRANSLATE_RIGHT;
                    break;
                }

                // System.out.println( "Steering: " + translate.x );
                translate.y = 0.5f;

                t3d.setTranslation(translate);
                m_TransformGroup.setTransform(t3d);
            }
        }
    }
}

From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java

@Override
public void processKeyEvent(java.awt.event.KeyEvent e, JXLayer<? extends V> l) {
    if (e.getID() != KeyEvent.KEY_PRESSED) {
        // We are only interested in KEY_PRESSED event.
        return;/*from   w  w  w .  java2s. c om*/
    }
    final int code = e.getKeyCode();
    switch (code) {
    case KeyEvent.VK_LEFT:
        this.updateTraceInfosIfPossible(-1);
        break;
    case KeyEvent.VK_RIGHT:
        this.updateTraceInfosIfPossible(+1);
        break;
    }
}

From source file:com.frostwire.gui.player.MediaPlayer.java

protected MediaPlayer() {
    lastRandomFiles = new LinkedList<MediaSource>();
    playExecutor = ExecutorsHelper.newProcessingQueue("AudioPlayer-PlayExecutor");

    String playerPath;// ww w .  j  a  va  2 s  . c o m
    playerPath = getPlayerPath();

    MPlayer.initialise(new File(playerPath));
    mplayer = new MPlayer();
    mplayer.addPositionListener(new PositionListener() {
        public void positionChanged(float currentTimeInSecs) {
            notifyProgress(currentTimeInSecs);
        }
    });
    mplayer.addStateListener(new StateListener() {
        public void stateChanged(MediaPlaybackState newState) {
            if (newState == MediaPlaybackState.Closed) { // This is the case
                                                         // mplayer is
                                                         // done with the
                                                         // current file
                playNextMedia();
            }
        }
    });
    mplayer.addIcyInfoListener(new IcyInfoListener() {
        public void newIcyInfoData(String data) {
            notifyIcyInfo(data);
        }
    });

    repeatMode = RepeatMode.values()[PlayerSettings.LOOP_PLAYLIST.getValue()];
    shuffle = PlayerSettings.SHUFFLE_PLAYLIST.getValue();
    playNextMedia = true;
    volume = PlayerSettings.PLAYER_VOLUME.getValue();
    notifyVolumeChanged();

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_SPACE) {
                Object s = e.getComponent();
                if (!(s instanceof JTextField)
                        && !(s instanceof JTable && ((JTable) s).isEditing() && !(s instanceof JCheckBox))) {
                    togglePause();
                    return true;
                }
            }
            return false;
        }
    });

    // prepare to receive UI events
    MPlayerUIEventHandler.instance().addListener(this);
}

From source file:com.igormaznitsa.sciareto.ui.MainFrame.java

private void menuFullScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuFullScreenActionPerformed
    final Component currentComponent = this.tabPane.getSelectedComponent();
    if (!(currentComponent instanceof Container)) {
        LOGGER.warn("Detected attempt to full screen not a container : " + currentComponent);
        return;/*  w  ww.  j  av a2  s .c om*/
    }

    final GraphicsConfiguration gconfig = this.getGraphicsConfiguration();
    if (gconfig != null) {
        final GraphicsDevice device = gconfig.getDevice();
        if (device.isFullScreenSupported()) {
            if (device.getFullScreenWindow() == null) {
                final JLabel label = new JLabel("Opened in full screen");
                final int tabIndex = this.tabPane.getSelectedIndex();
                this.tabPane.setComponentAt(tabIndex, label);
                final JWindow window = new JWindow(Main.getApplicationFrame());
                window.setAlwaysOnTop(true);
                window.setContentPane((Container) currentComponent);

                endFullScreenIfActive();

                final KeyEventDispatcher fullScreenEscCatcher = new KeyEventDispatcher() {
                    @Override
                    public boolean dispatchKeyEvent(@Nonnull final KeyEvent e) {
                        if (e.getID() == KeyEvent.KEY_PRESSED && (e.getKeyCode() == KeyEvent.VK_ESCAPE
                                || e.getKeyCode() == KeyEvent.VK_F11)) {
                            endFullScreenIfActive();
                            return true;
                        }
                        return false;
                    }
                };

                if (this.taskToEndFullScreen.compareAndSet(null, new Runnable() {
                    @Override
                    public void run() {
                        try {
                            window.dispose();
                        } finally {
                            tabPane.setComponentAt(tabIndex, currentComponent);
                            device.setFullScreenWindow(null);
                            KeyboardFocusManager.getCurrentKeyboardFocusManager()
                                    .removeKeyEventDispatcher(fullScreenEscCatcher);
                        }
                    }
                })) {
                    try {
                        KeyboardFocusManager.getCurrentKeyboardFocusManager()
                                .addKeyEventDispatcher(fullScreenEscCatcher);
                        device.setFullScreenWindow(window);
                    } catch (Exception ex) {
                        LOGGER.error("Can't turn on full screen", ex);
                        endFullScreenIfActive();
                        KeyboardFocusManager.getCurrentKeyboardFocusManager()
                                .removeKeyEventDispatcher(fullScreenEscCatcher);
                    }
                } else {
                    LOGGER.error("Unexpected state, processor is not null!");
                }
            } else {
                LOGGER.warn("Attempt to full screen device which already in full screen!");
            }
        } else {
            LOGGER.warn("Device doesn's support full screen");
            DialogProviderManager.getInstance().getDialogProvider()
                    .msgWarn("The Device doesn't support full-screen mode!");
        }
    } else {
        LOGGER.warn("Can't find graphics config for the frame");
    }
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

@Override
public void processKeyEvent(java.awt.event.KeyEvent e, JXLayer<? extends V> l) {
    if (e.getID() != KeyEvent.KEY_PRESSED) {
        // We are only interested in KEY_PRESSED event.
        return;/*from www. j  a  v  a2 s. c  om*/
    }
    final int code = e.getKeyCode();
    switch (code) {
    case KeyEvent.VK_LEFT:
        this.updatePointAndIndexIfPossible(-1);
        break;
    case KeyEvent.VK_RIGHT:
        this.updatePointAndIndexIfPossible(+1);
        break;
    case KeyEvent.VK_UP:
        // Switch to another stock.
        this.investmentFlowChartJDialog.selectPreviousJComboBoxSelection();
        break;
    case KeyEvent.VK_DOWN:
        // Switch to another stock.
        this.investmentFlowChartJDialog.selectNextJComboBoxSelection();
        break;
    }
}

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();
            }//  w w  w .  j  a v  a  2  s.c  o m
        } 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.jcraft.weirdx.DDXWindowImp.java

public void processKeyEvent(KeyEvent e) {
    int id = e.getID();
    if (id == KeyEvent.KEY_PRESSED) {
        keyPressed(e);//  w ww  .j  av  a2 s  .  c o m
    } else if (id == KeyEvent.KEY_RELEASED) {
        keyReleased(e);
    } else if (id == KeyEvent.KEY_TYPED) {
        keyTyped(e);
    }
    e.consume(); // ??
}