Search in sources :

Example 6 with MouseListener

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

the class IdeGlassPaneImpl method preprocess.

private boolean preprocess(final MouseEvent e, final boolean motion, JRootPane eventRootPane) {
    try {
        if (UIUtil.getWindow(this) != UIUtil.getWindow(e.getComponent()))
            return false;
        final MouseEvent event = MouseEventAdapter.convert(e, eventRootPane);
        if (event.isAltDown() && SwingUtilities.isLeftMouseButton(event) && event.getID() == MouseEvent.MOUSE_PRESSED) {
            Component c = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
            Balloon balloon = JBPopupFactory.getInstance().getParentBalloonFor(c);
            if (balloon instanceof BalloonImpl) {
                JComponent component = ((BalloonImpl) balloon).getComponent();
                component.getToolkit().getSystemClipboard().setContents(new StringSelection(UIUtil.getDebugText(component)), EmptyClipboardOwner.INSTANCE);
            }
        }
        if (!IdeGlassPaneUtil.canBePreprocessed(e)) {
            return false;
        }
        for (EventListener each : mySortedMouseListeners) {
            if (motion && each instanceof MouseMotionListener) {
                fireMouseMotion((MouseMotionListener) each, event);
            } else if (!motion && each instanceof MouseListener) {
                fireMouseEvent((MouseListener) each, event);
            }
            if (event.isConsumed()) {
                e.consume();
                return true;
            }
        }
        return false;
    } finally {
        if (eventRootPane == myRootPane) {
            Cursor cursor;
            if (!myListener2Cursor.isEmpty()) {
                cursor = myListener2Cursor.values().iterator().next();
                final Point point = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), myRootPane.getContentPane());
                Component target = SwingUtilities.getDeepestComponentAt(myRootPane.getContentPane().getParent(), point.x, point.y);
                if (canProcessCursorFor(target)) {
                    target = getCompWithCursor(target);
                    restoreLastComponent(target);
                    if (target != null) {
                        if (myLastCursorComponent != target) {
                            myLastCursorComponent = target;
                            myLastOriginalCursor = target.getCursor();
                        }
                        if (cursor != null && !cursor.equals(target.getCursor())) {
                            if (target instanceof JComponent) {
                                ((JComponent) target).putClientProperty(PREPROCESSED_CURSOR_KEY, Boolean.TRUE);
                            }
                            target.setCursor(cursor);
                        }
                    }
                    getRootPane().setCursor(cursor);
                }
            } else if (!e.isConsumed() && e.getID() != MouseEvent.MOUSE_DRAGGED) {
                cursor = Cursor.getDefaultCursor();
                JRootPane rootPane = getRootPane();
                if (rootPane != null) {
                    rootPane.setCursor(cursor);
                } else {
                    LOG.warn("Root pane is null. Event: " + e);
                }
                restoreLastComponent(null);
                myLastOriginalCursor = null;
                myLastCursorComponent = null;
            }
            myListener2Cursor.clear();
        }
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseListener(java.awt.event.MouseListener) Balloon(com.intellij.openapi.ui.popup.Balloon) BalloonImpl(com.intellij.ui.BalloonImpl) AWTEventListener(java.awt.event.AWTEventListener) MouseMotionListener(java.awt.event.MouseMotionListener) StringSelection(java.awt.datatransfer.StringSelection)

Example 7 with MouseListener

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

the class IdeGlassPaneImpl method dispatch.

public boolean dispatch(@NotNull final AWTEvent e) {
    JRootPane eventRootPane = myRootPane;
    if (e instanceof MouseEvent) {
        MouseEvent me = (MouseEvent) e;
        Window eventWindow = UIUtil.getWindow(me.getComponent());
        if (isContextMenu(eventWindow))
            return false;
        final Window thisGlassWindow = SwingUtilities.getWindowAncestor(myRootPane);
        if (eventWindow instanceof JWindow) {
            eventRootPane = ((JWindow) eventWindow).getRootPane();
            if (eventRootPane != null) {
                if (!(eventRootPane.getGlassPane() instanceof IdeGlassPane)) {
                    final Container parentWindow = eventWindow.getParent();
                    if (parentWindow instanceof Window) {
                        eventWindow = (Window) parentWindow;
                    }
                }
            }
        }
        if (eventWindow != thisGlassWindow)
            return false;
    }
    if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
        if (ApplicationManager.getApplication() != null) {
            IdeTooltipManager.getInstance().hideCurrent((MouseEvent) e);
        }
    }
    boolean dispatched;
    if (e.getID() == MouseEvent.MOUSE_PRESSED || e.getID() == MouseEvent.MOUSE_RELEASED || e.getID() == MouseEvent.MOUSE_CLICKED) {
        dispatched = preprocess((MouseEvent) e, false, eventRootPane);
    } else if (e.getID() == MouseEvent.MOUSE_MOVED || e.getID() == MouseEvent.MOUSE_DRAGGED) {
        dispatched = preprocess((MouseEvent) e, true, eventRootPane);
    } else if (e.getID() == MouseEvent.MOUSE_EXITED || e.getID() == MouseEvent.MOUSE_ENTERED) {
        dispatched = preprocess((MouseEvent) e, false, eventRootPane);
    } else {
        return false;
    }
    MouseEvent me = (MouseEvent) e;
    final Component meComponent = me.getComponent();
    if (!dispatched && meComponent != null) {
        final Window eventWindow = UIUtil.getWindow(meComponent);
        if (eventWindow != SwingUtilities.getWindowAncestor(myRootPane)) {
            return false;
        }
        int button1 = MouseEvent.BUTTON1_MASK | MouseEvent.BUTTON1_DOWN_MASK;
        final boolean pureMouse1Event = (me.getModifiersEx() | button1) == button1;
        if (pureMouse1Event && me.getClickCount() <= 1 && !me.isPopupTrigger()) {
            final Point point = SwingUtilities.convertPoint(meComponent, me.getPoint(), myRootPane.getContentPane());
            JMenuBar menuBar = myRootPane.getJMenuBar();
            point.y += menuBar != null ? menuBar.getHeight() : 0;
            final Component target = SwingUtilities.getDeepestComponentAt(myRootPane.getContentPane().getParent(), point.x, point.y);
            if (target instanceof DnDAware) {
                final Point targetPoint = SwingUtilities.convertPoint(myRootPane.getContentPane().getParent(), point.x, point.y, target);
                final boolean overSelection = ((DnDAware) target).isOverSelection(targetPoint);
                if (overSelection) {
                    final MouseListener[] listeners = target.getListeners(MouseListener.class);
                    final MouseEvent mouseEvent = MouseEventAdapter.convert(me, target);
                    switch(me.getID()) {
                        case MouseEvent.MOUSE_PRESSED:
                            boolean consumed = false;
                            if (target.isFocusable()) {
                                IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                                    IdeFocusManager.getGlobalInstance().requestFocus(target, true);
                                });
                            }
                            for (final MouseListener listener : listeners) {
                                final String className = listener.getClass().getName();
                                if (className.indexOf("BasicTreeUI$") >= 0 || className.indexOf("MacTreeUI$") >= 0)
                                    continue;
                                fireMouseEvent(listener, mouseEvent);
                                if (mouseEvent.isConsumed()) {
                                    consumed = true;
                                    break;
                                }
                            }
                            if (!mouseEvent.isConsumed()) {
                                final AWTEventListener[] eventListeners = Toolkit.getDefaultToolkit().getAWTEventListeners(MouseEvent.MOUSE_EVENT_MASK);
                                if (eventListeners != null && eventListeners.length > 0) {
                                    for (final AWTEventListener eventListener : eventListeners) {
                                        eventListener.eventDispatched(me);
                                        if (me.isConsumed())
                                            break;
                                    }
                                    if (me.isConsumed()) {
                                        consumed = true;
                                        break;
                                    }
                                }
                            }
                            if (!consumed) {
                                myPrevPressEvent = mouseEvent;
                            } else {
                                me.consume();
                            }
                            dispatched = true;
                            break;
                        case MouseEvent.MOUSE_RELEASED:
                            if (myPrevPressEvent != null && myPrevPressEvent.getComponent() == target) {
                                for (final MouseListener listener : listeners) {
                                    final String className = listener.getClass().getName();
                                    if (className.indexOf("BasicTreeUI$") >= 0 || className.indexOf("MacTreeUI$") >= 0) {
                                        fireMouseEvent(listener, myPrevPressEvent);
                                        fireMouseEvent(listener, mouseEvent);
                                        if (mouseEvent.isConsumed()) {
                                            break;
                                        }
                                    }
                                    fireMouseEvent(listener, mouseEvent);
                                    if (mouseEvent.isConsumed()) {
                                        break;
                                    }
                                }
                                if (mouseEvent.isConsumed()) {
                                    me.consume();
                                }
                                myPrevPressEvent = null;
                                dispatched = true;
                            }
                            break;
                        default:
                            myPrevPressEvent = null;
                            break;
                    }
                }
            }
        }
    }
    if (isVisible() && getComponentCount() == 0) {
        boolean cursorSet = false;
        if (meComponent != null) {
            final Point point = SwingUtilities.convertPoint(meComponent, me.getPoint(), myRootPane.getContentPane());
            if (myRootPane.getMenuBar() != null && myRootPane.getMenuBar().isVisible()) {
                point.y += myRootPane.getMenuBar().getHeight();
            }
            final Component target = SwingUtilities.getDeepestComponentAt(myRootPane.getContentPane().getParent(), point.x, point.y);
            if (target != null) {
                setCursor(target.getCursor());
                cursorSet = true;
            }
        }
        if (!cursorSet) {
            setCursor(Cursor.getDefaultCursor());
        }
    }
    return dispatched;
}
Also used : MouseEvent(java.awt.event.MouseEvent) AWTEventListener(java.awt.event.AWTEventListener) MouseListener(java.awt.event.MouseListener) DnDAware(com.intellij.ide.dnd.DnDAware) IdeGlassPane(com.intellij.openapi.wm.IdeGlassPane)

Example 8 with MouseListener

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

the class NlPreviewImagePanelTest method mousePressed.

private void mousePressed() {
    int x = 10;
    int y = 10;
    MouseEvent event = new MouseEvent(myPanel, MOUSE_PRESSED, System.currentTimeMillis(), BUTTON1_MASK | BUTTON1_DOWN_MASK, x, y, 1, false);
    for (MouseListener listener : myPanel.getMouseListeners()) {
        listener.mousePressed(event);
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseListener(java.awt.event.MouseListener)

Example 9 with MouseListener

use of java.awt.event.MouseListener in project adempiere by adempiere.

the class VSortTab method jbInit.

/**
	 * 	Static Layout
	 * 	@throws Exception
	 */
private void jbInit() throws Exception {
    this.setLayout(mainLayout);
    //
    noLabel.setText("No");
    yesLabel.setText("Yes");
    for (MouseMotionListener mml : noList.getMouseMotionListeners()) noList.removeMouseMotionListener(mml);
    for (MouseMotionListener mml : yesList.getMouseMotionListeners()) yesList.removeMouseMotionListener(mml);
    MouseListener mouseListener = new MouseAdapter() {

        public void mouseClicked(MouseEvent me) {
            if (me.getClickCount() > 1) {
                JList list = (JList) me.getComponent();
                Point p = me.getPoint();
                int index = list.locationToIndex(p);
                if (index > -1 && list.getCellBounds(index, index).contains(p))
                    migrateValueAcrossLists(me);
            }
        }
    };
    yesList.addMouseListener(mouseListener);
    noList.addMouseListener(mouseListener);
    //
    yesList.setCellRenderer(listRenderer);
    noList.setCellRenderer(listRenderer);
    ActionListener actionListener = new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            migrateValueAcrossLists(ae);
        }
    };
    bAdd.setIcon(Env.getImageIcon("Detail24.gif"));
    bAdd.setMargin(new Insets(2, 2, 2, 2));
    bAdd.addActionListener(actionListener);
    bRemove.setIcon(Env.getImageIcon("Parent24.gif"));
    bRemove.setMargin(new Insets(2, 2, 2, 2));
    bRemove.addActionListener(actionListener);
    MouseInputListener crossListMouseListener = new DragListener();
    yesList.addMouseListener(crossListMouseListener);
    yesList.addMouseMotionListener(crossListMouseListener);
    noList.addMouseListener(crossListMouseListener);
    noList.addMouseMotionListener(crossListMouseListener);
    actionListener = new ActionListener() {

        public void actionPerformed(ActionEvent ae) {
            migrateValueWithinYesList(ae);
        }
    };
    bUp.setIcon(Env.getImageIcon("Previous24.gif"));
    bUp.setMargin(new Insets(2, 2, 2, 2));
    bUp.addActionListener(actionListener);
    bDown.setIcon(Env.getImageIcon("Next24.gif"));
    bDown.setMargin(new Insets(2, 2, 2, 2));
    bDown.addActionListener(actionListener);
    MouseMotionListener yesListMouseMotionListener = new MouseMotionAdapter() {

        public void mouseDragged(MouseEvent me) {
            JList list = (JList) me.getComponent();
            Point p = me.getPoint();
            int index = list.locationToIndex(p);
            if (index > -1 && list.getCellBounds(index, index).contains(p))
                migrateValueWithinYesList(me);
        }
    };
    yesList.addMouseMotionListener(yesListMouseMotionListener);
    //	Yamel Senih, 2015-11-13
    //	Maximize Panel when the window is resized
    yesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    noList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    this.add(noLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    this.add(yesLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
    this.add(bDown, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 4, 4, 4), 0, 0));
    this.add(noPane, new GridBagConstraints(0, 1, 1, 3, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(4, 4, 4, 4), 0, 0));
    this.add(yesPane, new GridBagConstraints(2, 1, 1, 3, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(4, 4, 4, 4), 0, 0));
    this.add(bUp, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 4, 4, 4), 0, 0));
    this.add(bAdd, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 4, 4, 4), 0, 0));
    this.add(bRemove, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 4, 4, 4), 0, 0));
//	End Yamel Senih
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) MouseEvent(java.awt.event.MouseEvent) Insets(java.awt.Insets) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) Point(java.awt.Point) MouseMotionListener(java.awt.event.MouseMotionListener) Point(java.awt.Point) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseListener(java.awt.event.MouseListener) ActionListener(java.awt.event.ActionListener) MouseInputListener(javax.swing.event.MouseInputListener) JList(javax.swing.JList)

Example 10 with MouseListener

use of java.awt.event.MouseListener in project processing by processing.

the class JavaTextArea method tweakRemoveListeners.

/* remove all standard interaction listeners */
public void tweakRemoveListeners() {
    if (baseCompListeners == null) {
        // First time in tweak mode, grab the default listeners. Moved from the
        // constructor since not all listeners may have been added at that point.
        baseCompListeners = painter.getComponentListeners();
        baseMouseListeners = painter.getMouseListeners();
        baseMotionListeners = painter.getMouseMotionListeners();
        baseKeyListeners = editor.getKeyListeners();
    }
    ComponentListener[] componentListeners = painter.getComponentListeners();
    MouseListener[] mouseListeners = painter.getMouseListeners();
    MouseMotionListener[] mouseMotionListeners = painter.getMouseMotionListeners();
    KeyListener[] keyListeners = editor.getKeyListeners();
    for (ComponentListener cl : componentListeners) {
        painter.removeComponentListener(cl);
    }
    for (MouseListener ml : mouseListeners) {
        painter.removeMouseListener(ml);
    }
    for (MouseMotionListener mml : mouseMotionListeners) {
        painter.removeMouseMotionListener(mml);
    }
    for (KeyListener kl : keyListeners) {
        editor.removeKeyListener(kl);
    }
}
Also used : ComponentListener(java.awt.event.ComponentListener) MouseListener(java.awt.event.MouseListener) KeyListener(java.awt.event.KeyListener) MouseMotionListener(java.awt.event.MouseMotionListener)

Aggregations

MouseListener (java.awt.event.MouseListener)104 MouseEvent (java.awt.event.MouseEvent)67 Dimension (java.awt.Dimension)21 JLabel (javax.swing.JLabel)20 MouseAdapter (java.awt.event.MouseAdapter)19 JPanel (javax.swing.JPanel)16 Component (java.awt.Component)14 JComponent (javax.swing.JComponent)14 ActionEvent (java.awt.event.ActionEvent)13 ActionListener (java.awt.event.ActionListener)11 MouseMotionListener (java.awt.event.MouseMotionListener)11 JButton (javax.swing.JButton)11 JScrollPane (javax.swing.JScrollPane)11 Insets (java.awt.Insets)8 BorderLayout (java.awt.BorderLayout)7 Color (java.awt.Color)7 Point (java.awt.Point)7 File (java.io.File)7 ImageIcon (javax.swing.ImageIcon)6 JCheckBox (javax.swing.JCheckBox)6