List of usage examples for java.awt.geom Point2D getY
public abstract double getY();
From source file:net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffHandler.java
/** * Handle PRESSED, DRAGGED, RELEASED events to generate drag diff events * /*from w w w . ja v a 2s . c o m*/ * @return */ private Consumer<ChartGestureEvent> createConsumer() { return new Consumer<ChartGestureEvent>() { // variables boolean wasMouseZoomable = false; Point2D last = null, first = null; ChartGestureEvent startEvent = null, lastEvent = null; @Override public void accept(ChartGestureEvent event) { ChartViewWrapper chartPanel = event.getChartWrapper(); JFreeChart chart = chartPanel.getChart(); MouseEventWrapper e = event.getMouseEvent(); // released? if (event.checkEvent(Event.RELEASED)) { chartPanel.setMouseZoomable(wasMouseZoomable); last = null; } else if (event.checkEvent(Event.PRESSED)) { // get data space coordinates last = chartPanel.mouseXYToPlotXY(e.getX(), e.getY()); first = last; startEvent = event; lastEvent = event; if (last != null) { wasMouseZoomable = chartPanel.isMouseZoomable(); chartPanel.setMouseZoomable(false); } } else if (event.checkEvent(Event.DRAGGED)) { if (last != null) { // get data space coordinates Point2D released = chartPanel.mouseXYToPlotXY(e.getX(), e.getY()); if (released != null) { double offset = 0; double start = 0; // scroll x if (getOrientation(event).equals(Orientation.HORIZONTAL)) { offset = -(released.getX() - last.getX()); start = first.getX(); } // scroll y else { offset = -(released.getY() - last.getY()); start = first.getY(); } // new dragdiff event ChartGestureDragDiffEvent dragEvent = new ChartGestureDragDiffEvent(startEvent, lastEvent, event, start, offset, orient); // scroll / zoom / do anything with this new event // choose handler by key filter for (int i = 0; i < dragDiffHandler.length; i++) if (key[i].filter(event.getMouseEvent())) dragDiffHandler[i].accept(dragEvent); // set last event lastEvent = event; // save updated last last = chartPanel.mouseXYToPlotXY(e.getX(), e.getY()); } } } } }; }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationCalibrationPanel.java
public Point2D screenToDataCoords(Point2D p) { Rectangle2D data_area = theChartPanel.getScreenDataArea(); double x = thePlot.getDomainAxis().java2DToValue(p.getX(), data_area, thePlot.getDomainAxisEdge()); double y = thePlot.getRangeAxis().java2DToValue(p.getY(), data_area, thePlot.getRangeAxisEdge()); return new Point2D.Double(x, y); }
From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java
@Override public void paintInteraction(Graphics2D g, StateRenderer2D source) { super.paintInteraction(g, source); g.setStroke(new BasicStroke(1f)); paint(g, source);/*from ww w . j a v a 2 s . c o m*/ AssetPosition pivot = intercepted; if (pivot != null) { Point2D pt = source.getScreenPosition(pivot.getLoc()); g.setColor(Color.white); g.draw(new Ellipse2D.Double(pt.getX() - 6, pt.getY() - 6, 12, 12)); if (assetProperties.containsKey(pivot.getAssetName())) pivot.putExtra("Description", assetProperties.get(pivot.getAssetName()).description); if (assetProperties.containsKey(pivot.getAssetName())) pivot.putExtra("Friendly name", assetProperties.get(pivot.getAssetName()).friendly); lbl.setOpaque(true); lbl.setBackground(new Color(255, 255, 255, 128)); lbl.setText(pivot.getHtml()); Dimension d = lbl.getPreferredSize(); lbl.setSize(d); Graphics copy = g.create(); copy.translate(10, 10); lbl.paint(copy); } for (AssetTrack t : assets.values()) { AssetPosition prev = t.getLatest(); AssetPosition pred = t.getPrediction(); if (prev != null && pred != null) { if (prev.getTimestamp() < oldestTimestampSelection || prev.getTimestamp() > newestTimestampSelection) continue; g.setColor(new Color(t.getColor().getRed(), t.getColor().getGreen(), t.getColor().getBlue(), 128)); Point2D pt1 = source.getScreenPosition(prev.getLoc()); Point2D pt2 = source.getScreenPosition(pred.getLoc()); if (pt1.distance(pt2) < 1000) g.draw(new Line2D.Double(pt1, pt2)); } } }
From source file:com.github.lucapino.sheetmaker.renderer.JavaTemplateRenderer.java
public void drawString(Graphics g, String text, RectangularShape bounds, Align align, double angle, boolean multiline) { Graphics2D g2 = (Graphics2D) g; Font font = g2.getFont();/*from w w w . jav a2 s . c o m*/ if (angle != 0) { g2.setFont(font.deriveFont(AffineTransform.getRotateInstance(Math.toRadians(angle)))); } Rectangle2D sSize = g2.getFontMetrics().getStringBounds(text, g2); Point2D pos = getPoint(bounds, align); double x = pos.getX(); double y = pos.getY() + sSize.getHeight(); switch (align) { case TopCenter: case BottomCenter: case Center: x -= (sSize.getWidth() / 2); break; case TopRight: case MiddleRight: case BottomRight: x -= (sSize.getWidth()); break; case BottomLeft: case MiddleLeft: case TopLeft: break; } if (multiline) { // Create a new LineBreakMeasurer from the paragraph. // It will be cached and re-used. //if (lineMeasurer == null) { AttributedCharacterIterator paragraph = new AttributedString(text).getIterator(); paragraphStart = paragraph.getBeginIndex(); paragraphEnd = paragraph.getEndIndex(); FontRenderContext frc = g2.getFontRenderContext(); lineMeasurer = new LineBreakMeasurer(paragraph, frc); //} // Set break width to width of Component. float breakWidth = (float) bounds.getWidth(); float drawPosY = (float) y; // Set position to the index of the first character in the paragraph. lineMeasurer.setPosition(paragraphStart); // Get lines until the entire paragraph has been displayed. while (lineMeasurer.getPosition() < paragraphEnd) { // Retrieve next layout. A cleverer program would also cache // these layouts until the component is re-sized. TextLayout layout = lineMeasurer.nextLayout(breakWidth); // Compute pen x position. If the paragraph is right-to-left we // will align the TextLayouts to the right edge of the panel. // Note: this won't occur for the English text in this sample. // Note: drawPosX is always where the LEFT of the text is placed. float drawPosX = layout.isLeftToRight() ? (float) x : (float) x + breakWidth - layout.getAdvance(); // Move y-coordinate by the ascent of the layout. drawPosY += layout.getAscent(); // Draw the TextLayout at (drawPosX, drawPosY). layout.draw(g2, drawPosX, drawPosY); // Move y-coordinate in preparation for next layout. drawPosY += layout.getDescent() + layout.getLeading(); } } else { g2.drawString(text, (float) x, (float) y); } g2.setFont(font); }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * Method for calculating the minimum bounding rectangle for the given * tree layout/*w w w . j ava2 s . c o m*/ * @param treeLayout * the layout to calculate MBR for * @param rectangle * the rectangle up to now (should be null initially) * @return * the MBR */ private Rectangle2D.Double calculateBounds(VisualTreeNode treeLayout, Rectangle2D.Double rectangle) { Point2D position = treeLayout.getPosition(); if (rectangle == null) { rectangle = new Rectangle2D.Double(position.getX(), position.getY(), 0.0, 0.0); } else { if (position.getX() < rectangle.getMinX()) { double xDiff = rectangle.getMinX() - position.getX(); rectangle.x -= xDiff; rectangle.width += xDiff; } else if (position.getX() > rectangle.getMaxX()) { double xDiff = position.getX() - rectangle.getMaxX(); rectangle.width += xDiff; } if (position.getY() < rectangle.getMinY()) { double yDiff = rectangle.getMinY() - position.getY(); rectangle.y -= yDiff; rectangle.height += yDiff; } else if (position.getY() > rectangle.getMaxY()) { double yDiff = position.getY() - rectangle.getMaxY(); rectangle.height += yDiff; } } for (VisualTreeNode childNode : treeLayout.getChildNodes()) { rectangle = this.calculateBounds(childNode, rectangle); } return rectangle; }
From source file:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java
/** * Default constructor.// w ww. j av a2 s.c om * * @since 0.2.3 */ public JUNGCanvas(IVisualizationCallback callback, TopologyPanel topologyPanel) { this.callback = callback; transformNetPlanCoordinatesToJungCoordinates = vertex -> { final int vlIndex = this.callback.getVisualizationState() .getCanvasVisualizationOrderRemovingNonVisible(vertex.getLayer()); final double interLayerDistanceInNpCoord = currentInterLayerDistanceInNpCoordinates; final Point2D basePositionInNetPlanCoord = vertex.getAssociatedNetPlanNode().getXYPositionMap(); return new Point2D.Double(basePositionInNetPlanCoord.getX(), -(basePositionInNetPlanCoord.getY() + (vlIndex * interLayerDistanceInNpCoord))); }; g = new DirectedOrderedSparseMultigraph<>(); l = new StaticLayout<>(g, transformNetPlanCoordinatesToJungCoordinates); vv = new VisualizationViewer<>(l); osmStateManager = new OSMStateManager(callback, topologyPanel, this); originalEdgeShapeTransformer = new EdgeShape.QuadCurve<>(); ((EdgeShape.QuadCurve<GUINode, GUILink>) originalEdgeShapeTransformer).setControlOffsetIncrement(10); // how much they separate from the direct line (default is 20) //((EdgeShape.QuadCurve<GUINode, GUILink>) originalEdgeShapeTransformer).setEdgeIndexFunction(DefaultParallelEdgeIndexFunction.<GUINode, GUILink>getInstance()); // how much they separate from the direct line (default is 20) /* This functions gives an index to the links to show separate (curved): the order among the parallel links (BUT NOW only among the separated ones among them) */ ((EdgeShape.QuadCurve<GUINode, GUILink>) originalEdgeShapeTransformer) .setEdgeIndexFunction(new EdgeIndexFunction<GUINode, GUILink>() { public void reset(Graph<GUINode, GUILink> graph, GUILink e) { } public void reset() { } public int getIndex(Graph<GUINode, GUILink> graph, GUILink e) { final GUINode u = e.getOriginNode(); final GUINode v = e.getDestinationNode(); final HashSet<GUILink> commonEdgeSet = new HashSet<>(graph.getInEdges(v)); commonEdgeSet.retainAll(graph.getOutEdges(u)); commonEdgeSet.removeIf(ee -> !ee.isShownSeparated()); int count = 0; for (GUILink other : commonEdgeSet) if (other == e) return count; else count++; throw new RuntimeException(); } }); /* Customize the graph */ vv.getRenderContext().setVertexDrawPaintTransformer(n -> n.getDrawPaint()); vv.getRenderContext().setVertexFillPaintTransformer(n -> n.getFillPaint()); vv.getRenderContext().setVertexFontTransformer(n -> n.getFont()); vv.getRenderContext().setVertexIconTransformer(gn -> gn.getIcon()); vv.getRenderContext().setVertexIncludePredicate( guiNodeContext -> callback.getVisualizationState().isVisibleInCanvas(guiNodeContext.element)); vv.getRenderer().setVertexLabelRenderer(new NodeLabelRenderer()); vv.setVertexToolTipTransformer(node -> node.getToolTip()); vv.getRenderContext().setEdgeIncludePredicate( context -> callback.getVisualizationState().isVisibleInCanvas(context.element)); vv.getRenderContext().setEdgeArrowPredicate( context -> callback.getVisualizationState().isVisibleInCanvas(context.element) && context.element.getHasArrow()); vv.getRenderContext().setEdgeArrowStrokeTransformer(i -> i.getArrowStroke()); vv.getRenderContext() .setEdgeArrowTransformer(new ConstantTransformer(ArrowFactory.getNotchedArrow(7, 10, 5))); vv.getRenderContext().setEdgeLabelClosenessTransformer(new ConstantDirectionalEdgeValueTransformer(.6, .6)); vv.getRenderContext().setEdgeStrokeTransformer(i -> i.getEdgeStroke()); vv.getRenderContext().setEdgeDrawPaintTransformer(e -> e.getEdgeDrawPaint()); vv.getRenderContext().setArrowDrawPaintTransformer(e -> e.getArrowDrawPaint()); vv.getRenderContext().setArrowFillPaintTransformer(e -> e.getArrowFillPaint()); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.BLUE)); vv.getRenderer().setEdgeLabelRenderer(new BasicEdgeLabelRenderer<GUINode, GUILink>() { public void labelEdge(RenderContext<GUINode, GUILink> rc, Layout<GUINode, GUILink> layout, GUILink e, String label) { if (callback.getVisualizationState().isCanvasShowLinkLabels()) super.labelEdge(rc, layout, e, e.getLabel()); } }); vv.setEdgeToolTipTransformer(link -> link.getToolTip()); vv.getRenderContext().setEdgeShapeTransformer( c -> c.element.isShownSeparated() ? originalEdgeShapeTransformer.transform(c) : new Line2D.Float(0.0f, 0.0f, 1.0f, 0.0f)); // Background controller this.paintableAssociatedToBackgroundImage = null; gm = new PluggableGraphMouse(); vv.setGraphMouse(gm); scalingControl = new LayoutScalingControl(); ITopologyCanvasPlugin scalingPlugin = new ScalingCanvasPlugin(scalingControl, MouseEvent.NOBUTTON); addPlugin(scalingPlugin); vv.setOpaque(false); vv.setBackground(new Color(0, 0, 0, 0)); this.updateInterLayerDistanceInNpCoordinates(callback.getVisualizationState().getInterLayerSpaceInPixels()); // reset(); }
From source file:edu.uci.ics.jung.visualization.picking.ShapePickSupport.java
/** * Retrieves the shape template for <code>e</code> and * transforms it according to the positions of its endpoints * in <code>layout</code>./* ww w. j a va 2s .c o m*/ * @param layout the <code>Layout</code> which specifies * <code>e</code>'s endpoints' positions * @param e the edge whose shape is to be returned * @return */ private Shape getTransformedEdgeShape(Layout<V, E> layout, E e) { Pair<V> pair = layout.getGraph().getEndpoints(e); V v1 = pair.getFirst(); V v2 = pair.getSecond(); boolean isLoop = v1.equals(v2); Point2D p1 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v1)); Point2D p2 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, layout.transform(v2)); if (p1 == null || p2 == null) return null; float x1 = (float) p1.getX(); float y1 = (float) p1.getY(); float x2 = (float) p2.getX(); float y2 = (float) p2.getY(); // translate the edge to the starting vertex AffineTransform xform = AffineTransform.getTranslateInstance(x1, y1); Shape edgeShape = vv.getRenderContext().getEdgeShapeTransformer() .transform(Context.<Graph<V, E>, E>getInstance(vv.getGraphLayout().getGraph(), e)); if (isLoop) { // make the loops proportional to the size of the vertex Shape s2 = vv.getRenderContext().getVertexShapeTransformer().transform(v2); Rectangle2D s2Bounds = s2.getBounds2D(); xform.scale(s2Bounds.getWidth(), s2Bounds.getHeight()); // move the loop so that the nadir is centered in the vertex xform.translate(0, -edgeShape.getBounds2D().getHeight() / 2); } else { float dx = x2 - x1; float dy = y2 - y1; // rotate the edge to the angle between the vertices double theta = Math.atan2(dy, dx); xform.rotate(theta); // stretch the edge to span the distance between the vertices float dist = (float) Math.sqrt(dx * dx + dy * dy); xform.scale(dist, 1.0f); } // transform the edge to its location and dimensions edgeShape = xform.createTransformedShape(edgeShape); return edgeShape; }
From source file:org.bigwiv.blastgraph.gui.graphvisualization.EWLayout.java
protected synchronized void calcPositions(V v) { VertexData fvd = getData(v);//from ww w . j a va 2 s .c o m if (fvd == null) return; Point2D xyd = transform(v); double deltaLength = Math.max(EPSILON, fvd.norm()); double newXDisp = fvd.getX() / deltaLength * Math.min(deltaLength, temperature); if (Double.isNaN(newXDisp)) { throw new IllegalArgumentException("Unexpected mathematical result in FRLayout:calcPositions [xdisp]"); } double newYDisp = fvd.getY() / deltaLength * Math.min(deltaLength, temperature); xyd.setLocation(xyd.getX() + newXDisp, xyd.getY() + newYDisp); double borderWidth = getSize().getWidth() / 50.0; double newXPos = xyd.getX(); if (newXPos < borderWidth) { newXPos = borderWidth + Math.random() * borderWidth * 2.0; } else if (newXPos > (getSize().getWidth() - borderWidth)) { newXPos = getSize().getWidth() - borderWidth - Math.random() * borderWidth * 2.0; } double newYPos = xyd.getY(); if (newYPos < borderWidth) { newYPos = borderWidth + Math.random() * borderWidth * 2.0; } else if (newYPos > (getSize().getHeight() - borderWidth)) { newYPos = getSize().getHeight() - borderWidth - Math.random() * borderWidth * 2.0; } xyd.setLocation(newXPos, newYPos); }
From source file:extern.NpairsBoxAndWhiskerRenderer.java
/** * Draws a dot to represent an outlier.//from w w w .j a va 2 s . c o m * * @param point the location. * @param oRadius the radius. * @param g2 the graphics device. */ private void drawEllipse(Point2D point, double oRadius, Graphics2D g2) { Ellipse2D dot = new Ellipse2D.Double(point.getX() + oRadius / 2, point.getY(), oRadius, oRadius); g2.draw(dot); }
From source file:org.geoserver.wms.map.QuickTileCache.java
/** * Given an envelope and origin, find the tile coordinate (row,col) * /* w ww. j a v a 2 s . c o m*/ * @param env * @param origin * @return */ Point getTileCoordinates(Envelope env, Point2D origin) { // this was using the low left corner and Math.round, but turned // out to be fragile when fairly zoomed in. Using the tile center // and then flooring the division seems to work much more reliably. double centerx = env.getMinX() + env.getWidth() / 2; double centery = env.getMinY() + env.getHeight() / 2; int x = (int) Math.floor((centerx - origin.getX()) / env.getWidth()); int y = (int) Math.floor((centery - origin.getY()) / env.getWidth()); return new Point(x, y); }