Search in sources :

Example 11 with MouseMotionListener

use of java.awt.event.MouseMotionListener in project java-swing-tips by aterai.

the class DragWindowListener method makeInternalFrame.

private static JInternalFrame makeInternalFrame() {
    JInternalFrame internal = new JInternalFrame("@title@");
    BasicInternalFrameUI ui = (BasicInternalFrameUI) internal.getUI();
    Component title = ui.getNorthPane();
    for (MouseMotionListener l : title.getListeners(MouseMotionListener.class)) {
        title.removeMouseMotionListener(l);
    }
    DragWindowListener dwl = new DragWindowListener();
    title.addMouseListener(dwl);
    title.addMouseMotionListener(dwl);
    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    focusManager.addPropertyChangeListener(e -> {
        String prop = e.getPropertyName();
        // System.out.println(prop);
        if ("activeWindow".equals(prop)) {
            try {
                internal.setSelected(Objects.nonNull(e.getNewValue()));
            } catch (PropertyVetoException ex) {
                throw new IllegalStateException(ex);
            }
        // System.out.println("---------------------");
        }
    });
    // });
    return internal;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) BasicInternalFrameUI(javax.swing.plaf.basic.BasicInternalFrameUI) MouseMotionListener(java.awt.event.MouseMotionListener)

Example 12 with MouseMotionListener

use of java.awt.event.MouseMotionListener in project java-swing-tips by aterai.

the class LookAndFeelUtil method updateUI.

@Override
public void updateUI() {
    super.updateUI();
    BasicInternalFrameUI ui = (BasicInternalFrameUI) getUI();
    Component titleBar = ui.getNorthPane();
    for (MouseMotionListener l : titleBar.getListeners(MouseMotionListener.class)) {
        titleBar.removeMouseMotionListener(l);
    }
    DragWindowListener dwl = new DragWindowListener();
    titleBar.addMouseListener(dwl);
    titleBar.addMouseMotionListener(dwl);
}
Also used : BasicInternalFrameUI(javax.swing.plaf.basic.BasicInternalFrameUI) MouseMotionListener(java.awt.event.MouseMotionListener)

Example 13 with MouseMotionListener

use of java.awt.event.MouseMotionListener in project vcell by virtualcell.

the class BasicGraphEditor method installListeners.

/**
 */
protected void installListeners() {
    // Installs mouse wheel listener for zooming
    MouseWheelListener wheelTracker = new MouseWheelListener() {

        /**
         */
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getSource() instanceof mxGraphOutline || e.isControlDown()) {
                BasicGraphEditor.this.mouseWheelMoved(e);
            }
        }
    };
    // Handles mouse wheel events in the outline and graph component
    graphOutline.addMouseWheelListener(wheelTracker);
    graphComponent.addMouseWheelListener(wheelTracker);
    // Installs the popup menu in the outline
    graphOutline.addMouseListener(new MouseAdapter() {

        /**
         */
        public void mousePressed(MouseEvent e) {
            // Handles context menu on the Mac where the trigger is on mousepressed
            mouseReleased(e);
        }

        /**
         */
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showOutlinePopupMenu(e);
            }
        }
    });
    // Installs the popup menu in the graph component
    graphComponent.getGraphControl().addMouseListener(new MouseAdapter() {

        /**
         */
        public void mousePressed(MouseEvent e) {
            // Handles context menu on the Mac where the trigger is on mousepressed
            mouseReleased(e);
        }

        /**
         */
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showGraphPopupMenu(e);
            }
        }
    });
    // Installs a mouse motion listener to display the mouse location
    graphComponent.getGraphControl().addMouseMotionListener(new MouseMotionListener() {

        /*
					 * (non-Javadoc)
					 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
					 */
        public void mouseDragged(MouseEvent e) {
            mouseLocationChanged(e);
        }

        /*
					 * (non-Javadoc)
					 * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
					 */
        public void mouseMoved(MouseEvent e) {
            mouseDragged(e);
        }
    });
}
Also used : com.mxgraph.swing.mxGraphOutline(com.mxgraph.swing.mxGraphOutline) MouseEvent(java.awt.event.MouseEvent) MouseWheelEvent(java.awt.event.MouseWheelEvent) MouseAdapter(java.awt.event.MouseAdapter) MouseWheelListener(java.awt.event.MouseWheelListener) MouseMotionListener(java.awt.event.MouseMotionListener)

Example 14 with MouseMotionListener

use of java.awt.event.MouseMotionListener in project lionengine by b3dgs.

the class MouseAwtTest method testMouse.

/**
 * Test move.
 */
@Test
void testMouse() {
    final MouseAwt mouse = createMouse();
    final MouseListener clicker = mouse.getClicker();
    final MouseMotionListener mover = mouse.getMover();
    mover.mouseMoved(createEvent(MouseAwt.LEFT, 0, 0));
    mover.mouseDragged(createEvent(Integer.valueOf(0), 0, 0));
    mouse.update(1.0);
    assertEquals(0, mouse.getMoveX());
    assertEquals(0, mouse.getMoveY());
    clicker.mouseEntered(null);
    clicker.mouseExited(null);
    clicker.mouseClicked(null);
}
Also used : MouseListener(java.awt.event.MouseListener) MouseMotionListener(java.awt.event.MouseMotionListener) Test(org.junit.jupiter.api.Test)

Example 15 with MouseMotionListener

use of java.awt.event.MouseMotionListener in project lionengine by b3dgs.

the class MouseAwtTest method testLocation.

/**
 * Test location.
 */
@Test
void testLocation() {
    final MouseAwt mouse = createMouse();
    final MouseMotionListener mover = mouse.getMover();
    mover.mouseMoved(createEvent(MouseAwt.LEFT, 0, 0));
    assertEquals(0, mouse.getX());
    assertEquals(0, mouse.getY());
    mover.mouseMoved(createEvent(MouseAwt.LEFT, 10, 20));
    assertEquals(10, mouse.getX());
    assertEquals(20, mouse.getY());
}
Also used : MouseMotionListener(java.awt.event.MouseMotionListener) Test(org.junit.jupiter.api.Test)

Aggregations

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