private void initializeCanvas() { panel.setSize(50 + 1 + graphWidth + "px", 25 + graphHeight + "px"); canvas.setWidth(graphWidth); canvas.setHeight(graphHeight); canvas.getElement().getStyle().setPropertyPx("width", graphWidth); canvas.getElement().getStyle().setPropertyPx("height", graphHeight); }
private void paintGraph() { selectionBox.setSelectionBoxVisible(false); fps = 1f / ((System.currentTimeMillis() - paintStartTime) / 1000f); paintStartTime = System.currentTimeMillis(); if (showInfo) { if (info != null) { canvas.remove(info); } canvas.add(info = getInfo()); } }
private void removeLinkLine() { if (linkLine != null) { canvas.remove(linkLine); linkLine = null; } onLink = false; }
private void removeSelectionBox() { if (selectionBox.isSelectionBoxVisible()) { canvas.remove(selectionBox); selectionBox.setSelectionBoxVisible(false); VConsole.log("selection box removed from canvas"); selectionBox.setSelectionBoxRightHandSide(true); } }
@Override public void onMouseMove(final MouseMoveEvent event) { final int currentX = event.getX(); final int currentY = event.getY(); if (selectionBox.isSelectionBoxVisible()) { selectionBox.drawSelectionBox(canvas, currentX, currentY); } else if (graph.getMovedShape() != null) { final VNode moved = graph.getMovedShape(); moved.moveNode(currentX, currentY); } else if (onLink) { if (linkLine != null) { canvas.remove(linkLine); } linkLine = getLinkLine(currentX, currentY); canvas.add(linkLine); } else if (onMove && event.getSource().equals(canvas)) { graph.moveGraph(startX - currentX, startY - currentY); startX = currentX; startY = currentY; } }
private VectorObject getInfo() { final NumberFormat df = NumberFormat.getDecimalFormat(); final String zoom = df.format(zoomFactor); final String angl = df.format(angle); final String fpss = df.format(fps); final Text info = new Text(canvas.getWidth() - 130, 10, "Zoom: " + zoom + " Rot.: " + angl + " Fps " + fpss); info.setStrokeOpacity(0); info.setFillColor(style.getEdgeColor()); info.setFontSize(8); return info; }
/** * The constructor should first call super() to initialize the component and then handle any * initialization relevant to Vaadin. */ public VCytographer() { panel = new FocusPanel(); panel.setSize(graphWidth + "px", graphHeight + "px"); panel.addKeyDownHandler(this); panel.addKeyUpHandler(this); canvas = new VFocusDrawingArea(this, graphWidth, graphHeight); canvas.addKeyDownHandler(this); canvas.addKeyUpHandler(this); canvas.addMouseMoveHandler(this); canvas.addDoubleClickHandler(this); canvas.addMouseUpHandler(this); canvas.addMouseDownHandler(this); canvas.addClickHandler(this); canvas.addMouseWheelHandler(this); graph = new VGraph(this, style, canvas, graphWidth, graphHeight); panel.add(canvas); canvas.add(graph); initWidget(panel); setStyleName(CLASSNAME); DOM.setStyleAttribute(canvas.getElement(), "border", "1px solid black"); disableContextMenu(canvas.getElement()); }