Search in sources :

Example 1 with MouseMotionListener

use of java.awt.event.MouseMotionListener 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 2 with MouseMotionListener

use of java.awt.event.MouseMotionListener 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 3 with MouseMotionListener

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

Example 4 with MouseMotionListener

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

the class JavaTextAreaPainter method startTweakMode.

protected void startTweakMode() {
    addMouseListener(new MouseListener() {

        @Override
        public void mouseReleased(MouseEvent e) {
            if (mouseHandle != null) {
                mouseHandle.resetProgress();
                mouseHandle = null;
                updateCursor(e.getX(), e.getY());
                repaint();
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            int currentTab = getCurrentCodeIndex();
            // check for clicks on number handles
            for (Handle n : handles.get(currentTab)) {
                if (n.pick(e.getX(), e.getY())) {
                    cursorType = -1;
                    JavaTextAreaPainter.this.setCursor(blankCursor);
                    mouseHandle = n;
                    mouseHandle.setCenterX(e.getX());
                    repaint();
                    return;
                }
            }
            // check for clicks on color boxes
            for (ColorControlBox box : colorBoxes.get(currentTab)) {
                if (box.pick(e.getX(), e.getY())) {
                    if (colorSelector != null) {
                        // we already show a color selector, close it
                        colorSelector.frame.dispatchEvent(new WindowEvent(colorSelector.frame, WindowEvent.WINDOW_CLOSING));
                    }
                    colorSelector = new ColorSelector(box);
                    colorSelector.frame.addWindowListener(new WindowAdapter() {

                        public void windowClosing(WindowEvent e) {
                            colorSelector.frame.setVisible(false);
                            colorSelector = null;
                        }
                    });
                    colorSelector.show(getLocationOnScreen().x + e.getX() + 30, getLocationOnScreen().y + e.getY() - 130);
                }
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
        }
    });
    addMouseMotionListener(new MouseMotionListener() {

        @Override
        public void mouseMoved(MouseEvent e) {
            updateCursor(e.getX(), e.getY());
            if (!Settings.alwaysShowColorBoxes) {
                showHideColorBoxes(e.getY());
            }
        }

        @Override
        public void mouseDragged(MouseEvent e) {
            if (mouseHandle != null) {
                // set the current drag amount of the arrows
                mouseHandle.setCurrentX(e.getX());
                // update code text with the new value
                updateCodeText();
                if (colorSelector != null) {
                    colorSelector.refreshColor();
                }
                repaint();
            }
        }
    });
    tweakMode = true;
    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    repaint();
}
Also used : MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) ColorControlBox(processing.mode.java.tweak.ColorControlBox) ColorSelector(processing.mode.java.tweak.ColorSelector) MouseMotionListener(java.awt.event.MouseMotionListener) Cursor(java.awt.Cursor) Handle(processing.mode.java.tweak.Handle)

Example 5 with MouseMotionListener

use of java.awt.event.MouseMotionListener in project JMRI by JMRI.

the class SliderSnap method attachTo.

/**
     * Called to attach mouse listeners to the JSlider
     *
     * @param c JSlider to be attached to
     */
private static void attachTo(JSlider c) {
    MouseMotionListener[] listeners = c.getMouseMotionListeners();
    for (MouseMotionListener m : listeners) {
        if (m instanceof TrackListener) {
            // Remove the original listener
            c.removeMouseMotionListener(m);
            // Create a new snap listener and add it
            SnapListener listen = new SnapListener(m, (BasicSliderUI) c.getUI(), c);
            c.addMouseMotionListener(listen);
            c.addMouseListener(listen);
            //NOI18N
            c.addPropertyChangeListener("UI", listen);
        }
    }
}
Also used : MouseMotionListener(java.awt.event.MouseMotionListener)

Aggregations

MouseMotionListener (java.awt.event.MouseMotionListener)29 MouseEvent (java.awt.event.MouseEvent)17 MouseListener (java.awt.event.MouseListener)11 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)8 MouseAdapter (java.awt.event.MouseAdapter)7 JPanel (javax.swing.JPanel)6 BoxLayout (javax.swing.BoxLayout)4 JComponent (javax.swing.JComponent)4 JLabel (javax.swing.JLabel)4 Point (java.awt.Point)3 KeyAdapter (java.awt.event.KeyAdapter)3 KeyEvent (java.awt.event.KeyEvent)3 MouseMotionAdapter (java.awt.event.MouseMotionAdapter)3 Component (java.awt.Component)2 Dimension (java.awt.Dimension)2 DropTarget (java.awt.dnd.DropTarget)2 MouseWheelEvent (java.awt.event.MouseWheelEvent)2 MouseWheelListener (java.awt.event.MouseWheelListener)2 WindowAdapter (java.awt.event.WindowAdapter)2