Example usage for java.awt.event KeyEvent getKeyCode

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

Introduction

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

Prototype

public int getKeyCode() 

Source Link

Document

Returns the integer keyCode associated with the key in this event.

Usage

From source file:nz.govt.natlib.ndha.manualdeposit.dialogs.EnterEntityNameAndPrefix.java

private void txtEnterEntityNameKeyPressed(final java.awt.event.KeyEvent evt) {
    if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
        cancel();//from w  w w  .  j a  v a  2s  .  c  om
    }
}

From source file:sturesy.core.ui.loaddialog.SubsettedJListPair.java

private void registerListeners() {
    _ui.getSourceList().addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent keyEvent) {
            subsetSourceListKeyEvent(keyEvent.getKeyCode());
        }// w ww . j a v  a2  s . co  m
    });
    _ui.getContentList().addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent keyEvent) {
            subsetContentListKeyEvent(keyEvent.getKeyCode());
        }
    });
    _ui.getSourceList().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evnt) {
            informSourceListChanged(evnt.getValueIsAdjusting());
        }
    });
}

From source file:com.mindcognition.mindraider.ui.swing.dialogs.UpdateOutlineJDialog.java

public UpdateOutlineJDialog(ResourceDescriptor notebookDescriptor) {
    super("Rename or Change Outline Labels", "Update");

    final KeyListener keyListener = new KeyListener() {
        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                updateNotebook();//  ww  w  . j av a  2  s  . c om
            }
            if (keyEvent.getKeyCode() == KeyEvent.VK_ESCAPE) {
                dispose();
            }
        }

        public void keyReleased(KeyEvent e) {
        }

        public void keyTyped(KeyEvent e) {
        }
    };

    this.oldNotebookDescriptor = notebookDescriptor;
    outlineTitle.setText(notebookDescriptor.getLabel());
    outlineTitle.addKeyListener(keyListener);
    outlineUri.setText(notebookDescriptor.getUri());
    outlineNcName.setText(notebookDescriptor.getUri().substring(notebookDescriptor.getUri().indexOf('#') + 1));

    // initialize categories
    ResourceDescriptor[] notebookFolders = MindRaider.labelCustodian
            .getNotebookFolders(notebookDescriptor.getUri());
    outlineLabels.setText("");
    outlineLabels.addKeyListener(keyListener);
    if (notebookFolders != null && notebookFolders.length > 0) {
        StringBuffer labelBuffer = new StringBuffer();
        for (ResourceDescriptor label : notebookFolders) {
            oldLabels.put(label.getLabel(), label);
            labelBuffer.append(label.getLabel());
            labelBuffer.append(", ");
        }
        if (labelBuffer.length() > 0) {
            outlineLabels.setText(labelBuffer.toString().substring(0, labelBuffer.length() - 2));
        }
    }

    // buttons
    doButton.addActionListener(UpdateNotebookActionListener());
    cancelButton.addActionListener(AbstractNotebookCancelActionListener());

    // show
    pack();
    Gfx.centerAndShowWindow(this);
}

From source file:com.github.alexfalappa.nbspringboot.cfgprops.completion.CfgPropCompletionItem.java

@Override
public void processKeyEvent(KeyEvent evt) {
    // detect if Ctrl + Enter is pressed
    overwrite = evt.getKeyCode() == KeyEvent.VK_ENTER && (evt.getModifiers() & KeyEvent.CTRL_MASK) != 0;
}

From source file:com.wafflesoft.kinectcontroller.Main.java

public void run() {
    KinectUserTracker kinectUserTracker = new KinectUserTracker(_csm);

    _done = false;//from   w w  w. j  a  v a  2 s. c  o m
    _frame = new JFrame("Kinect Controller");

    // register to key events
    _frame.addKeyListener(new KeyListener() {
        public void keyTyped(KeyEvent arg) {
        }

        public void keyReleased(KeyEvent arg) {
        }

        public void keyPressed(KeyEvent arg) {
            if (arg.getKeyCode() == KeyEvent.VK_ESCAPE) {
                _done = true;
            }
        }
    });

    // register to closing event
    _frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            _done = true;
        }
    });

    kinectUserTracker.kinectWindow.setSize(800, 600);

    _frame.add("Center", kinectUserTracker.kinectWindow);

    _eventWindow = new JTextArea();
    _eventWindow.setVisible(!_arguments.hasOption('d'));
    _frame.add(new JScrollPane(_eventWindow));

    _frame.setSize(kinectUserTracker.kinectWindow.getWidth(), kinectUserTracker.kinectWindow.getHeight());
    _frame.setVisible(true);

    while (!_done) {
        _frame.repaint();
        try {
            Thread.sleep(16);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.tascape.qa.th.android.tools.UiAutomatorViewer.java

private void start() throws Exception {
    SwingUtilities.invokeLater(() -> {
        jd = new ViewerParameterDialog("Launch Android App");

        JPanel jpParameters = new JPanel();
        jpParameters.setLayout(new BoxLayout(jpParameters, BoxLayout.PAGE_AXIS));
        jd.setParameterPanel(jpParameters);
        {/*  w w  w .  j  a  v a 2  s .  c o  m*/
            JPanel jp = new JPanel();
            jpParameters.add(jp);
            jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS));
            jp.add(new JLabel("Devices"));
            jp.add(jcbDevices);
        }
        {
            JPanel jp = new JPanel();
            jpParameters.add(jp);
            jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS));
            jp.add(new JLabel("App Package Name"));
            jp.add(jtfApp);
            if (StringUtils.isNotEmpty(appPackageName)) {
                jtfApp.setText(appPackageName);
            }

            jtfApp.addKeyListener(new KeyAdapter() {
                @Override
                public void keyPressed(KeyEvent e) {
                    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                        jbLaunch.doClick();
                    }
                }
            });
        }
        {
            JPanel jp = new JPanel();
            jpParameters.add(jp);
            jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS));
            jp.add(new JLabel("Interaction time (minute)"));
            jsDebugMinutes.getEditor().setEnabled(false);
            jp.add(jsDebugMinutes);
        }
        {
            JPanel jp = new JPanel();
            jpParameters.add(jp);
            jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS));
            jp.add(Box.createRigidArea(new Dimension(518, 2)));
        }

        JPanel jpAction = new JPanel();
        jd.setActionPanel(jpAction);
        jpAction.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
        jpAction.setLayout(new BoxLayout(jpAction, BoxLayout.LINE_AXIS));
        jbLaunch.setFont(jbLaunch.getFont().deriveFont(Font.BOLD));
        jbLaunch.setBorder(BorderFactory.createEtchedBorder());
        jbLaunch.setEnabled(false);
        jpAction.add(jbLaunch);
        jbLaunch.addActionListener(event -> {
            new Thread() {
                @Override
                public void run() {
                    launchApp();
                }
            }.start();
        });

        jd.showDialog();

        new Thread() {
            @Override
            public void run() {
                try {
                    detectDevices();
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            }
        }.start();
    });
}

From source file:edu.cwru.sepia.agent.visual.VisualAgent.java

private void setupScreen() {
    gamePanel = createGamePanel();/*  www .jav a 2  s  . c o  m*/
    actions = new HashSet<Action>();
    final KeyAdapter canvasKeyListener = new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            //            System.out.println(e.getKeyCode());
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                stepSignal.drainPermits();
                stepSignal.release();
            }
        }
    };
    Runnable runner = new Runnable() {
        @Override
        public void run() {
            screen = new GameScreen(gamePanel, controlPanel, statusPanel);
            screen.pack();
            gamePanel.addKeyListener(canvasKeyListener);
            controlPanel.addStepperListener(VisualAgent.this);
        }
    };
    SwingUtilities.invokeLater(runner);
}

From source file:org.kalypso.ogc.gml.map.widgets.MeasureMapWidget.java

@Override
public void keyPressed(final KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_SPACE) {
        e.consume();/*from   w ww .j av a 2  s .co m*/

        final int currentIndex = ArrayUtils.indexOf(m_delegates, m_delegate);
        final int newIndex = (currentIndex + 1) % m_delegates.length;
        updateDelegate(newIndex);

        getMapPanel().repaintMap();
        return;
    }

    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
        e.consume();

        reset();
        getMapPanel().repaintMap();
        return;
    }

    super.keyPressed(e);
}

From source file:Text2DTest.java

/**
 * Process a keyboard event to move or rotate the viewer.
 *//*from www .ja  va  2s .  com*/
void processManualEvent(AWTEvent[] events) {

    for (int i = 0; i < events.length; ++i) {
        if (events[i] instanceof KeyEvent) {
            KeyEvent event = (KeyEvent) events[i];
            if (event.getKeyCode() == KeyEvent.VK_EQUALS) {
                continue;
            }
            Transform3D t = new Transform3D();
            viewTransformGroup.getTransform(t);
            Vector3f viewDir = new Vector3f(0f, 0f, -1f);
            Vector3f translation = new Vector3f();
            t.get(translation);
            t.transform(viewDir);
            if (event.getKeyCode() == KeyEvent.VK_UP) {
                translation.x += viewDir.x;
                translation.y += viewDir.y;
                translation.z += viewDir.z;
            } else if (event.getKeyCode() == KeyEvent.VK_DOWN) {
                translation.x -= viewDir.x;
                translation.y -= viewDir.y;
                translation.z -= viewDir.z;
            } else if (event.getKeyCode() == KeyEvent.VK_RIGHT) {
                rotation += -.1;
            } else if (event.getKeyCode() == KeyEvent.VK_LEFT) {
                rotation += .1;
            }
            t.rotY(rotation);
            t.setTranslation(translation);
            viewTransformGroup.setTransform(t);
        }
    }
}

From source file:com.googlecode.gmail4j.util.LoginDialog.java

/**
 * Creates the required listeners/* w  w  w  .j  av a 2  s  .  c  om*/
 * 
 * @param login Credentials object for filling the data
 */
private void createListeners(final Credentials login) {
    pass.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                setCredentials(login);
                dialog.setVisible(false);
            }
        }
    });
    ok.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            setCredentials(login);
            dialog.setVisible(false);
        }
    });
    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(final WindowEvent e) {
            log.warn("Login dialog closed, no username/password specified");
            latch.countDown();
        }
    });
}