Search in sources :

Example 1 with PopupHandler

use of com.intellij.ui.PopupHandler in project intellij-community by JetBrains.

the class RepositoryBrowserDialog method createBrowserComponent.

public JComponent createBrowserComponent(final boolean toolWindow) {
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints gc = new GridBagConstraints();
    gc.gridx = 0;
    gc.gridwidth = 1;
    gc.gridy = 0;
    gc.gridheight = 1;
    gc.gridx = 0;
    gc.gridwidth = 2;
    gc.gridy += 1;
    gc.gridheight = 1;
    gc.weightx = 1;
    gc.weighty = 1;
    gc.fill = GridBagConstraints.BOTH;
    gc.anchor = GridBagConstraints.WEST;
    panel.add(getRepositoryBrowser(), gc);
    gc.gridy += 1;
    gc.weighty = 0;
    gc.fill = GridBagConstraints.HORIZONTAL;
    panel.add(new JLabel(), gc);
    Collection<String> urls = SvnApplicationSettings.getInstance().getCheckoutURLs();
    ArrayList<SVNURL> svnURLs = new ArrayList<>();
    for (final String url : urls) {
        try {
            svnURLs.add(SVNURL.parseURIEncoded(url));
        } catch (SVNException e) {
        //
        }
    }
    getRepositoryBrowser().setRepositoryURLs(svnURLs.toArray(new SVNURL[svnURLs.size()]), myShowFiles);
    getRepositoryBrowser().getRepositoryTree().addMouseListener(new PopupHandler() {

        @Override
        public void invokePopup(Component comp, int x, int y) {
            JTree tree = getRepositoryBrowser().getRepositoryTree();
            int row = tree.getRowForLocation(x, y);
            if (row >= 0) {
                tree.setSelectionRow(row);
            }
            JPopupMenu popupMenu = createPopup(toolWindow);
            if (popupMenu != null) {
                popupMenu.show(comp, x, y);
            }
        }
    });
    return panel;
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) SVNURL(org.tmatesoft.svn.core.SVNURL) ArrayList(java.util.ArrayList) SVNException(org.tmatesoft.svn.core.SVNException)

Example 2 with PopupHandler

use of com.intellij.ui.PopupHandler in project intellij-community by JetBrains.

the class CustomizationUtil method installPopupHandler.

public static MouseListener installPopupHandler(JComponent component, @NotNull final String groupId, final String place) {
    if (ApplicationManager.getApplication() == null)
        return new MouseAdapter() {
        };
    PopupHandler popupHandler = new PopupHandler() {

        @Override
        public void invokePopup(Component comp, int x, int y) {
            ActionGroup group = (ActionGroup) CustomActionsSchema.getInstance().getCorrectedAction(groupId);
            final ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(place, group);
            popupMenu.getComponent().show(comp, x, y);
        }
    };
    component.addMouseListener(popupHandler);
    return popupHandler;
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) MouseAdapter(java.awt.event.MouseAdapter)

Example 3 with PopupHandler

use of com.intellij.ui.PopupHandler 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;
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) NameFilteringListModel(com.intellij.ui.speedSearch.NameFilteringListModel) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) NameFilteringListModel(com.intellij.ui.speedSearch.NameFilteringListModel) JBList(com.intellij.ui.components.JBList)

Example 4 with PopupHandler

use of com.intellij.ui.PopupHandler in project intellij-community by JetBrains.

the class TreeView method createPanel.

private JPanel createPanel() {
    createModel();
    myTree = new MyTree();
    myTree.setLineStyleAngled();
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    myTree.updateUI();
    myTree.setLargeModel(true);
    myTree.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                OpenSourceUtil.openSourcesFrom(DataManager.getInstance().getDataContext(myTree), false);
            }
        }
    });
    myTree.addMouseListener(new PopupHandler() {

        public void invokePopup(Component comp, int x, int y) {
            popupInvoked(comp, x, y);
        }
    });
    EditSourceOnDoubleClickHandler.install(myTree);
    myAutoScrollToSourceHandler.install(myTree);
    myOccurenceNavigatorSupport = new OccurenceNavigatorSupport(myTree) {

        protected Navigatable createDescriptorForNode(DefaultMutableTreeNode node) {
            if (!(node instanceof MessageNode)) {
                return null;
            }
            MessageNode messageNode = (MessageNode) node;
            AntBuildMessageView.MessageType type = messageNode.getType();
            if (type != AntBuildMessageView.MessageType.MESSAGE && type != AntBuildMessageView.MessageType.ERROR) {
                return null;
            }
            if (!isValid(messageNode.getFile())) {
                return null;
            }
            return new OpenFileDescriptor(myProject, messageNode.getFile(), messageNode.getOffset());
        }

        @Nullable
        public String getNextOccurenceActionName() {
            return AntBundle.message("ant.execution.next.error.warning.action.name");
        }

        @Nullable
        public String getPreviousOccurenceActionName() {
            return AntBundle.message("ant.execution.previous.error.warning.action.name");
        }
    };
    return JBUI.Panels.simplePanel(MessageTreeRenderer.install(myTree));
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) KeyAdapter(java.awt.event.KeyAdapter) Navigatable(com.intellij.pom.Navigatable) KeyEvent(java.awt.event.KeyEvent) OccurenceNavigatorSupport(com.intellij.ide.OccurenceNavigatorSupport) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with PopupHandler

use of com.intellij.ui.PopupHandler in project intellij-community by JetBrains.

the class ToolWindowContentUi method initMouseListeners.

public static void initMouseListeners(final JComponent c, final ToolWindowContentUi ui) {
    if (c.getClientProperty(ui) != null)
        return;
    final Point[] myLastPoint = new Point[1];
    c.addMouseMotionListener(new MouseMotionAdapter() {

        public void mouseDragged(final MouseEvent e) {
            if (myLastPoint[0] == null)
                return;
            final Window window = SwingUtilities.windowForComponent(c);
            if (window instanceof IdeFrame)
                return;
            final Point windowLocation = window.getLocationOnScreen();
            PointerInfo info = MouseInfo.getPointerInfo();
            if (info == null)
                return;
            final Point newPoint = info.getLocation();
            Point p = myLastPoint[0];
            windowLocation.translate(newPoint.x - p.x, newPoint.y - p.y);
            window.setLocation(windowLocation);
            myLastPoint[0] = newPoint;
        }
    });
    c.addMouseListener(new MouseAdapter() {

        public void mousePressed(final MouseEvent e) {
            PointerInfo info = MouseInfo.getPointerInfo();
            myLastPoint[0] = info != null ? info.getLocation() : e.getLocationOnScreen();
            if (!e.isPopupTrigger()) {
                if (!UIUtil.isCloseClick(e)) {
                    ui.myWindow.fireActivated();
                }
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (!e.isPopupTrigger()) {
                if (UIUtil.isCloseClick(e, MouseEvent.MOUSE_RELEASED)) {
                    ui.processHide(e);
                }
            }
        }
    });
    c.addMouseListener(new PopupHandler() {

        public void invokePopup(final Component comp, final int x, final int y) {
            final Content content = c instanceof BaseLabel ? ((BaseLabel) c).getContent() : null;
            ui.showContextMenu(comp, x, y, ui.myWindow.getPopupGroup(), content);
        }
    });
    c.putClientProperty(ui, Boolean.TRUE);
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) IdeFrame(com.intellij.openapi.wm.IdeFrame) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Aggregations

PopupHandler (com.intellij.ui.PopupHandler)11 Nullable (org.jetbrains.annotations.Nullable)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 KeyAdapter (java.awt.event.KeyAdapter)2 KeyEvent (java.awt.event.KeyEvent)2 MouseAdapter (java.awt.event.MouseAdapter)2 AndroidSourceSet (com.android.tools.idea.npw.project.AndroidSourceSet)1 IconProperty (com.android.tools.idea.ui.properties.swing.IconProperty)1 SelectedItemProperty (com.android.tools.idea.ui.properties.swing.SelectedItemProperty)1 TextProperty (com.android.tools.idea.ui.properties.swing.TextProperty)1 VisibleProperty (com.android.tools.idea.ui.properties.swing.VisibleProperty)1 Validator (com.android.tools.idea.ui.validation.Validator)1 OccurenceNavigatorSupport (com.intellij.ide.OccurenceNavigatorSupport)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 NodeRenderer (com.intellij.ide.util.treeView.NodeRenderer)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1 ActionPopupMenu (com.intellij.openapi.actionSystem.ActionPopupMenu)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1