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