List of usage examples for java.awt.geom Point2D getX
public abstract double getX();
From source file:org.squidy.designer.shape.ZoomShape.java
/** * @param goalDirectedZoom//from www.j av a2 s . c om */ public ZoomShape(boolean goalDirectedZoom) { setBounds(Constants.DEFAULT_NODE_BOUNDS); if (goalDirectedZoom) { addInputEventListener(new PBasicInputEventHandler() { @Override public void mouseClicked(PInputEvent event) { if (!event.isHandled() && event.isLeftMouseButton() && event.getClickCount() == 2) { PNode store = event.getPickedNode(); while (store != null && !(store instanceof IModelStore)) { store = store.getParent(); } PNode node = event.getPickedNode(); while (node != null && !(node instanceof ZoomShape<?>)) { node = node.getParent(); } if (node instanceof ZoomShape<?>) { // if (LOG.isDebugEnabled()) { // LOG.debug("Selected node to zoom is " + node + " and this is " + ZoomShape.this); // } node.moveToFront(); // PBounds boundsView = event.getCamera() // .getViewBounds(); // PBounds boundsNode = ((ZoomShape<?>) node) // .getGlobalBoundsZoomedIn(); // boolean sameNode = (Math.abs(boundsView.x // - boundsNode.x) < 0.1 && Math // .abs(boundsView.width - boundsNode.width) < 0.1) // || (Math.abs(boundsView.y - boundsNode.y) < 0.1 && Math // .abs(boundsView.height // - boundsNode.height) < 0.1); // // if (!sameNode) { if (store != null) { ((IModelStore) store).getModel().setZoomedShape((ZoomShape<?>) node); ((IModelStore) store).getModel().setZoomedBounds(getGlobalBoundsZoomedIn()); } animateToCenterView(event.getCamera()); // } event.setHandled(true); } } } }); } if (this instanceof Draggable) { addInputEventListener(new PDragEventHandler() { private PNode draggable; /* * (non-Javadoc) * * @seeedu.umd.cs.piccolo.event.PDragEventHandler# * shouldStartDragInteraction * (edu.umd.cs.piccolo.event.PInputEvent) */ @Override protected boolean shouldStartDragInteraction(PInputEvent event) { if (!event.isHandled()) { PNode node = event.getPickedNode(); while (node != null && !(node instanceof Draggable)) { node = node.getParent(); } // Set dragged node to allow drag transformation. draggable = node; if (node instanceof Draggable) { if (((Draggable) node).isDraggable() && super.shouldStartDragInteraction(event)) { return true; } } return false; } return false; } /* * (non-Javadoc) * * @see * edu.umd.cs.piccolo.event.PDragEventHandler#drag(edu.umd.cs * .piccolo .event.PInputEvent) */ @Override protected void drag(PInputEvent event) { if (!event.isHandled()) { if (!event.getPath().acceptsNode(draggable)) { if (LOG.isDebugEnabled()) { LOG.debug("Pick path doesn't accept node " + draggable.getClass().getName() + "."); } return; } PNode parent = draggable.getParent(); PDimension d = event.getDeltaRelativeTo(draggable); draggable.localToParent(d); PBounds parentBounds = parent.getBoundsReference(); Rectangle2D draggableBounds = draggable .localToParent(draggable.getBounds().moveBy(d.getWidth(), d.getHeight())); if (parentBounds.contains(draggableBounds)) { draggable.offset(d.getWidth(), d.getHeight()); } Point2D offset = draggable.getOffset(); if (offset.getX() < 0) { draggable.setOffset(0, offset.getY()); } if (offset.getY() < 0) { draggable.setOffset(offset.getX(), 0); } if (offset.getX() > parentBounds.getWidth() - draggableBounds.getWidth()) { draggable.setOffset(parentBounds.getWidth() - draggableBounds.getWidth(), offset.getY()); } if (offset.getY() > parentBounds.getHeight() - draggableBounds.getHeight()) { draggable.setOffset(offset.getX(), parentBounds.getHeight() - draggableBounds.getHeight()); } event.setHandled(true); } // if (!event.isHandled()) { // if (!event.getPath().acceptsNode(draggable)) { // if (LOG.isDebugEnabled()) { // LOG.debug("Pick path doesn't accept node " + // draggable.getClass().getName() + "."); // } // return; // } // // Point2D current = // event.getPositionRelativeTo(ZoomShape.this); // draggable.localToParent(current); // // Point2D dest = new Point2D.Double(); // // dest.setLocation((current.getX()), (current.getY())); // // dest.setLocation(dest.getX() - (dest.getX() % 20), // dest.getY() - (dest.getY() % 20)); // // // dest.setLocation(nodeStartPosition.getX() - (d.getX() // % 20), nodeStartPosition.getY() - (d.getY() % 20)); // // System.out.println("OFFSET: " + dest); // // draggable.setOffset(dest.getX(), dest.getY()); // // // } // event.setHandled(true); // } } }); } MultiSelectionHandler multiSelectionHandler = new MultiSelectionHandler() { /* (non-Javadoc) * @see org.squidy.designer.event.MultiSelectionHandler#selectionAllowed(edu.umd.cs.piccolo.event.PInputEvent) */ @Override protected boolean selectionAllowed(PInputEvent event) { PNode node = event.getPickedNode(); return node instanceof Draggable && !((Draggable) node).isDraggable(); } /* * (non-Javadoc) * * @see * org.squidy.designer.event.MultiSelectionHandler#startSelection * (edu.umd.cs.piccolo.event.PInputEvent, java.awt.Shape) */ @Override public void startSelection(PInputEvent event, Shape selectionShape) { if (!event.isHandled()) { multiSelection = selectionShape; event.setHandled(true); invalidatePaint(); } } /* * (non-Javadoc) * * @see * org.squidy.designer.event.MultiSelectionHandler#selection * (edu.umd.cs.piccolo.event.PInputEvent, java.awt.Shape) */ @Override public void selection(PInputEvent event, Shape selectionShape) { if (!event.isHandled()) { multiSelection = selectionShape; event.setHandled(true); invalidatePaint(); } } /* * (non-Javadoc) * * @see * org.squidy.designer.event.MultiSelectionHandler#endSelection * (edu.umd.cs.piccolo.event.PInputEvent, java.awt.Shape) */ @Override public void endSelection(PInputEvent event, Shape selectionShape) { if (!event.isHandled()) { multiSelection = null; for (Object o : getChildrenReference()) { if (o instanceof VisualShape<?>) { VisualShape<?> shape = (VisualShape<?>) o; PBounds bounds = shape.getGlobalFullBounds(); if (selectionShape.contains(bounds)) { System.out.println("containing: " + shape); } } } event.setHandled(true); invalidatePaint(); } } }; // addInputEventListener(multiSelectionHandler); // Add knowledge base to zoom object if class is of type // <code>KnowledgeBased</code>. if (this instanceof NodeBased<?>) { boolean isWorkspace = this instanceof WorkspaceShape; knowledgeBase = new AdvancedKnowledgeBase<ZoomShape<VisualShape<?>>>(isWorkspace); addChild(knowledgeBase); knowledgeBase.setOffset(0, 895); } }
From source file:lu.lippmann.cdb.graph.GraphViewImpl.java
/** * FIXME : faulty center method// w w w .j ava 2 s .c o m * @param panelWidth * @param panelHeigth * @param ratioPanel * @param center */ private void doFitGraphToSubPanel(double panelWidth, double panelHeigth, final double ratioPanel, Point2D center) { while (isLayoutChanging) { System.out.println("Waiting layout to finish !"); try { Thread.sleep(100); } catch (InterruptedException e) { } } vv.setPreferredSize(new Dimension((int) panelWidth, (int) panelHeigth)); vv.setMinimumSize(new Dimension((int) panelWidth, (int) panelHeigth)); vv.setMaximumSize(new Dimension((int) panelWidth, (int) panelHeigth)); double minX = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, minY = Integer.MAX_VALUE, maxY = Integer.MIN_VALUE; final MutableTransformer viewTransformer = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.VIEW); //final MutableTransformer layoutTransformer = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT); //Reset graph layout (zoom level & translation) resetLayout(); final Graph<CNode, CEdge> graph = vv.getModel().getGraphLayout().getGraph(); if (graph.getVertices().size() == 0) { return; } else if (graph.getVertices().size() == 1) { final CNode n = graph.getVertices().iterator().next(); final Point2D point = vv.getModel().getGraphLayout().transform(n); //center of the node minX = point.getX(); maxX = point.getX(); minY = point.getY(); maxY = point.getY(); } else { for (final CNode n : graph.getVertices()) { final Point2D point = vv.getModel().getGraphLayout().transform(n); //center of the node double nodeMinX = point.getX() - (n.getShape().getWidth() / 2); double nodeMaxX = point.getX() + (n.getShape().getWidth() / 2); double nodeMinY = point.getY() - (n.getShape().getHeight() / 2); double nodeMaxY = point.getY() + (n.getShape().getHeight() / 2); if (nodeMinX < minX) { minX = nodeMinX; } if (nodeMaxX > maxX) { maxX = nodeMaxX; } if (nodeMinY < minY) { minY = nodeMinY; } if (nodeMaxY > maxY) { maxY = nodeMaxY; } } } final int graphWidth = (int) (maxX - minX); final int graphHeigth = (int) (maxY - minY); //System.out.println("Graph heigth : " + graphHeigth); //System.out.println("Graph graphWidth : " + graphWidth); final double scale1 = ratioPanel / 100.0d * panelWidth / graphWidth; final double scale2 = panelHeigth / graphHeigth; final double ratio = Math.min(Math.min(scale1, scale2), 1.0f); //offset margin //System.out.println("Ratio used : " + ratio); viewTransformer.scale(ratio, ratio, center); viewTransformer.translate(((panelWidth * ratioPanel / 100.0f - graphWidth * ratio) / 2.0f) / ratio - minX, ((panelHeigth - graphHeigth * ratio) / 2.0f) / ratio - minY); }
From source file:com.diversityarrays.kdxplore.scatterplot.ScatterPlotPanel.java
@SuppressWarnings("unchecked") public void redrawSelectedPlots() { if (syncedOption.getSyncWhat().isSync() && !getSelectionChanging()) { XYPlot xyplot = getChart().getXYPlot(); // curationControls.setSyncedState(true); Double yscale = (xyplot.getRangeAxis().getUpperBound() - xyplot.getRangeAxis().getLowerBound()) / 50; Double xscale = (xyplot.getDomainAxis().getUpperBound() - xyplot.getDomainAxis().getLowerBound()) / 50; Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3 }, 0);// w ww . j a v a2s . c om Paint paint = Color.RED; for (Annotation anno : (List<Annotation>) xyplot.getAnnotations()) { if (anno != intervalAnnotation && anno instanceof XYShapeAnnotation) { xyplot.removeAnnotation((XYShapeAnnotation) anno); } } for (Point2D point : selectedPoints) { double x = point.getX(); double y = point.getY(); double y1 = y - yscale; double y2 = y + yscale; double x1 = x - xscale; double x2 = x + xscale; Ellipse2D oval = new Ellipse2D.Double(x1, y1, x2 - x1, y2 - y1); XYShapeAnnotation lineanno0 = new XYShapeAnnotation(oval, stroke, paint); addRangeMarker(lineanno0); } } curationControls.updateButtons(); }
From source file:org.jax.maanova.test.gui.VolcanoPlotPanel.java
private void mouseMoved(MouseEvent e) { if (this.showTooltip) { Point2D chartPoint = this.chartPanel.toChartPoint(e.getPoint()); // find the nearest probe XYProbeData xyProbeData = this.getXYData(); double[][] xyData = new double[][] { xyProbeData.getXData(), xyProbeData.getYData() }; int nearestDotIndex = PlotUtil.getNearestDataIndex(xyData, chartPoint.getX(), chartPoint.getY()); if (nearestDotIndex == -1) { this.clearProbePopup(); } else {/*from ww w . j a v a 2s . co m*/ Point2D probeJava2DCoord = this.getJava2DCoordinates(xyData, nearestDotIndex); double java2DDist = probeJava2DCoord.distance(e.getX(), e.getY()); // is the probe close enough to be worth showing (in pixel distance) if (java2DDist <= PlotUtil.SCATTER_PLOT_DOT_SIZE_PIXELS * 2) { this.showProbePopup(xyProbeData.getProbeIndices()[nearestDotIndex], e.getX(), e.getY()); } else { this.clearProbePopup(); } } } }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
public Peak findPeakAt(Point2D p) { if (theDocument.size() > 0) { Point2D dp = screenToDataCoords(p); double mz_toll = screenToDataX(3.); double int_toll = screenToDataY(3.); return findNearestPeak(dp.getX(), dp.getY(), mz_toll, int_toll); }/*from w w w . jav a 2 s . c o m*/ return null; }
From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java
@Override public void paint(Graphics2D g, StateRenderer2D renderer) { double radius = isActive() ? 6 : 2.5; for (AssetTrack track : assets.values()) { List<AssetPosition> positions = track.getTrack(); Point2D lastLoc = null;//w w w . j av a 2 s . c o m long lastAge = 0; for (AssetPosition p : positions) { if (hiddenPosTypes.contains(p.getType())) continue; if (p.getTimestamp() < oldestTimestampSelection || p.getTimestamp() > newestTimestampSelection) continue; //if (p.getAge() >= maxAge * 3600 * 1000) // continue; Point2D pt = renderer.getScreenPosition(p.getLoc()); if (assetProperties.containsKey(track.getAssetName())) g.setColor(assetProperties.get(track.getAssetName()).color); else g.setColor(track.getColor()); if (lastLoc != null && lastLoc.distance(pt) < 20000) { g.draw(new Line2D.Double(lastLoc, pt)); } g.fill(new Ellipse2D.Double(pt.getX() - radius, pt.getY() - radius, radius * 2, radius * 2)); lastLoc = pt; lastAge = p.getAge(); } g.setStroke(new BasicStroke(2.0f)); if (lastLoc != null) { Color c = cmap2.getColor(1 - (lastAge / (7200000.0))); g.setColor(c); g.setStroke(new BasicStroke(2.0f)); g.draw(new Ellipse2D.Double(lastLoc.getX() - radius - 1.5, lastLoc.getY() - radius - 1.5, radius * 2 + 3, radius * 2 + 3)); } } if (paintLabels) paintLabels(g, renderer); if (paintIcons) paintIcons(g, renderer); }
From source file:edu.uci.ics.jung.algorithms.layout.SpringLayout2.java
@Override protected void moveNodes() { synchronized (getSize()) { try {//w w w .j a v a 2s.c o m for (V v : getGraph().getVertices()) { if (isLocked(v)) continue; SpringVertexData vd = springVertexData.get(v); if (vd == null) continue; Point2D xyd = transform(v); vd.dx += vd.repulsiondx + vd.edgedx; vd.dy += vd.repulsiondy + vd.edgedy; // int currentCount = currentIteration % this.loopCountMax; // System.err.println(averageCounter+" --- vd.dx="+vd.dx+", vd.dy="+vd.dy); // System.err.println("averageDelta was "+averageDelta); averageDelta.setLocation( ((averageDelta.getX() * averageCounter) + vd.dx) / (averageCounter + 1), ((averageDelta.getY() * averageCounter) + vd.dy) / (averageCounter + 1)); // System.err.println("averageDelta now "+averageDelta); // System.err.println(); averageCounter++; // keeps nodes from moving any faster than 5 per time unit xyd.setLocation(xyd.getX() + Math.max(-5, Math.min(5, vd.dx)), xyd.getY() + Math.max(-5, Math.min(5, vd.dy))); Dimension d = getSize(); int width = d.width; int height = d.height; if (xyd.getX() < 0) { xyd.setLocation(0, xyd.getY());// setX(0); } else if (xyd.getX() > width) { xyd.setLocation(width, xyd.getY()); //setX(width); } if (xyd.getY() < 0) { xyd.setLocation(xyd.getX(), 0);//setY(0); } else if (xyd.getY() > height) { xyd.setLocation(xyd.getX(), height); //setY(height); } } } catch (ConcurrentModificationException cme) { moveNodes(); } } }
From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java
public void Animator(String vertex) { Layout<String, String> layout = vv.getGraphLayout(); Point2D q = layout.transform(vertex); Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter()); final double dx = (lvc.getX() - q.getX()) / 10; final double dy = (lvc.getY() - q.getY()) / 10; Runnable animator = new Runnable() { public void run() { for (int i = 0; i < 10; i++) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(dx, dy); try { Thread.sleep(100); } catch (InterruptedException ex) { }/*www . j a v a 2s. c o m*/ } } }; Thread thread = new Thread(animator); thread.start(); }
From source file:org.graphwalker.GUI.App.java
private void centerOnVertex() { Vertex v = mbt.getCurrentVertex();// w w w . j a v a 2s. c om if (v != null) { Point2D target = getVv().getGraphLayout().transform(v); Point2D current = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter()); double dx = current.getX() - target.getX(); double dy = current.getY() - target.getY(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(dx, dy); } }
From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java
public void EdgeAnimator(Pair edge) { Layout<String, String> layout = vv.getGraphLayout(); String first = (String) edge.getFirst(); String second = (String) edge.getSecond(); Point2D q = layout.transform(first); Point2D y = layout.transform(second); Line2D line = new Line2D.Double(q.getX(), q.getY(), y.getX(), y.getY()); Point2D lvc = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(vv.getCenter()); final double dx = (lvc.getX() - line.getBounds().getCenterX()) / 10; final double dy = (lvc.getY() - line.getBounds().getCenterY()) / 10; Runnable edgeAnimator = new Runnable() { public void run() { for (int i = 0; i < 10; i++) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(dx, dy); try { Thread.sleep(100); } catch (InterruptedException ex) { }/*from w w w . ja v a 2 s . co m*/ } } }; Thread thread = new Thread(edgeAnimator); thread.start(); }