Search in sources :

Example 36 with KeyEvent

use of java.awt.event.KeyEvent 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 37 with KeyEvent

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

the class TargetChooserDialog method createCenterPanel.

@Nullable
protected JComponent createCenterPanel() {
    myTree = initTree();
    myTree.addKeyListener(new KeyAdapter() {

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

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            if (mySelectedTarget != null) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(myTree);
    return JBUI.Panels.simplePanel(ScrollPaneFactory.createScrollPane(myTree));
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) Nullable(org.jetbrains.annotations.Nullable)

Example 38 with KeyEvent

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

the class VcsStructureChooser method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myTree = new Tree();
    myTree.setBorder(BORDER);
    myTree.setShowsRootHandles(true);
    myTree.setRootVisible(false);
    myTree.setExpandableItemsEnabled(false);
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, true, false, true) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            if (!super.isFileVisible(file, showHiddenFiles))
                return false;
            if (myRoots.contains(file))
                return false;
            ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
            return !changeListManager.isIgnoredFile(file) && !changeListManager.isUnversioned(file);
        }
    };
    descriptor.withRoots(new ArrayList<>(myRoots)).withShowHiddenFiles(true).withHideIgnored(true);
    final MyCheckboxTreeCellRenderer cellRenderer = new MyCheckboxTreeCellRenderer(mySelectionManager, myModulesSet, myProject, myTree, myRoots);
    FileSystemTreeImpl fileSystemTree = new FileSystemTreeImpl(myProject, descriptor, myTree, cellRenderer, null, o -> {
        DefaultMutableTreeNode lastPathComponent = ((DefaultMutableTreeNode) o.getLastPathComponent());
        Object uo = lastPathComponent.getUserObject();
        if (uo instanceof FileNodeDescriptor) {
            VirtualFile file = ((FileNodeDescriptor) uo).getElement().getFile();
            String module = myModulesSet.get(file);
            if (module != null)
                return module;
            return file == null ? "" : file.getName();
        }
        return o.toString();
    });
    fileSystemTree.getTreeBuilder().getUi().setNodeDescriptorComparator((o1, o2) -> {
        if (o1 instanceof FileNodeDescriptor && o2 instanceof FileNodeDescriptor) {
            VirtualFile f1 = ((FileNodeDescriptor) o1).getElement().getFile();
            VirtualFile f2 = ((FileNodeDescriptor) o2).getElement().getFile();
            boolean isDir1 = f1.isDirectory();
            boolean isDir2 = f2.isDirectory();
            if (isDir1 != isDir2)
                return isDir1 ? -1 : 1;
            return f1.getPath().compareToIgnoreCase(f2.getPath());
        }
        return o1.getIndex() - o2.getIndex();
    });
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            int row = myTree.getRowForLocation(e.getX(), e.getY());
            if (row < 0)
                return false;
            Object o = myTree.getPathForRow(row).getLastPathComponent();
            if (getTreeRoot() == o || getFile(o) == null)
                return false;
            Rectangle rowBounds = myTree.getRowBounds(row);
            cellRenderer.setBounds(rowBounds);
            Rectangle checkBounds = cellRenderer.myCheckbox.getBounds();
            checkBounds.setLocation(rowBounds.getLocation());
            if (checkBounds.height == 0)
                checkBounds.height = rowBounds.height;
            if (checkBounds.contains(e.getPoint())) {
                mySelectionManager.toggleSelection((DefaultMutableTreeNode) o);
                myTree.revalidate();
                myTree.repaint();
            }
            return true;
        }
    }.installOn(myTree);
    myTree.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                TreePath[] paths = myTree.getSelectionPaths();
                if (paths == null)
                    return;
                for (TreePath path : paths) {
                    if (path == null)
                        continue;
                    Object o = path.getLastPathComponent();
                    if (getTreeRoot() == o || getFile(o) == null)
                        return;
                    mySelectionManager.toggleSelection((DefaultMutableTreeNode) o);
                }
                myTree.revalidate();
                myTree.repaint();
                e.consume();
            }
        }
    });
    JBPanel panel = new JBPanel(new BorderLayout());
    panel.add(new JBScrollPane(fileSystemTree.getTree()), BorderLayout.CENTER);
    final JLabel selectedLabel = new JLabel("");
    selectedLabel.setBorder(JBUI.Borders.empty(2, 0));
    panel.add(selectedLabel, BorderLayout.SOUTH);
    mySelectionManager.setSelectionChangeListener(new PlusMinus<VirtualFile>() {

        @Override
        public void plus(VirtualFile virtualFile) {
            mySelectedFiles.add(virtualFile);
            recalculateErrorText();
        }

        private void recalculateErrorText() {
            checkEmpty();
            if (mySelectionManager.canAddSelection()) {
                selectedLabel.setText("");
            } else {
                selectedLabel.setText(CAN_NOT_ADD_TEXT);
            }
            selectedLabel.revalidate();
        }

        @Override
        public void minus(VirtualFile virtualFile) {
            mySelectedFiles.remove(virtualFile);
            recalculateErrorText();
        }
    });
    panel.setPreferredSize(JBUI.size(400, 300));
    return panel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) Tree(com.intellij.ui.treeStructure.Tree) MouseEvent(java.awt.event.MouseEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileSystemTreeImpl(com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl) FileNodeDescriptor(com.intellij.openapi.fileChooser.ex.FileNodeDescriptor) JBPanel(com.intellij.ui.components.JBPanel) TreePath(javax.swing.tree.TreePath) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 39 with KeyEvent

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

the class DiffWalkerAction method update.

public void update(AnActionEvent event) {
    FocusDiffSide side = DiffUtil.getFocusDiffSide(event.getDataContext());
    Presentation presentation = event.getPresentation();
    if (side == null) {
        presentation.setEnabled(false);
    } else {
        presentation.setEnabled(getLineNumberToGo(side) >= 0 || event.getInputEvent() instanceof KeyEvent);
    }
}
Also used : KeyEvent(java.awt.event.KeyEvent) Presentation(com.intellij.openapi.actionSystem.Presentation) FocusDiffSide(com.intellij.openapi.diff.impl.util.FocusDiffSide)

Example 40 with KeyEvent

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

the class FileEditorManagerImpl method isOpenInNewWindow.

private static boolean isOpenInNewWindow() {
    AWTEvent event = IdeEventQueue.getInstance().getTrueCurrentEvent();
    // Shift was used while clicking
    if (event instanceof MouseEvent && ((MouseEvent) event).isShiftDown() && (event.getID() == MouseEvent.MOUSE_CLICKED || event.getID() == MouseEvent.MOUSE_PRESSED || event.getID() == MouseEvent.MOUSE_RELEASED)) {
        return true;
    }
    if (event instanceof KeyEvent) {
        KeyEvent ke = (KeyEvent) event;
        Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
        String[] ids = keymap.getActionIds(KeyStroke.getKeyStroke(ke.getKeyCode(), ke.getModifiers()));
        return Arrays.asList(ids).contains("OpenElementInNewWindow");
    }
    return false;
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) Keymap(com.intellij.openapi.keymap.Keymap)

Aggregations

KeyEvent (java.awt.event.KeyEvent)144 KeyAdapter (java.awt.event.KeyAdapter)74 MouseEvent (java.awt.event.MouseEvent)34 ActionEvent (java.awt.event.ActionEvent)24 KeyListener (java.awt.event.KeyListener)22 ActionListener (java.awt.event.ActionListener)20 MouseAdapter (java.awt.event.MouseAdapter)20 JPanel (javax.swing.JPanel)19 JLabel (javax.swing.JLabel)18 JTextField (javax.swing.JTextField)15 BorderLayout (java.awt.BorderLayout)14 JButton (javax.swing.JButton)14 JScrollPane (javax.swing.JScrollPane)14 NotNull (org.jetbrains.annotations.NotNull)12 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 TreePath (javax.swing.tree.TreePath)11 FlowLayout (java.awt.FlowLayout)10 Tree (com.intellij.ui.treeStructure.Tree)9 Dimension (java.awt.Dimension)9 FocusEvent (java.awt.event.FocusEvent)9