Search in sources :

Example 21 with MouseMotionListener

use of java.awt.event.MouseMotionListener in project knime-core by knime.

the class SelectionPanel method createIncludePanel.

private void createIncludePanel() {
    m_includePanel = new JPanel(new GridBagLayout());
    new DropTarget(m_includePanel, DnDConstants.ACTION_MOVE, this, true, null);
    m_scrollPane = new JScrollPane(m_includePanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    m_scrollPane.setPreferredSize(new Dimension(300, 200));
    m_scrollPane.getVerticalScrollBar().setUnitIncrement(20);
    MouseMotionListener doScrollRectToVisible = new MouseMotionAdapter() {

        int lasty = 0;

        @Override
        public void mouseDragged(final MouseEvent e) {
            if (Math.abs(lasty - e.getY()) < 10) {
                int i = m_scrollPane.getVerticalScrollBar().getValue();
                if (e.getY() > lasty) {
                    m_scrollPane.getVerticalScrollBar().setValue(i + 2);
                } else if (e.getY() < lasty) {
                    m_scrollPane.getVerticalScrollBar().setValue(i - 2);
                }
            }
            if (e.getY() < 10) {
                lasty = 10;
            } else if (e.getY() > m_includePanel.getVisibleRect().getMaxY()) {
                lasty = (int) m_includePanel.getVisibleRect().getMaxY() - 10;
            } else if (Math.abs(lasty - e.getY()) > 10) {
                lasty = e.getY();
            }
        }
    };
    m_includePanel.addMouseMotionListener(doScrollRectToVisible);
    m_includePanel.setAutoscrolls(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) MouseEvent(java.awt.event.MouseEvent) GridBagLayout(java.awt.GridBagLayout) DropTarget(java.awt.dnd.DropTarget) Dimension(java.awt.Dimension) MouseMotionListener(java.awt.event.MouseMotionListener)

Example 22 with MouseMotionListener

use of java.awt.event.MouseMotionListener in project artisynth_core by artisynth.

the class LabeledComponentPanel method doAddWidget.

protected void doAddWidget(Component comp, int idx) {
    boolean resetNeeded = false;
    LabeledComponentPanel topPanel = null;
    if (comp instanceof HasAlignableLabels) {
        if (comp instanceof LabeledComponent) {
            ((LabeledComponent) comp).setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
        } else if (comp instanceof LabeledPanel) {
            ((LabeledPanel) comp).setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
        }
        topPanel = getTopPanel(this);
        HasAlignableLabels lcomp = (HasAlignableLabels) comp;
        LabelSpacing spc = new LabelSpacing();
        LabelSpacing top = new LabelSpacing();
        lcomp.getPreferredLabelSpacing(spc);
        topPanel.getLabelSpacing(top);
        top.labelWidth -= getLeftInsetToTop();
        if (spc.labelWidth > top.labelWidth || spc.preSpacing > top.preSpacing) {
            resetNeeded = true;
        } else {
            if (spc.expand(top)) {
                lcomp.setLabelSpacing(spc);
            }
        }
    }
    if (comp instanceof JComponent) {
        JComponent jcomp = (JComponent) comp;
        jcomp.setAlignmentX(Component.LEFT_ALIGNMENT);
        // Prevent JSeparators from acting as stretchable components:
        if (jcomp instanceof JSeparator) {
            Dimension maxsize = new Dimension(jcomp.getMaximumSize());
            maxsize.height = jcomp.getPreferredSize().height;
            jcomp.setMaximumSize(maxsize);
        }
    }
    myWidgets.add(idx, comp);
    if (resetNeeded) {
        topPanel.resetLabelAlignment();
    }
    // mouse events.
    for (MouseListener l : getMouseListeners()) {
        comp.addMouseListener(l);
    }
    for (MouseMotionListener l : getMouseMotionListeners()) {
        comp.addMouseMotionListener(l);
    }
}
Also used : MouseListener(java.awt.event.MouseListener) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) MouseMotionListener(java.awt.event.MouseMotionListener) JSeparator(javax.swing.JSeparator)

Example 23 with MouseMotionListener

use of java.awt.event.MouseMotionListener in project com.revolsys.open by revolsys.

the class MouseOverlay method mouseDragged.

@Override
public void mouseDragged(final MouseEvent e) {
    updateEventPoint(e);
    requestFocusInWindow();
    for (final Component overlay : getOverlays()) {
        if (overlay instanceof MouseMotionListener) {
            final MouseMotionListener listener = (MouseMotionListener) overlay;
            listener.mouseDragged(e);
            if (e.isConsumed()) {
                return;
            }
        }
    }
}
Also used : JComponent(javax.swing.JComponent) Component(java.awt.Component) MouseMotionListener(java.awt.event.MouseMotionListener)

Example 24 with MouseMotionListener

use of java.awt.event.MouseMotionListener in project cytoscape-impl by cytoscape.

the class GradientEditor method init.

// ==[ PRIVATE METHODS ]============================================================================================
private void init() {
    setLayout(null);
    // Transparent if Aqua
    setOpaque(!LookAndFeelUtil.isAquaLAF());
    addBtn.setBounds(20, 70, 75, 20);
    add(addBtn);
    editBtn.setBounds(100, 70, 75, 20);
    editBtn.setEnabled(false);
    add(editBtn);
    delBtn.setBounds(180, 70, 75, 20);
    delBtn.setEnabled(false);
    add(delBtn);
    addBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            addPoint();
        }
    });
    delBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            delPoint();
        }
    });
    editBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editPoint();
        }
    });
    poly.addPoint(0, 0);
    poly.addPoint(5, 10);
    poly.addPoint(-5, 10);
    this.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            selectPoint(e.getX(), e.getY());
            repaint(0);
            if (e.getClickCount() == 2)
                editPoint();
        }
    });
    this.addMouseMotionListener(new MouseMotionListener() {

        @Override
        public void mouseDragged(MouseEvent e) {
            movePoint(e.getX(), e.getY());
            repaint(0);
        }

        @Override
        public void mouseMoved(MouseEvent e) {
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) MouseMotionListener(java.awt.event.MouseMotionListener)

Example 25 with MouseMotionListener

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

the class MouseAwtTest method testDoClick.

/**
 * Test do click robot.
 */
@Test
void testDoClick() {
    final MouseAwt mouse = createMouse();
    final MouseMotionListener mover = mouse.getMover();
    assertFalse(mouse.isPushed(MouseAwt.RIGHT));
    mover.mouseMoved(createEvent(MouseAwt.LEFT, 0, 0));
    mouse.doClickAt(MouseAwt.RIGHT, 500, 500);
    mouse.update(1.0);
    try {
        assertEquals(500, mouse.getOnScreenX());
        assertEquals(500, mouse.getOnScreenY());
        assertTrue(mouse.isPushed(MouseAwt.RIGHT));
    } finally {
        mouse.doClickAt(MouseAwt.LEFT, 499, 499);
    }
    assertTrue(mouse.isPushed(MouseAwt.LEFT));
    mouse.doClick(MouseAwt.LEFT);
    assertTrue(mouse.isPushed(MouseAwt.LEFT));
    mouse.update(1.0);
    mouse.doClick(MouseAwt.MIDDLE);
    mouse.update(1.0);
    mouse.doSetMouse(1, 2);
    assertEquals(1, mouse.getOnScreenX());
    assertEquals(2, mouse.getOnScreenY());
    mouse.doMoveMouse(3, 4);
    assertEquals(3, mouse.getOnScreenX());
    assertEquals(4, mouse.getOnScreenY());
    mouse.lock();
    mouse.lock(500, 500);
}
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