private void mouseMove(GwtEvent<? extends EventHandler> event) { int[] coord = getCoordinates(event); int x = coord[0]; int y = coord[1]; if (isMouseDown) { // Do panning int dx = x - previousX; int dy = y - previousY; if (draggableNode != null) { WidgetStyle.setCursor(canvas, Cursor.POINTER); double scale = canvas.getScale(); int scaleDeltaX = (int) (dx / scale); int scaleDeltaY = (int) (dy / scale); diagramPane.drag(draggableNode, scaleDeltaX, scaleDeltaY); } else { WidgetStyle.setCursor(canvas, Cursor.DEFAULT); diagramPane.translate(dx, dy); diagramPane.update(); } previousX = x; previousY = y; isDragging = true; } else { diagramPane.hover(x, y); } }
private void hiliteAndCentreObjects(SelectionEvent e) { if (canvas.getObjectsForRendering() == null) return; // Un-hilight objects first for (GraphObject obj : canvas.getObjectsForRendering()) { obj.setHighlighted(false); } // Highlight the selected object and connected objects List<GraphObject> selectedObjects = e.getSelectedObjects(); for (GraphObject obj : selectedObjects) { if (obj instanceof Node) { Node node = (Node) obj; List<HyperEdge> reactions = node.getConnectedReactions(); for (HyperEdge edge : reactions) edge.setHighlighted(true); } else if (obj instanceof HyperEdge) { HyperEdge edge = (HyperEdge) obj; List<Node> nodes = edge.getConnectedNodes(); for (Node node : nodes) node.setHighlighted(true); } if (e.isDoCentring()) { centreObject(obj); } } diagramPane.update(); }
private void arrowKeyUp(KeyUpEvent event) { if (!diagramPane.getPopupMenu().isShowing()) { int x = 0; int y = 0; if (event.isLeftArrow()) { x = Parameters.MOVEX; } else if (event.isRightArrow()) { x = -Parameters.MOVEX; } else if (event.isUpArrow()) { y = Parameters.MOVEY; } else if (event.isDownArrow()) { y = -Parameters.MOVEY; } diagramPane.translate(x, y); diagramPane.update(); } }
private void mouseWheel(MouseWheelEvent event) { if (diagramPane.getPopupMenu().isShowing() || ignoreMouseWheelEvent) return; Timer stopIgnoringEventTimer = new Timer() { @Override public void run() { ignoreMouseWheelEvent = false; } }; ignoreMouseWheelEvent = true; stopIgnoringEventTimer.schedule(250); Point scrollPoint = new Point(event.getX(), event.getY()); if (event.getDeltaY() < 0) { diagramPane.zoomIn(scrollPoint); } else if (event.getDeltaY() > 0) { diagramPane.zoomOut(scrollPoint); } diagramPane.update(); }