List of usage examples for java.awt.geom Point2D getY
public abstract double getY();
From source file:lcmc.gui.ResourceGraph.java
/** Returns position of the last vertex. */ protected final Point2D getLastPosition() { double lastX = 0; double lastY = 0; final Map<Vertex, Point2D> vl = getVertexLocations(); for (final Vertex v : vl.keySet()) { final Point2D last = vl.get(v); if (last != null) { if (last.getX() > lastX) { lastX = last.getX();//w w w.j a v a2s. c o m } if (last.getY() > lastY) { lastY = last.getY(); } } } putVertexLocations(); return new Point2D.Double(lastX, lastY + 40); }
From source file:lcmc.common.ui.ResourceGraph.java
/** Returns positions of the vertices (by value). */ final public void getPositions(final Map<String, Point2D> positions) { mGraphLock.lock();/* w w w. ja v a 2 s.c o m*/ try { for (final Vertex v : graph.getVertices()) { final Info info = getInfo(v); final Point2D p = new Point2D.Double(); final Point2D loc = layout.transform(v); if (loc == null) { continue; } p.setLocation(loc); p.setLocation(p.getX() + (getDefaultVertexWidth(v) - getVertexWidth(v)) / 2, p.getY() + (getDefaultVertexHeight(v) - getVertexHeight(v)) / 2); if (info != null) { final String id = getId(info); if (id != null) { positions.put(id, p); } } } } finally { mGraphLock.unlock(); } }
From source file:spinworld.gui.RadarPlot.java
private void drawTicks(Graphics2D g2, Rectangle2D radarArea, double axisAngle, int cat) { double[] ticks = { 0.5d, 1d }; for (int i = 0; i < ticks.length; i++) { double tick = ticks[i]; Point2D middlePoint = getWebPoint(radarArea, axisAngle, tick); double xt = middlePoint.getX(); double yt = middlePoint.getY(); double angrad = Math.toRadians(-axisAngle); g2.translate(xt, yt);/* w w w. j a v a 2 s .c o m*/ g2.rotate(angrad); g2.drawLine(0, (int) -TICK_MARK_LENGTH / 2, 0, (int) TICK_MARK_LENGTH / 2); g2.rotate(-angrad); g2.translate(-xt, -yt); drawTickLabel(g2, radarArea, middlePoint, axisAngle, cat, tick); } }
From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
public Point2D normalize(final Point2D e) { final double topBorder = getTopBorder(); final double leftBorder = getLeftBorder(); final float scaleFactor = getRenderContext().getZoomModel().getZoomAsPercentage(); final double x = (e.getX() / scaleFactor) - leftBorder; final double y = (e.getY() / scaleFactor) - topBorder; final Point2D o = getOffset(); o.setLocation(x, y + o.getY());// ww w . j a v a 2 s . c om return o; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
private void setPaint(final boolean invert, final double xoffset, final double yoffset, final boolean fill) { if (paint instanceof Color) { final Color color = (Color) paint; final int alpha = color.getAlpha(); if (fill) { if (alpha != currentFillGState) { currentFillGState = alpha; PdfGState gs = fillGState[alpha]; if (gs == null) { gs = new PdfGState(); gs.setFillOpacity(alpha / 255.00f); fillGState[alpha] = gs; }/* www .ja va 2 s. c o m*/ cb.setGState(gs); } cb.setColorFill(color); } else { if (alpha != currentStrokeGState) { currentStrokeGState = alpha; PdfGState gs = strokeGState[alpha]; if (gs == null) { gs = new PdfGState(); gs.setStrokeOpacity(alpha / 255.0f); strokeGState[alpha] = gs; } cb.setGState(gs); } cb.setColorStroke(color); } } else if (paint instanceof GradientPaint) { final GradientPaint gp = (GradientPaint) paint; final Point2D p1 = gp.getPoint1(); transform.transform(p1, p1); final Point2D p2 = gp.getPoint2(); transform.transform(p2, p2); final Color c1 = gp.getColor1(); final Color c2 = gp.getColor2(); final PdfShading shading = PdfShading.simpleAxial(cb.getPdfWriter(), (float) p1.getX(), normalizeY((float) p1.getY()), (float) p2.getX(), normalizeY((float) p2.getY()), c1, c2); final PdfShadingPattern pat = new PdfShadingPattern(shading); if (fill) { cb.setShadingFill(pat); } else { cb.setShadingStroke(pat); } } else if (paint instanceof TexturePaint) { try { final TexturePaint tp = (TexturePaint) paint; final BufferedImage img = tp.getImage(); final Rectangle2D rect = tp.getAnchorRect(); final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null); final PdfPatternPainter pattern = cb.createPattern(image.getWidth(), image.getHeight()); final AffineTransform inverse = this.normalizeMatrix(); inverse.translate(rect.getX(), rect.getY()); inverse.scale(rect.getWidth() / image.getWidth(), -rect.getHeight() / image.getHeight()); final double[] mx = new double[6]; inverse.getMatrix(mx); pattern.setPatternMatrix((float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4], (float) mx[5]); image.setAbsolutePosition(0, 0); pattern.addImage(image); if (fill) { cb.setPatternFill(pattern); } else { cb.setPatternStroke(pattern); } } catch (Exception ex) { if (fill) { cb.setColorFill(Color.gray); } else { cb.setColorStroke(Color.gray); } } } else { try { int type = BufferedImage.TYPE_4BYTE_ABGR; if (paint.getTransparency() == Transparency.OPAQUE) { type = BufferedImage.TYPE_3BYTE_BGR; } final BufferedImage img = new BufferedImage((int) width, (int) height, type); final Graphics2D g = (Graphics2D) img.getGraphics(); g.transform(transform); final AffineTransform inv = transform.createInverse(); Shape fillRect = new Rectangle2D.Double(0, 0, img.getWidth(), img.getHeight()); fillRect = inv.createTransformedShape(fillRect); g.setPaint(paint); g.fill(fillRect); if (invert) { final AffineTransform tx = new AffineTransform(); tx.scale(1, -1); tx.translate(-xoffset, -yoffset); g.drawImage(img, tx, null); } g.dispose(); // g = null; final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null); final PdfPatternPainter pattern = cb.createPattern(width, height); image.setAbsolutePosition(0, 0); pattern.addImage(image); if (fill) { cb.setPatternFill(pattern); } else { cb.setPatternStroke(pattern); } } catch (Exception ex) { if (fill) { cb.setColorFill(Color.gray); } else { cb.setColorStroke(Color.gray); } } } }
From source file:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java
public Point2D getPointInChart(MouseEvent e) { Insets insets = getInsets();// w w w . ja va2 s.c o m //System.out.println("inset.top="+insets.top+" inset.left="+insets.left); //System.out.println("scaleX="+chartPaneltest.getScaleX()+" scaleY="+chartPaneltest.getScaleY()); //System.out.println(e.getX()); // int mouseX = (int) ((e.getX() - insets.left) / chartPaneltest.getScaleX()); // int mouseY = (int) ((e.getY() - insets.top) / chartPaneltest.getScaleY()); int mouseX = (int) (e.getX() - insets.left); int mouseY = (int) (e.getY() - insets.top); // Point2D pt = new Point2D.Double(); //pt.setLocation(mouseX, mouseY); //return pt; // System.out.println("x = " + mouseX + ", y = " + mouseY); Point2D p = chartPaneltest.translateScreenToJava2D(new Point(mouseX, mouseY)); XYPlot plot = (XYPlot) chart.getPlot(); ChartRenderingInfo info = chartPaneltest.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); ValueAxis domainAxis = plot.getDomainAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); ValueAxis rangeAxis = plot.getRangeAxis(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); double chartX = domainAxis.java2DToValue(p.getX(), dataArea, domainAxisEdge); double chartY = rangeAxis.java2DToValue(p.getY(), dataArea, rangeAxisEdge); Point2D pt2 = new Point2D.Double(); //double scale = (double)CHART_SIZE_X/(double)CHART_SIZE_Y; //System.out.println("scale="+scale); pt2.setLocation(chartX, chartY); //System.out.println("Chart: x = " + (chartX) + ", y = " + chartY); return pt2; }
From source file:spinworld.gui.RadarPlot.java
/** * Draws a radar plot polygon./*from w w w. j a v a 2s . c o 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(); // Finds our starting angle from the centre for this axis double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount); // 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 double _maxValue = getMaxValue(cat).doubleValue(); double _origin = getOrigin(cat).doubleValue(); double lowerBound = Math.min(_origin, _maxValue); double upperBound = Math.max(_origin, _maxValue); boolean lesser = value < lowerBound; boolean greater = value > upperBound; if ((lesser || greater) && !drawOutOfRangePoints) { continue; } if (lesser) { value = lowerBound; } if (greater) { value = upperBound; } double length = _maxValue == _origin ? 0 : (value - lowerBound) / (upperBound - lowerBound); if (_maxValue < _origin) { // inversed length = 1 - length; } Point2D point = getWebPoint(plotArea, angle, length); polygon.addPoint((int) point.getX(), (int) point.getY()); Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); double px = point.getX(); double py = point.getY(); g2.setPaint(paint); if (lesser || greater) { // user crosshair for out-of-range data points distinguish g2.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL)); double delta = 3; g2.draw(new Line2D.Double(px - delta, py, px + delta, py)); g2.draw(new Line2D.Double(px, py - delta, px, py + delta)); } else { // put an elipse at the point being plotted.. Ellipse2D head = new Ellipse2D.Double(px - headW / 2, py - headH / 2, headW, headH); g2.fill(head); g2.setStroke(getHeadOutlineStroke(series)); 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:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
protected void paintElementAlignment(final Graphics2D g2d) { if (WorkspaceSettings.getInstance().isShowElementAlignmentHints()) { final float scaleFactor = getRenderContext().getZoomModel().getZoomAsPercentage(); g2d.setColor(WorkspaceSettings.getInstance().getAlignmentHintColor()); g2d.setStroke(new BasicStroke(.2f)); final double gridHeight = getHeight(); final double gridWidth = getWidth(); final long[] hPositions; if (getHorizontalPositionsModel() == null) { final BreakPositionsList horizontalPositions = getHorizontalEdgePositions(); hPositions = horizontalPositions.getKeys(); } else {// w ww . jav a 2s . com hPositions = getHorizontalPositionsModel().getBreaks(); } final Line2D.Double line = new Line2D.Double(); for (int i = 0; i < hPositions.length; i++) { final double position = StrictGeomUtility.toExternalValue(hPositions[i]); final double x = position * scaleFactor; line.setLine(x, 0, x, gridHeight); g2d.draw(line); } final Point2D offset = getOffset(); final BreakPositionsList verticalPositions = getVerticalEdgePositions(); final long[] vPositions = verticalPositions.getKeys(); for (int i = 0; i < vPositions.length; i++) { final double position = StrictGeomUtility.toExternalValue(vPositions[i]) - offset.getY(); final double y2 = position * scaleFactor; line.setLine(0, y2, gridWidth, y2); g2d.draw(line); } } }
From source file:lcmc.gui.ResourceGraph.java
/** Returns positions of the vertices (by value). */ final void getPositions(final Map<String, Point2D> positions) { mGraphLock.lock();/*from ww w . ja va 2 s . co m*/ try { for (final Vertex v : graph.getVertices()) { final Info info = getInfo(v); final Point2D p = new Point2D.Double(); final Point2D loc = layout.transform(v); if (loc == null) { continue; } p.setLocation(loc); p.setLocation(p.getX() + (getDefaultVertexWidth(v) - getVertexWidth(v)) / 2, p.getY() + (getDefaultVertexHeight(v) - getVertexHeight(v)) / 2); if (info != null) { final String id = getId(info); if (id != null) { positions.put(id, p); } } } } finally { mGraphLock.unlock(); } }
From source file:org.gumtree.vis.awt.JChartPanel.java
private void findSelectedMarker(Point point) { Line2D marker = null;//from w ww.j a va2 s .c o m double distance = Double.MAX_VALUE; double cDis; for (Entry<Line2D, Color> entry : domainMarkerMap.entrySet()) { Line2D line = entry.getKey(); Point2D p2 = line.getP2(); double height = p2.getY(); cDis = Double.MAX_VALUE; if (height < 1e-4) { double xScr = ChartMaskingUtilities.translateChartPoint(p2, getScreenDataArea(), getChart()).getX(); cDis = Math.abs(point.getX() - xScr); } else { Point2D newP2 = ChartMaskingUtilities.translateChartPoint(p2, getScreenDataArea(), getChart()); if (newP2.getY() < point.getY()) { cDis = Math.abs(point.getX() - newP2.getX()); } else { cDis = newP2.distance(point); } } if (cDis <= distance) { distance = cDis; marker = line; } } for (Entry<Line2D, Color> entry : rangeMarkerMap.entrySet()) { Line2D line = entry.getKey(); Point2D p1 = line.getP1(); Point2D p2 = line.getP2(); double width = p2.getX(); cDis = Double.MAX_VALUE; if (width < 1e-4) { double yScr = ChartMaskingUtilities.translateChartPoint(p1, getScreenDataArea(), getChart()).getY(); cDis = Math.abs(point.getY() - yScr); } else { Point2D newP2 = ChartMaskingUtilities.translateChartPoint(p2, getScreenDataArea(), getChart()); if (newP2.getX() > point.getX()) { cDis = Math.abs(point.getY() - newP2.getY()); } else { cDis = newP2.distance(point); } } if (cDis <= distance) { distance = cDis; marker = line; } } for (Entry<Line2D, Color> entry : markerMap.entrySet()) { Line2D line = entry.getKey(); Point2D p1 = line.getP1(); p1 = ChartMaskingUtilities.translateChartPoint(p1, getScreenDataArea(), getChart()); cDis = p1.distance(point); if (cDis <= distance) { distance = cDis; marker = line; } } if (distance < 5) { selectedMarker = marker; } else { selectedMarker = null; } }