Search in sources :

Example 61 with MouseEvent

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

the class LightweightHint method show.

/**
   * Shows the hint in the layered pane. Coordinates <code>x</code> and <code>y</code>
   * are in <code>parentComponent</code> coordinate system. Note that the component
   * appears on 250 layer.
   */
@Override
public void show(@NotNull final JComponent parentComponent, final int x, final int y, final JComponent focusBackComponent, @NotNull final HintHint hintHint) {
    myParentComponent = parentComponent;
    myHintHint = hintHint;
    myFocusBackComponent = focusBackComponent;
    LOG.assertTrue(myParentComponent.isShowing());
    myEscListener = new MyEscListener();
    myComponent.registerKeyboardAction(myEscListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    myComponent.registerKeyboardAction(myEscListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_FOCUSED);
    final JLayeredPane layeredPane = parentComponent.getRootPane().getLayeredPane();
    myComponent.validate();
    if (!myForceShowAsPopup && (myForceLightweightPopup || fitsLayeredPane(layeredPane, myComponent, new RelativePoint(parentComponent, new Point(x, y)), hintHint))) {
        beforeShow();
        final Dimension preferredSize = myComponent.getPreferredSize();
        if (hintHint.isAwtTooltip()) {
            IdeTooltip tooltip = new IdeTooltip(hintHint.getOriginalComponent(), hintHint.getOriginalPoint(), myComponent, hintHint, myComponent) {

                @Override
                protected boolean canAutohideOn(TooltipEvent event) {
                    if (!LightweightHint.this.canAutoHideOn(event)) {
                        return false;
                    } else if (event.getInputEvent() instanceof MouseEvent) {
                        return !(hintHint.isContentActive() && event.isIsEventInsideBalloon());
                    } else if (event.getAction() != null) {
                        return false;
                    } else {
                        return true;
                    }
                }

                @Override
                protected void onHidden() {
                    fireHintHidden();
                    TooltipController.getInstance().resetCurrent();
                }

                @Override
                public boolean canBeDismissedOnTimeout() {
                    return false;
                }
            }.setToCenterIfSmall(hintHint.isMayCenterTooltip()).setPreferredPosition(hintHint.getPreferredPosition()).setHighlighterType(hintHint.isHighlighterType()).setTextForeground(hintHint.getTextForeground()).setTextBackground(hintHint.getTextBackground()).setBorderColor(hintHint.getBorderColor()).setBorderInsets(hintHint.getBorderInsets()).setFont(hintHint.getTextFont()).setCalloutShift(hintHint.getCalloutShift()).setPositionChangeShift(hintHint.getPositionChangeX(), hintHint.getPositionChangeY()).setExplicitClose(hintHint.isExplicitClose()).setRequestFocus(hintHint.isRequestFocus()).setHint(true);
            myComponent.validate();
            myCurrentIdeTooltip = IdeTooltipManager.getInstance().show(tooltip, hintHint.isShowImmediately(), hintHint.isAnimationEnabled());
        } else {
            final Point layeredPanePoint = SwingUtilities.convertPoint(parentComponent, x, y, layeredPane);
            myComponent.setBounds(layeredPanePoint.x, layeredPanePoint.y, preferredSize.width, preferredSize.height);
            layeredPane.add(myComponent, JLayeredPane.POPUP_LAYER);
            myComponent.validate();
            myComponent.repaint();
        }
    } else {
        myIsRealPopup = true;
        Point actualPoint = new Point(x, y);
        JComponent actualComponent = new OpaquePanel(new BorderLayout());
        actualComponent.add(myComponent, BorderLayout.CENTER);
        if (isAwtTooltip()) {
            int inset = BalloonImpl.getNormalInset();
            actualComponent.setBorder(new LineBorder(hintHint.getTextBackground(), inset));
            actualComponent.setBackground(hintHint.getTextBackground());
            actualComponent.validate();
        }
        myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(actualComponent, myFocusRequestor).setRequestFocus(myFocusRequestor != null).setFocusable(myFocusRequestor != null).setResizable(myResizable).setMovable(myTitle != null).setTitle(myTitle).setModalContext(false).setShowShadow(isRealPopup() && !isForceHideShadow()).setCancelKeyEnabled(false).setCancelOnClickOutside(myCancelOnClickOutside).setCancelCallback(() -> {
            onPopupCancel();
            return true;
        }).setCancelOnOtherWindowOpen(myCancelOnOtherWindowOpen).createPopup();
        beforeShow();
        myPopup.show(new RelativePoint(myParentComponent, new Point(actualPoint.x, actualPoint.y)));
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) LineBorder(javax.swing.border.LineBorder) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) OpaquePanel(com.intellij.ui.components.panels.OpaquePanel) RelativePoint(com.intellij.ui.awt.RelativePoint) TooltipEvent(com.intellij.ide.TooltipEvent) IdeTooltip(com.intellij.ide.IdeTooltip)

Example 62 with MouseEvent

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

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

the class IdeMouseEventDispatcherTest method testActionBlocking.

public void testActionBlocking() throws Exception {
    assertFalse(myDispatcher.dispatchMouseEvent(new MouseEvent(myEventSource, MouseEvent.MOUSE_PRESSED, 0, 0, 0, 0, 1, false, MouseEvent.BUTTON2)));
    MouseEvent dragEvent = new MouseEvent(myEventSource, MouseEvent.MOUSE_DRAGGED, 0, 0, 0, 0, 0, false, MouseEvent.BUTTON2);
    assertFalse(myDispatcher.dispatchMouseEvent(dragEvent));
    myDispatcher.blockNextEvents(dragEvent, IdeEventQueue.BlockMode.ACTIONS);
    assertFalse(myDispatcher.dispatchMouseEvent(new MouseEvent(myEventSource, MouseEvent.MOUSE_RELEASED, 0, 0, 0, 0, 1, false, MouseEvent.BUTTON2)));
    assertEquals(0, myActionExecutionCount);
}
Also used : MouseEvent(java.awt.event.MouseEvent)

Example 64 with MouseEvent

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

the class UserTreeTest method testDeliverLocalMessage.

public void testDeliverLocalMessage() throws Exception {
    MockIdeaMessage message = new MockIdeaMessage();
    myLocalMessageDispatcher.addPendingMessage(myUser, message);
    MouseEvent mouseEvent = createMouseEvent();
    myUserTree.onClick(myTreePath, myTreePath.getLastPathComponent(), mouseEvent);
    verifyMessageDelivery();
}
Also used : MouseEvent(java.awt.event.MouseEvent) MockIdeaMessage(jetbrains.communicator.mock.MockIdeaMessage)

Example 65 with MouseEvent

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

the class UserTreeTest method testDoubleClickEventsInQueue.

public void testDoubleClickEventsInQueue() throws Exception {
    MockIdeaMessage message = new MockIdeaMessage();
    myLocalMessageDispatcher.addPendingMessage(myUser, message);
    MouseEvent mouseEvent = createMouseEvent();
    myUserTree.onClick(myTreePath, myTreePath.getLastPathComponent(), mouseEvent);
    myUserTree.onDblClick(myTreePath, myTreePath.getLastPathComponent(), mouseEvent);
    verifyMessageDelivery();
}
Also used : MouseEvent(java.awt.event.MouseEvent) MockIdeaMessage(jetbrains.communicator.mock.MockIdeaMessage)

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