Search in sources :

Example 16 with InputEvent

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());
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) NotNull(org.jetbrains.annotations.NotNull) LinkedHashMap(java.util.LinkedHashMap) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) DefaultDebugExecutor(com.intellij.execution.executors.DefaultDebugExecutor) Executor(com.intellij.execution.Executor) JBList(com.intellij.ui.components.JBList) InputEvent(java.awt.event.InputEvent) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ProgramRunner(com.intellij.execution.runners.ProgramRunner)

Example 17 with InputEvent

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());
    }
}
Also used : BranchPopupBuilder(com.intellij.vcs.log.ui.filter.BranchPopupBuilder) MouseEvent(java.awt.event.MouseEvent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) InputEvent(java.awt.event.InputEvent) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction)

Example 18 with InputEvent

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("");
    }
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) EditorGutter(com.intellij.openapi.editor.EditorGutter) InputEvent(java.awt.event.InputEvent) Presentation(com.intellij.openapi.actionSystem.Presentation) Location(com.intellij.execution.Location)

Example 19 with InputEvent

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);
            }
    }
}
Also used : InputMethod(java.awt.im.spi.InputMethod) InputMethodEvent(java.awt.event.InputMethodEvent) InputEvent(java.awt.event.InputEvent) Component(java.awt.Component) FocusEvent(java.awt.event.FocusEvent)

Example 20 with InputEvent

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);
        }
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) AWTEvent(java.awt.AWTEvent) InputEvent(java.awt.event.InputEvent)

Aggregations

InputEvent (java.awt.event.InputEvent)21 MouseEvent (java.awt.event.MouseEvent)7 Editor (com.intellij.openapi.editor.Editor)4 Project (com.intellij.openapi.project.Project)4 NotNull (org.jetbrains.annotations.NotNull)4 ListPopup (com.intellij.openapi.ui.popup.ListPopup)3 AWTEvent (java.awt.AWTEvent)3 ActionEvent (java.awt.event.ActionEvent)3 Presentation (com.intellij.openapi.actionSystem.Presentation)2 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)2 ActionCallback (com.intellij.openapi.util.ActionCallback)2 Pair (com.intellij.openapi.util.Pair)2 JBList (com.intellij.ui.components.JBList)2 Nullable (org.jetbrains.annotations.Nullable)2 ExecutionBundle (com.intellij.execution.ExecutionBundle)1 ExecutionManager (com.intellij.execution.ExecutionManager)1 Executor (com.intellij.execution.Executor)1 KillableProcess (com.intellij.execution.KillableProcess)1 Location (com.intellij.execution.Location)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1