List of usage examples for java.awt.event KeyEvent getKeyCode
public int getKeyCode()
From source file:gtu._work.ui.DirectoryCompareUI.java
private JTextField getSearchText() { if (searchText == null) { searchText = new JTextField(); ToolTipManager.sharedInstance().setInitialDelay(0); searchText.setToolTipText(/*from w w w . j a v a2s .c o m*/ ": date >= 20140829, ?: size < 1mb, ??: name *= action, path *= WEB-INF [:" + SEARCHTEXTPATTERN.pattern() + "]"); searchText.setPreferredSize(new java.awt.Dimension(222, 24)); searchText.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { System.out.println("KeyEvent.getKeyCode = " + evt.getKeyCode()); int[] keyCodeIgnore = new int[] { 38, 40, 37, 39, 8, 17, 18, 16 }; if (!ArrayUtils.contains(keyCodeIgnore, evt.getKeyCode())) { totalScanFiles(evt); } } }); } return searchText; }
From source file:edu.ku.brc.af.ui.db.DatabaseLoginPanel.java
/** * Creates a Document listener so the UI is updated when the doc changes * @param uiComponent the text field to be changed *//* w ww.ja v a 2s .c o m*/ protected void addKeyListenerFor(final JComponent comp, final boolean checkForRet) { class KeyAdp extends KeyAdapter { private boolean checkForRetLocal = false; public KeyAdp(final boolean checkForRetArg) { this.checkForRetLocal = checkForRetArg; } @Override public void keyReleased(KeyEvent e) { updateUIControls(); if (checkForRetLocal && e.getKeyCode() == KeyEvent.VK_ENTER) { doLogin(); } } } comp.addKeyListener(new KeyAdp(checkForRet)); }
From source file:statechum.analysis.learning.Visualiser.java
public void construct(Graph g, LayoutOptions options) { if (!globalConfig.isAssertEnabled() && Boolean.getBoolean(globalConfig.getProperty(G_PROPERTIES.ASSERT_ENABLED))) { System.err.println("Pass the -ea argument to JVM to enable assertions"); }/*from w w w . ja v a 2 s . c o m*/ // if (Boolean.valueOf(GlobalConfiguration.getConfiguration() .getProperty(GlobalConfiguration.G_PROPERTIES.CLOSE_TERMINATE))) this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); else if (Boolean.valueOf( GlobalConfiguration.getConfiguration().getProperty(GlobalConfiguration.G_PROPERTIES.ESC_TERMINATE))) this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); else this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); this.addWindowListener(new WindowEventHandler()); /* this.addComponentListener(new ComponentListener() { @Override public void componentShown(@SuppressWarnings("unused") ComponentEvent e) {} @Override public void componentResized(@SuppressWarnings("unused") ComponentEvent e) { if (viewer != null) viewer.getModel().getGraphLayout().resize(getSize()); } @Override public void componentMoved(@SuppressWarnings("unused") ComponentEvent e) {} @Override public void componentHidden(@SuppressWarnings("unused") ComponentEvent e) {} });*/ this.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent arg0) { Action act = keyToActionMap.get(arg0.getKeyCode()); if (act != null) { act.actionPerformed(null); } } @Override public void keyReleased(@SuppressWarnings("unused") KeyEvent arg0) {// this method is intentionally left blank - keypresses/releases are handled by the keyPressed method. } @Override public void keyTyped(@SuppressWarnings("unused") KeyEvent key) {// this method is intentionally left blank - keypresses/releases are handled by the keyPressed method. } }); popupMenu = new JPopupMenu(); // Icon loading is from http://www.javaworld.com/javaworld/javaqa/2000-06/03-qa-0616-icon.html Image icon = Toolkit.getDefaultToolkit() .getImage(GlobalConfiguration.getConfiguration().getProperty(G_PROPERTIES.RESOURCES) + File.separator + "icon.jpg"); if (icon != null) { setIconImage(icon); } setVisualiserKeyBindings(); setStateChumKeyBindings(this, propName, keyToActionMap); updatePopupMenu(popupMenu, keyToActionMap); //getContentPane().removeAll(); WindowPosition framePosition = globalConfig.loadFrame(propName); viewer = new VisualizationViewer( new DefaultVisualizationModel( new XMLPersistingLayout(propName >= 0 ? new FRLayout(g) : new KKLayout(g))), constructRenderer(g, options)); viewer.setBackground(Color.WHITE); final DefaultModalGraphMouse graphMouse = new XMLModalGraphMouse(); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); graphMouse.add(new PickingGraphMousePlugin()); viewer.setGraphMouse(graphMouse); viewer.setPickSupport(new ShapePickSupport()); viewer.addMouseListener(this); final GraphZoomScrollPane panel = new GraphZoomScrollPane(viewer); getContentPane().add(panel); pack(); viewer.setPreferredSize(getSize()); //viewer.getModel().getGraphLayout().initialize(getSize()); restoreLayout(true, currentGraph); setBounds(framePosition.getRect()); framesVisible.add(this);// register as an active frame. setVisible(true); }
From source file:tax.MainForm.java
private void afmTextKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_afmTextKeyPressed String text = afmText.getText(); if (evt.getKeyCode() == KeyEvent.VK_ENTER) { if (text.length() == 9) { for (Object key : afmToName.keySet()) { if (afmToName.get(key).equals(text)) nameText.setText(key.toString()); }// w ww.j a v a2 s .c o m // Util.fadeInAndOut(afmText, Util.darkGreen); addRowBut.doClick(); } else if (text.length() == 0) { Util.fadeInAndOut(afmText, Color.white); nameText.setEnabled(true); nameText.requestFocus(); } else Util.fadeInAndOut(afmText, Util.darkOrange); } else if (!evt.isActionKey() && !evt.isAltDown() && !evt.isControlDown() && !evt.isShiftDown() && !evt.isMetaDown() && (evt.getKeyCode() != KeyEvent.VK_BACK_SPACE) && (evt.getKeyCode() != KeyEvent.VK_DELETE) && (evt.getKeyCode() != KeyEvent.VK_ESCAPE)) { EventQueue.invokeLater(new Runnable() { @Override public void run() { String text = afmText.getText(); int afmLength = text.length(); while (lastAFMTextLength == afmLength) { try { Thread.sleep(100); System.out.println("text: " + text); System.out.println(lastAFMTextLength + " " + afmLength); return; } catch (InterruptedException ex) { Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex); } text = afmText.getText(); afmLength = text.length(); } try { int num = Integer.decode(text); if (afmLength > 9) { if (text.length() > 0) afmText.setText(text.substring(0, afmLength - 1)); else afmText.setText(""); return; } } catch (Exception e) { if (text.length() > 0) afmText.setText(text.substring(0, afmLength - 1)); else afmText.setText(""); return; } lastAFMTextLength = afmLength; } }); } }
From source file:vista.ventas.DialogEntregas.java
private void tblItemsKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tblItemsKeyPressed if (evt.getKeyCode() == KeyEvent.VK_ENTER) { cargarArticuloDeItem();/*from w w w.j a v a 2 s . c om*/ } }
From source file:vista.ventas.DialogEntregas.java
private void tblArticulosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tblArticulosKeyPressed if (evt.getKeyCode() == KeyEvent.VK_DELETE && tblArticulos.getSelectedRow() != -1) { quitarArticuloLista();/*from w w w .j av a 2s . com*/ } }
From source file:Report_PRCR_New_EPF_Excel_File_Generator.java
private void yearfield1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_yearfield1KeyPressed if (evt.getKeyCode() == KeyEvent.VK_UP) { yearfield.setText("" + (Integer.parseInt(yearfield.getText()) + 1)); yearfield.selectAll();//from w ww. j a va 2s .c om } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { yearfield.setText("" + (Integer.parseInt(yearfield.getText()) - 1)); yearfield.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_LEFT) { monthfield.requestFocus(); monthfield.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_ENTER) { } }
From source file:vista.ventas.DialogEntregas.java
private void tblOrdenesDeCompraKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tblOrdenesDeCompraKeyPressed if (evt.getKeyCode() == KeyEvent.VK_ENTER) { seleccionarOrdenDeCompra();/* ww w . j a v a 2s.c o m*/ } }
From source file:org.executequery.gui.editor.QueryEditorTextPane.java
/** * Overrides <code>processKeyEvent</code> to additional process events. *//*from w w w .j a v a 2 s . c o m*/ protected void processKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { int keyCode = e.getKeyCode(); // add the processing for SHIFT-TAB if (e.isShiftDown() && keyCode == KeyEvent.VK_TAB) { // int currentPosition = getCurrentPosition(); int selectionStart = getSelectionStart(); int selectionEnd = getSelectionEnd(); if (selectionStart == selectionEnd) { int start = getCurrentRowStart(); int end = getCurrentRowEnd(); shiftTextLeft(start, end); /* int newPosition = currentPosition - QueryEditorSettings.getTabSize(); int currentRowPosition = getCurrentRowStart(); if (!isAtStartOfRow()) { if (newPosition < 0) { setCaretPosition(0); } else if (newPosition < currentRowPosition) { setCaretPosition(currentRowPosition); } else { setCaretPosition(newPosition); } } */ } else { document.shiftTabEvent(selectionStart, selectionEnd); } } else if (keyCode == KeyEvent.VK_INSERT && e.getModifiers() == 0) { // toggle insert mode on the document int insertMode = document.getInsertMode(); if (insertMode == SqlMessages.INSERT_MODE) { document.setInsertMode(SqlMessages.OVERWRITE_MODE); editorPanel.getStatusBar().setInsertionMode("OVR"); } else { document.setInsertMode(SqlMessages.INSERT_MODE); editorPanel.getStatusBar().setInsertionMode("INS"); } ((EditorCaret) getCaret()).modeChanged(); } else if (keyCode == KeyEvent.VK_SPACE) { checkForShortcutText(); } } super.processKeyEvent(e); updateLineBorder(); }
From source file:net.rptools.maptool.launcher.MapToolLauncher.java
private JPanel buildAdvancedPanel() { final JPanel p = new JPanel(); p.setLayout(new BorderLayout()); p.setBorder(new LineBorder(Color.BLACK)); final JPanel controlPanel = new JPanel(); controlPanel.setLayout(new BorderLayout()); final JPanel argPanel = new JPanel(); argPanel.setLayout(new BorderLayout()); jtfArgs.setInfo(CopiedFromOtherJars.getText("msg.info.javaArgumentsHere")); //$NON-NLS-1$ jtfArgs.setText(extraArgs);// www . ja va2 s. com jtfArgs.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.javaArgumentsHere")); //$NON-NLS-1$ jtfArgs.setCaretPosition(0); jtfArgs.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { jbLaunch.requestFocusInWindow(); } } }); jtfArgs.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent arg0) { jtfArgs.selectAll(); } @Override public void focusLost(FocusEvent arg0) { jtfArgs.setCaretPosition(0); if (!jtfArgs.getText().trim().equals(extraArgs)) { extraArgs = jtfArgs.getText(); jcbEnableAssertions.setSelected(extraArgs.contains(ASSERTIONS_OPTION)); if (extraArgs.contains(DATADIR_OPTION)) { extraArgs = cleanExtraArgs(extraArgs); } updateCommand(); } } }); argPanel.add(jtfArgs, BorderLayout.CENTER); controlPanel.add(argPanel, BorderLayout.NORTH); final JPanel holdPanel = new JPanel(); holdPanel.setLayout(new GridLayout(0, 1)); jcbRelativePath.setText(CopiedFromOtherJars.getText("msg.info.useRelativePathnames")); //$NON-NLS-1$ jcbRelativePath.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.useRelativePathnames")); //$NON-NLS-1$ jcbRelativePath.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { updateCommand(); } }); // jcbRelativePath.setSelected(false); // since initComponents() is called after reading the config, don't do this here jcbConsole.setText(CopiedFromOtherJars.getText("msg.info.launchWithConsole")); //$NON-NLS-1$ jcbConsole.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.launchWithConsole")); //$NON-NLS-1$ jcbConsole.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { startConsole = jcbConsole.isSelected(); updateCommand(); } }); jcbConsole.setSelected(startConsole); jbPath.setText(jbPathText); jbPath.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.dirForAltJava")); //$NON-NLS-1$ jbPath.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jbPath.getText().equalsIgnoreCase(CopiedFromOtherJars.getText("msg.info.setJavaVersion"))) { //$NON-NLS-1$ final JFileChooser jfc = new JFileChooser(); if (!javaDir.isEmpty()) { jfc.setCurrentDirectory(new File(javaDir)); } else { jfc.setCurrentDirectory(new File(".")); //$NON-NLS-1$ } jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); final int returnVal = jfc.showOpenDialog(jbPath); if (returnVal == JFileChooser.APPROVE_OPTION) { final File f = jfc.getSelectedFile(); final String test = f.getPath() + File.separator; // Lee: naive search for java command. will improve in the future final List<String> fileList = Arrays.asList(f.list()); boolean javaFound = false; for (final String fileName : fileList) { final File check = new File(f, fileName); final String lc = check.getName().toLowerCase(); if (lc.equals("java") || (IS_WINDOWS && lc.startsWith("java."))) { //$NON-NLS-1$ //$NON-NLS-2$ javaFound = true; break; } } if (javaFound) { jbPath.setText(CopiedFromOtherJars.getText("msg.info.resetToDefaultJava")); //$NON-NLS-1$ javaDir = test; updateCommand(); } else { logMsg(Level.SEVERE, "Java executable not found in {0}", //$NON-NLS-1$ "msg.error.javaCommandNotFound", f); //$NON-NLS-2$ } } } else { jbPath.setText(CopiedFromOtherJars.getText("msg.info.setJavaVersion")); //$NON-NLS-1$ javaDir = EMPTY; } } }); holdPanel.add(jcbRelativePath); holdPanel.add(jcbConsole); holdPanel.add(jbPath); controlPanel.add(holdPanel, BorderLayout.SOUTH); final JPanel logPanel = new JPanel(); logPanel.setLayout(new GridLayout(0, 1)); logPanel.setBorder( new TitledBorder(new LineBorder(Color.BLACK), CopiedFromOtherJars.getText("msg.logPanel.border"))); //$NON-NLS-1$ for (final LoggingConfig config : logConfigs) { config.chkbox.setText(config.getProperty("desc")); //$NON-NLS-1$ config.chkbox.setToolTipText(config.getProperty("ttip")); //$NON-NLS-1$ logPanel.add(config.chkbox); } p.add(logPanel, BorderLayout.CENTER); p.add(controlPanel, BorderLayout.SOUTH); return p; }