use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class MacIntelliJComboBoxUI method createEditor.
@Override
protected ComboBoxEditor createEditor() {
final ComboBoxEditor comboBoxEditor = new BasicComboBoxEditor.UIResource() {
@Override
protected JTextField createEditorComponent() {
return new JTextField() {
{
setOpaque(false);
setBorder(ourDefaultEditorBorder);
}
@Override
public Color getBackground() {
if (!isEnabled()) {
return Gray.xF8;
}
return super.getBackground();
}
public void setText(String s) {
if (getText().equals(s)) {
return;
}
super.setText(s);
}
@Override
public void setBorder(Border border) {
}
@Override
public Border getBorder() {
return ourDefaultEditorBorder;
}
@Override
public Dimension getPreferredSize() {
Dimension size = super.getPreferredSize();
return new Dimension(size.width, DEFAULT_ICON.getIconHeight() - 6);
}
};
}
};
if (comboBoxEditor.getEditorComponent() != null) {
comboBoxEditor.getEditorComponent().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
process(e);
}
@Override
public void keyReleased(KeyEvent e) {
process(e);
}
private void process(KeyEvent e) {
final int code = e.getKeyCode();
if ((code == KeyEvent.VK_UP || code == KeyEvent.VK_DOWN) && e.getModifiers() == 0) {
comboBox.dispatchEvent(e);
}
}
});
comboBoxEditor.getEditorComponent().addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
update();
}
@Override
public void focusLost(FocusEvent e) {
update();
}
void update() {
if (comboBox != null) {
comboBox.revalidate();
comboBox.repaint();
}
}
});
}
return comboBoxEditor;
}
use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class DarculaLaf method initialize.
@Override
public void initialize() {
try {
base.initialize();
} catch (Exception ignore) {
}
myDisposable = Disposer.newDisposable();
Application application = ApplicationManager.getApplication();
if (application != null) {
Disposer.register(application, myDisposable);
}
myMnemonicAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, myDisposable);
IdeEventQueue.getInstance().addDispatcher(e -> {
if (e instanceof KeyEvent && ((KeyEvent) e).getKeyCode() == KeyEvent.VK_ALT) {
myAltPressed = e.getID() == KeyEvent.KEY_PRESSED;
myMnemonicAlarm.cancelAllRequests();
final Component focusOwner = IdeFocusManager.findInstance().getFocusOwner();
if (focusOwner != null) {
myMnemonicAlarm.addRequest(() -> repaintMnemonics(focusOwner, myAltPressed), 10);
}
}
return false;
}, myDisposable);
}
use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class NewRecentProjectPanel method createList.
@Override
protected JBList createList(AnAction[] recentProjectActions, Dimension size) {
final JBList list = super.createList(recentProjectActions, size);
list.setBackground(FlatWelcomeFrame.getProjectsBackground());
list.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
Object selected = list.getSelectedValue();
final ProjectGroup group;
if (selected instanceof ProjectGroupActionGroup) {
group = ((ProjectGroupActionGroup) selected).getGroup();
} else {
group = null;
}
int keyCode = e.getKeyCode();
if (keyCode == KeyEvent.VK_RIGHT) {
if (group != null) {
if (!group.isExpanded()) {
group.setExpanded(true);
ListModel model = ((NameFilteringListModel) list.getModel()).getOriginalModel();
int index = list.getSelectedIndex();
RecentProjectsWelcomeScreenActionBase.rebuildRecentProjectDataModel((DefaultListModel) model);
list.setSelectedIndex(group.getProjects().isEmpty() ? index : index + 1);
}
} else {
FlatWelcomeFrame frame = UIUtil.getParentOfType(FlatWelcomeFrame.class, list);
if (frame != null) {
FocusTraversalPolicy policy = frame.getFocusTraversalPolicy();
if (policy != null) {
Component next = policy.getComponentAfter(frame, list);
if (next != null) {
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(next, true);
});
}
}
}
}
} else if (keyCode == KeyEvent.VK_LEFT) {
if (group != null && group.isExpanded()) {
group.setExpanded(false);
int index = list.getSelectedIndex();
ListModel model = ((NameFilteringListModel) list.getModel()).getOriginalModel();
RecentProjectsWelcomeScreenActionBase.rebuildRecentProjectDataModel((DefaultListModel) model);
list.setSelectedIndex(index);
}
}
}
});
list.addMouseListener(new PopupHandler() {
@Override
public void invokePopup(Component comp, int x, int y) {
final int index = list.locationToIndex(new Point(x, y));
if (index != -1 && Arrays.binarySearch(list.getSelectedIndices(), index) < 0) {
list.setSelectedIndex(index);
}
final ActionGroup group = (ActionGroup) ActionManager.getInstance().getAction("WelcomeScreenRecentProjectActionGroup");
if (group != null) {
ActionManager.getInstance().createActionPopupMenu(ActionPlaces.WELCOME_SCREEN, group).getComponent().show(comp, x, y);
}
}
});
return list;
}
use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class IdeEventQueueTest method testKeyboardEventsAreDetected.
public void testKeyboardEventsAreDetected() throws InterruptedException {
assertTrue(EventQueue.isDispatchThread());
IdeEventQueue ideEventQueue = IdeEventQueue.getInstance();
assertSame(ideEventQueue, Toolkit.getDefaultToolkit().getSystemEventQueue());
PlatformTestUtil.dispatchAllEventsInIdeEventQueue();
ideEventQueue.addDispatcher(e -> {
LOG.debug("dispatch: " + e);
return false;
}, getTestRootDisposable());
ideEventQueue.addPostprocessor(e -> {
LOG.debug("post dispatch: " + e);
return false;
}, getTestRootDisposable());
ideEventQueue.addPostEventListener(e -> {
LOG.debug("post event hook: " + e);
return false;
}, getTestRootDisposable());
int posted = ideEventQueue.myKeyboardEventsPosted.get();
int dispatched = ideEventQueue.myKeyboardEventsDispatched.get();
KeyEvent pressX = new KeyEvent(new JLabel("mykeypress"), KeyEvent.KEY_PRESSED, 1, InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, 11, 'x');
postCarefully(pressX);
assertEquals(posted + 1, ideEventQueue.myKeyboardEventsPosted.get());
assertEquals(dispatched, ideEventQueue.myKeyboardEventsDispatched.get());
assertEquals(pressX, dispatchAllInvocationEventsUntilOtherEvent(ideEventQueue));
assertEquals(posted + 1, ideEventQueue.myKeyboardEventsPosted.get());
assertEquals(dispatched + 1, ideEventQueue.myKeyboardEventsDispatched.get());
// do not react to other events
AWTEvent ev2 = new ActionEvent(new JLabel(), ActionEvent.ACTION_PERFORMED, "myCommand");
postCarefully(ev2);
assertEquals(posted + 1, ideEventQueue.myKeyboardEventsPosted.get());
assertEquals(dispatched + 1, ideEventQueue.myKeyboardEventsDispatched.get());
assertEquals(ev2, dispatchAllInvocationEventsUntilOtherEvent(ideEventQueue));
assertEquals(posted + 1, ideEventQueue.myKeyboardEventsPosted.get());
assertEquals(dispatched + 1, ideEventQueue.myKeyboardEventsDispatched.get());
KeyEvent keyRelease = new KeyEvent(new JLabel("mykeyrelease"), KeyEvent.KEY_RELEASED, 1, InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, 11, 'x');
postCarefully(keyRelease);
assertEquals(posted + 2, ideEventQueue.myKeyboardEventsPosted.get());
assertEquals(dispatched + 1, ideEventQueue.myKeyboardEventsDispatched.get());
assertEquals(keyRelease, dispatchAllInvocationEventsUntilOtherEvent(ideEventQueue));
assertEquals(posted + 2, ideEventQueue.myKeyboardEventsPosted.get());
assertEquals(dispatched + 2, ideEventQueue.myKeyboardEventsDispatched.get());
}
use of java.awt.event.KeyEvent in project intellij-community by JetBrains.
the class ResumeAction method isEnabled.
@Override
protected boolean isEnabled(AnActionEvent e) {
Project project = e.getProject();
if (project == null)
return false;
XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
if (session != null && !session.isStopped()) {
return session.isPaused();
}
// disable visual representation but leave the shortcut action enabled
return e.getInputEvent() instanceof KeyEvent;
}
Aggregations