List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:net.sf.jasperreports.charts.util.ChartUtil.java
/** * /*from www.j a va 2s . com*/ */ public static List<JRPrintImageAreaHyperlink> getImageAreaHyperlinks(JFreeChart chart, ChartHyperlinkProvider chartHyperlinkProvider, Graphics2D grx, Rectangle2D renderingArea)// throws JRException { List<JRPrintImageAreaHyperlink> areaHyperlinks = null; if (chartHyperlinkProvider != null && chartHyperlinkProvider.hasHyperlinks()) { ChartRenderingInfo renderingInfo = new ChartRenderingInfo(); if (grx == null) { chart.createBufferedImage((int) renderingArea.getWidth(), (int) renderingArea.getHeight(), renderingInfo); } else { chart.draw(grx, renderingArea, renderingInfo); } EntityCollection entityCollection = renderingInfo.getEntityCollection(); if (entityCollection != null && entityCollection.getEntityCount() > 0) { areaHyperlinks = new ArrayList<JRPrintImageAreaHyperlink>(entityCollection.getEntityCount()); for (@SuppressWarnings("unchecked") Iterator<ChartEntity> it = entityCollection.iterator(); it.hasNext();) { ChartEntity entity = it.next(); JRPrintHyperlink printHyperlink = chartHyperlinkProvider.getEntityHyperlink(entity); if (printHyperlink != null) { JRPrintImageArea area = getImageArea(entity); JRPrintImageAreaHyperlink areaHyperlink = new JRPrintImageAreaHyperlink(); areaHyperlink.setArea(area); areaHyperlink.setHyperlink(printHyperlink); areaHyperlinks.add(areaHyperlink); } } } } return areaHyperlinks; }
From source file:savant.util.MiscUtils.java
/** * Patterned off GraphPane.drawMessageHelper, draws a string centred in the given box. *//*from w ww. j a v a 2s .c om*/ public static void drawMessage(Graphics2D g2, String message, Rectangle2D box) { FontMetrics metrics = g2.getFontMetrics(); Rectangle2D stringBounds = g2.getFont().getStringBounds(message, g2.getFontRenderContext()); float x = (float) (box.getX() + (box.getWidth() - stringBounds.getWidth()) / 2.0); float y = (float) (box.getY() + (box.getHeight() + metrics.getAscent() - metrics.getDescent()) / 2.0); g2.drawString(message, x, y); }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java
private static Shape createShape(double x, double y, Rectangle2D hotspot) { Area result = new Area(new RoundRectangle2D.Double(hotspot.getX(), hotspot.getY(), hotspot.getWidth(), hotspot.getHeight(), 8, 8)); boolean right = hotspot.getMinX() > x; Polygon po = new Polygon(); po.addPoint(0, 0);//from w w w . j a v a 2 s. co m po.addPoint(0, 10); po.addPoint(10, 0); AffineTransform af = new AffineTransform(); if (right) { af.translate(hotspot.getX() - 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(-Math.PI / 4); } else { af.translate(hotspot.getMaxX() + 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(Math.PI * 3 / 4); } Shape shape = af.createTransformedShape(po); result.add(new Area(shape)); return result; }
From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java
public static Transform getTransformForBounds(Dimension canvasSize, Rectangle2D bounds, Double zoomStep) { double widthRatio = canvasSize.width / bounds.getWidth(); double heightRatio = canvasSize.height / bounds.getHeight(); double canvasCenterX = canvasSize.width / 2.0; double canvasCenterY = canvasSize.height / 2.0; double centerX = bounds.getCenterX(); double centerY = bounds.getCenterY(); double scale = Math.min(widthRatio, heightRatio); if (zoomStep != null) { int zoom = (int) (Math.log(scale) / Math.log(2.0)); scale = Math.pow(2.0, zoom); }/*from w w w . java2 s . c o m*/ double scaleX = scale; double scaleY = scale; double translationX = canvasCenterX - centerX * scaleX; double translationY = canvasCenterY - centerY * scaleY; return new Transform(scaleX, scaleY, translationX, translationY); }
From source file:org.jfree.experimental.chart.plot.dial.DialPlot.java
/** * A utility method that computes a rectangle using relative radius values. * /* ww w . j a v a 2s .c o m*/ * @param rect the reference rectangle. * @param radiusW the width radius (must be > 0.0) * @param radiusH the height radius. * * @return A new rectangle. */ public static Rectangle2D rectangleByRadius(Rectangle2D rect, double radiusW, double radiusH) { double x = rect.getCenterX(); double y = rect.getCenterY(); double w = rect.getWidth() * radiusW; double h = rect.getHeight() * radiusH; return new Rectangle2D.Double(x - w / 2.0, y - h / 2.0, w, h); }
From source file:com.t_oster.visicut.misc.Helper.java
/** * Returns the distance between two Rectangles * @param r first rectangle/* w ww.ja v a2 s. c o m*/ * @param q second rectangle * @return Distance between two rectangles */ public static double distance(Rectangle2D r, Rectangle2D q) { double qx0 = q.getX(); double qy0 = q.getY(); double qx1 = q.getX() + q.getWidth(); double qy1 = q.getY() + q.getHeight(); double rx0 = r.getX(); double ry0 = r.getY(); double rx1 = r.getX() + r.getWidth(); double ry1 = r.getY() + r.getHeight(); //Check for Overlap if (qx0 <= rx1 && qy0 <= ry1 && rx0 <= qx1 && ry0 <= qy1) { return 0; } double d = 0; if (rx0 > qx1) { d += (rx0 - qx1) * (rx0 - qx1); } else if (qx0 > rx1) { d += (qx0 - rx1) * (qx0 - rx1); } if (ry0 > qy1) { d += (ry0 - qy1) * (ry0 - qy1); } else if (qy0 > ry1) { d += (qy0 - ry1) * (qy0 - ry1); } return Math.sqrt(d); }
From source file:com.t_oster.visicut.misc.Helper.java
public static Rectangle toRect(Rectangle2D src) { if (src == null) { return new Rectangle(0, 0, 0, 0); }/*w ww . j av a 2s. c o m*/ return new Rectangle((int) src.getX(), (int) src.getY(), (int) src.getWidth(), (int) src.getHeight()); }
From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.JFreeChartConn.java
/** * Updates the point-related properties of a plot. * // w w w . j a v a2s. c o m * @param aPlot * Plot to be updated. * @param aScatter * Visual settings to be applied. */ private static void updateScatter(XYPlot aPlot, ScatterSettings aScatter) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) aPlot.getRenderer(); renderer.setSeriesPaint(0, aScatter.getPointColor()); final Rectangle2D ds = AbstractRenderer.DEFAULT_SHAPE.getBounds2D(); final double x = ds.getX(); final double y = ds.getY(); final double w = ds.getWidth(); final double h = ds.getHeight(); Shape shape = null; switch (aScatter.getPointShape()) { case POINT: shape = new Rectangle2D.Double(x + w / 2, y + h / 2, 1, 1); renderer.setBaseShapesFilled(true); break; case CIRCLE: shape = new Ellipse2D.Double(x, y, w, h); renderer.setBaseShapesFilled(false); break; case FILLED_CIRCLE: shape = new Ellipse2D.Double(x, y, w, h); renderer.setBaseShapesFilled(true); break; case SQUARE: shape = new Rectangle2D.Double(x, y, w, h); renderer.setBaseShapesFilled(false); break; case FILLED_SQUARE: shape = new Rectangle2D.Double(x, y, w, h); renderer.setBaseShapesFilled(true); break; case CROSS: shape = new Cross(x, y, w, h); renderer.setBaseShapesFilled(false); } renderer.setSeriesShape(0, shape); }
From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java
public static double translateChartY(double chartY, Rectangle2D imageArea, JFreeChart chart) { XYPlot plot = chart.getXYPlot();//from w w w. j ava2 s . co m boolean isRangeInverted = plot.getRangeAxis().isInverted(); Range rangeSection = plot.getRangeAxis().getRange(); if (!isRangeInverted) { return imageArea.getMinY() + (rangeSection.getUpperBound() - chartY) / rangeSection.getLength() * imageArea.getHeight(); } else { return imageArea.getMinY() + (chartY - rangeSection.getLowerBound()) / rangeSection.getLength() * imageArea.getHeight(); } }
From source file:ShapeTransform.java
/** * Clips the given shape to the given bounds. If the shape is a Line2D, manual * clipping is performed, as the built in Area does not handle lines. * //ww w. j a va 2s . c o m * @param s * the shape to be clipped * @param bounds * the bounds to which the shape should be clipped * @return the clipped shape. */ public static Shape performCliping(final Shape s, final Rectangle2D bounds) { if (s instanceof Line2D) { final Line2D line = (Line2D) s; final Point2D[] clipped = getClipped(line.getX1(), line.getY1(), line.getX2(), line.getY2(), -DELTA, DELTA + bounds.getWidth(), -DELTA, DELTA + bounds.getHeight()); if (clipped == null) { return new GeneralPath(); } return new Line2D.Float(clipped[0], clipped[1]); } final Rectangle2D boundsCorrected = bounds.getBounds2D(); boundsCorrected.setRect(-DELTA, -DELTA, DELTA + boundsCorrected.getWidth(), DELTA + boundsCorrected.getHeight()); final Area a = new Area(boundsCorrected); if (a.isEmpty()) { // don't clip ... Area does not like lines // operations with lines always result in an empty Bounds:(0,0,0,0) area return new GeneralPath(); } final Area clipArea = new Area(s); a.intersect(clipArea); return a; }