use of java.awt.event.InputEvent in project intellij-community by JetBrains.
the class AbstractRerunFailedTestsAction method execute.
void execute(@NotNull AnActionEvent e, @NotNull ExecutionEnvironment environment) {
MyRunProfile profile = getRunProfile(environment);
if (profile == null) {
return;
}
final ExecutionEnvironmentBuilder environmentBuilder = new ExecutionEnvironmentBuilder(environment).runProfile(profile);
final InputEvent event = e.getInputEvent();
if (!(event instanceof MouseEvent) || !event.isShiftDown()) {
performAction(environmentBuilder);
return;
}
final LinkedHashMap<Executor, ProgramRunner> availableRunners = new LinkedHashMap<>();
for (Executor ex : new Executor[] { DefaultRunExecutor.getRunExecutorInstance(), DefaultDebugExecutor.getDebugExecutorInstance() }) {
final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(ex.getId(), profile);
if (runner != null) {
availableRunners.put(ex, runner);
}
}
if (availableRunners.isEmpty()) {
LOG.error(environment.getExecutor().getActionName() + " is not available now");
} else if (availableRunners.size() == 1) {
//noinspection ConstantConditions
performAction(environmentBuilder.runner(availableRunners.get(environment.getExecutor())));
} else {
final JBList list = new JBList(availableRunners.keySet());
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSelectedValue(environment.getExecutor(), true);
list.setCellRenderer(new DefaultListCellRenderer() {
@NotNull
@Override
public Component getListCellRendererComponent(@NotNull JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
final Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof Executor) {
setText(UIUtil.removeMnemonic(((Executor) value).getStartActionText()));
setIcon(((Executor) value).getIcon());
}
return component;
}
});
//noinspection ConstantConditions
JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Restart Failed Tests").setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
final Object value = list.getSelectedValue();
if (value instanceof Executor) {
//noinspection ConstantConditions
performAction(environmentBuilder.runner(availableRunners.get(value)).executor((Executor) value));
}
}).createPopup().showUnderneathOf(event.getComponent());
}
}
use of java.awt.event.InputEvent in project intellij-community by JetBrains.
the class DeepCompareAction method selectBranchAndPerformAction.
private static void selectBranchAndPerformAction(@NotNull VcsLogDataPack dataPack, @NotNull AnActionEvent event, @NotNull final Consumer<String> consumer, @NotNull Collection<VirtualFile> visibleRoots) {
ActionGroup actionGroup = new BranchPopupBuilder(dataPack, visibleRoots, null) {
@NotNull
@Override
protected AnAction createAction(@NotNull final String name) {
return new DumbAwareAction(name) {
@Override
public void actionPerformed(AnActionEvent e) {
consumer.consume(name);
}
};
}
}.build();
ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup("Select branch to compare", actionGroup, event.getDataContext(), false, false, false, null, -1, null);
InputEvent inputEvent = event.getInputEvent();
if (inputEvent instanceof MouseEvent) {
popup.show(new RelativePoint((MouseEvent) inputEvent));
} else {
popup.showInBestPositionFor(event.getDataContext());
}
}
use of java.awt.event.InputEvent in project intellij-community by JetBrains.
the class PyStudyRunContextAction method update.
@Override
public void update(AnActionEvent event) {
final ConfigurationContext context = ConfigurationContext.getFromContext(event.getDataContext());
final Location location = context.getLocation();
if (location == null)
return;
super.update(event);
final InputEvent inputEvent = event.getInputEvent();
final Presentation presentation = event.getPresentation();
if (inputEvent == null && !(context.getDataContext().getData(PlatformDataKeys.CONTEXT_COMPONENT) instanceof EditorGutter)) {
presentation.setText("");
}
}
use of java.awt.event.InputEvent in project jdk8u_jdk by JetBrains.
the class InputContext method dispatchEvent.
/**
* @see java.awt.im.InputContext#dispatchEvent
*/
@SuppressWarnings("fallthrough")
public void dispatchEvent(AWTEvent event) {
if (event instanceof InputMethodEvent) {
return;
}
// This is a workaround. Should be removed after 4452384 is fixed.
if (event instanceof FocusEvent) {
Component opposite = ((FocusEvent) event).getOppositeComponent();
if ((opposite != null) && (getComponentWindow(opposite) instanceof InputMethodWindow) && (opposite.getInputContext() == this)) {
return;
}
}
InputMethod inputMethod = getInputMethod();
int id = event.getID();
switch(id) {
case FocusEvent.FOCUS_GAINED:
focusGained((Component) event.getSource());
break;
case FocusEvent.FOCUS_LOST:
focusLost((Component) event.getSource(), ((FocusEvent) event).isTemporary());
break;
case KeyEvent.KEY_PRESSED:
if (checkInputMethodSelectionKey((KeyEvent) event)) {
// pop up the input method selection menu
InputMethodManager.getInstance().notifyChangeRequestByHotKey((Component) event.getSource());
break;
}
default:
if ((inputMethod != null) && (event instanceof InputEvent)) {
inputMethod.dispatchEvent(event);
}
}
}
use of java.awt.event.InputEvent in project adempiere by adempiere.
the class VNumber method fireActionPerformed.
// addActionListener
/**
* Fire Action Event to listeners
*/
protected void fireActionPerformed() {
int modifiers = 0;
AWTEvent currentEvent = EventQueue.getCurrentEvent();
if (currentEvent instanceof InputEvent)
modifiers = ((InputEvent) currentEvent).getModifiers();
else if (currentEvent instanceof ActionEvent)
modifiers = ((ActionEvent) currentEvent).getModifiers();
ActionEvent ae = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, currentEvent.getClass().getSimpleName(), EventQueue.getMostRecentEventTime(), modifiers);
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying those that are interested in this event
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == ActionListener.class) {
((ActionListener) listeners[i + 1]).actionPerformed(ae);
}
}
}
Aggregations