Search in sources :

Example 56 with MouseEvent

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

the class IdePopupManager method dispatch.

public boolean dispatch(@NotNull final AWTEvent e) {
    LOG.assertTrue(isPopupActive());
    if (e.getID() == WindowEvent.WINDOW_LOST_FOCUS) {
        ApplicationManager.getApplication().invokeLater(() -> {
            if (!isPopupActive())
                return;
            boolean shouldCloseAllPopup = false;
            Window focused = ((WindowEvent) e).getOppositeWindow();
            if (focused == null) {
                focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
            }
            if (focused == null) {
                shouldCloseAllPopup = true;
            }
            Component ultimateParentForFocusedComponent = UIUtil.findUltimateParent(focused);
            Window sourceWindow = ((WindowEvent) e).getWindow();
            Component ultimateParentForEventWindow = UIUtil.findUltimateParent(sourceWindow);
            if (!shouldCloseAllPopup && ultimateParentForEventWindow == null || ultimateParentForFocusedComponent == null) {
                shouldCloseAllPopup = true;
            }
            if (!shouldCloseAllPopup && ultimateParentForEventWindow instanceof IdeFrameEx) {
                IdeFrameEx ultimateParentWindowForEvent = ((IdeFrameEx) ultimateParentForEventWindow);
                if (ultimateParentWindowForEvent.isInFullScreen() && !ultimateParentForFocusedComponent.equals(ultimateParentForEventWindow)) {
                    shouldCloseAllPopup = true;
                }
            }
            if (!shouldCloseAllPopup && isPopupWindow(sourceWindow) && sourceWindow.getParent() == ((WindowEvent) e).getOppositeWindow()) {
                shouldCloseAllPopup = true;
            }
            if (shouldCloseAllPopup) {
                closeAllPopups();
            }
        });
    }
    if (e instanceof KeyEvent || e instanceof MouseEvent) {
        for (int i = myDispatchStack.size() - 1; (i >= 0 && i < myDispatchStack.size()); i--) {
            final boolean dispatched = myDispatchStack.get(i).dispatch(e);
            if (dispatched)
                return true;
        }
    }
    return false;
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) WindowEvent(java.awt.event.WindowEvent) IdeFrameEx(com.intellij.openapi.wm.ex.IdeFrameEx)

Example 57 with MouseEvent

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

the class ChooseElementsDialog method initializeDialog.

private void initializeDialog(final List<? extends T> items, final String title, boolean sort) {
    setTitle(title);
    myChooser = new ElementsChooser<T>(false) {

        protected String getItemText(@NotNull final T item) {
            return ChooseElementsDialog.this.getItemText(item);
        }
    };
    myChooser.setColorUnmarkedElements(false);
    List<? extends T> elements = new ArrayList<T>(items);
    if (sort) {
        Collections.sort(elements, new Comparator<T>() {

            public int compare(final T o1, final T o2) {
                return getItemText(o1).compareToIgnoreCase(getItemText(o2));
            }
        });
    }
    setElements(elements, elements.size() > 0 ? elements.subList(0, 1) : Collections.<T>emptyList());
    myChooser.getComponent().registerKeyboardAction(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            doOKAction();
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            doOKAction();
            return true;
        }
    }.installOn(myChooser.getComponent());
    init();
}
Also used : MouseEvent(java.awt.event.MouseEvent) ActionListener(java.awt.event.ActionListener) DoubleClickListener(com.intellij.ui.DoubleClickListener) ActionEvent(java.awt.event.ActionEvent)

Example 58 with MouseEvent

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

the class EventLogConsole method createLogEditor.

private Editor createLogEditor() {
    Project project = myProjectModel.getProject();
    final EditorEx editor = ConsoleViewUtil.setupConsoleEditor(project, false, false);
    editor.getSettings().setWhitespacesShown(false);
    installNotificationsFont(editor);
    myProjectModel.getProject().getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerAdapter() {

        @Override
        public void projectClosed(Project project) {
            if (project == myProjectModel.getProject()) {
                EditorFactory.getInstance().releaseEditor(editor);
            }
        }
    });
    ((EditorMarkupModel) editor.getMarkupModel()).setErrorStripeVisible(true);
    final ClearLogAction clearLog = new ClearLogAction(this);
    clearLog.registerCustomShortcutSet(ActionManager.getInstance().getAction(IdeActions.CONSOLE_CLEAR_ALL).getShortcutSet(), editor.getContentComponent());
    // disabling default context menu
    editor.setContextMenuGroupId(null);
    editor.addEditorMouseListener(new EditorPopupHandler() {

        public void invokePopup(final EditorMouseEvent event) {
            final ActionManager actionManager = ActionManager.getInstance();
            DefaultActionGroup actions = createPopupActions(actionManager, clearLog, editor, event);
            final ActionPopupMenu menu = actionManager.createActionPopupMenu(ActionPlaces.EDITOR_POPUP, actions);
            final MouseEvent mouseEvent = event.getMouseEvent();
            menu.getComponent().show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
        }
    });
    return editor;
}
Also used : Project(com.intellij.openapi.project.Project) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) MouseEvent(java.awt.event.MouseEvent) EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) ProjectManagerAdapter(com.intellij.openapi.project.ProjectManagerAdapter) EditorPopupHandler(com.intellij.util.EditorPopupHandler)

Example 59 with MouseEvent

use of java.awt.event.MouseEvent 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)

Example 60 with MouseEvent

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

the class ShowUIDefaultsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final UIDefaults defaults = UIManager.getDefaults();
    Enumeration keys = defaults.keys();
    final Object[][] data = new Object[defaults.size()][2];
    int i = 0;
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        data[i][0] = key;
        data[i][1] = defaults.get(key);
        i++;
    }
    Arrays.sort(data, (o1, o2) -> StringUtil.naturalCompare(o1[0].toString(), o2[0].toString()));
    final Project project = getEventProject(e);
    new DialogWrapper(project) {

        {
            setTitle("Edit LaF Defaults");
            setModal(false);
            init();
        }

        public JBTable myTable;

        @Nullable
        @Override
        public JComponent getPreferredFocusedComponent() {
            return myTable;
        }

        @Nullable
        @Override
        protected String getDimensionServiceKey() {
            return project == null ? null : "UI.Defaults.Dialog";
        }

        @Override
        protected JComponent createCenterPanel() {
            final JBTable table = new JBTable(new DefaultTableModel(data, new Object[] { "Name", "Value" }) {

                @Override
                public boolean isCellEditable(int row, int column) {
                    return column == 1 && getValueAt(row, column) instanceof Color;
                }
            }) {

                @Override
                public boolean editCellAt(int row, int column, EventObject e) {
                    if (isCellEditable(row, column) && e instanceof MouseEvent) {
                        final Object color = getValueAt(row, column);
                        final Color newColor = ColorPicker.showDialog(this, "Choose Color", (Color) color, true, null, true);
                        if (newColor != null) {
                            final ColorUIResource colorUIResource = new ColorUIResource(newColor);
                            final Object key = getValueAt(row, 0);
                            UIManager.put(key, colorUIResource);
                            setValueAt(colorUIResource, row, column);
                        }
                    }
                    return false;
                }
            };
            table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {

                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    final JPanel panel = new JPanel(new BorderLayout());
                    final JLabel label = new JLabel(value == null ? "" : value.toString());
                    panel.add(label, BorderLayout.CENTER);
                    if (value instanceof Color) {
                        final Color c = (Color) value;
                        label.setText(String.format("[r=%d,g=%d,b=%d] hex=0x%s", c.getRed(), c.getGreen(), c.getBlue(), ColorUtil.toHex(c)));
                        label.setForeground(ColorUtil.isDark(c) ? Color.white : Color.black);
                        panel.setBackground(c);
                        return panel;
                    } else if (value instanceof Icon) {
                        try {
                            final Icon icon = new IconWrap((Icon) value);
                            if (icon.getIconHeight() <= 20) {
                                label.setIcon(icon);
                            }
                            label.setText(String.format("(%dx%d) %s)", icon.getIconWidth(), icon.getIconHeight(), label.getText()));
                        } catch (Throwable e1) {
                        //
                        }
                        return panel;
                    } else if (value instanceof Border) {
                        try {
                            final Insets i = ((Border) value).getBorderInsets(null);
                            label.setText(String.format("[%d, %d, %d, %d] %s", i.top, i.left, i.bottom, i.right, label.getText()));
                            return panel;
                        } catch (Exception ignore) {
                        }
                    }
                    return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                }
            });
            final JBScrollPane pane = new JBScrollPane(table);
            new TableSpeedSearch(table, (o, cell) -> cell.column == 1 ? null : String.valueOf(o));
            table.setShowGrid(false);
            final JPanel panel = new JPanel(new BorderLayout());
            panel.add(pane, BorderLayout.CENTER);
            myTable = table;
            TableUtil.ensureSelectionExists(myTable);
            return panel;
        }
    }.show();
}
Also used : EmptyIcon(com.intellij.util.ui.EmptyIcon) Arrays(java.util.Arrays) DefaultTableModel(javax.swing.table.DefaultTableModel) Enumeration(java.util.Enumeration) StringUtil(com.intellij.openapi.util.text.StringUtil) AnAction(com.intellij.openapi.actionSystem.AnAction) ColorUIResource(javax.swing.plaf.ColorUIResource) MouseEvent(java.awt.event.MouseEvent) JBScrollPane(com.intellij.ui.components.JBScrollPane) Border(javax.swing.border.Border) EventObject(java.util.EventObject) java.awt(java.awt) JBTable(com.intellij.ui.table.JBTable) Nullable(org.jetbrains.annotations.Nullable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) PairFunction(com.intellij.util.PairFunction) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Project(com.intellij.openapi.project.Project) DumbAware(com.intellij.openapi.project.DumbAware) Comparator(java.util.Comparator) javax.swing(javax.swing) DefaultTableModel(javax.swing.table.DefaultTableModel) JBTable(com.intellij.ui.table.JBTable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Enumeration(java.util.Enumeration) MouseEvent(java.awt.event.MouseEvent) ColorUIResource(javax.swing.plaf.ColorUIResource) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) EventObject(java.util.EventObject) Project(com.intellij.openapi.project.Project) EventObject(java.util.EventObject) EmptyIcon(com.intellij.util.ui.EmptyIcon) Border(javax.swing.border.Border) Nullable(org.jetbrains.annotations.Nullable) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Aggregations

MouseEvent (java.awt.event.MouseEvent)918 MouseAdapter (java.awt.event.MouseAdapter)595 Dimension (java.awt.Dimension)183 JPanel (javax.swing.JPanel)174 ActionEvent (java.awt.event.ActionEvent)172 JLabel (javax.swing.JLabel)169 Point (java.awt.Point)143 ActionListener (java.awt.event.ActionListener)123 BorderLayout (java.awt.BorderLayout)119 JScrollPane (javax.swing.JScrollPane)113 JButton (javax.swing.JButton)109 KeyEvent (java.awt.event.KeyEvent)85 ChangeEvent (javax.swing.event.ChangeEvent)85 ChangeListener (javax.swing.event.ChangeListener)83 Insets (java.awt.Insets)79 MouseListener (java.awt.event.MouseListener)72 KeyAdapter (java.awt.event.KeyAdapter)65 JPopupMenu (javax.swing.JPopupMenu)64 JSlider (javax.swing.JSlider)63 GridBagConstraints (java.awt.GridBagConstraints)62