use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class GrTypeComboBox method registerUpDownHint.
public static void registerUpDownHint(JComponent component, final GrTypeComboBox combo) {
final AnAction arrow = new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
if (e.getInputEvent() instanceof KeyEvent) {
final int code = ((KeyEvent) e.getInputEvent()).getKeyCode();
scrollBy(code == KeyEvent.VK_DOWN ? 1 : code == KeyEvent.VK_UP ? -1 : 0, combo);
}
}
};
final KeyboardShortcut up = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_DOWN_MASK), null);
final KeyboardShortcut down = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK), null);
arrow.registerCustomShortcutSet(new CustomShortcutSet(up, down), component);
}
use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class IpnbEditablePanel method createEditablePanel.
private JTextArea createEditablePanel() {
final JTextArea textArea = new JTextArea(getRawCellText());
textArea.setLineWrap(true);
textArea.setEditable(true);
textArea.setBorder(BorderFactory.createLineBorder(JBColor.lightGray));
textArea.setBackground(IpnbEditorUtil.getEditablePanelBackground());
textArea.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 1) {
setEditing(true);
final Container parent = getParent();
parent.repaint();
if (parent instanceof IpnbFilePanel) {
((IpnbFilePanel) parent).setSelectedCellPanel(IpnbEditablePanel.this);
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(textArea, true);
});
}
}
}
});
textArea.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
setEditing(false);
final Container parent = getParent();
if (parent instanceof IpnbFilePanel) {
parent.repaint();
UIUtil.requestFocus((IpnbFilePanel) parent);
}
}
}
});
return textArea;
}
use of java.awt.event.KeyEvent 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.KeyEvent in project intellij-community by JetBrains.
the class EmmetAbbreviationBalloon method show.
public void show(@NotNull final CustomTemplateCallback customTemplateCallback) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
if (ourTestingAbbreviation == null) {
throw new RuntimeException("Testing abbreviation is not set. See EmmetAbbreviationBalloon#setTestingAbbreviation");
}
myCallback.onEnter(ourTestingAbbreviation);
return;
}
final TextFieldWithStoredHistory field = new TextFieldWithStoredHistory(myAbbreviationsHistoryKey);
final Dimension fieldPreferredSize = field.getPreferredSize();
field.setPreferredSize(new Dimension(Math.max(220, fieldPreferredSize.width), fieldPreferredSize.height));
field.setHistorySize(10);
final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
final BalloonImpl balloon = (BalloonImpl) popupFactory.createDialogBalloonBuilder(field, myTitle).setCloseButtonEnabled(false).setBlockClicksThroughBalloon(true).setAnimationCycle(0).setHideOnKeyOutside(true).setHideOnClickOutside(true).createBalloon();
final DocumentAdapter documentListener = new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
if (!isValid(customTemplateCallback)) {
balloon.hide();
return;
}
validateTemplateKey(field, balloon, field.getText(), customTemplateCallback);
}
};
field.addDocumentListener(documentListener);
final KeyAdapter keyListener = new KeyAdapter() {
@Override
public void keyPressed(@NotNull KeyEvent e) {
if (!field.isPopupVisible()) {
if (!isValid(customTemplateCallback)) {
balloon.hide();
return;
}
switch(e.getKeyCode()) {
case KeyEvent.VK_ENTER:
final String abbreviation = field.getText();
if (validateTemplateKey(field, balloon, abbreviation, customTemplateCallback)) {
myCallback.onEnter(abbreviation);
PropertiesComponent.getInstance().setValue(myLastAbbreviationKey, abbreviation);
field.addCurrentTextToHistory();
balloon.hide();
}
break;
case KeyEvent.VK_ESCAPE:
balloon.hide(false);
break;
}
}
}
};
field.addKeyboardListener(keyListener);
balloon.addListener(new JBPopupListener.Adapter() {
@Override
public void beforeShown(LightweightWindowEvent event) {
field.setText(PropertiesComponent.getInstance().getValue(myLastAbbreviationKey, ""));
}
@Override
public void onClosed(LightweightWindowEvent event) {
field.removeKeyListener(keyListener);
field.removeDocumentListener(documentListener);
super.onClosed(event);
}
});
balloon.show(popupFactory.guessBestPopupLocation(customTemplateCallback.getEditor()), Balloon.Position.below);
final IdeFocusManager focusManager = IdeFocusManager.getInstance(customTemplateCallback.getProject());
focusManager.doWhenFocusSettlesDown(() -> {
focusManager.requestFocus(field, true);
field.selectText();
});
}
use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class ToBeMergedDialog method addRevisionListListeners.
private void addRevisionListListeners() {
final int checkboxWidth = new JCheckBox().getPreferredSize().width;
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent e, int clickCount) {
final int idx = myRevisionsList.rowAtPoint(e.getPoint());
if (idx >= 0) {
final Rectangle baseRect = myRevisionsList.getCellRect(idx, 0, false);
baseRect.setSize(checkboxWidth, baseRect.height);
if (baseRect.contains(e.getPoint())) {
toggleInclusion(myRevisionsModel.getRowValue(idx));
myRevisionsList.repaint(baseRect);
}
}
return true;
}
}.installOn(myRevisionsList);
myRevisionsList.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (KeyEvent.VK_SPACE == e.getKeyCode()) {
List<SvnChangeList> selected = myRevisionsList.getSelectedObjects();
if (!selected.isEmpty()) {
selected.forEach(ToBeMergedDialog.this::toggleInclusion);
myRevisionsList.repaint();
e.consume();
}
}
}
});
}
Aggregations