Search in sources :

Example 41 with MouseAdapter

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

the class ClickListener method installOn.

public void installOn(@NotNull Component c) {
    myListener = new MouseAdapter() {

        private Point pressPoint;

        private Point lastClickPoint;

        private long lastTimeClicked = -1;

        private int clickCount = 0;

        @Override
        public void mousePressed(MouseEvent e) {
            final Point point = e.getPoint();
            SwingUtilities.convertPointToScreen(point, e.getComponent());
            if (Math.abs(lastTimeClicked - e.getWhen()) > UIUtil.getMultiClickInterval() || lastClickPoint != null && !isWithinEps(lastClickPoint, point)) {
                clickCount = 0;
                lastClickPoint = null;
            }
            clickCount++;
            lastTimeClicked = e.getWhen();
            if (!e.isPopupTrigger()) {
                pressPoint = point;
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            Point releasedAt = e.getPoint();
            SwingUtilities.convertPointToScreen(releasedAt, e.getComponent());
            Point clickedAt = pressPoint;
            lastClickPoint = clickedAt;
            pressPoint = null;
            if (e.isConsumed() || clickedAt == null || e.isPopupTrigger() || !e.getComponent().contains(e.getPoint())) {
                return;
            }
            if (isWithinEps(releasedAt, clickedAt) && onClick(e, clickCount)) {
                e.consume();
            }
        }
    };
    c.addMouseListener(myListener);
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter)

Example 42 with MouseAdapter

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

the class LineTooltipRenderer method show.

@Override
public LightweightHint show(@NotNull final Editor editor, @NotNull final Point p, final boolean alignToRight, @NotNull final TooltipGroup group, @NotNull final HintHint hintHint) {
    if (myText == null)
        return null;
    //setup text
    myText = myText.replaceAll(String.valueOf(UIUtil.MNEMONIC), "");
    final boolean expanded = myCurrentWidth > 0 && dressDescription(editor);
    final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
    final JComponent contentComponent = editor.getContentComponent();
    final JComponent editorComponent = editor.getComponent();
    if (!editorComponent.isShowing())
        return null;
    final JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();
    final JEditorPane pane = IdeTooltipManager.initPane(new Html(myText).setKeepFont(true), hintHint, layeredPane);
    hintHint.setContentActive(isActiveHtml(myText));
    if (!hintHint.isAwtTooltip()) {
        correctLocation(editor, pane, p, alignToRight, expanded, myCurrentWidth);
    }
    final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(pane);
    scrollPane.setBorder(null);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setOpaque(hintHint.isOpaqueAllowed());
    scrollPane.getViewport().setOpaque(hintHint.isOpaqueAllowed());
    scrollPane.setBackground(hintHint.getTextBackground());
    scrollPane.getViewport().setBackground(hintHint.getTextBackground());
    scrollPane.setViewportBorder(null);
    if (hintHint.isRequestFocus()) {
        pane.setFocusable(true);
    }
    final Ref<AnAction> actionRef = new Ref<>();
    final LightweightHint hint = new LightweightHint(scrollPane) {

        @Override
        public void hide() {
            onHide(pane);
            super.hide();
            final AnAction action = actionRef.get();
            if (action != null) {
                action.unregisterCustomShortcutSet(contentComponent);
            }
        }
    };
    actionRef.set(new AnAction() {

        // an action to expand description when tooltip was shown after mouse move; need to unregister from editor component
        {
            registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_SHOW_ERROR_DESCRIPTION)), contentComponent);
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            // The tooltip gets the focus if using a screen reader and invocation through a keyboard shortcut.
            hintHint.setRequestFocus(ScreenReader.isActive() && (e.getInputEvent() instanceof KeyEvent));
            expand(hint, editor, p, pane, alignToRight, group, hintHint);
        }
    });
    pane.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(final HyperlinkEvent e) {
            myActiveLink = true;
            if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
                myActiveLink = false;
                return;
            }
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                final URL url = e.getURL();
                if (url != null) {
                    BrowserUtil.browse(url);
                    hint.hide();
                    return;
                }
                final String description = e.getDescription();
                if (description != null && handle(description, editor)) {
                    hint.hide();
                    return;
                }
                if (!expanded) {
                    expand(hint, editor, p, pane, alignToRight, group, hintHint);
                } else {
                    stripDescription();
                    hint.hide();
                    TooltipController.getInstance().showTooltip(editor, new Point(p.x - 3, p.y - 3), createRenderer(myText, 0), false, group, hintHint);
                }
            }
        }
    });
    // This listener makes hint transparent for mouse events. It means that hint is closed
    // by MousePressed and this MousePressed goes into the underlying editor component.
    pane.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (!myActiveLink) {
                MouseEvent newMouseEvent = SwingUtilities.convertMouseEvent(e.getComponent(), e, contentComponent);
                hint.hide();
                contentComponent.dispatchEvent(newMouseEvent);
            }
        }

        @Override
        public void mouseExited(final MouseEvent e) {
            if (!expanded) {
                hint.hide();
            }
        }
    });
    hintManager.showEditorHint(hint, editor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_OTHER_HINT | HintManager.HIDE_BY_SCROLLING, 0, false, hintHint);
    return hint;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) Html(com.intellij.util.ui.Html) LightweightHint(com.intellij.ui.LightweightHint) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) URL(java.net.URL) KeyEvent(java.awt.event.KeyEvent) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) Ref(com.intellij.openapi.util.Ref) HyperlinkListener(javax.swing.event.HyperlinkListener)

Example 43 with MouseAdapter

use of java.awt.event.MouseAdapter 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 44 with MouseAdapter

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

the class ColorPipetteBase method getOrCreatePickerDialog.

@NotNull
protected Dialog getOrCreatePickerDialog() {
    if (myPickerFrame == null) {
        Window owner = SwingUtilities.getWindowAncestor(myParent);
        if (owner instanceof Dialog) {
            myPickerFrame = new JDialog((Dialog) owner);
        } else if (owner instanceof Frame) {
            myPickerFrame = new JDialog((Frame) owner);
        } else {
            myPickerFrame = new JDialog(new JFrame());
        }
        myPickerFrame.setTitle("intellijPickerDialog");
    }
    myPickerFrame.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            e.consume();
            pickAndClose();
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            e.consume();
        }
    });
    myPickerFrame.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            switch(e.getKeyCode()) {
                case KeyEvent.VK_ESCAPE:
                    cancelPipette();
                    break;
                case KeyEvent.VK_ENTER:
                    pickAndClose();
                    break;
            }
        }
    });
    myPickerFrame.setUndecorated(true);
    myPickerFrame.setAlwaysOnTop(!SystemInfo.isJavaVersionAtLeast("1.8.0") || canUseMacPipette());
    JRootPane rootPane = myPickerFrame.getRootPane();
    rootPane.putClientProperty("Window.shadow", Boolean.FALSE);
    return myPickerFrame;
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) NotNull(org.jetbrains.annotations.NotNull)

Example 45 with MouseAdapter

use of java.awt.event.MouseAdapter in project android by JetBrains.

the class CpuMonitorView method populateUi.

@Override
protected void populateUi(JPanel container, Choreographer choreographer) {
    container.setLayout(new TabularLayout("*", "*"));
    Range viewRange = getMonitor().getTimeline().getViewRange();
    Range dataRange = getMonitor().getTimeline().getDataRange();
    final JLabel label = new JLabel(getMonitor().getName());
    label.setBorder(MONITOR_LABEL_PADDING);
    label.setVerticalAlignment(JLabel.TOP);
    // Cpu usage is shown as percentages (e.g. 0 - 100) and no range animation is needed.
    Range leftYRange = new Range(0, 100);
    final JPanel axisPanel = new JBPanel(new BorderLayout());
    axisPanel.setOpaque(false);
    AxisComponent.Builder builder = new AxisComponent.Builder(leftYRange, CPU_USAGE_AXIS, AxisComponent.AxisOrientation.RIGHT).showAxisLine(false).showMax(true).showUnitAtMax(true).setMarkerLengths(MARKER_LENGTH, MARKER_LENGTH).clampToMajorTicks(true).setMargins(0, Y_AXIS_TOP_MARGIN);
    final AxisComponent leftAxis = builder.build();
    axisPanel.add(leftAxis, BorderLayout.WEST);
    final JPanel lineChartPanel = new JBPanel(new BorderLayout());
    lineChartPanel.setOpaque(false);
    lineChartPanel.setBorder(BorderFactory.createEmptyBorder(Y_AXIS_TOP_MARGIN, 0, 0, 0));
    final LineChart lineChart = new LineChart();
    RangedContinuousSeries cpuSeries = new RangedContinuousSeries("CPU", viewRange, leftYRange, getMonitor().getThisProcessCpuUsage());
    lineChart.addLine(cpuSeries, new LineConfig(ProfilerColors.CPU_USAGE).setFilled(true));
    lineChartPanel.add(lineChart, BorderLayout.CENTER);
    final LegendComponent legend = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, LEGEND_UPDATE_FREQUENCY_MS);
    legend.setLegendData(Collections.singletonList(lineChart.createLegendRenderData(cpuSeries, CPU_USAGE_AXIS, dataRange)));
    final JPanel legendPanel = new JBPanel(new BorderLayout());
    legendPanel.setOpaque(false);
    legendPanel.add(label, BorderLayout.WEST);
    legendPanel.add(legend, BorderLayout.EAST);
    choreographer.register(lineChart);
    choreographer.register(leftAxis);
    choreographer.register(legend);
    container.add(legendPanel, new TabularLayout.Constraint(0, 0));
    container.add(leftAxis, new TabularLayout.Constraint(0, 0));
    container.add(lineChartPanel, new TabularLayout.Constraint(0, 0));
    container.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            getMonitor().expand();
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) TabularLayout(com.android.tools.adtui.TabularLayout) MouseAdapter(java.awt.event.MouseAdapter) AxisComponent(com.android.tools.adtui.AxisComponent) Range(com.android.tools.adtui.model.Range) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) JBPanel(com.intellij.ui.components.JBPanel) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LegendComponent(com.android.tools.adtui.LegendComponent) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Aggregations

MouseAdapter (java.awt.event.MouseAdapter)202 MouseEvent (java.awt.event.MouseEvent)199 JLabel (javax.swing.JLabel)52 JPanel (javax.swing.JPanel)48 ActionEvent (java.awt.event.ActionEvent)36 JScrollPane (javax.swing.JScrollPane)36 BorderLayout (java.awt.BorderLayout)35 Dimension (java.awt.Dimension)34 JButton (javax.swing.JButton)33 ActionListener (java.awt.event.ActionListener)32 Insets (java.awt.Insets)24 GridBagConstraints (java.awt.GridBagConstraints)20 KeyEvent (java.awt.event.KeyEvent)20 KeyAdapter (java.awt.event.KeyAdapter)19 JTextField (javax.swing.JTextField)16 ListSelectionEvent (javax.swing.event.ListSelectionEvent)16 Component (java.awt.Component)15 Point (java.awt.Point)15 JTable (javax.swing.JTable)15 ListSelectionListener (javax.swing.event.ListSelectionListener)15