use of java.awt.event.MouseMotionListener in project Terasology by MovingBlocks.
the class AwtMouseDevice method registerToAwtGlCanvas.
public void registerToAwtGlCanvas(AWTGLCanvas canvas) {
canvas.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
int button = e.getButton() - 1;
buttonStates.add(button);
MouseInput mouseInput = MouseInput.find(InputType.MOUSE_BUTTON, button);
queue.offer(new MouseAction(mouseInput, ButtonState.DOWN, getPosition()));
}
@Override
public void mouseReleased(MouseEvent e) {
int button = e.getButton() - 1;
buttonStates.remove(button);
MouseInput mouseInput = MouseInput.find(InputType.MOUSE_BUTTON, button);
queue.offer(new MouseAction(mouseInput, ButtonState.UP, getPosition()));
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
canvas.addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e) {
updateMouse(e.getX(), e.getY());
}
@Override
public void mouseMoved(MouseEvent e) {
updateMouse(e.getX(), e.getY());
}
});
canvas.addMouseWheelListener(e -> {
int yOffset = e.getUnitsToScroll();
if (yOffset != 0.0) {
int id = (yOffset > 0) ? 1 : -1;
queue.offer(new MouseAction(InputType.MOUSE_WHEEL.getInput(id), 1, getPosition()));
}
});
}
use of java.awt.event.MouseMotionListener in project airavata by apache.
the class GraphCanvas method initGUI.
/**
* Initializes the GUI.
*/
private void initGUI() {
this.panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
GraphCanvas.this.paintComponent((Graphics2D) g);
}
};
this.panel.setLayout(null);
// To make the background color visible.
this.panel.setOpaque(true);
this.panel.setBackground(new Color(255, 255, 255));
this.panel.setDoubleBuffered(true);
this.panel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
GraphCanvas.this.mouseClicked(event);
}
@Override
public void mousePressed(MouseEvent event) {
GraphCanvas.this.mousePressed(event);
}
@Override
public void mouseReleased(MouseEvent event) {
GraphCanvas.this.mouseReleased(event);
notifyListeners(new GraphCanvasEvent(GraphCanvasEvent.GraphCanvasEventType.WORKFLOW_CHANGED, GraphCanvas.this, GraphCanvas.this.workflow));
}
});
this.panel.addMouseMotionListener(new MouseMotionListener() {
public void mouseDragged(MouseEvent event) {
GraphCanvas.this.mouseDragged(event);
}
public void mouseMoved(MouseEvent event) {
GraphCanvas.this.mouseMoved(event);
}
});
this.panel.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
GraphCanvas.this.keyPressed(event);
}
@Override
public void keyReleased(KeyEvent event) {
GraphCanvas.this.keyReleased(event);
}
});
this.scrollPane = new JScrollPane(this.panel);
// Set up drag and drop
DropTargetListener dropTargetListener = new DropTargetAdapter() {
public void drop(DropTargetDropEvent event) {
GraphCanvas.this.drop(event);
}
};
new DropTarget(this.panel, DnDConstants.ACTION_COPY_OR_MOVE, dropTargetListener);
createPopupMenu();
}
use of java.awt.event.MouseMotionListener in project gate-core by GateNLP.
the class AnnotationEditor method initListeners.
protected void initListeners() {
// resize the window when the table changes.
featuresEditor.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
// the table has changed size -> resize the window too!
popupWindow.pack();
}
});
KeyAdapter keyAdapter = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
hideTimer.stop();
}
};
typeCombo.getEditor().getEditorComponent().addKeyListener(keyAdapter);
MouseListener windowMouseListener = new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent evt) {
hideTimer.stop();
}
// allow a JWindow to be dragged with a mouse
@Override
public void mousePressed(MouseEvent me) {
pressed = me;
}
};
MouseMotionListener windowMouseMotionListener = new MouseMotionAdapter() {
Point location;
// allow a JWindow to be dragged with a mouse
@Override
public void mouseDragged(MouseEvent me) {
location = popupWindow.getLocation(location);
int x = location.x - pressed.getX() + me.getX();
int y = location.y - pressed.getY() + me.getY();
popupWindow.setLocation(x, y);
pinnedButton.setSelected(true);
}
};
popupWindow.getRootPane().addMouseListener(windowMouseListener);
popupWindow.getRootPane().addMouseMotionListener(windowMouseMotionListener);
InputMap inputMap = ((JComponent) popupWindow.getContentPane()).getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
actionMap = ((JComponent) popupWindow.getContentPane()).getActionMap();
// add the key-action bindings of this Component to the parent window
solAction = new StartOffsetLeftAction("", MainFrame.getIcon("extend-left"), SOL_DESC, KeyEvent.VK_LEFT);
solButton.setAction(solAction);
setShortCuts(inputMap, SOL_KEY_STROKES, "solAction");
actionMap.put("solAction", solAction);
sorAction = new StartOffsetRightAction("", MainFrame.getIcon("extend-right"), SOR_DESC, KeyEvent.VK_RIGHT);
sorButton.setAction(sorAction);
setShortCuts(inputMap, SOR_KEY_STROKES, "sorAction");
actionMap.put("sorAction", sorAction);
delAction = new DeleteAnnotationAction("", MainFrame.getIcon("remove-annotation"), "Delete the annotation", KeyEvent.VK_DELETE);
delButton.setAction(delAction);
inputMap.put(KeyStroke.getKeyStroke("alt DELETE"), "delAction");
actionMap.put("delAction", delAction);
eolAction = new EndOffsetLeftAction("", MainFrame.getIcon("extend-left"), EOL_DESC, KeyEvent.VK_LEFT);
eolButton.setAction(eolAction);
setShortCuts(inputMap, EOL_KEY_STROKES, "eolAction");
actionMap.put("eolAction", eolAction);
eorAction = new EndOffsetRightAction("", MainFrame.getIcon("extend-right"), EOR_DESC, KeyEvent.VK_RIGHT);
eorButton.setAction(eorAction);
setShortCuts(inputMap, EOR_KEY_STROKES, "eorAction");
actionMap.put("eorAction", eorAction);
pinnedButton.setToolTipText("<html>Press to pin window in place" + " <font color=#667799><small>Ctrl-P" + " </small></font></html>");
inputMap.put(KeyStroke.getKeyStroke("control P"), "toggle pin");
actionMap.put("toggle pin", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
pinnedButton.doClick();
}
});
DismissAction dismissAction = new DismissAction("", null, "Close the window", KeyEvent.VK_ESCAPE);
dismissButton.setAction(dismissAction);
inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "dismissAction");
inputMap.put(KeyStroke.getKeyStroke("alt ESCAPE"), "dismissAction");
actionMap.put("dismissAction", dismissAction);
ApplyAction applyAction = new ApplyAction("Apply", null, "", KeyEvent.VK_ENTER);
inputMap.put(KeyStroke.getKeyStroke("alt ENTER"), "applyAction");
actionMap.put("applyAction", applyAction);
typeCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
String newType = typeCombo.getSelectedItem().toString();
if (ann == null || ann.getType().equals(newType))
return;
// annotation editing
Integer oldId = ann.getId();
Annotation oldAnn = ann;
set.remove(ann);
try {
set.add(oldId, oldAnn.getStartNode().getOffset(), oldAnn.getEndNode().getOffset(), newType, oldAnn.getFeatures());
Annotation newAnn = set.get(oldId);
// update the selection to the new annotation
getOwner().selectAnnotation(new AnnotationDataImpl(set, newAnn));
editAnnotation(newAnn, set);
owner.annotationChanged(newAnn, set, oldAnn.getType());
} catch (InvalidOffsetException ioe) {
throw new GateRuntimeException(ioe);
}
}
});
hideTimer = new Timer(HIDE_DELAY, new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
annotationEditorInstance.setVisible(false);
}
});
hideTimer.setRepeats(false);
AncestorListener textAncestorListener = new AncestorListener() {
@Override
public void ancestorAdded(AncestorEvent event) {
if (wasShowing) {
annotationEditorInstance.setVisible(true);
}
wasShowing = false;
}
@Override
public void ancestorRemoved(AncestorEvent event) {
if (isShowing()) {
wasShowing = true;
popupWindow.dispose();
}
}
@Override
public void ancestorMoved(AncestorEvent event) {
}
private boolean wasShowing = false;
};
owner.getTextComponent().addAncestorListener(textAncestorListener);
}
use of java.awt.event.MouseMotionListener in project GDSC-SMLM by aherbert.
the class ImageJ3DResultsViewer method createImage3DUniverse.
/**
* Creates the image 3D universe with a unique name.
*
* @param title the title
* @param titleList the title list (of titles to ignore)
* @return the image 3D universe
*/
private Image3DUniverse createImage3DUniverse(String title, List<String> titleList) {
// Get a unique name by appending numbers to the end
String title2 = title;
int counter = 2;
while (titleList.contains(title2)) {
title2 = title + " " + (counter++);
}
final Image3DUniverse universe = new Image3DUniverse();
universe.addUniverseListener(new LocalUniverseListener());
universe.setShowBoundingBoxUponSelection(false);
universe.showAttribute(DefaultUniverse.ATTRIBUTE_SCALEBAR, false);
// Capture a canvas mouse click/region and identify the coordinates.
final ImageCanvas3D canvas = (ImageCanvas3D) universe.getCanvas();
final BranchGroup scene = universe.getScene();
final MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent event) {
if (!consumeEvent(event)) {
return;
}
// Consume the event
event.consume();
// This finds the vertex indices of the rendered object.
final Pair<Content, IntersectionInfo> pair = getPickedContent(canvas, scene, event.getX(), event.getY());
if (pair == null) {
// Do the same as the mouseClicked in Image3DUniverse
universe.select(null);
return;
}
// Only process content added from localisations
final Content c = pair.getKey();
if (!(c.getUserData() instanceof ResultsMetaData)) {
// Do the same as the mouseClicked in Image3DUniverse
universe.select(c);
return;
}
final ResultsMetaData data = (ResultsMetaData) c.getUserData();
final MemoryPeakResults results = data.results;
// Look up the localisation from the clicked vertex
final ContentInstant content = c.getCurrent();
int index = -1;
if (content.getContent() instanceof CustomMeshNode) {
final CustomMeshNode node = (CustomMeshNode) content.getContent();
final CustomMesh mesh = node.getMesh();
int vertexCount;
final GeometryArray ga = (GeometryArray) mesh.getGeometry();
// Default to the number of vertices
vertexCount = ga.getValidVertexCount();
final int countPerLocalisation = vertexCount / results.size();
// Determine the localisation
final int vertexIndex = pair.getValue().getVertexIndices()[0];
index = vertexIndex / countPerLocalisation;
} else if (content.getContent() instanceof ItemGroupNode) {
// All shapes have the index as the user data
final Object o = pair.getValue().getGeometry().getUserData();
if (o instanceof Integer) {
index = (Integer) pair.getValue().getGeometry().getUserData();
}
}
if (index == -1) {
return;
}
final PeakResult result = results.get(index);
if (event.getClickCount() > 1) {
// Centre on the localisation
final Point3d coordinate = new Point3d();
coordinate.set(data.points.get(index));
// Handle the local transform of the content ...
final Transform3D vWorldToLocal = getVworldToLocal(content);
vWorldToLocal.transform(coordinate);
universe.centerAt(coordinate);
} else if (event.isShiftDown()) {
// Ctrl+Shift held down to remove selected
data.removeFromSelectionModel(result);
} else {
// Ctrl held down to set selection
data.addToSelectionModel(result);
}
}
private boolean consumeEvent(final MouseEvent event) {
if (event.isConsumed() || event.getButton() != MouseEvent.BUTTON1 || !(event.isControlDown())) {
return false;
}
if (event.getClickCount() == 1) {
return true;
}
return (event.getClickCount() == 2);
}
};
// 0 = ImageCanvas3D
// 1 = DefaultUniverse
// 2 = Image3DUniverse
final MouseListener[] l = canvas.getMouseListeners();
for (int i = 0; i < l.length; i++) {
if (l[i].getClass().getName().contains("Image3DUniverse")) {
// We want to be before the Image3DUniverse to allow consuming the click event.
// Only allow the click event.
// This disables the right-click pop-up menu.
// It doesn't have anything of use for localisations anyway.
canvas.removeMouseListener(l[i]);
canvas.addMouseListener(mouseListener);
canvas.addMouseListener(new MouseListenerWrapper(l[i], MouseListenerWrapper.MOUSE_CLICKED));
}
}
// 0 = ImageCanvas3D
// 1 = DefaultUniverse
// 2 = Image3DUniverse
// 3 = EventCatcher (from scijava)
final MouseMotionListener[] ml = canvas.getMouseMotionListeners();
for (int i = 0; i < ml.length; i++) {
if (ml[i].getClass().getName().contains("Image3DUniverse")) {
// Ignore this as it just shows the name in the IJ status bar
canvas.removeMouseMotionListener(ml[i]);
}
}
// Finally display the window
universe.show();
final ImageWindow3D window = universe.getWindow();
GUI.center(window);
window.setTitle(title2);
WindowManager.addWindow(window);
window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent event) {
WindowManager.removeWindow(window);
}
});
// Add a new menu for SMLM functionality
createSmlmMenuBar(universe);
return universe;
}
use of java.awt.event.MouseMotionListener in project archi by archimatetool.
the class SimpleSwingExample method createMainPanel.
private void createMainPanel() {
// see below for class definition
mainPanel = new MainPanel();
mainPanel.setPreferredSize(new Dimension(INITIAL_PANEL_WIDTH, INITIAL_PANEL_HEIGHT));
mainPanel.setBackground(Color.WHITE);
mainPanel.setLayout(null);
mainFrame.getContentPane().add(new JScrollPane(mainPanel), BorderLayout.CENTER);
mainPanel.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
selectedEntity = null;
for (Iterator iter = entities.iterator(); iter.hasNext() && selectedEntity == null; ) {
SimpleNode entity = (SimpleNode) iter.next();
double x = entity.getX();
double y = entity.getY();
double w = entity.getWidth();
double h = entity.getHeight();
Rectangle2D.Double rect = new Rectangle2D.Double(x, y, w, h);
if (rect.contains(e.getX(), e.getY())) {
selectedEntity = entity;
}
}
if (selectedEntity != null) {
mouseDownPoint = e.getPoint();
selectedEntityPositionAtMouseDown = new Point((int) selectedEntity.getX(), (int) selectedEntity.getY());
} else {
mouseDownPoint = null;
selectedEntityPositionAtMouseDown = null;
}
updateGUI();
}
@Override
public void mouseReleased(MouseEvent e) {
selectedEntity = null;
mouseDownPoint = null;
selectedEntityPositionAtMouseDown = null;
updateGUI();
}
});
mainPanel.addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e) {
// if (selectedEntity != null) {
// //TODO: Add mouse moving
// //selectedEntity.setLocationInLayout(selectedEntityPositionAtMouseDown.x + dx, selectedEntityPositionAtMouseDown.y + dy);
// updateGUI();
// }
}
@Override
public void mouseMoved(MouseEvent e) {
}
});
}
Aggregations