List of usage examples for java.awt.event KeyEvent getKeyCode
public int getKeyCode()
From source file:org.nuclos.client.layout.wysiwyg.editor.ui.panels.WYSIWYGMetaInformationPicker.java
/** * /*from w w w . j a v a2s. c o m*/ * @param values * @param parent */ private WYSIWYGMetaInformationPicker(Window owner, List<String> values, TableLayoutPanel parent) { super(owner); this.setIconImage(NuclosIcons.getInstance().getScaledDialogIcon(48).getImage()); Container contentPane = this.getContentPane(); contentPane.setLayout(new TableLayout(layoutDefinition)); originalValues = values; filter = new JTextField(); /** the keybinding*/ filter.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { /** up and down cursor for selecting the next or previous entry */ if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) { int selectedItem = itemList.getSelectedIndex(); if (e.getKeyCode() == KeyEvent.VK_UP) selectedItem--; else if (e.getKeyCode() == KeyEvent.VK_DOWN) selectedItem++; if (selectedItem < 0) { selectedItem = listModel.getSize() - 1; } else if (selectedItem == listModel.getSize()) { selectedItem = 0; } itemList.setSelectedIndex(selectedItem); itemList.ensureIndexIsVisible(selectedItem); } else if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_ESCAPE) { /** enter for saving, esc for cancel */ if (e.getKeyCode() == KeyEvent.VK_ESCAPE) selectedEntity = null; dispose(); } else { /** every other key is used for filtering the entries */ filterItems(WYSIWYGMetaInformationPicker.this.filter.getText()); } } @Override public void keyTyped(KeyEvent e) { } }); /** request focus in the filter window */ filter.requestFocusInWindow(); this.add(filter, new TableLayoutConstraints(1, 1, 3, 1)); itemList = new JList(listModel); itemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); itemList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (itemList.getSelectedValue() != null) selectedEntity = (String) itemList.getSelectedValue(); } }); freeExpr = new JCheckBox(SpringLocaleDelegate.getInstance() .getMessageFromResource("wysiwg.metainformation.picker.freeexpr")); this.add(freeExpr, new TableLayoutConstraints(1, 2, 3, 2)); freeExpr.setVisible(true); // double click on item to select itemList.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { performSaveAction(); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); filterItems(null); JScrollPane scrollpane = new JScrollPane(itemList); this.add(scrollpane, new TableLayoutConstraints(1, 4, 3, 4)); JButton apply = new JButton(BUTTON_LABELS.LABEL_APPLY); apply.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { performSaveAction(); } }); this.add(apply, new TableLayoutConstraints(1, 6)); JButton cancel = new JButton(BUTTON_LABELS.LABEL_CANCEL); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { performCancelAction(); } }); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { performCancelAction(); } }); this.add(cancel, new TableLayoutConstraints(3, 6)); this.setBounds(this.getBounds().x, this.getBounds().y, 300, 400); this.setTitle(TABLELAYOUT_PANEL.SELECT_FIELD_FOR_METAINFORMATION); this.setModal(true); }
From source file:org.lnicholls.galleon.gui.HMEConfigurationPanel.java
public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { updateEditor(); } }
From source file:org.squidy.designer.zoom.impl.SourceCodeShape.java
private JEditorPane createCodePane(URL sourceCodeURL) { codePane = new JEditorPane() { @Override/*from w ww . j a v a 2s . c o m*/ protected void processComponentKeyEvent(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE && e.isControlDown()) { System.out.println("Code completion"); int caretPosition = codePane.getCaretPosition(); String code = codePane.getText(); switch (code.charAt(caretPosition - 1)) { case '.': int pseudoCaret = caretPosition - 1; StringBuilder word = new StringBuilder(); for (char c = code.charAt(--pseudoCaret); !isEndOfWord(c); c = code.charAt(--pseudoCaret)) { word.append(c); } word = word.reverse(); System.out.println("WORD: " + word); // Class<?> type = // ReflectionUtil.loadClass(word.toString()); // // System.out.println("TYPE: " + type); JPopupMenu menu = new JPopupMenu("sdaf"); Point p = codePane.getCaret().getMagicCaretPosition(); System.out.println("CARET POS: " + p); // Point p = codePane.get // menu.setPreferredSize(new Dimension(200, 200)); menu.setLocation(30, 30); menu.add("test"); codePane.add(menu); // System.out.println(p); // codePane.get menu.show(codePane, p.x, p.y); break; } } super.processComponentKeyEvent(e); } /** * @param c * @return */ private boolean isEndOfWord(char c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t'; } }; EditorKit editorKit = new StyledEditorKit() { /** * */ private static final long serialVersionUID = 7024886168909204806L; public Document createDefaultDocument() { return new SyntaxDocument(); } }; codePane.setEditorKitForContentType("text/java", editorKit); codePane.setContentType("text/java"); try { FileInputStream fis = new FileInputStream(sourceCodeURL.getPath()); codePane.read(fis, null); originSourceCode = codePane.getText(); computeHeightOfCodePane(); codePane.setAutoscrolls(true); } catch (Exception e) { codePane.setText("File not found!"); } codePane.requestFocus(); codePane.setBorder(BorderFactory.createLineBorder(Color.BLACK)); codePane.addKeyListener(new KeyAdapter() { /* * (non-Javadoc) * * @see * java.awt.event.KeyAdapter#keyPressed(java.awt.event.KeyEvent) */ @Override public void keyPressed(KeyEvent e) { super.keyPressed(e); switch (e.getKeyCode()) { case KeyEvent.VK_ENTER: case KeyEvent.VK_DELETE: case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_SPACE: computeHeightOfCodePane(); break; } markDirty(); } }); // final JPopupMenu menu = new JPopupMenu(); // // JMenuItem i = new JMenuItem("Option 1"); // JMenuItem i2 = new JMenuItem("Option 2"); // menu.add(i); // menu.add(i2); // edit.add(menu); // getComponent().addKeyListener(new KeyAdapter() { // // public void keyTyped(KeyEvent e) { // if(e.getModifiers() == 2 && e.getKeyChar() == ' ') { // Point popupLoc = edit.getCaret().getMagicCaretPosition(); // System.out.println(popupLoc); // menu.setLocation(new // Point((int)popupLoc.getX(),(int)popupLoc.getY())); // menu.setVisible(true); // } // // } // }); return codePane; }
From source file:net.sf.jabref.gui.autocompleter.AutoCompleteListener.java
@Override public void keyTyped(KeyEvent e) { LOGGER.debug("key typed event caught " + e.getKeyCode()); char ch = e.getKeyChar(); if (ch == '\n') { // this case is handled at keyPressed(e) return;//from w ww. j a v a 2s . c o m } // don't do auto completion inside words if (!atEndOfWord((JTextComponent) e.getSource())) { return; } if ((e.getModifiers() | InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK) { // plain key or SHIFT + key is pressed, no handling of CTRL+key, META+key, ... if (Character.isLetter(ch) || Character.isDigit(ch) || (Character.isWhitespace(ch) && completer.isSingleUnitField())) { JTextComponent comp = (JTextComponent) e.getSource(); if (toSetIn == null) { LOGGER.debug("toSetIn is null"); } else { LOGGER.debug("toSetIn: >" + toSetIn + '<'); } // The case-insensitive system is a bit tricky here // If keyword is "TODO" and user types "tO", then this is treated as "continue" as the "O" matches the "O" // If keyword is "TODO" and user types "To", then this is treated as "discont" as the "o" does NOT match the "O". if ((toSetIn != null) && (toSetIn.length() > 1) && (ch == toSetIn.charAt(1))) { // User continues on the word that was suggested. LOGGER.debug("cont"); toSetIn = toSetIn.substring(1); if (!toSetIn.isEmpty()) { int cp = comp.getCaretPosition(); //comp.setCaretPosition(cp+1-toSetIn.); comp.select((cp + 1) - toSetIn.length(), cp); lastBeginning = lastBeginning + ch; e.consume(); lastCaretPosition = comp.getCaretPosition(); lastCompletions = findCompletions(lastBeginning); lastShownCompletion = 0; for (int i = 0; i < lastCompletions.size(); i++) { String lastCompletion = lastCompletions.get(i); if (lastCompletion.endsWith(toSetIn)) { lastShownCompletion = i; break; } } if (toSetIn.length() < 2) { // User typed the last character of the autocompleted word // We have to replace the automcompletion word by the typed word. // This helps if the user presses "space" after the completion // "space" indicates that the user does NOT want the autocompletion, // but the typed word String text = comp.getText(); comp.setText(text.substring(0, lastCaretPosition - lastBeginning.length()) + lastBeginning + text.substring(lastCaretPosition)); // there is no selected text, therefore we are not updating the selection toSetIn = null; } return; } } if ((toSetIn != null) && ((toSetIn.length() <= 1) || (ch != toSetIn.charAt(1)))) { // User discontinues the word that was suggested. lastBeginning = lastBeginning + ch; LOGGER.debug("discont toSetIn: >" + toSetIn + "'<' lastBeginning: >" + lastBeginning + '<'); List<String> completed = findCompletions(lastBeginning); if ((completed != null) && (!completed.isEmpty())) { lastShownCompletion = 0; lastCompletions = completed; String sno = completed.get(0); // toSetIn = string used for autocompletion last time // this string has to be removed // lastCaretPosition is the position of the caret after toSetIn. int lastLen = toSetIn.length() - 1; toSetIn = sno.substring(lastBeginning.length() - 1); String text = comp.getText(); //we do not use toSetIn as we want to obey the casing of "sno" comp.setText(text.substring(0, (lastCaretPosition - lastLen - lastBeginning.length()) + 1) + sno + text.substring(lastCaretPosition)); int startSelect = (lastCaretPosition + 1) - lastLen; int endSelect = (lastCaretPosition + toSetIn.length()) - lastLen; comp.select(startSelect, endSelect); lastCaretPosition = comp.getCaretPosition(); e.consume(); return; } else { setUnmodifiedTypedLetters(comp, true, false); e.consume(); toSetIn = null; return; } } LOGGER.debug("case else"); comp.replaceSelection(""); StringBuffer currentword = getCurrentWord(comp); // only "real characters" end up here assert (!Character.isISOControl(ch)); currentword.append(ch); startCompletion(currentword, e); return; } else { if (Character.isWhitespace(ch)) { assert (!completer.isSingleUnitField()); LOGGER.debug("whitespace && !singleUnitField"); // start a new search if end-of-field is reached // replace displayed letters with typed letters setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, true); resetAutoCompletion(); return; } LOGGER.debug("No letter/digit/whitespace or CHAR_UNDEFINED"); // replace displayed letters with typed letters setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, !Character.isISOControl(ch)); resetAutoCompletion(); return; } } resetAutoCompletion(); }
From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java
@Override //Overridden to prevent cell editing from starting just because the //user pressed the command key (which is necessary for discontiguous //cell selection) public boolean editCellAt(int row, int column, EventObject e) { if (e instanceof KeyEvent) { KeyEvent ke = (KeyEvent) e; if ((ke.getKeyCode() == 0 || ke.getKeyCode() == 157) && (ke.getModifiers() == 260 || ke.getModifiers() == 4)) { return false; }/*from ww w . jav a 2 s . com*/ } return super.editCellAt(row, column, e); }
From source file:net.sf.jabref.gui.AutoCompleteListener.java
@Override public void keyTyped(KeyEvent e) { LOGGER.debug("key typed event caught " + e.getKeyCode()); char ch = e.getKeyChar(); if (ch == '\n') { // this case is handled at keyPressed(e) return;/*ww w .j av a 2 s . c o m*/ } if ((e.getModifiers() | InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK) { // plain key or SHIFT + key is pressed, no handling of CTRL+key, META+key, ... if (Character.isLetter(ch) || Character.isDigit(ch) || (Character.isWhitespace(ch) && completer.isSingleUnitField())) { JTextComponent comp = (JTextComponent) e.getSource(); if (toSetIn == null) { LOGGER.debug("toSetIn is null"); } else { LOGGER.debug("toSetIn: >" + toSetIn + '<'); } // The case-insensitive system is a bit tricky here // If keyword is "TODO" and user types "tO", then this is treated as "continue" as the "O" matches the "O" // If keyword is "TODO" and user types "To", then this is treated as "discont" as the "o" does NOT match the "O". if ((toSetIn != null) && (toSetIn.length() > 1) && (ch == toSetIn.charAt(1))) { // User continues on the word that was suggested. LOGGER.debug("cont"); toSetIn = toSetIn.substring(1); if (!toSetIn.isEmpty()) { int cp = comp.getCaretPosition(); //comp.setCaretPosition(cp+1-toSetIn.); //System.out.println(cp-toSetIn.length()+" - "+cp); comp.select((cp + 1) - toSetIn.length(), cp); lastBeginning = lastBeginning + ch; e.consume(); lastCaretPosition = comp.getCaretPosition(); //System.out.println("Added char: '"+toSetIn+"'"); //System.out.println("LastBeginning: '"+lastBeginning+"'"); lastCompletions = findCompletions(lastBeginning, comp); lastShownCompletion = 0; for (int i = 0; i < lastCompletions.length; i++) { String lastCompletion = lastCompletions[i]; //System.out.println("Completion["+i+"] = "+lastCompletion); if (lastCompletion.endsWith(toSetIn)) { lastShownCompletion = i; break; } } //System.out.println("Index now: "+lastShownCompletion); if (toSetIn.length() < 2) { // User typed the last character of the autocompleted word // We have to replace the automcompletion word by the typed word. // This helps if the user presses "space" after the completion // "space" indicates that the user does NOT want the autocompletion, // but the typed word String text = comp.getText(); comp.setText(text.substring(0, lastCaretPosition - lastBeginning.length()) + lastBeginning + text.substring(lastCaretPosition)); // there is no selected text, therefore we are not updating the selection toSetIn = null; } return; } } if ((toSetIn != null) && ((toSetIn.length() <= 1) || (ch != toSetIn.charAt(1)))) { // User discontinues the word that was suggested. lastBeginning = lastBeginning + ch; LOGGER.debug("discont toSetIn: >" + toSetIn + "'<' lastBeginning: >" + lastBeginning + '<'); String[] completed = findCompletions(lastBeginning, comp); if ((completed != null) && (completed.length > 0)) { lastShownCompletion = 0; lastCompletions = completed; String sno = completed[0]; // toSetIn = string used for autocompletion last time // this string has to be removed // lastCaretPosition is the position of the caret after toSetIn. int lastLen = toSetIn.length() - 1; toSetIn = sno.substring(lastBeginning.length() - 1); String text = comp.getText(); //Util.pr(""+lastLen); //we do not use toSetIn as we want to obey the casing of "sno" comp.setText(text.substring(0, (lastCaretPosition - lastLen - lastBeginning.length()) + 1) + sno + text.substring(lastCaretPosition)); int startSelect = (lastCaretPosition + 1) - lastLen; int endSelect = (lastCaretPosition + toSetIn.length()) - lastLen; comp.select(startSelect, endSelect); lastCaretPosition = comp.getCaretPosition(); e.consume(); return; } else { setUnmodifiedTypedLetters(comp, true, false); e.consume(); toSetIn = null; return; } } LOGGER.debug("case else"); comp.replaceSelection(""); StringBuffer currentword = getCurrentWord(comp); if (currentword == null) { currentword = new StringBuffer(); } // only "real characters" end up here assert (!Character.isISOControl(ch)); currentword.append(ch); startCompletion(currentword, e); return; } else { if (Character.isWhitespace(ch)) { assert (!completer.isSingleUnitField()); LOGGER.debug("whitespace && !singleUnitField"); // start a new search if end-of-field is reached // replace displayed letters with typed letters setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, true); resetAutoCompletion(); return; } LOGGER.debug("No letter/digit/whitespace or CHAR_UNDEFINED"); // replace displayed letters with typed letters setUnmodifiedTypedLetters((JTextComponent) e.getSource(), false, !Character.isISOControl(ch)); resetAutoCompletion(); return; } } resetAutoCompletion(); }
From source file:gtu._work.ui.TextScanUI.java
private void groupListKeyPressed(KeyEvent evt) { DefaultListModel model = (DefaultListModel) groupList.getModel(); int index = groupList.getLeadSelectionIndex(); switch (evt.getKeyCode()) { case 127:// del model.removeElementAt(index);//from w ww . ja va 2 s . co m jTextField2filterAgain(false); break; } }
From source file:net.sf.xmm.moviemanager.gui.DialogIMDB.java
/** * Creates a panel containing a text field used to search * @return//from w w w . jav a 2 s .c om */ private JPanel createSearchStringPanel() { JPanel searchStringPanel = new JPanel(); searchStringPanel.setLayout(new BorderLayout()); searchStringPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Localizer.get("DialogIMDB.panel-search-string.title")), //$NON-NLS-1$ BorderFactory.createEmptyBorder(4, 4, 4, 4))); searchStringField = new JTextField(27); searchStringField.setActionCommand("Search String:"); //$NON-NLS-1$ searchStringField.setCaretPosition(0); searchStringField.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { executeSearch(); } } }); searchStringPanel.add(searchStringField, BorderLayout.NORTH); return searchStringPanel; }
From source file:burp.BurpExtender.java
private JPanel createMainPanel() { JPanel main = new JPanel(); main.setLayout(new GridBagLayout()); // Create Settings Panel JPanel settings = new JPanel(new GridBagLayout()); createTitle("Settings", settings); KeyListener projectEnter = new KeyAdapter() { @Override/*from www .j av a 2 s . c om*/ public void keyPressed(KeyEvent k) { if (k.getKeyCode() == KeyEvent.VK_ENTER) updateProjects(); } }; serverUrl = labelTextField("Server URL: ", settings, callbacks.loadExtensionSetting(BurpExtender.SERVER_KEY)); serverUrl.addKeyListener(projectEnter); serverUrl.addFocusListener(new JTextFieldSettingFocusListener(BurpExtender.SERVER_KEY, callbacks)); apiKey = labelTextField("API Key: ", settings, callbacks.loadExtensionSetting(BurpExtender.API_KEY)); apiKey.addKeyListener(projectEnter); apiKey.addFocusListener(new JTextFieldSettingFocusListener(BurpExtender.API_KEY, callbacks)); JButton targetRefresh = new JButton(); targetRefresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateTargets(); } }); targetUrl = createComboBox("Target URL: ", settings, 3, targetRefresh); projectRefresh = new JButton(); projectRefresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Thread updateThread = new Thread() { public void run() { NameValuePair selected = getProject(); if (selected != null) callbacks.saveExtensionSetting(BurpExtender.PROJECT_KEY, selected.getValue()); updateProjects(); } }; updateThread.start(); } }); projectBox = createComboBox("Projects: ", settings, 4, projectRefresh); GridBagConstraints setGBC = new GridBagConstraints(); setGBC.gridy = 3; setGBC.anchor = GridBagConstraints.NORTHWEST; main.add(settings, setGBC); // Separator Insets ins = new Insets(10, 10, 2, 10); JSeparator sep = new JSeparator(JSeparator.HORIZONTAL); callbacks.customizeUiComponent(sep); GridBagConstraints sepGBC = new GridBagConstraints(); sepGBC.gridwidth = 3; sepGBC.gridx = 0; sepGBC.fill = GridBagConstraints.HORIZONTAL; sepGBC.insets = ins; main.add(sep, sepGBC); // Create Export Button JButton exportBtn = new JButton(); exportBtn.setText("Send to Code Dx"); exportBtn.addActionListener(new ExportActionListener(this, callbacks)); callbacks.customizeUiComponent(exportBtn); GridBagConstraints btnGBC = new GridBagConstraints(); btnGBC.gridx = 0; btnGBC.weightx = 1.0; btnGBC.weighty = 1.0; btnGBC.insets = ins; btnGBC.anchor = GridBagConstraints.NORTHWEST; main.add(exportBtn, btnGBC); updateTargets(); return main; }
From source file:Report_PRCR_New_ETF_Excel_File_Generator.java
private void yearfieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_yearfieldKeyPressed if (evt.getKeyCode() == KeyEvent.VK_UP) { yearfield.setText("" + (Integer.parseInt(yearfield.getText()) + 1)); yearfield.selectAll();/*from w ww. j a v a 2 s. 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) { ////// ChaNGE focus on enter//////////////// // dayfield2.requestFocus(); // dayfield2.selectAll(); } }