Search in sources :

Example 61 with KeyAdapter

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

the class MacColorPipette method getOrCreatePickerDialog.

@NotNull
@Override
protected Dialog getOrCreatePickerDialog() {
    Dialog pickerDialog = getPickerDialog();
    if (pickerDialog == null) {
        pickerDialog = super.getOrCreatePickerDialog();
        pickerDialog.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent event) {
                super.keyPressed(event);
                int diff = BitUtil.isSet(event.getModifiers(), Event.SHIFT_MASK) ? 10 : 1;
                Point location = updateLocation();
                if (myRobot != null && location != null) {
                    switch(event.getKeyCode()) {
                        case KeyEvent.VK_DOWN:
                            myRobot.mouseMove(location.x, location.y + diff);
                            break;
                        case KeyEvent.VK_UP:
                            myRobot.mouseMove(location.x, location.y - diff);
                            break;
                        case KeyEvent.VK_LEFT:
                            myRobot.mouseMove(location.x - diff, location.y);
                            break;
                        case KeyEvent.VK_RIGHT:
                            myRobot.mouseMove(location.x + diff, location.y);
                            break;
                    }
                    updateLocation();
                }
            }
        });
        final JLabel label = new JLabel() {

            @Override
            public void paint(Graphics g) {
                applyRenderingHints(g);
                Dialog pickerDialog = getPickerDialog();
                if (pickerDialog != null && pickerDialog.isShowing()) {
                    Point mouseLoc = updateLocation();
                    if (mouseLoc == null)
                        return;
                    //final int pixels = UIUtil.isRetina(graphics2d) ? PIXELS / 2 + 1 : PIXELS;
                    int left = PIXELS / 2 + 1;
                    Rectangle captureRectangle = new Rectangle(mouseLoc.x - left, mouseLoc.y - left, PIXELS, PIXELS);
                    BufferedImage captureScreen = captureScreen(pickerDialog, captureRectangle);
                    if (captureScreen == null || captureScreen.getWidth() < PIXELS || captureRectangle.getHeight() < PIXELS) {
                        cancelPipette();
                        return;
                    }
                    //noinspection UseJBColor
                    Color newColor = new Color(captureScreen.getRGB(captureRectangle.width / 2, captureRectangle.height / 2));
                    Graphics2D graphics2d = ((Graphics2D) g);
                    Point offset = new Point(10, 10);
                    graphics2d.setComposite(AlphaComposite.Clear);
                    graphics2d.fillRect(0, 0, getWidth(), getHeight());
                    graphics2d.setComposite(AlphaComposite.Src);
                    graphics2d.clip(new Ellipse2D.Double(offset.x, offset.y, SIZE, SIZE));
                    graphics2d.drawImage(captureScreen, offset.x, offset.y, SIZE, SIZE, this);
                    // paint magnifier
                    graphics2d.setComposite(AlphaComposite.SrcOver);
                    drawPixelGrid(graphics2d, offset);
                    drawCenterPixel(graphics2d, offset, newColor);
                    drawCurrentColorRectangle(graphics2d, offset, newColor);
                    graphics2d.setClip(0, 0, getWidth(), getHeight());
                    drawMagnifierBorder(newColor, graphics2d, offset);
                    pickerDialog.repaint();
                    if (!newColor.equals(getColor())) {
                        setColor(newColor);
                        notifyListener(newColor, 300);
                    }
                }
            }
        };
        pickerDialog.add(label);
        pickerDialog.setSize(DIALOG_SIZE, DIALOG_SIZE);
        pickerDialog.setBackground(myTransparentColor);
        BufferedImage emptyImage = UIUtil.createImage(pickerDialog, 1, 1, Transparency.TRANSLUCENT);
        pickerDialog.setCursor(myParent.getToolkit().createCustomCursor(emptyImage, new Point(0, 0), "ColorPicker"));
    }
    return pickerDialog;
}
Also used : KeyAdapter(java.awt.event.KeyAdapter) BufferedImage(java.awt.image.BufferedImage) Ellipse2D(java.awt.geom.Ellipse2D) KeyEvent(java.awt.event.KeyEvent) NotNull(org.jetbrains.annotations.NotNull)

Example 62 with KeyAdapter

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

the class AddMultipleFilesOptionsDialog method createTree.

private void createTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    for (AddedFileInfo myRoot : myRoots) {
        root.add(myRoot);
    }
    myModel = new ListTreeTableModelOnColumns(root, COLUMNS);
    myTreeTable = new TreeTableView(myModel);
    int comboHeight = new JComboBox().getPreferredSize().height;
    int checkBoxHeight = new JCheckBox().getPreferredSize().height;
    myTreeTable.setMinRowHeight(Math.max(comboHeight, checkBoxHeight) + 2);
    myTreeTable.setRootVisible(false);
    final JTableHeader tableHeader = myTreeTable.getTableHeader();
    tableHeader.setReorderingAllowed(false);
    tableHeader.setResizingAllowed(false);
    final TreeTableTree tree = myTreeTable.getTree();
    myTreeTable.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            final int keyCode = e.getKeyCode();
            if (keyCode == KeyEvent.VK_SPACE) {
                final int selectedColumn = myTreeTable.getSelectedColumn();
                if (selectedColumn == 0) {
                    return;
                }
                final int[] selectedRows = myTreeTable.getSelectedRows();
                if (selectedRows.length == 0) {
                    return;
                }
                final boolean included = !((AddedFileInfo) myTreeTable.getValueAt(selectedRows[0], 1)).included();
                for (int selectedRow : selectedRows) {
                    final AddedFileInfo addedFileInfo = (AddedFileInfo) myTreeTable.getValueAt(selectedRow, 1);
                    addedFileInfo.setIncluded(included);
                    myModel.nodeChanged(addedFileInfo);
                }
            }
        }
    });
    tree.setCellRenderer(new AddedFileCellRenderer());
    TreeUtil.installActions(tree);
}
Also used : ListTreeTableModelOnColumns(com.intellij.ui.treeStructure.treetable.ListTreeTableModelOnColumns) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) JTableHeader(javax.swing.table.JTableHeader) TreeTableView(com.intellij.ui.dualView.TreeTableView) KeyEvent(java.awt.event.KeyEvent) TreeTableTree(com.intellij.ui.treeStructure.treetable.TreeTableTree) AddedFileInfo(com.intellij.cvsSupport2.cvsoperations.cvsAdd.AddedFileInfo)

Example 63 with KeyAdapter

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

the class LanguageConsoleImpl method setupComponents.

private void setupComponents() {
    myHelper.setupEditor(myConsoleEditor);
    myHelper.setupEditor(myHistoryViewer);
    myHistoryViewer.getComponent().setMinimumSize(JBUI.emptySize());
    myHistoryViewer.getComponent().setPreferredSize(JBUI.emptySize());
    myHistoryViewer.setCaretEnabled(false);
    myConsoleEditor.setContextMenuGroupId(IdeActions.GROUP_CONSOLE_EDITOR_POPUP);
    myConsoleEditor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(getVirtualFile(), myConsoleEditor.getColorsScheme(), getProject()));
    setHistoryScrollBarVisible(false);
    myHistoryViewer.getContentComponent().addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent event) {
            if (isConsoleEditorEnabled() && UIUtil.isReallyTypedEvent(event)) {
                IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                    IdeFocusManager.getGlobalInstance().requestFocus(myConsoleEditor.getContentComponent(), true);
                });
                myConsoleEditor.processKeyTyped(event);
            }
        }
    });
    EmptyAction.registerActionShortcuts(myHistoryViewer.getComponent(), myConsoleEditor.getComponent());
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyAdapter(java.awt.event.KeyAdapter)

Example 64 with KeyAdapter

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

the class CopiesPanel method setFocusableForLinks.

@SuppressWarnings("MethodMayBeStatic")
private void setFocusableForLinks(final LinkLabel label) {
    final Border border = new DottedBorder(new Insets(1, 2, 1, 1), JBColor.BLACK);
    label.setFocusable(true);
    label.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            super.focusGained(e);
            label.setBorder(border);
        }

        @Override
        public void focusLost(FocusEvent e) {
            super.focusLost(e);
            label.setBorder(null);
        }
    });
    label.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                label.doClick();
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) FocusAdapter(java.awt.event.FocusAdapter) KeyAdapter(java.awt.event.KeyAdapter) DottedBorder(com.intellij.ui.DottedBorder) Border(javax.swing.border.Border) DottedBorder(com.intellij.ui.DottedBorder) FocusEvent(java.awt.event.FocusEvent)

Example 65 with KeyAdapter

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

the class ResourceBundleEditor method recreateEditorsPanel.

void recreateEditorsPanel() {
    if (!myProject.isOpen() || myDisposed)
        return;
    myValuesPanel.removeAll();
    myValuesPanel.setLayout(new CardLayout());
    JPanel valuesPanelComponent = new MyJPanel(new GridBagLayout());
    myValuesPanel.add(new JBScrollPane(valuesPanelComponent) {

        @Override
        public void updateUI() {
            super.updateUI();
            getViewport().setBackground(UIUtil.getPanelBackground());
        }
    }, VALUES);
    myValuesPanel.add(myNoPropertySelectedPanel, NO_PROPERTY_SELECTED);
    final List<PropertiesFile> propertiesFiles = myResourceBundle.getPropertiesFiles();
    GridBagConstraints gc = new GridBagConstraints(0, 0, 0, 0, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, JBUI.insets(5), 0, 0);
    releaseAllEditors();
    myTitledPanels.clear();
    int y = 0;
    Editor previousEditor = null;
    Editor firstEditor = null;
    for (final PropertiesFile propertiesFile : propertiesFiles) {
        final EditorEx editor = createEditor();
        final Editor oldEditor = myEditors.put(propertiesFile.getVirtualFile(), editor);
        if (firstEditor == null) {
            firstEditor = editor;
        }
        if (previousEditor != null) {
            editor.putUserData(ChooseSubsequentPropertyValueEditorAction.PREV_EDITOR_KEY, previousEditor);
            previousEditor.putUserData(ChooseSubsequentPropertyValueEditorAction.NEXT_EDITOR_KEY, editor);
        }
        previousEditor = editor;
        if (oldEditor != null) {
            EditorFactory.getInstance().releaseEditor(oldEditor);
        }
        editor.setViewer(!propertiesFile.getVirtualFile().isWritable());
        editor.getContentComponent().addKeyListener(new KeyAdapter() {

            @Override
            public void keyTyped(KeyEvent e) {
                if (editor.isViewer()) {
                    editor.setViewer(ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(propertiesFile.getVirtualFile()).hasReadonlyFiles());
                }
            }
        });
        editor.addFocusListener(new FocusChangeListener() {

            @Override
            public void focusGained(final Editor editor) {
                mySelectedEditor = editor;
            }

            @Override
            public void focusLost(final Editor editor) {
                if (!editor.isViewer() && propertiesFile.getContainingFile().isValid()) {
                    writeEditorPropertyValue(null, editor, propertiesFile.getVirtualFile());
                    myVfsListener.flush();
                }
            }
        });
        gc.gridx = 0;
        gc.gridy = y++;
        gc.gridheight = 1;
        gc.gridwidth = GridBagConstraints.REMAINDER;
        gc.weightx = 1;
        gc.weighty = 1;
        gc.anchor = GridBagConstraints.CENTER;
        String title = propertiesFile.getName();
        title += PropertiesUtil.getPresentableLocale(propertiesFile.getLocale());
        JComponent comp = new JPanel(new BorderLayout()) {

            @Override
            public Dimension getPreferredSize() {
                Insets insets = getBorder().getBorderInsets(this);
                return new Dimension(100, editor.getLineHeight() * 4 + insets.top + insets.bottom);
            }
        };
        comp.add(editor.getComponent(), BorderLayout.CENTER);
        comp.setBorder(IdeBorderFactory.createTitledBorder(title, false));
        myTitledPanels.put(propertiesFile.getVirtualFile(), (JPanel) comp);
        valuesPanelComponent.add(comp, gc);
    }
    if (previousEditor != null) {
        previousEditor.putUserData(ChooseSubsequentPropertyValueEditorAction.NEXT_EDITOR_KEY, firstEditor);
        firstEditor.putUserData(ChooseSubsequentPropertyValueEditorAction.PREV_EDITOR_KEY, previousEditor);
    }
    gc.gridx = 0;
    gc.gridy = y;
    gc.gridheight = GridBagConstraints.REMAINDER;
    gc.gridwidth = GridBagConstraints.REMAINDER;
    gc.weightx = 10;
    gc.weighty = 1;
    valuesPanelComponent.add(new JPanel(), gc);
    selectionChanged();
    myValuesPanel.repaint();
    updateEditorsFromProperties(true);
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) JBScrollPane(com.intellij.ui.components.JBScrollPane) FocusChangeListener(com.intellij.openapi.editor.ex.FocusChangeListener)

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