List of usage examples for java.awt.event KeyEvent getSource
public Object getSource()
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 ww . j a v a2 s . co 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:pl.otros.logview.gui.actions.MarkAllFoundAction.java
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == 10 && KeyEvent.CTRL_MASK == e.getModifiers()) { actionPerformed(new ActionEvent(e.getSource(), e.getID(), "")); }/* w w w . j av a 2 s . com*/ }
From source file:kenh.xscript.elements.Debug.java
@Override public void keyPressed(KeyEvent e) { if (e.getKeyChar() == KeyEvent.VK_ENTER) { Object obj = e.getSource(); if (obj instanceof JTextField) { parse((JTextField) obj); }//from w ww. java 2 s . c o m } }
From source file:ome.formats.importer.gui.FileQueueChooser.java
/** * @param evt key pressed event// w w w. ja va 2s.c om */ public void keyPressed(KeyEvent evt) { Object src = evt.getSource(); int keyCode = evt.getKeyCode(); if (src == fileList && keyCode == KeyEvent.VK_ENTER) { File[] arr = getSelectedFiles(); if (arr.length == 1 && arr[0].isFile()) { approveSelection(); } } }
From source file:is.iclt.jcorpald.CorpaldView.java
public void keyReleased(KeyEvent event) { // it can either be the root node field ... if (event.getSource() == txtRootNode) { controller.setRootNode(txtRootNode.getText()); } else { // ... or the query itself controller.setQuery(txtQuery.getText()); }/*from w w w .j a v a2 s . co m*/ }
From source file:net.sf.jabref.gui.autocompleter.AutoCompleteListener.java
/** * Start a new completion attempt (instead of treating a continuation of an existing word or an interrupt of the * current word)/*w ww. j ava 2 s .c om*/ */ private void startCompletion(StringBuffer currentword, KeyEvent e) { JTextComponent comp = (JTextComponent) e.getSource(); List<String> completed = findCompletions(currentword.toString()); String prefix = completer.getPrefix(); String cWord = (prefix != null) && (!prefix.isEmpty()) ? currentword.toString().substring(prefix.length()) : currentword.toString(); LOGGER.debug("StartCompletion currentword: >" + currentword + "'<' prefix: >" + prefix + "'<' cword: >" + cWord + '<'); int no = 0; // We use the first word in the array of completions. if ((completed != null) && (!completed.isEmpty())) { lastShownCompletion = 0; lastCompletions = completed; String sno = completed.get(no); // these two lines obey the user's input //toSetIn = Character.toString(ch); //toSetIn = toSetIn.concat(sno.substring(cWord.length())); // BUT we obey the completion toSetIn = sno.substring(cWord.length() - 1); LOGGER.debug("toSetIn: >" + toSetIn + '<'); StringBuilder alltext = new StringBuilder(comp.getText()); int cp = comp.getCaretPosition(); alltext.insert(cp, toSetIn); comp.setText(alltext.toString()); comp.setCaretPosition(cp); comp.select(cp + 1, (cp + 1 + sno.length()) - cWord.length()); e.consume(); lastCaretPosition = comp.getCaretPosition(); char ch = e.getKeyChar(); LOGGER.debug("Appending >" + ch + '<'); if (cWord.length() <= 1) { lastBeginning = Character.toString(ch); } else { lastBeginning = cWord.substring(0, cWord.length() - 1).concat(Character.toString(ch)); } } }
From source file:net.sf.jabref.gui.AutoCompleteListener.java
/** * Start a new completion attempt/* w w w. ja v a 2s . co m*/ * (instead of treating a continuation of an existing word or an interrupt of the current word) */ private void startCompletion(StringBuffer currentword, KeyEvent e) { JTextComponent comp = (JTextComponent) e.getSource(); String[] completed = findCompletions(currentword.toString(), comp); String prefix = completer.getPrefix(); String cWord = (prefix != null) && (!prefix.isEmpty()) ? currentword.toString().substring(prefix.length()) : currentword.toString(); LOGGER.debug("StartCompletion currentword: >" + currentword + "'<' prefix: >" + prefix + "'<' cword: >" + cWord + '<'); int no = 0; // We use the first word in the array of completions. if ((completed != null) && (completed.length > 0)) { lastShownCompletion = 0; lastCompletions = completed; String sno = completed[no]; // these two lines obey the user's input //toSetIn = Character.toString(ch); //toSetIn = toSetIn.concat(sno.substring(cWord.length())); // BUT we obey the completion toSetIn = sno.substring(cWord.length() - 1); LOGGER.debug("toSetIn: >" + toSetIn + '<'); StringBuilder alltext = new StringBuilder(comp.getText()); int cp = comp.getCaretPosition(); alltext.insert(cp, toSetIn); comp.setText(alltext.toString()); comp.setCaretPosition(cp); comp.select(cp + 1, (cp + 1 + sno.length()) - cWord.length()); e.consume(); lastCaretPosition = comp.getCaretPosition(); char ch = e.getKeyChar(); LOGGER.debug("Appending >" + ch + '<'); if (cWord.length() <= 1) { lastBeginning = Character.toString(ch); } else { lastBeginning = cWord.substring(0, cWord.length() - 1).concat(Character.toString(ch)); } } }
From source file:edu.ku.brc.specify.datamodel.busrules.DeterminationBusRules.java
/** * @param e/*from w w w. j a va2s.com*/ * @param taxComp * @param altNameComp * * Disables the taxon field when the alternateName field is non-empty. * Enables the taxon field when the alternateNameField is empty. */ protected void nameChanged(KeyEvent e, final ValComboBoxFromQuery taxComp, final Component altNameComp) { if (e.getSource() != null) { if (e.getSource().equals(altNameComp)) { taxComp.setEnabled(StringUtils.isBlank(((JTextField) altNameComp).getText())); } else if (e.getSource().equals(taxComp)) { taxonChanged(taxComp, altNameComp); } } }
From source file:com.willwinder.ugs.nbp.setupwizard.panels.WizardPanelStepCalibration.java
private KeyListener createKeyListener(Axis axis, JLabel label) { return new KeyListener() { @Override// w w w .j a v a 2s.c o m public void keyTyped(KeyEvent event) { } @Override public void keyPressed(KeyEvent event) { } @Override public void keyReleased(KeyEvent event) { JTextField source = (JTextField) event.getSource(); if (source != null) { updateEstimationFromMesurement(source, axis, label); } } }; }
From source file:net.sf.jabref.gui.autocompleter.AutoCompleteListener.java
@Override public void keyPressed(KeyEvent e) { if ((toSetIn != null) && (e.getKeyCode() == KeyEvent.VK_ENTER)) { JTextComponent comp = (JTextComponent) e.getSource(); // replace typed characters by characters from completion lastBeginning = lastCompletions.get(lastShownCompletion); int end = comp.getSelectionEnd(); comp.select(end, end);//from w w w . ja va2 s. c om toSetIn = null; if (consumeEnterKey) { e.consume(); } } // Cycle through alternative completions when user presses PGUP/PGDN: else if ((e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) && (toSetIn != null)) { cycle((JTextComponent) e.getSource(), 1); e.consume(); } else if ((e.getKeyCode() == KeyEvent.VK_PAGE_UP) && (toSetIn != null)) { cycle((JTextComponent) e.getSource(), -1); e.consume(); } // else if ((e.getKeyCode() == KeyEvent.VK_BACK_SPACE)) { // StringBuffer currentword = getCurrentWord((JTextComponent) e.getSource()); // // delete last char to obey semantics of back space // currentword.deleteCharAt(currentword.length()-1); // doCompletion(currentword, e); // } else if (e.getKeyChar() == KeyEvent.CHAR_UNDEFINED) { if (e.getKeyCode() == KeyEvent.VK_SHIFT) { // shift is OK, everything else leads to a reset LOGGER.debug("Special case: shift pressed. No action."); } else { resetAutoCompletion(); } } else { LOGGER.debug("Special case: defined character, but not caught above"); } }