Search in sources :

Example 26 with KeyAdapter

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

the class ShowUsagesAction method prepareTable.

@NotNull
private Runnable prepareTable(final MyTable table, final Editor editor, final RelativePoint popupPosition, final FindUsagesHandler handler, final int maxUsages, @NotNull final FindUsagesOptions options, final boolean previewMode) {
    SpeedSearchBase<JTable> speedSearch = new MySpeedSearch(table);
    speedSearch.setComparator(new SpeedSearchComparator(false));
    table.setRowHeight(PlatformIcons.CLASS_ICON.getIconHeight() + 2);
    table.setShowGrid(false);
    table.setShowVerticalLines(false);
    table.setShowHorizontalLines(false);
    table.setTableHeader(null);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    table.setIntercellSpacing(new Dimension(0, 0));
    final AtomicReference<List<Object>> selectedUsages = new AtomicReference<>();
    final AtomicBoolean moreUsagesSelected = new AtomicBoolean();
    final AtomicBoolean outsideScopeUsagesSelected = new AtomicBoolean();
    table.getSelectionModel().addListSelectionListener(e -> {
        selectedUsages.set(null);
        outsideScopeUsagesSelected.set(false);
        moreUsagesSelected.set(false);
        List<Object> usages = null;
        for (int i : table.getSelectedRows()) {
            Object value = table.getValueAt(i, 0);
            if (value instanceof UsageNode) {
                Usage usage = ((UsageNode) value).getUsage();
                if (usage == USAGES_OUTSIDE_SCOPE_SEPARATOR) {
                    outsideScopeUsagesSelected.set(true);
                    usages = null;
                    break;
                } else if (usage == MORE_USAGES_SEPARATOR) {
                    moreUsagesSelected.set(true);
                    usages = null;
                    break;
                } else {
                    if (usages == null)
                        usages = new ArrayList<>();
                    usages.add(usage instanceof UsageInfo2UsageAdapter ? ((UsageInfo2UsageAdapter) usage).getUsageInfo().copy() : usage);
                }
            }
        }
        selectedUsages.set(usages);
    });
    final Runnable itemChosenCallback = () -> {
        if (moreUsagesSelected.get()) {
            appendMoreUsages(editor, popupPosition, handler, maxUsages, options);
            return;
        }
        if (outsideScopeUsagesSelected.get()) {
            options.searchScope = GlobalSearchScope.projectScope(handler.getProject());
            showElementUsages(editor, popupPosition, handler, maxUsages, options);
            return;
        }
        List<Object> usages = selectedUsages.get();
        if (usages != null) {
            for (Object usage : usages) {
                if (usage instanceof UsageInfo) {
                    UsageViewUtil.navigateTo((UsageInfo) usage, true);
                } else if (usage instanceof Navigatable) {
                    ((Navigatable) usage).navigate(true);
                }
            }
        }
    };
    if (previewMode) {
        table.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseReleased(MouseEvent e) {
                if (UIUtil.isActionClick(e, MouseEvent.MOUSE_RELEASED) && !UIUtil.isSelectionButtonDown(e) && !e.isConsumed()) {
                    itemChosenCallback.run();
                }
            }
        });
        table.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                    itemChosenCallback.run();
                }
            }
        });
    }
    return itemChosenCallback;
}
Also used : MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) AtomicReference(java.util.concurrent.atomic.AtomicReference) RelativePoint(com.intellij.ui.awt.RelativePoint) Navigatable(com.intellij.pom.Navigatable) KeyEvent(java.awt.event.KeyEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) List(java.util.List) UsageInfo(com.intellij.usageView.UsageInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with KeyAdapter

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

the class AbstractTreeClassChooserDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
    myTree = new Tree(model);
    ProjectAbstractTreeStructureBase treeStructure = new AbstractProjectTreeStructure(myProject) {

        @Override
        public boolean isFlattenPackages() {
            return false;
        }

        @Override
        public boolean isShowMembers() {
            return myIsShowMembers;
        }

        @Override
        public boolean isHideEmptyMiddlePackages() {
            return true;
        }

        @Override
        public boolean isAbbreviatePackageNames() {
            return false;
        }

        @Override
        public boolean isShowLibraryContents() {
            return myIsShowLibraryContents;
        }

        @Override
        public boolean isShowModules() {
            return false;
        }
    };
    myBuilder = new ProjectTreeBuilder(myProject, myTree, model, AlphaComparator.INSTANCE, treeStructure);
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    myTree.expandRow(0);
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    myTree.setCellRenderer(new NodeRenderer());
    UIUtil.setLineStyleAngled(myTree);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    scrollPane.setPreferredSize(JBUI.size(500, 300));
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                doOKAction();
            }
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent event) {
            TreePath path = myTree.getPathForLocation(event.getX(), event.getY());
            if (path != null && myTree.isPathSelected(path)) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(myTree);
    myTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            handleSelectionChanged();
        }
    });
    new TreeSpeedSearch(myTree);
    myTabbedPane = new TabbedPaneWrapper(getDisposable());
    final JPanel dummyPanel = new JPanel(new BorderLayout());
    String name = null;
    /*
    if (myInitialClass != null) {
      name = myInitialClass.getName();
    }
*/
    myGotoByNamePanel = new ChooseByNamePanel(myProject, createChooseByNameModel(), name, myScope.isSearchInLibraries(), getContext()) {

        @Override
        protected void showTextFieldPanel() {
        }

        @Override
        protected void close(boolean isOk) {
            super.close(isOk);
            if (isOk) {
                doOKAction();
            } else {
                doCancelAction();
            }
        }

        @NotNull
        @Override
        protected Set<Object> filter(@NotNull Set<Object> elements) {
            return doFilter(elements);
        }

        @Override
        protected void initUI(ChooseByNamePopupComponent.Callback callback, ModalityState modalityState, boolean allowMultipleSelection) {
            super.initUI(callback, modalityState, allowMultipleSelection);
            dummyPanel.add(myGotoByNamePanel.getPanel(), BorderLayout.CENTER);
            IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                IdeFocusManager.getGlobalInstance().requestFocus(IdeFocusTraversalPolicy.getPreferredFocusedComponent(myGotoByNamePanel.getPanel()), true);
            });
        }

        @Override
        protected void showList() {
            super.showList();
            if (myInitialClass != null && myList.getModel().getSize() > 0) {
                myList.setSelectedValue(myInitialClass, true);
                myInitialClass = null;
            }
        }

        @Override
        protected void chosenElementMightChange() {
            handleSelectionChanged();
        }
    };
    Disposer.register(myDisposable, myGotoByNamePanel);
    myTabbedPane.addTab(IdeBundle.message("tab.chooser.search.by.name"), dummyPanel);
    myTabbedPane.addTab(IdeBundle.message("tab.chooser.project"), scrollPane);
    myGotoByNamePanel.invoke(new MyCallback(), getModalityState(), false);
    myTabbedPane.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            handleSelectionChanged();
        }
    });
    return myTabbedPane.getComponent();
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DoubleClickListener(com.intellij.ui.DoubleClickListener) KeyAdapter(java.awt.event.KeyAdapter) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) TreeSelectionListener(javax.swing.event.TreeSelectionListener) NotNull(org.jetbrains.annotations.NotNull) AbstractProjectTreeStructure(com.intellij.ide.projectView.impl.AbstractProjectTreeStructure) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) KeyEvent(java.awt.event.KeyEvent) ProjectAbstractTreeStructureBase(com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase) Tree(com.intellij.ui.treeStructure.Tree) ChangeListener(javax.swing.event.ChangeListener) MouseEvent(java.awt.event.MouseEvent) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) BaseProjectTreeBuilder(com.intellij.ide.projectView.BaseProjectTreeBuilder) ProjectTreeBuilder(com.intellij.ide.projectView.impl.ProjectTreeBuilder) ModalityState(com.intellij.openapi.application.ModalityState) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 28 with KeyAdapter

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

the class ScopeTreeViewPanel method initTree.

private void initTree() {
    HintUpdateSupply.installDataContextHintUpdateSupply(myTree);
    myTree.setCellRenderer(new MyTreeCellRenderer());
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    UIUtil.setLineStyleAngled(myTree);
    TreeUtil.installActions(myTree);
    EditSourceOnDoubleClickHandler.install(myTree);
    new TreeSpeedSearch(myTree);
    myCopyPasteDelegator = new CopyPasteDelegator(myProject, this) {

        @Override
        @NotNull
        protected PsiElement[] getSelectedElements() {
            return getSelectedPsiElements();
        }
    };
    myTreeExpansionMonitor = PackageTreeExpansionMonitor.install(myTree, myProject);
    final ScopeTreeStructureExpander[] extensions = Extensions.getExtensions(ScopeTreeStructureExpander.EP_NAME, myProject);
    for (ScopeTreeStructureExpander expander : extensions) {
        myTree.addTreeWillExpandListener(expander);
    }
    if (extensions.length == 0) {
        myTree.addTreeWillExpandListener(new SortingExpandListener());
    }
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                final Object component = myTree.getLastSelectedPathComponent();
                if (component instanceof DefaultMutableTreeNode) {
                    final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) component;
                    if (selectedNode.isLeaf()) {
                        OpenSourceUtil.openSourcesFrom(DataManager.getInstance().getDataContext(myTree), false);
                    }
                }
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with KeyAdapter

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

the class StructureViewComponent method addTreeKeyListener.

private void addTreeKeyListener() {
    getTree().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                DataContext dataContext = DataManager.getInstance().getDataContext(getTree());
                OpenSourceUtil.openSourcesFrom(dataContext, false);
            } else if (KeyEvent.VK_ESCAPE == e.getKeyCode()) {
                if (e.isConsumed()) {
                    return;
                }
                PsiCopyPasteManager copyPasteManager = PsiCopyPasteManager.getInstance();
                boolean[] isCopied = new boolean[1];
                if (copyPasteManager.getElements(isCopied) != null && !isCopied[0]) {
                    copyPasteManager.clear();
                    e.consume();
                }
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyAdapter(java.awt.event.KeyAdapter) PsiCopyPasteManager(com.intellij.ide.PsiCopyPasteManager)

Example 30 with KeyAdapter

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

the class LayoutProjectCodeDialog method initFileTypeFilter.

private void initFileTypeFilter() {
    FindDialog.initFileFilter(myFileFilter, myEnableFileNameFilterCb);
    myEnableFileNameFilterCb.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateMaskWarning();
        }
    });
    myFileFilter.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            updateMaskWarning();
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter)

Aggregations

KeyAdapter (java.awt.event.KeyAdapter)70 KeyEvent (java.awt.event.KeyEvent)70 MouseEvent (java.awt.event.MouseEvent)26 MouseAdapter (java.awt.event.MouseAdapter)16 JPanel (javax.swing.JPanel)15 ActionEvent (java.awt.event.ActionEvent)14 JLabel (javax.swing.JLabel)14 ActionListener (java.awt.event.ActionListener)13 JButton (javax.swing.JButton)12 JScrollPane (javax.swing.JScrollPane)12 BorderLayout (java.awt.BorderLayout)11 JTextField (javax.swing.JTextField)11 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 TreePath (javax.swing.tree.TreePath)11 NotNull (org.jetbrains.annotations.NotNull)11 FlowLayout (java.awt.FlowLayout)10 Tree (com.intellij.ui.treeStructure.Tree)9 Dimension (java.awt.Dimension)8 ListSelectionEvent (javax.swing.event.ListSelectionEvent)7 ListSelectionListener (javax.swing.event.ListSelectionListener)7