use of java.awt.event.KeyListener in project cayenne by apache.
the class AutoCompletion method enable.
/**
* Enables auto-completion for specified combobox
*
* @param comboBox Combo to be featured
* @param strict Whether strict matching (check 'startWith' or 'contains') should be used
* @param allowsUserValues Whether non-present items are allowed
*/
public static void enable(JComboBox comboBox, boolean strict, boolean allowsUserValues) {
comboBox.setEditable(true);
KeyListener[] listeners = comboBox.getEditor().getEditorComponent().getListeners(KeyListener.class);
comboBox.setEditor(new CustomTypeComboBoxEditor(comboBox, allowsUserValues));
for (KeyListener listener : listeners) {
comboBox.getEditor().getEditorComponent().addKeyListener(listener);
}
AutoCompletion ac = new AutoCompletion(comboBox, strict, allowsUserValues);
comboBox.addFocusListener(ac);
ac.textEditor.addKeyListener(ac);
// original keys would not work properly
SwingUtilities.replaceUIActionMap(comboBox, null);
}
use of java.awt.event.KeyListener in project cayenne by apache.
the class EjbqlQueryScriptsTab method initView.
private void initView() {
scriptArea = new JUndoableCayenneTextPane(new EJBQLSyntaxConstant());
scriptArea.getDocument().addDocumentListener(this);
scriptArea.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
}
public void insertUpdate(DocumentEvent e) {
try {
String text = scriptArea.getDocument().getText(e.getOffset(), 1);
if (text.equals(" ") || text.equals("\n") || text.equals("\t")) {
getQuery().setEjbql(scriptArea.getDocumentTextDirect());
validateEJBQL();
}
} catch (BadLocationException ex) {
logger.warn("Error reading document", ex);
}
}
public void removeUpdate(DocumentEvent e) {
getQuery().setEjbql(scriptArea.getDocumentTextDirect());
validateEJBQL();
}
});
scriptArea.getPane().addFocusListener(new FocusListener() {
EJBQLValidationThread thread;
public void focusGained(FocusEvent e) {
thread = new EJBQLValidationThread();
thread.start();
}
public void focusLost(FocusEvent e) {
thread.terminate();
}
});
scriptArea.getPane().addKeyListener(new KeyListener() {
boolean pasteOrCut;
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_END || e.getKeyCode() == KeyEvent.VK_HOME || e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT || e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_UNDO) {
getQuery().setEjbql(scriptArea.getText());
validateEJBQL();
}
if ((e.getKeyCode() == KeyEvent.VK_V || e.getKeyCode() == KeyEvent.VK_X) && e.isControlDown()) {
pasteOrCut = true;
}
}
public void keyReleased(KeyEvent e) {
if ((pasteOrCut && e.getKeyCode() == KeyEvent.VK_CONTROL) || e.getKeyCode() == KeyEvent.VK_DELETE) {
scriptArea.removeHighlightText();
getQuery().setEjbql(scriptArea.getText());
validateEJBQL();
pasteOrCut = false;
}
}
public void keyTyped(KeyEvent e) {
}
});
setLayout(new BorderLayout());
add(scriptArea, BorderLayout.WEST);
add(scriptArea.getScrollPane(), BorderLayout.CENTER);
setVisible(true);
}
use of java.awt.event.KeyListener in project enumerable by hraberg.
the class LambdaTest method lambdaAsKeyListener.
@Test
public void lambdaAsKeyListener() throws Exception {
List<KeyEvent> events = new ArrayList<KeyEvent>();
KeyListener keyListener = λ(ke, events.add(ke)).as(KeyListener.class);
KeyEvent event = new KeyEvent(new JButton(), 0, 0, 0, 0, (char) 0);
keyListener.keyPressed(event);
assertEquals(1, events.size());
}
use of java.awt.event.KeyListener in project enumerable by hraberg.
the class LambdaTest method lambdaAsKeyListenerWithExactMatchAndMatchingParameterType.
@Test
public void lambdaAsKeyListenerWithExactMatchAndMatchingParameterType() throws Exception {
List<KeyEvent> events = new ArrayList<KeyEvent>();
KeyListener keyListener = λ(ke, events.add(ke)).as(KeyListener.class, "keyPressed", EventObject.class);
KeyEvent event = new KeyEvent(new JButton(), 0, 0, 0, 0, (char) 0);
keyListener.keyPressed(event);
assertEquals(1, events.size());
keyListener.keyReleased(event);
assertEquals(1, events.size());
keyListener.keyPressed(null);
assertEquals(2, events.size());
}
use of java.awt.event.KeyListener in project enumerable by hraberg.
the class LambdaTest method lambdaAsKeyListenerWithExactMatchAndNonMatchingParameterType.
@Test
public void lambdaAsKeyListenerWithExactMatchAndNonMatchingParameterType() throws Exception {
List<KeyEvent> events = new ArrayList<KeyEvent>();
KeyListener keyListener = λ(ke, events.add(ke)).as(KeyListener.class, "keyPressed", ActionEvent.class);
KeyEvent event = new KeyEvent(new JButton(), 0, 0, 0, 0, (char) 0);
keyListener.keyPressed(event);
assertTrue(events.isEmpty());
}
Aggregations