List of usage examples for java.awt.geom Point2D getY
public abstract double getY();
From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java
/** * Returns the location for a label/*from w w w . java 2s . com*/ * * @param labelBounds the label bounds. * @param ascent the ascent (height of font). * @param plotArea the plot area * @param startAngle the start angle for the pie series. * * @return The location for a label. */ protected Point2D calculateLabelLocation(Rectangle2D labelBounds, double ascent, Rectangle2D plotArea, double startAngle) { Arc2D arc1 = new Arc2D.Double(plotArea, startAngle, 0, Arc2D.OPEN); Point2D point1 = arc1.getEndPoint(); double deltaX = -(point1.getX() - plotArea.getCenterX()) * this.axisLabelGap; double deltaY = -(point1.getY() - plotArea.getCenterY()) * this.axisLabelGap; double labelX = point1.getX() - deltaX; double labelY = point1.getY() - deltaY; if (labelX < plotArea.getCenterX()) { labelX -= labelBounds.getWidth(); } if (labelX == plotArea.getCenterX()) { labelX -= labelBounds.getWidth() / 2; } if (labelY > plotArea.getCenterY()) { labelY += ascent; } return new Point2D.Double(labelX, labelY); }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Translates a Java2D point on the chart to a screen location. * * @param java2DPoint the Java2D point. * * @return the screen location./* w ww. j a va2 s. co m*/ */ public Point translateJava2DToScreen(Point2D java2DPoint) { Insets insets = getInsets(); int x = (int) (java2DPoint.getX() + insets.left); int y = (int) (java2DPoint.getY() + insets.top); return new Point(x, y); }
From source file:Hexagon.java
public Hexagon(Point2D center, int size) { super();//from ww w . jav a 2s .c om this.center = center; this.size = size; /** * MATH: * With the hexagon points={TOP, UPPER-RIGHT, LOWER-RIGHT, BOTTOM, LOWER-LEFT, UPPER-RIGHT} * size = length of each actual segment of the hexagon * width = bounding rectangle width * height = bounding rectangle height * each inner angle is 120 degrees * outside angles are 30-60-90 triangles with 30 near TOP and BOTTOM and 60 near sides * hOffset = height difference between 'size' edge and bounding rectangle corners * wOffset = width difference between TOP/BOTTOM points and bounding rectangle corners */ double thirtyDegrees = Math.toRadians(30); hOffset = Math.sin(thirtyDegrees) * size; wOffset = Math.cos(thirtyDegrees) * size; height = (2 * hOffset) + size; width = (2 * wOffset); double left = center.getX() - (width / 2); double right = center.getX() + (width / 2); double top = center.getY() - (height / 2); double bottom = center.getY() + (height / 2); boundingBox = new Rectangle2D.Double(left, top, width, height); boundingCorners = new HashMap<BoundingCorner, Point2D>(); boundingCorners.put(BoundingCorner.TopRight, new Point2D.Double(right, top)); boundingCorners.put(BoundingCorner.TopLeft, new Point2D.Double(left, top)); boundingCorners.put(BoundingCorner.BottomRight, new Point2D.Double(right, bottom)); boundingCorners.put(BoundingCorner.BottomLeft, new Point2D.Double(left, bottom)); corners = new HashMap<Corner, Point2D>(); corners.put(Corner.Top, new Point2D.Double(center.getX(), top)); corners.put(Corner.UpperRight, new Point2D.Double(right, (top + hOffset))); corners.put(Corner.LowerRight, new Point2D.Double(right, (bottom - hOffset))); corners.put(Corner.Bottom, new Point2D.Double(center.getX(), bottom)); corners.put(Corner.LowerLeft, new Point2D.Double(left, (bottom - hOffset))); corners.put(Corner.UpperLeft, new Point2D.Double(left, (top + hOffset))); for (Corner corner : Corner.values()) { Point2D p2d = corners.get(corner); addPoint((int) p2d.getX(), (int) p2d.getY()); } }
From source file:lcmc.common.ui.ResourceGraph.java
protected final void showPopup(final JPopupMenu popup, final Point2D p) { final int posX = (int) p.getX(); final int posY = (int) p.getY(); swingUtils.invokeAndWait(new Runnable() { @Override//from w w w . j av a 2 s . c om public void run() { if (visualizationViewer.isShowing() && visualizationViewer.isDisplayable()) { popup.show(visualizationViewer, posX, posY); popup.repaint(); } } }); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
private void placeStructures(Vector<AnnotationObject> annotations, boolean init) { // get starting point double y = thePlot.getRangeAxis().getRange().getUpperBound(); double cur_x = thePlot.getDomainAxis().getRange().getLowerBound(); double all_width = 0.; for (AnnotationObject a : annotations) { if (a.hasAnnotations()) all_width += screenToDataX(rectangles_complete.get(a).width); }//w ww.j av a 2 s.c o m double min_pp_x = annotations.firstElement().getPeakPoint().getX(); double max_pp_x = annotations.lastElement().getPeakPoint().getX(); double center_pp_x = (max_pp_x + min_pp_x) / 2; cur_x = Math.max(cur_x, center_pp_x - all_width / 2); // place annotations for (AnnotationObject a : annotations) { Point2D pp = a.getPeakPoint(); if (a.hasAnnotations()) { double cur_width = screenToDataX(rectangles_complete.get(a).width); double x = cur_x + cur_width / 2.; theDocument.getAnchor(a).setLocation(x, y); theDocument.getControlPoints().put(a, theDocument.computeControlPoint(new Point2D.Double(x, y), pp)); cur_x += cur_width; } else { theDocument.getAnchor(a).setLocation(pp.getX(), pp.getY()); theDocument.getControlPoints().put(a, theDocument.computeControlPoint(pp, pp)); } } // refine control points for (int i = 0; i < annotations.size(); i++) { AnnotationObject ai = annotations.get(i); Point2D aai = theDocument.getAnchor(ai); Point2D cpi = theDocument.getControlPoint(ai); if (aai.getX() < cpi.getX()) { for (int l = i + 1; l < annotations.size(); l++) { AnnotationObject al = annotations.get(l); Point2D aal = theDocument.getAnchor(al); Point2D cpl = theDocument.getControlPoint(al); if (aal.getX() > cpi.getX()) break; if (cpl.getY() < cpi.getY()) { cpl.setLocation(cpl.getX(), cpi.getY()); ai = al; aai = aal; cpi = cpl; } else break; } } else { for (int l = i - 1; l >= 0; l--) { AnnotationObject al = annotations.get(l); Point2D aal = theDocument.getAnchor(al); Point2D cpl = theDocument.getControlPoint(al); if (aal.getX() < cpi.getX()) break; if (cpl.getY() < cpi.getY()) { cpl.setLocation(cpl.getX(), cpi.getY()); ai = al; aai = aal; cpi = cpl; } else break; } } } // fire events if (init) theDocument.fireDocumentInit(); else theDocument.fireDocumentChanged(); }
From source file:genlab.gui.jfreechart.EnhancedSpiderWebPlot.java
/** * Draws a radar plot polygon./*from w ww . j a v a 2s. co m*/ * * @param g2 the graphics device. * @param plotArea the area we are plotting in (already adjusted). * @param centre the centre point of the radar axes * @param info chart rendering info. * @param series the series within the dataset we are plotting * @param catCount the number of categories per radar plot * @param headH the data point height * @param headW the data point width */ protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info, int series, int catCount, double headH, double headW) { Polygon polygon = new Polygon(); EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // plot the data... for (int cat = 0; cat < catCount; cat++) { Number dataValue = getPlotValue(series, cat); if (dataValue != null) { double value = dataValue.doubleValue(); if (value >= 0) { // draw the polygon series... // Finds our starting angle from the centre for this axis double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / (catCount > 2 ? catCount : 3)); // The following angle calc will ensure there isn't a top // vertical axis - this may be useful if you don't want any // given criteria to 'appear' move important than the // others.. // + (getDirection().getFactor() // * (cat + 0.5) * 360 / catCount); // find the point at the appropriate distance end point // along the axis/angle identified above and add it to the // polygon Point2D point = getWebPoint(plotArea, angle, value / this.maxValue); polygon.addPoint((int) point.getX(), (int) point.getY()); // put an elipse at the point being plotted.. Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); Stroke outlineStroke = getSeriesOutlineStroke(series); Ellipse2D head = new Ellipse2D.Double(point.getX() - headW / 2, point.getY() - headH / 2, headW, headH); g2.setPaint(paint); g2.fill(head); g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(head); if (entities != null) { int row = 0; int col = 0; if (this.dataExtractOrder == TableOrder.BY_ROW) { row = series; col = cat; } else { row = cat; col = series; } String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip(this.dataset, row, col); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, row, col); } Shape area = new Rectangle((int) (point.getX() - headW), (int) (point.getY() - headH), (int) (headW * 2), (int) (headH * 2)); CategoryItemEntity entity = new CategoryItemEntity(area, tip, url, this.dataset, this.dataset.getRowKey(row), this.dataset.getColumnKey(col)); entities.add(entity); } } } } // Plot the polygon Paint paint = getSeriesPaint(series); g2.setPaint(paint); g2.setStroke(getSeriesOutlineStroke(series)); g2.draw(polygon); // Lastly, fill the web polygon if this is required if (this.webFilled) { g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); g2.fill(polygon); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); } }
From source file:lcmc.common.ui.ResourceGraph.java
/** * Scales the graph, so that all vertices can be seen. The graph can * get smaller but not bigger.//from w w w . j ava2 s . c o m */ public void scale() { final Point2D max = getLastPosition(); final float maxXPos = (float) max.getX(); final float maxYPos = (float) max.getY(); if (maxXPos <= 0 || maxYPos <= 0) { return; } final Float vvX = new Float(getLayout().getSize().getWidth()); final Float vvY = new Float(getLayout().getSize().getHeight()); if (maxXPos > vvX || maxYPos > vvY) { final float x = maxXPos > vvX ? maxXPos : vvX; final float y = maxYPos > vvY ? maxYPos : vvY; getLayout().setSize(new Dimension((int) x, (int) y)); visualizationViewer.setGraphLayout(getLayout()); } if (changed) { somethingChangedReset(); } visualizationViewer.repaint(); }
From source file:lcmc.common.ui.ResourceGraph.java
/** Returns position adjusted to scrollbar. */ protected Point2D posWithScrollbar(final Point2D oldPos) { final double newX = oldPos.getX() + scrollPane.getHorizontalScrollBar().getValue(); final double newY = oldPos.getY() + scrollPane.getVerticalScrollBar().getValue(); return new Point2D.Double(newX, newY); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
@Override public void mouseReleased(MouseEvent e) { // if we've been panning, we need to reset now that the mouse is // released... Rectangle2D zoomRectangle = (Rectangle2D) getChartFieldValueByName("zoomRectangle"); Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint"); if (getChartFieldValueByName("panLast") != null) { setChartFieldValue((getChartFieldByName("panLast")), null); setCursor(Cursor.getDefaultCursor()); } else if (zoomRectangle != null) { boolean hZoom = false; boolean vZoom = false; if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) { hZoom = (Boolean) getChartFieldValueByName("rangeZoomable"); vZoom = (Boolean) getChartFieldValueByName("domainZoomable"); } else {/*from w w w . ja va2 s .c o m*/ hZoom = (Boolean) getChartFieldValueByName("domainZoomable"); vZoom = (Boolean) getChartFieldValueByName("rangeZoomable"); } boolean zoomTrigger1 = hZoom && Math .abs(e.getX() - zoomPoint.getX()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance"); boolean zoomTrigger2 = vZoom && Math .abs(e.getY() - zoomPoint.getY()) >= (Integer) getChartFieldValueByName("zoomTriggerDistance"); if (zoomTrigger1 || zoomTrigger2) { if ((hZoom && (e.getX() < zoomPoint.getX())) || (vZoom && (e.getY() < zoomPoint.getY()))) { restoreAutoBounds(); } else { double x, y, w, h; Rectangle2D screenDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) zoomPoint.getY()); double maxX = screenDataArea.getMaxX(); double maxY = screenDataArea.getMaxY(); // for mouseReleased event, (horizontalZoom || verticalZoom) // will be true, so we can just test for either being false; // otherwise both are true if (!vZoom) { x = zoomPoint.getX(); y = screenDataArea.getMinY(); w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX()); h = screenDataArea.getHeight(); } else if (!hZoom) { x = screenDataArea.getMinX(); y = zoomPoint.getY(); w = screenDataArea.getWidth(); h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY()); } else { x = zoomPoint.getX(); y = zoomPoint.getY(); w = Math.min(zoomRectangle.getWidth(), maxX - zoomPoint.getX()); h = Math.min(zoomRectangle.getHeight(), maxY - zoomPoint.getY()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); zoom(zoomArea); } setChartFieldValue(getChartFieldByName("zoomPoint"), null); setChartFieldValue(getChartFieldByName("zoomRectangle"), null); } else { // erase the zoom rectangle Graphics2D g2 = (Graphics2D) getGraphics(); if ((Boolean) getChartFieldValueByName("useBuffer")) { repaint(); } else { drawZoomRectangle(g2, true); } g2.dispose(); setChartFieldValue(getChartFieldByName("zoomPoint"), null); setChartFieldValue(getChartFieldByName("zoomRectangle"), null); } } else if (e.isPopupTrigger()) { if (getChartFieldValueByName("popup") != null) { displayPopupMenu(e.getX(), e.getY()); } } }
From source file:com.net2plan.gui.tools.GUINetworkDesign.java
@Override public void moveNodeTo(final GUINode guiNode, final Point2D toPoint) { if (!vs.isNetPlanEditable()) throw new UnsupportedOperationException("NetPlan is not editable"); final ITopologyCanvas canvas = topologyPanel.getCanvas(); final Node node = guiNode.getAssociatedNetPlanNode(); final Point2D netPlanPoint = canvas.getCanvasPointFromMovement(toPoint); if (netPlanPoint == null) return;/*from ww w . j a v a 2s . co m*/ final Point2D jungPoint = canvas.getCanvasPointFromNetPlanPoint(toPoint); node.setXYPositionMap(netPlanPoint); viewEditTopTables.updateView(); // Updating GUINodes position having in mind the selected layer. final List<GUINode> guiNodes = vs.getCanvasVerticallyStackedGUINodes(node); final int selectedLayerVisualizationOrder = vs .getCanvasVisualizationOrderRemovingNonVisible(guiNode.getLayer()); for (GUINode stackedGUINode : guiNodes) { final int vlIndex = vs.getCanvasVisualizationOrderRemovingNonVisible(stackedGUINode.getLayer()); final double interLayerDistanceInNpCoord = canvas.getInterLayerDistanceInNpCoordinates(); if (vlIndex > selectedLayerVisualizationOrder) { final int layerDistance = vlIndex - selectedLayerVisualizationOrder; canvas.moveVertexToXYPosition(stackedGUINode, new Point2D.Double(jungPoint.getX(), -(jungPoint.getY() + (layerDistance * interLayerDistanceInNpCoord)))); } else if (vlIndex == selectedLayerVisualizationOrder) { canvas.moveVertexToXYPosition(stackedGUINode, new Point2D.Double(jungPoint.getX(), -(jungPoint.getY()))); } else { final int layerDistance = selectedLayerVisualizationOrder - vlIndex; canvas.moveVertexToXYPosition(stackedGUINode, new Point2D.Double(jungPoint.getX(), -(jungPoint.getY() - (layerDistance * interLayerDistanceInNpCoord)))); } } canvas.refresh(); }