Search in sources :

Example 41 with MouseEvent

use of java.awt.event.MouseEvent in project intellij-community by JetBrains.

the class PyLineMarkerProviderTest method testOverriding.

/**
   * Checks method has "up" arrow when overrides, and this arrow works
   */
public void testOverriding() throws Exception {
    myFixture.copyDirectoryToProject("lineMarkerTest", "");
    myFixture.configureByFile("spam.py");
    final ASTNode functionNode = myFixture.getElementAtCaret().getNode();
    // We need IDENTIFIER node
    final ASTNode[] functionChildren = functionNode.getChildren(TokenSet.create(PyTokenTypes.IDENTIFIER));
    assert functionChildren.length == 1 : "Wrong number of identifiers: " + functionChildren.length;
    final PsiElement element = functionChildren[0].getPsi();
    @SuppressWarnings("unchecked") final LineMarkerInfo<PsiElement> lineMarkerInfo = new PyLineMarkerProvider().getLineMarkerInfo(element);
    Assert.assertNotNull("No gutter displayed", lineMarkerInfo);
    final GutterIconNavigationHandler<PsiElement> handler = lineMarkerInfo.getNavigationHandler();
    Assert.assertNotNull("Gutter has no navigation handle", handler);
    handler.navigate(new MouseEvent(new JLabel(), 0, 0, 0, 0, 0, 0, false), element);
    final NavigatablePsiElement[] targets = PyLineMarkerNavigator.getNavigationTargets(element);
    Assert.assertNotNull("No navigation targets found", targets);
    Assert.assertThat("Wrong number of targets found", targets, Matchers.arrayWithSize(1));
    final NavigatablePsiElement parentMethod = targets[0];
    Assert.assertThat("Navigation target has wrong type", parentMethod, Matchers.instanceOf(PyPossibleClassMember.class));
    final PyClass parentClass = ((PyPossibleClassMember) parentMethod).getContainingClass();
    Assert.assertNotNull("Function overrides other function, but no parent displayed", parentClass);
    Assert.assertEquals("Wrong parent class name", "Eggs", parentClass.getName());
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) MouseEvent(java.awt.event.MouseEvent) ASTNode(com.intellij.lang.ASTNode) PyPossibleClassMember(com.jetbrains.python.psi.PyPossibleClassMember) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement)

Example 42 with MouseEvent

use of java.awt.event.MouseEvent in project intellij-community by JetBrains.

the class MavenKeymapExtension method createGroup.

@Override
public KeymapGroup createGroup(Condition<AnAction> condition, final Project project) {
    KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(TasksBundle.message("maven.tasks.action.group.name"), MavenIcons.MavenLogo);
    if (project == null)
        return result;
    Comparator<MavenProject> projectComparator = (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
    Map<MavenProject, Set<Pair<String, String>>> projectToActionsMapping = new TreeMap<>(projectComparator);
    ActionManager actionManager = ActionManager.getInstance();
    //noinspection TestOnlyProblems
    for (String eachId : actionManager.getActionIds(getActionPrefix(project, null))) {
        AnAction eachAction = actionManager.getAction(eachId);
        if (!(eachAction instanceof MavenGoalAction))
            continue;
        if (condition != null && !condition.value(actionManager.getActionOrStub(eachId)))
            continue;
        MavenGoalAction mavenAction = (MavenGoalAction) eachAction;
        MavenProject mavenProject = mavenAction.getMavenProject();
        Set<Pair<String, String>> actions = projectToActionsMapping.get(mavenProject);
        if (actions == null) {
            final List<String> projectGoals = collectGoals(mavenProject);
            actions = new TreeSet<>((o1, o2) -> {
                String goal1 = o1.getFirst();
                String goal2 = o2.getFirst();
                int index1 = projectGoals.indexOf(goal1);
                int index2 = projectGoals.indexOf(goal2);
                if (index1 == index2)
                    return goal1.compareToIgnoreCase(goal2);
                return (index1 < index2 ? -1 : 1);
            });
            projectToActionsMapping.put(mavenProject, actions);
        }
        actions.add(Pair.create(mavenAction.getGoal(), eachId));
    }
    for (Map.Entry<MavenProject, Set<Pair<String, String>>> each : projectToActionsMapping.entrySet()) {
        Set<Pair<String, String>> goalsToActionIds = each.getValue();
        for (Pair<String, String> eachGoalToActionId : goalsToActionIds) {
            result.addActionId(eachGoalToActionId.getSecond());
        }
    }
    Icon icon = SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add;
    ((Group) result).addHyperlink(new Hyperlink(icon, "Choose a phase/goal to assign a shortcut") {

        @Override
        public void onClick(MouseEvent e) {
            SelectMavenGoalDialog dialog = new SelectMavenGoalDialog(project);
            if (dialog.showAndGet() && dialog.getResult() != null) {
                MavenProjectsStructure.GoalNode goalNode = dialog.getResult();
                String goal = goalNode.getGoal();
                String actionId = MavenShortcutsManager.getInstance(project).getActionId(goalNode.getProjectPath(), goal);
                getOrRegisterAction(goalNode.getMavenProject(), actionId, goal);
                ApplicationManager.getApplication().getMessageBus().syncPublisher(KeymapListener.CHANGE_TOPIC).processCurrentKeymapChanged();
                Settings allSettings = Settings.KEY.getData(DataManager.getInstance().getDataContext(e.getComponent()));
                KeymapPanel keymapPanel = allSettings != null ? allSettings.find(KeymapPanel.class) : null;
                if (keymapPanel != null) {
                    // clear actions filter
                    keymapPanel.showOption("");
                    keymapPanel.selectAction(actionId);
                }
            }
        }
    });
    return result;
}
Also used : KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) Settings(com.intellij.openapi.options.ex.Settings) KeymapGroupFactory(com.intellij.openapi.keymap.KeymapGroupFactory) KeymapPanel(com.intellij.openapi.keymap.impl.ui.KeymapPanel) SystemInfoRt(com.intellij.openapi.util.SystemInfoRt) java.util(java.util) AllIcons(com.intellij.icons.AllIcons) KeymapListener(com.intellij.openapi.keymap.impl.ui.KeymapListener) MavenActionUtil(org.jetbrains.idea.maven.utils.actions.MavenActionUtil) Hyperlink(com.intellij.openapi.keymap.impl.ui.Hyperlink) MavenRunConfigurationType(org.jetbrains.idea.maven.execution.MavenRunConfigurationType) Group(com.intellij.openapi.keymap.impl.ui.Group) SelectMavenGoalDialog(org.jetbrains.idea.maven.navigator.SelectMavenGoalDialog) MavenPluginInfo(org.jetbrains.idea.maven.utils.MavenPluginInfo) ExternalSystemKeymapExtension(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemKeymapExtension) Project(com.intellij.openapi.project.Project) MavenConstants(org.jetbrains.idea.maven.model.MavenConstants) MavenProjectsStructure(org.jetbrains.idea.maven.navigator.MavenProjectsStructure) MavenIcons(icons.MavenIcons) DataManager(com.intellij.ide.DataManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters) MavenAction(org.jetbrains.idea.maven.utils.actions.MavenAction) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenArtifactUtil(org.jetbrains.idea.maven.utils.MavenArtifactUtil) TestOnly(org.jetbrains.annotations.TestOnly) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) MavenPlugin(org.jetbrains.idea.maven.model.MavenPlugin) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) Group(com.intellij.openapi.keymap.impl.ui.Group) SelectMavenGoalDialog(org.jetbrains.idea.maven.navigator.SelectMavenGoalDialog) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Settings(com.intellij.openapi.options.ex.Settings) Pair(com.intellij.openapi.util.Pair) MouseEvent(java.awt.event.MouseEvent) KeymapPanel(com.intellij.openapi.keymap.impl.ui.KeymapPanel) KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) Hyperlink(com.intellij.openapi.keymap.impl.ui.Hyperlink)

Example 43 with MouseEvent

use of java.awt.event.MouseEvent in project intellij-community by JetBrains.

the class StudyBrowserWindow method makeGoButton.

private JButton makeGoButton(@NotNull final String toolTipText, @NotNull final Icon icon, final int direction) {
    final JButton button = new JButton(icon);
    button.setEnabled(false);
    button.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 1) {
                Platform.runLater(() -> myEngine.getHistory().go(direction));
            }
        }
    });
    button.setToolTipText(toolTipText);
    return button;
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter)

Example 44 with MouseEvent

use of java.awt.event.MouseEvent 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;
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter)

Example 45 with MouseEvent

use of java.awt.event.MouseEvent in project intellij-community by JetBrains.

the class IpnbEditablePanel method addRightClickMenu.

@Override
protected void addRightClickMenu() {
    myViewPanel.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e) && e.getClickCount() == 1) {
                final DefaultActionGroup group = new DefaultActionGroup(new IpnbMergeCellAboveAction(), new IpnbMergeCellBelowAction());
                final ListPopup menu = createPopupMenu(group);
                menu.show(RelativePoint.fromScreen(e.getLocationOnScreen()));
            }
        }
    });
    myEditableTextArea.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e) && e.getClickCount() == 1) {
                final DefaultActionGroup group = new DefaultActionGroup(new IpnbSplitCellAction());
                final ListPopup menu = createPopupMenu(group);
                menu.show(RelativePoint.fromScreen(e.getLocationOnScreen()));
            }
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) IpnbMergeCellBelowAction(org.jetbrains.plugins.ipnb.editor.actions.IpnbMergeCellBelowAction) MouseAdapter(java.awt.event.MouseAdapter) ListPopup(com.intellij.openapi.ui.popup.ListPopup) IpnbMergeCellAboveAction(org.jetbrains.plugins.ipnb.editor.actions.IpnbMergeCellAboveAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) IpnbSplitCellAction(org.jetbrains.plugins.ipnb.editor.actions.IpnbSplitCellAction)

Aggregations

MouseEvent (java.awt.event.MouseEvent)407 MouseAdapter (java.awt.event.MouseAdapter)201 JLabel (javax.swing.JLabel)78 JPanel (javax.swing.JPanel)71 ActionEvent (java.awt.event.ActionEvent)60 JScrollPane (javax.swing.JScrollPane)53 ActionListener (java.awt.event.ActionListener)52 Dimension (java.awt.Dimension)51 BorderLayout (java.awt.BorderLayout)46 JButton (javax.swing.JButton)45 Point (java.awt.Point)44 MouseListener (java.awt.event.MouseListener)41 Insets (java.awt.Insets)40 KeyEvent (java.awt.event.KeyEvent)36 JTable (javax.swing.JTable)34 GridBagConstraints (java.awt.GridBagConstraints)33 KeyAdapter (java.awt.event.KeyAdapter)30 JTextField (javax.swing.JTextField)30 GridBagLayout (java.awt.GridBagLayout)27 ListSelectionEvent (javax.swing.event.ListSelectionEvent)26