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);
}
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);
}
}
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;
}
}
}
}
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) {
}
});
}
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);
}
Aggregations