List of usage examples for java.awt.event KeyEvent getKeyCode
public int getKeyCode()
From source file:modmanager.MainWindow.java
private void registerSearch() { searchField.addKeyListener(new KeyListener() { @Override/*w w w. j av a2s .c o m*/ public void keyTyped(KeyEvent ke) { } @Override public void keyPressed(KeyEvent ke) { } @Override public void keyReleased(KeyEvent ke) { String sub = searchField.getText(); for (Modification mod : modifications.getModifications()) { if (mod.getName().toLowerCase().contains(sub.toLowerCase())) { modificationList.setSelectedValue(mod, true); if (ke.getKeyCode() == KeyEvent.VK_ENTER) { modificationList.requestFocus(); searchField.setText(""); } break; } } } }); }
From source file:org.yccheok.jstock.gui.AutoCompleteJComboBox.java
private KeyAdapter getEditorComponentKeyAdapter() { return new KeyAdapter() { @Override//from ww w . j a v a 2 s. c o m public void keyReleased(KeyEvent e) { if (KeyEvent.VK_ENTER == e.getKeyCode()) { // We are no longer busy. busySubject.notify(AutoCompleteJComboBox.this, false); StockInfo lastEnteredStockInfo = null; DispType lastEnteredDispType = null; if (AutoCompleteJComboBox.this.getItemCount() > 0) { int index = AutoCompleteJComboBox.this.getSelectedIndex(); if (index == -1) { Object object = AutoCompleteJComboBox.this.getItemAt(0); if (object instanceof StockInfo) { lastEnteredStockInfo = (StockInfo) object; } else if (object instanceof DispType) { lastEnteredDispType = (DispType) object; } } else { Object object = AutoCompleteJComboBox.this.getItemAt(index); if (object instanceof StockInfo) { lastEnteredStockInfo = (StockInfo) object; } else if (object instanceof DispType) { lastEnteredDispType = (DispType) object; } } } else { // If item count is 0, this means stockInfoDatabase // unable provide us any result based on user query. I // suspect we still need to below code, as // stockInfoDatabase will just return null. However, it // should make no harm at this moment. if (AutoCompleteJComboBox.this.stockInfoDatabase != null) { final Object object = AutoCompleteJComboBox.this.getEditor().getItem(); if (object instanceof String) { String lastEnteredString = ((String) object).trim(); lastEnteredStockInfo = AutoCompleteJComboBox.this.stockInfoDatabase .searchStockInfo(lastEnteredString); } else { assert (false); } } } AutoCompleteJComboBox.this.removeAllItems(); if (lastEnteredStockInfo != null) { AutoCompleteJComboBox.this.stockInfoSubject.notify(AutoCompleteJComboBox.this, lastEnteredStockInfo); } else if (lastEnteredDispType != null) { AutoCompleteJComboBox.this.dispSubject.notify(AutoCompleteJComboBox.this, lastEnteredDispType); } else { // Do nothing. } return; } /* if(KeyEvent.VK_ENTER == e.getKeyCode()) */ // If user removes item from text field, we will hidePopup and // removeAllItems. Please refer DocumentListener.handle, on why // don't we handle hidePopup and removeAllItems there. final Object object = AutoCompleteJComboBox.this.getEditor().getItem(); if (object == null || object.toString().length() <= 0) { AutoCompleteJComboBox.this.hidePopup(); AutoCompleteJComboBox.this.removeAllItems(); } } /* public void keyReleased(KeyEvent e) */ }; }
From source file:dylemator.DylematorUI.java
private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed char key = evt.getKeyChar(); int keyCode = evt.getKeyCode(); if (keyCode == 27) { this.displayCenteredText(""); this.threadRunning = false; setFullscreen(false);/*from w w w . j a va 2 s . c o m*/ mainMenuBar.setVisible(true); answerPanel.setVisible(true); } switch (key) { case ' ': if (this.questionThread != null) { synchronized (this.questionThread) { if (this.questionThread.readMode == true) this.questionThread.notifyAll(); if (this.questionThread.nextTextMode == true) this.questionThread.notifyAll(); } } break; case 'V': case 'v': if (this.questionThread.questionMode == true) this.questionThread.answer("TAK"); break; case 'N': case 'n': if (this.questionThread.questionMode == true) this.questionThread.answer("NIE"); break; case 'S': case 's': startButtonActionPerformed(null); break; // case 'F': // case 'f': this.setFullscreen(true); // this.answerPanel.setVisible(false); // firstScreen(0); } }
From source file:ru.goodfil.catalog.ui.forms.OePanel.java
private void tbSearchBrandKeyTyped(KeyEvent e) { if (e != null) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { tbSearchBrand.setText(""); }/*from w w w . j a va 2 s .co m*/ if (e.getKeyCode() == KeyEvent.VK_ENTER) { btnSearchBrandActionPerformed(null); } } adjustButtonsEnabled(); }
From source file:ru.goodfil.catalog.ui.forms.OePanel.java
private void tbSearchOeKeyPressed(KeyEvent e) { if (e != null) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { tbSearchOe.setText(""); }// w w w . j a va 2s.c o m if (e.getKeyCode() == KeyEvent.VK_ENTER) { btnSearchOeActionPerformed(null); } } adjustButtonsEnabled(); }
From source file:ru.goodfil.catalog.ui.forms.OePanel.java
private void lstBrandsKeyPressed(KeyEvent e) { if (e != null) { if (e.getKeyCode() == KeyEvent.VK_INSERT) { btnCreateBrandActionPerformed(null); }/*from www .j a v a2 s . c om*/ if (e.getKeyCode() == KeyEvent.VK_DELETE) { btnRemoveBrandActionPerformed(null); } if (e.getKeyCode() == KeyEvent.VK_SPACE) { btnEditBrandActionPerformed(null); } } }
From source file:org.nekorp.workflow.desktop.view.DatosAutoView.java
private void numeroSerieKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_numeroSerieKeyPressed if (evt.getKeyCode() == KeyEvent.VK_UP) { if (this.search.getModel().getSize() > 0) { if (this.search.isSelectionEmpty()) { //si no hay nada seleccionado int nuevoIndex = this.search.getModel().getSize() - 1; this.search.setSelectedIndex(nuevoIndex); calculaNuevaPosicionScrollUp(nuevoIndex); } else { int nuevoIndex = this.search.getSelectedIndex() - 1; if (nuevoIndex < 0) { nuevoIndex = this.search.getModel().getSize() - 1; }// w w w .jav a 2 s.c o m this.search.setSelectedIndex(nuevoIndex); calculaNuevaPosicionScrollUp(nuevoIndex); } } } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { if (this.search.getModel().getSize() > 0) { if (this.search.isSelectionEmpty()) { //si no hay nada seleccionado this.search.setSelectedIndex(0); calculaNuevaPosicionScrollDown(0); } else { int nuevoIndex = this.search.getSelectedIndex() + 1; if (nuevoIndex > this.search.getModel().getSize() - 1) { nuevoIndex = 0; } this.search.setSelectedIndex(nuevoIndex); calculaNuevaPosicionScrollDown(nuevoIndex); } } } if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) { this.searchScroll.setVisible(false); } }
From source file:me.mayo.telnetkek.MainPanel.java
private void txtCommandKeyPressed(java.awt.event.KeyEvent evt)//GEN-FIRST:event_txtCommandKeyPressed {//GEN-HEADEREND:event_txtCommandKeyPressed if (!txtCommand.isEnabled()) { return;//from w w w . j a v a 2 s . com } if (evt.getKeyCode() == KeyEvent.VK_ENTER) { getConnectionManager().sendCommand(txtCommand.getText()); txtCommand.selectAll(); } }
From source file:xtrememp.PlaylistManager.java
private void initComponents() { JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false);/*from w w w . j av a2 s . c o m*/ openPlaylistButton = new JButton(Utilities.DOCUMENT_OPEN_ICON); openPlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.OpenPlaylist")); openPlaylistButton.addActionListener(this); toolBar.add(openPlaylistButton); savePlaylistButton = new JButton(Utilities.DOCUMENT_SAVE_ICON); savePlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.SavePlaylist")); savePlaylistButton.addActionListener(this); toolBar.add(savePlaylistButton); toolBar.addSeparator(); addToPlaylistButton = new JButton(Utilities.LIST_ADD_ICON); addToPlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.AddToPlaylist")); addToPlaylistButton.addActionListener(this); toolBar.add(addToPlaylistButton); remFromPlaylistButton = new JButton(Utilities.LIST_REMOVE_ICON); remFromPlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.RemoveFromPlaylist")); remFromPlaylistButton.addActionListener(this); remFromPlaylistButton.setEnabled(false); toolBar.add(remFromPlaylistButton); clearPlaylistButton = new JButton(Utilities.EDIT_CLEAR_ICON); clearPlaylistButton.setToolTipText(tr("MainFrame.PlaylistManager.ClearPlaylist")); clearPlaylistButton.addActionListener(this); clearPlaylistButton.setEnabled(false); toolBar.add(clearPlaylistButton); toolBar.addSeparator(); moveUpButton = new JButton(Utilities.GO_UP_ICON); moveUpButton.setToolTipText(tr("MainFrame.PlaylistManager.MoveUp")); moveUpButton.addActionListener(this); moveUpButton.setEnabled(false); toolBar.add(moveUpButton); moveDownButton = new JButton(Utilities.GO_DOWN_ICON); moveDownButton.setToolTipText(tr("MainFrame.PlaylistManager.MoveDown")); moveDownButton.addActionListener(this); moveDownButton.setEnabled(false); toolBar.add(moveDownButton); toolBar.addSeparator(); mediaInfoButton = new JButton(Utilities.MEDIA_INFO_ICON); mediaInfoButton.setToolTipText(tr("MainFrame.PlaylistManager.MediaInfo")); mediaInfoButton.addActionListener(this); mediaInfoButton.setEnabled(false); toolBar.add(mediaInfoButton); toolBar.add(Box.createHorizontalGlue()); searchTextField = new SearchTextField(15); searchTextField.setMaximumSize(new Dimension(120, searchTextField.getPreferredSize().height)); searchTextField.getTextField().getDocument().addDocumentListener(new SearchFilterListener()); toolBar.add(searchTextField); toolBar.add(Box.createHorizontalStrut(6)); this.add(toolBar, BorderLayout.NORTH); playlistTable = new JTable(playlistTableModel, playlistTableColumnModel); playlistTable.setDefaultRenderer(String.class, new PlaylistCellRenderer()); playlistTable.setActionMap(null); playlistTable.getTableHeader().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent ev) { if (SwingUtilities.isRightMouseButton(ev) || (MouseInfo.getNumberOfButtons() == 1 && ev.isControlDown())) { playlistTableColumnModel.getPopupMenu().show(playlistTable.getTableHeader(), ev.getX(), ev.getY()); return; } int clickedColumn = playlistTableColumnModel.getColumnIndexAtX(ev.getX()); PlaylistTableColumn playlistColumn = playlistTableColumnModel.getColumn(clickedColumn); playlistTableColumnModel.resetAll(playlistColumn.getModelIndex()); playlistColumn.setSortOrderUp(!playlistColumn.isSortOrderUp()); playlistTableModel.sort(playlistColumn.getComparator()); colorizeRow(); } }); playlistTable.setFillsViewportHeight(true); playlistTable.setShowGrid(false); playlistTable.setRowSelectionAllowed(true); playlistTable.setColumnSelectionAllowed(false); playlistTable.setDragEnabled(false); playlistTable.setFont(playlistTable.getFont().deriveFont(Font.BOLD)); playlistTable.setIntercellSpacing(new Dimension(0, 0)); playlistTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); playlistTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent ev) { int selectedRow = playlistTable.rowAtPoint(ev.getPoint()); if (SwingUtilities.isLeftMouseButton(ev) && ev.getClickCount() == 2) { if (selectedRow != -1) { playlist.setCursorPosition(selectedRow); controlListener.acOpenAndPlay(); } } } }); playlistTable.getSelectionModel().addListSelectionListener(this); playlistTable.getColumnModel().getSelectionModel().addListSelectionListener(this); playlistTable.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { // View Media Info if (e.getKeyCode() == KeyEvent.VK_I && e.getModifiers() == KeyEvent.CTRL_MASK) { viewMediaInfo(); } // Select all else if (e.getKeyCode() == KeyEvent.VK_A && e.getModifiers() == KeyEvent.CTRL_MASK) { playlistTable.selectAll(); } else if (e.getKeyCode() == KeyEvent.VK_UP) { // Move selected track(s) up if (e.getModifiers() == KeyEvent.ALT_MASK) { moveUp(); } // Select previous track else { if (playlistTable.getSelectedRow() > 0) { int previousRowIndex = playlistTable.getSelectedRow() - 1; playlistTable.clearSelection(); playlistTable.addRowSelectionInterval(previousRowIndex, previousRowIndex); makeRowVisible(previousRowIndex); } } } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { // Move selected track(s) down if (e.getModifiers() == KeyEvent.ALT_MASK) { moveDown(); } // Select next track else { if (playlistTable.getSelectedRow() < playlistTable.getRowCount() - 1) { int nextRowIndex = playlistTable.getSelectedRow() + 1; playlistTable.clearSelection(); playlistTable.addRowSelectionInterval(nextRowIndex, nextRowIndex); makeRowVisible(nextRowIndex); } } } // Play selected track else if (e.getKeyCode() == KeyEvent.VK_ENTER) { int selectedRow = playlistTable.getSelectedRow(); if (selectedRow != -1) { playlist.setCursorPosition(selectedRow); controlListener.acOpenAndPlay(); } } // Add new tracks else if (e.getKeyCode() == KeyEvent.VK_INSERT) { addFilesDialog(false); } // Delete selected tracks else if (e.getKeyCode() == KeyEvent.VK_DELETE) { remove(); } } }); XtremeMP.getInstance().getMainFrame().setDropTarget(new DropTarget(playlistTable, this)); JScrollPane ptScrollPane = new JScrollPane(playlistTable); ptScrollPane.setActionMap(null); this.add(ptScrollPane, BorderLayout.CENTER); }
From source file:org.tmpotter.ui.ActionHandler.java
public void onTablePressed(final KeyEvent event) { int index;/*from w w w .j av a 2s . c o m*/ if (modelMediator.getTmViewSelectedRow() != -1) { index = modelMediator.getTmViewSelectedRow(); tmData.setPositionTextArea(0); } else { index = 1; } if (index < modelMediator.getTmViewRows() - 1) { if ((event.getKeyCode() == KeyEvent.VK_DOWN) || (event.getKeyCode() == KeyEvent.VK_NUMPAD2)) { if (tmData.getIndexPrevious() < tmData.getDocumentOriginalSize()) { tmData.setOriginalDocumentAnt(restoreText(modelMediator.getLeftEdit())); tmData.setTranslationDocumentAnt(restoreText(modelMediator.getRightEdit())); } modelMediator.setLeftEdit(formatText(modelMediator.getLeftSegment(index + 1))); modelMediator.setRightEdit(formatText(modelMediator.getRightSegment(index + 1))); tmData.setIndexCurrent(index + 1); } else if ((event.getKeyCode() == KeyEvent.VK_UP) || (event.getKeyCode() == KeyEvent.VK_NUMPAD8)) { tmData.setIndexCurrent(index - 1); if (index == 0) { index = 1; tmData.setIndexCurrent(0); } if (tmData.getIndexPrevious() < tmData.getDocumentOriginalSize()) { tmData.setOriginalDocumentAnt(restoreText(modelMediator.getLeftEdit())); tmData.setTranslationDocumentAnt(restoreText(modelMediator.getRightEdit())); } modelMediator.setLeftEdit(formatText(modelMediator.getLeftSegment(index - 1))); modelMediator.setRightEdit(formatText(modelMediator.getRightSegment(index - 1))); } if (tmData.isIdentTop()) { modelMediator.setJoinEnabled(false); } else { modelMediator.setJoinEnabled(true); } tmData.setIndexPrevious(tmData.getIndexCurrent()); } modelMediator.updateTmView(); }