use of java.awt.event.KeyListener in project enumerable by hraberg.
the class LambdaTest method lambdaAsKeyListenerWithRegex.
@Test
public void lambdaAsKeyListenerWithRegex() throws Exception {
List<KeyEvent> events = new ArrayList<KeyEvent>();
KeyListener keyListener = λ(ke, events.add(ke)).as(KeyListener.class, ".*Typed");
KeyEvent event = new KeyEvent(new JButton(), 0, 0, 0, 0, (char) 0);
keyListener.keyPressed(event);
assertTrue(events.isEmpty());
keyListener.keyReleased(event);
assertTrue(events.isEmpty());
keyListener.keyTyped(event);
assertEquals(1, events.size());
}
use of java.awt.event.KeyListener in project intellij-community by JetBrains.
the class AddRepositoryLocationDialog method createCenterPanel.
protected JComponent createCenterPanel() {
JLabel selectText = new JLabel(message("repository.browser.add.location.prompt"));
selectText.setUI(new MultiLineLabelUI());
JPanel mainPanel = new JPanel(new GridBagLayout());
GridBagConstraints gb = new GridBagConstraints(0, 0, 1, 1, 1, 0, NORTHWEST, NONE, insets(5), 0, 0);
mainPanel.add(selectText, gb);
++gb.gridy;
myCombo = new ComboBox<>(new CollectionComboBoxModel<>(myPreviousLocations));
myCombo.setEditable(true);
myCombo.setMinimumSize(size(250, 20));
gb.fill = HORIZONTAL;
mainPanel.add(myCombo, gb);
gb.fill = NONE;
myComboField = (JTextField) myCombo.getEditor().getEditorComponent();
myComboField.addInputMethodListener(new InputMethodListener() {
public void inputMethodTextChanged(InputMethodEvent event) {
validateMe();
}
public void caretPositionChanged(InputMethodEvent event) {
validateMe();
}
});
myComboField.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
validateMe();
}
public void keyPressed(KeyEvent e) {
validateMe();
}
public void keyReleased(KeyEvent e) {
validateMe();
}
});
myCombo.addActionListener(e -> validateMe());
validateMe();
JPanel wrapper = new JPanel(new GridBagLayout());
wrapper.add(mainPanel, new GridBagConstraints(0, 0, 1, 1, 1, 1, NORTHWEST, HORIZONTAL, emptyInsets(), 0, 0));
wrapper.setPreferredSize(size(400, 70));
return wrapper;
}
use of java.awt.event.KeyListener in project intellij-community by JetBrains.
the class CheckboxTreeHelper method initTree.
public void initTree(@NotNull final Tree tree, JComponent mainComponent, CheckboxTreeBase.CheckboxTreeCellRendererBase cellRenderer) {
removeTreeListeners(mainComponent);
tree.setCellRenderer(cellRenderer);
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.setLineStyleAngled();
TreeUtil.installActions(tree);
KeyListener keyListener = setupKeyListener(tree, mainComponent);
ClickListener clickListener = setupMouseListener(tree, mainComponent, cellRenderer);
UIUtil.putClientProperty(mainComponent, TREE_LISTENERS_REMOVER, () -> {
mainComponent.removeKeyListener(keyListener);
clickListener.uninstall(mainComponent);
});
}
use of java.awt.event.KeyListener in project intellij-community by JetBrains.
the class ImageOrColorPreviewManager method registerListeners.
private void registerListeners(final Editor editor) {
if (editor.isOneLineMode()) {
return;
}
Project project = editor.getProject();
if (project == null || project.isDisposed()) {
return;
}
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (psiFile == null || psiFile instanceof PsiCompiledElement || !isSupportedFile(psiFile)) {
return;
}
editor.addEditorMouseMotionListener(this);
KeyListener keyListener = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SHIFT && !editor.isOneLineMode()) {
PointerInfo pointerInfo = MouseInfo.getPointerInfo();
if (pointerInfo != null) {
Point location = pointerInfo.getLocation();
SwingUtilities.convertPointFromScreen(location, editor.getContentComponent());
alarm.cancelAllRequests();
alarm.addRequest(new PreviewRequest(location, editor, true), 100);
}
}
}
};
editor.getContentComponent().addKeyListener(keyListener);
EDITOR_LISTENER_ADDED.set(editor, keyListener);
}
use of java.awt.event.KeyListener in project processing by processing.
the class JavaTextArea method tweakRemoveListeners.
/* remove all standard interaction listeners */
public void tweakRemoveListeners() {
if (baseCompListeners == null) {
// First time in tweak mode, grab the default listeners. Moved from the
// constructor since not all listeners may have been added at that point.
baseCompListeners = painter.getComponentListeners();
baseMouseListeners = painter.getMouseListeners();
baseMotionListeners = painter.getMouseMotionListeners();
baseKeyListeners = editor.getKeyListeners();
}
ComponentListener[] componentListeners = painter.getComponentListeners();
MouseListener[] mouseListeners = painter.getMouseListeners();
MouseMotionListener[] mouseMotionListeners = painter.getMouseMotionListeners();
KeyListener[] keyListeners = editor.getKeyListeners();
for (ComponentListener cl : componentListeners) {
painter.removeComponentListener(cl);
}
for (MouseListener ml : mouseListeners) {
painter.removeMouseListener(ml);
}
for (MouseMotionListener mml : mouseMotionListeners) {
painter.removeMouseMotionListener(mml);
}
for (KeyListener kl : keyListeners) {
editor.removeKeyListener(kl);
}
}
Aggregations