Search in sources :

Example 36 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)

Example 37 with KeyAdapter

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

the class ImageOrColorPreviewManager method registerListeners.

private void registerListeners(final Editor editor) {
    if (editor.isOneLineMode()) {
        return;
    }
    Project project = editor.getProject();
    if (project == null || project.isDisposed()) {
        return;
    }
    PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    if (psiFile == null || psiFile instanceof PsiCompiledElement || !isSupportedFile(psiFile)) {
        return;
    }
    editor.addEditorMouseMotionListener(this);
    KeyListener keyListener = new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SHIFT && !editor.isOneLineMode()) {
                PointerInfo pointerInfo = MouseInfo.getPointerInfo();
                if (pointerInfo != null) {
                    Point location = pointerInfo.getLocation();
                    SwingUtilities.convertPointFromScreen(location, editor.getContentComponent());
                    alarm.cancelAllRequests();
                    alarm.addRequest(new PreviewRequest(location, editor, true), 100);
                }
            }
        }
    };
    editor.getContentComponent().addKeyListener(keyListener);
    EDITOR_LISTENER_ADDED.set(editor, keyListener);
}
Also used : KeyEvent(java.awt.event.KeyEvent) Project(com.intellij.openapi.project.Project) KeyAdapter(java.awt.event.KeyAdapter) PsiCompiledElement(com.intellij.psi.PsiCompiledElement) PsiFile(com.intellij.psi.PsiFile) KeyListener(java.awt.event.KeyListener)

Example 38 with KeyAdapter

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

the class OptionTreeWithPreviewPanel method createOptionsTree.

protected JTree createOptionsTree() {
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    String groupName = "";
    DefaultMutableTreeNode groupNode = null;
    List<BooleanOptionKey> result = sortOptions(orderByGroup(myKeys));
    for (BooleanOptionKey key : result) {
        String newGroupName = key.groupName;
        if (!newGroupName.equals(groupName) || groupNode == null) {
            groupName = newGroupName;
            groupNode = new DefaultMutableTreeNode(newGroupName);
            rootNode.add(groupNode);
        }
        if (isOptionVisible(key)) {
            groupNode.add(new MyToggleTreeNode(key, key.title));
        }
    }
    DefaultTreeModel model = new DefaultTreeModel(rootNode);
    final Tree optionsTree = new Tree(model);
    new TreeSpeedSearch(optionsTree).setComparator(new SpeedSearchComparator(false));
    TreeUtil.installActions(optionsTree);
    optionsTree.setRootVisible(false);
    UIUtil.setLineStyleAngled(optionsTree);
    optionsTree.setShowsRootHandles(true);
    optionsTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (!optionsTree.isEnabled())
                return;
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                TreePath treePath = optionsTree.getLeadSelectionPath();
                selectCheckbox(treePath);
                e.consume();
            }
        }
    });
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            if (!optionsTree.isEnabled())
                return false;
            TreePath treePath = optionsTree.getPathForLocation(e.getX(), e.getY());
            selectCheckbox(treePath);
            return true;
        }
    }.installOn(optionsTree);
    int row = 0;
    while (row < optionsTree.getRowCount()) {
        optionsTree.expandRow(row);
        row++;
    }
    return optionsTree;
}
Also used : MouseEvent(java.awt.event.MouseEvent) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) Tree(com.intellij.ui.treeStructure.Tree) SpeedSearchComparator(com.intellij.ui.SpeedSearchComparator) ClickListener(com.intellij.ui.ClickListener)

Example 39 with KeyAdapter

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

the class BaseExecuteBeforeRunDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    myRoot = buildNodes();
    final Tree tree = new Tree(myRoot);
    final MyTreeCellRenderer cellRenderer = new MyTreeCellRenderer();
    tree.setCellRenderer(cellRenderer);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setLineStyleAngled();
    TreeUtil.installActions(tree);
    new TreeSpeedSearch(tree);
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            int row = tree.getRowForLocation(e.getX(), e.getY());
            if (row >= 0) {
                Rectangle rowBounds = tree.getRowBounds(row);
                cellRenderer.setBounds(rowBounds);
                Rectangle checkBounds = cellRenderer.myCheckbox.getBounds();
                checkBounds.setLocation(rowBounds.getLocation());
                if (checkBounds.contains(e.getPoint())) {
                    toggleNode(tree, (DefaultMutableTreeNode) tree.getPathForRow(row).getLastPathComponent());
                    e.consume();
                    tree.setSelectionRow(row);
                }
            }
        }
    });
    tree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                TreePath treePath = tree.getLeadSelectionPath();
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
                toggleNode(tree, node);
                e.consume();
            }
        }
    });
    expacndChecked(tree);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(tree);
    scrollPane.setPreferredSize(JBUI.size(400, 400));
    panel.add(scrollPane, BorderLayout.CENTER);
    return panel;
}
Also used : MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) KeyEvent(java.awt.event.KeyEvent) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree)

Example 40 with KeyAdapter

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

the class AbstractProjectViewPSIPane method initTree.

private void initTree() {
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    UIUtil.setLineStyleAngled(myTree);
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    myTree.expandPath(new TreePath(myTree.getModel().getRoot()));
    myTree.setSelectionPath(new TreePath(myTree.getModel().getRoot()));
    EditSourceOnDoubleClickHandler.install(myTree);
    ToolTipManager.sharedInstance().registerComponent(myTree);
    TreeUtil.installActions(myTree);
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            fireTreeChangeListener();
        }
    });
    myTree.getModel().addTreeModelListener(new TreeModelListener() {

        @Override
        public void treeNodesChanged(TreeModelEvent e) {
            fireTreeChangeListener();
        }

        @Override
        public void treeNodesInserted(TreeModelEvent e) {
            fireTreeChangeListener();
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent e) {
            fireTreeChangeListener();
        }

        @Override
        public void treeStructureChanged(TreeModelEvent e) {
            fireTreeChangeListener();
        }
    });
    new MySpeedSearch(myTree);
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                final DefaultMutableTreeNode selectedNode = ((ProjectViewTree) myTree).getSelectedNode();
                if (selectedNode != null && !selectedNode.isLeaf()) {
                    return;
                }
                DataContext dataContext = DataManager.getInstance().getDataContext(myTree);
                OpenSourceUtil.openSourcesFrom(dataContext, ScreenReader.isActive());
            } 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();
                }
            }
        }
    });
    CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionPlaces.PROJECT_VIEW_POPUP);
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeModelListener(javax.swing.event.TreeModelListener) KeyAdapter(java.awt.event.KeyAdapter) PsiCopyPasteManager(com.intellij.ide.PsiCopyPasteManager) TreeSelectionListener(javax.swing.event.TreeSelectionListener) KeyEvent(java.awt.event.KeyEvent) DataContext(com.intellij.openapi.actionSystem.DataContext) TreePath(javax.swing.tree.TreePath) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Aggregations

KeyAdapter (java.awt.event.KeyAdapter)77 KeyEvent (java.awt.event.KeyEvent)75 MouseEvent (java.awt.event.MouseEvent)29 MouseAdapter (java.awt.event.MouseAdapter)19 JPanel (javax.swing.JPanel)16 ActionEvent (java.awt.event.ActionEvent)15 JLabel (javax.swing.JLabel)15 ActionListener (java.awt.event.ActionListener)14 JScrollPane (javax.swing.JScrollPane)13 BorderLayout (java.awt.BorderLayout)12 JButton (javax.swing.JButton)12 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)9 ListSelectionEvent (javax.swing.event.ListSelectionEvent)9 ListSelectionListener (javax.swing.event.ListSelectionListener)9