List of usage examples for java.awt.geom Rectangle2D getY
public abstract double getY();
From source file:net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.java
protected TextLine toTextLine(int measureIndex, Rectangle2D measuredBounds) { SimpleTextLine textLine = new SimpleTextLine(); textLine.setAscent((float) -measuredBounds.getY()); textLine.setDescent((float) (measuredBounds.getMaxY() - fontInfo.fontInfo.leading)); textLine.setLeading(fontInfo.fontInfo.leading); textLine.setCharacterCount(measureIndex - paragraphPosition); textLine.setAdvance((float) measuredBounds.getWidth()); textLine.setLeftToRight(paragraphLeftToRight); // update the paragraph position paragraphPosition = measureIndex;/* w w w . java 2s .c o m*/ return textLine; }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * Transform the tree layout so that it fits nicely in the given image * dimensions//from w ww. jav a 2s .co m * @param treeLayout * the layout to transform * @param imageWidth * the image width * @param imageHeight * the image height */ private void transformTreeLayout(VisualTreeNode treeLayout, int imageWidth, int imageHeight, FontRenderContext frc) { Dimension2D maximalNodeLabelDimension = this.calculateMaximalNodeDimension(treeLayout, frc); double widthBuffer = maximalNodeLabelDimension.getWidth() + BORDER_WHITE_SPACE; double heightBuffer = maximalNodeLabelDimension.getHeight() + BORDER_WHITE_SPACE; // perform rotation to improve the use of space { // center around 0, 0 VisualTreeNode[] mostDistantPair = this.getMostDistantNodePair(treeLayout); Point2D distantPoint1 = mostDistantPair[0].getPosition(); Point2D distantPoint2 = mostDistantPair[1].getPosition(); double xDiff = distantPoint1.getX() - distantPoint2.getX(); double yDiff = distantPoint1.getY() - distantPoint2.getY(); this.translateTreeLayout(treeLayout, (xDiff / 2.0) - distantPoint1.getX(), (yDiff / 2.0) - distantPoint2.getY()); // rotate double thetaRadians = Math.atan2(yDiff, xDiff); if (imageWidth >= imageHeight) { this.rotateTreeLayout(treeLayout, -thetaRadians); } else { this.rotateTreeLayout(treeLayout, (Math.PI / 2.0 - thetaRadians)); } } Rectangle2D boundingRectangle = this.calculateBounds(treeLayout, null); // center around the middle of the display area this.translateTreeLayout(treeLayout, -boundingRectangle.getX(), -boundingRectangle.getY()); // grow the image to fill a larger area double xScale = (imageWidth - widthBuffer) / boundingRectangle.getWidth(); double yScale = (imageHeight - heightBuffer) / boundingRectangle.getHeight(); double smallerScale = Math.min(xScale, yScale); this.scaleTreeLayout(treeLayout, smallerScale); // center around the middle of the display area boundingRectangle = this.calculateBounds(treeLayout, null); this.translateTreeLayout(treeLayout, ((imageWidth - boundingRectangle.getWidth()) / 2.0) - boundingRectangle.getX(), ((imageHeight - boundingRectangle.getHeight()) / 2.0) - boundingRectangle.getY()); }
From source file:net.sourceforge.processdash.ui.web.reports.RadarPlot.java
/** * Draws the plot on a Java 2D graphics device (such as the screen * or a printer)./*from w w w . ja va 2 s. c o m*/ * @param g2 The graphics device. * @param plotArea The area within which the plot should be drawn. */ @Override public void draw(Graphics2D g2, Rectangle2D plotArea, Point2D anchor, PlotState state, PlotRenderingInfo info) { // adjust for insets... RectangleInsets insets = getInsets(); if (insets != null) { plotArea.setRect(plotArea.getX() + insets.getLeft(), plotArea.getY() + insets.getTop(), plotArea.getWidth() - insets.getLeft() - insets.getRight(), plotArea.getHeight() - insets.getTop() - insets.getBottom()); } if (info != null) { info.setPlotArea(plotArea); info.setDataArea(plotArea); } drawBackground(g2, plotArea); drawOutline(g2, plotArea); Shape savedClip = g2.getClip(); g2.clip(plotArea); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); if (this.dataset != null) { drawRadar(g2, plotArea, info, 0, this.dataset); } else { drawNoDataMessage(g2, plotArea); } g2.clip(savedClip); g2.setComposite(originalComposite); drawOutline(g2, plotArea); }
From source file:Polygon2D.java
/** * Tests if the interior of this <code>Polygon</code> entirely * contains the specified <code>Rectangle2D</code>. * @param r the specified <code>Rectangle2D</code> * @return <code>true</code> if this <code>Polygon</code> entirely * contains the specified <code>Rectangle2D</code>; * <code>false</code> otherwise. * @see #contains(double, double, double, double) *//*from w w w. j a v a 2 s .c om*/ public boolean contains(Rectangle2D r) { return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight()); }
From source file:Polygon2D.java
/** * Tests if the interior of this <code>Polygon</code> intersects the * interior of a specified <code>Rectangle2D</code>. * @param r a specified <code>Rectangle2D</code> * @return <code>true</code> if this <code>Polygon</code> and the * interior of the specified <code>Rectangle2D</code> * intersect each other; <code>false</code> * otherwise./* w w w . jav a2 s . c o m*/ */ public boolean intersects(Rectangle2D r) { return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); }
From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java
/**<!====== drawItem ======================================================> Draws a 3D bar to represent one data item. <! Name Description> @param g2 the graphics device. @param state the renderer state. @param dataArea the area for plotting the data. @param plot the plot.//from ww w. j ava 2 s . c o m @param domainAxis the domain axis. @param rangeAxis the range axis. @param dataset the dataset. @param row the row index (zero-based). @param column the column index (zero-based). @param pass the pass index. <!=======================================================================>*/ @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // check the value we are plotting... Number dataValue = dataset.getValue(row, column); if (dataValue == null) { return; } g2.setStroke(new BasicStroke(1)); double value = dataValue.doubleValue(); Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(), dataArea.getY() + getYOffset(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); PlotOrientation orientation = plot.getOrientation(); double barW0 = calculateBarW0(plot, orientation, adjusted, domainAxis, state, row, column); double[] barL0L1 = calculateBarL0L1(value); if (barL0L1 == null) { return; // the bar is not visible } RectangleEdge edge = plot.getRangeAxisEdge(); double transL0 = rangeAxis.valueToJava2D(barL0L1[0], adjusted, edge); double transL1 = rangeAxis.valueToJava2D(barL0L1[1], adjusted, edge); double barL0 = Math.min(transL0, transL1); double barLength = Math.abs(transL1 - transL0); // draw the bar... Rectangle2D bar = null; if (orientation == PlotOrientation.HORIZONTAL) { bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth()); } else { bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength); } Paint itemPaint = getItemPaint(row, column); if (itemPaint instanceof Color) { Color endColor = getFrontDark((Color) itemPaint); Color startColor = (Color) itemPaint; Paint paint = new GradientPaint((float) bar.getX(), (float) bar.getY(), startColor, (float) (bar.getX()), (float) (bar.getY() + bar.getHeight()), endColor); g2.setPaint(paint); } g2.fill(bar); double x0 = bar.getMinX(); // left double x1 = x0 + getXOffset(); // offset left double x2 = bar.getMaxX(); // right double x3 = x2 + getXOffset(); // offset right double y0 = bar.getMinY() - getYOffset(); // offset top double y1 = bar.getMinY(); // bar top double y2 = bar.getMaxY() - getYOffset(); // offset bottom double y3 = bar.getMaxY(); // bottom //Rectangle2D.Double line = new Rectangle2D.Double(x2, y1, 2, bar.getHeight()); Line2D.Double line = new Line2D.Double(x2, y1, x2, y3); g2.draw(line); GeneralPath bar3dRight = null; GeneralPath bar3dTop = null; g2.setPaint(itemPaint); // Draw the right side if (barLength > 0.0) { bar3dRight = new GeneralPath(); bar3dRight.moveTo((float) x2, (float) y3); bar3dRight.lineTo((float) x2, (float) y1); bar3dRight.lineTo((float) x3, (float) y0); bar3dRight.lineTo((float) x3, (float) y2); bar3dRight.closePath(); if (itemPaint instanceof Color) { Color startColor = getSideLight((Color) itemPaint); Color endColor = getSideDark((Color) itemPaint); Paint paint = new GradientPaint((float) x3, (float) y0, startColor, (float) x2, (float) y3, endColor); g2.setPaint(paint); } g2.fill(bar3dRight); } // Draw the top bar3dTop = new GeneralPath(); bar3dTop.moveTo((float) x0, (float) y1); // bottom left bar3dTop.lineTo((float) x1, (float) y0); // top left bar3dTop.lineTo((float) x3, (float) y0); // top right bar3dTop.lineTo((float) x2, (float) y1); // bottom right bar3dTop.closePath(); if (itemPaint instanceof Color) { Color endColor = getTopDark((Color) itemPaint); Color startColor = getTopLight((Color) itemPaint); //Paint paint = new GradientPaint((float)x2, (float)y0, startColor, (float)x0, (float)(y1), endColor); Point2D.Double topRight = new Point2D.Double(x3, y0); Point2D.Double bottomLeft = new Point2D.Double(x0, y1); //Point2D.Double darkEnd = getTargetPoint(bottomLeft, topRight, ((y0-y1)/(x3-x2))); Point2D.Double darkEnd = new Point2D.Double(x1, y0 - (x3 - x1) * ((y0 - y1) / (x3 - x2))); Paint paint = new GradientPaint((float) topRight.getX(), (float) topRight.getY(), startColor, (float) darkEnd.getX(), (float) darkEnd.getY(), endColor); g2.setPaint(paint); //drawMarker(topRight, g2, startColor); } g2.fill(bar3dTop); g2.setPaint(itemPaint); if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) { g2.setStroke(getItemOutlineStroke(row, column)); g2.setPaint(getItemOutlinePaint(row, column)); g2.draw(bar); if (bar3dRight != null) { g2.draw(bar3dRight); } if (bar3dTop != null) { g2.draw(bar3dTop); } } CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column); if (generator != null && isItemLabelVisible(row, column)) { drawItemLabel(g2, dataset, row, column, plot, generator, bar, (value < 0.0)); } // add an item entity, if this information is being collected EntityCollection entities = state.getEntityCollection(); if (entities != null) { GeneralPath barOutline = new GeneralPath(); barOutline.moveTo((float) x0, (float) y3); barOutline.lineTo((float) x0, (float) y1); barOutline.lineTo((float) x1, (float) y0); barOutline.lineTo((float) x3, (float) y0); barOutline.lineTo((float) x3, (float) y2); barOutline.lineTo((float) x2, (float) y3); barOutline.closePath(); addItemEntity(entities, dataset, row, column, barOutline); } }
From source file:org.apache.xmlgraphics.ps.PSGenerator.java
/** * Formats a Rectangle2D to an array.//from w w w.ja va2s .c o m * @param rect the rectangle * @return the formatted array */ public String formatRectangleToArray(Rectangle2D rect) { return "[" + formatDouble(rect.getX()) + " " + formatDouble(rect.getY()) + " " + formatDouble(rect.getWidth()) + " " + formatDouble(rect.getHeight()) + "]"; }
From source file:LineGraphDrawable.java
/** * Draws the bar-graph into the given Graphics2D context in the given area. * This method will not draw a graph if the data given is null or empty. * /* ww w . j av a 2s . co m*/ * @param graphics * the graphics context on which the bargraph should be rendered. * @param drawArea * the area on which the bargraph should be drawn. */ public void draw(final Graphics2D graphics, final Rectangle2D drawArea) { if (graphics == null) { throw new NullPointerException(); } if (drawArea == null) { throw new NullPointerException(); } final int height = (int) drawArea.getHeight(); if (height <= 0) { return; } final Graphics2D g2 = (Graphics2D) graphics.create(); if (background != null) { g2.setPaint(background); g2.draw(drawArea); } if (data == null || data.length == 0) { g2.dispose(); return; } g2.translate(drawArea.getX(), drawArea.getY()); float d = getDivisor(data, height); final int spacing = getSpacing(); final int w = (((int) drawArea.getWidth()) - (spacing * (data.length - 1))) / (data.length - 1); float min = Float.MAX_VALUE; for (int index = 0; index < data.length; index++) { Number i = data[index]; if (i == null) { continue; } final float value = i.floatValue(); if (value < min) { min = value; } } int x = 0; int y = -1; if (d == 0.0) { // special case -- a horizontal straight line d = 1.0f; y = -height / 2; } final Line2D.Double line = new Line2D.Double(); for (int i = 0; i < data.length - 1; i++) { final int px1 = x; x += (w + spacing); final int px2 = x; g2.setPaint(color); final Number number = data[i]; final Number nextNumber = data[i + 1]; if (number == null && nextNumber == null) { final float delta = height - ((0 - min) / d); line.setLine(px1, y + delta, px2, y + delta); } else if (number == null) { line.setLine(px1, y + (height - ((0 - min) / d)), px2, y + (height - ((nextNumber.floatValue() - min) / d))); } else if (nextNumber == null) { line.setLine(px1, y + (height - ((number.floatValue() - min) / d)), px2, y + (height - ((0 - min) / d))); } else { line.setLine(px1, y + (height - ((number.floatValue() - min) / d)), px2, y + (height - ((nextNumber.floatValue() - min) / d))); } g2.draw(line); } g2.dispose(); }
From source file:it.unibo.alchemist.boundary.monitors.Generic2DDisplay.java
private Shape convertObstacle(final Obstacle2D o) { final Rectangle2D r = o.getBounds2D(); final Position[] points = new Position[] { new Continuous2DEuclidean(r.getX(), r.getY()), new Continuous2DEuclidean(r.getX() + r.getWidth(), r.getY()), new Continuous2DEuclidean(r.getX() + r.getWidth(), r.getY() + r.getHeight()), new Continuous2DEuclidean(r.getX(), r.getY() + r.getHeight()) }; final Path2D path = new GeneralPath(); for (int i = 0; i < points.length; i++) { final Point pt = wormhole.getViewPoint(points[i]); if (i == 0) { path.moveTo(pt.getX(), pt.getY()); }/*from w w w . j a v a 2s .c o m*/ path.lineTo(pt.getX(), pt.getY()); } path.closePath(); return path; }
From source file:piramide.interaction.reasoner.FuzzyReasonerWizardFacade.java
private BufferedImage createErrorMessagesImage(String text) { final Font font = TextTitle.DEFAULT_FONT; final Font bigBold = new Font(font.getName(), Font.BOLD, 24); final FontRenderContext frc = new FontRenderContext(null, true, false); final TextLayout layout = new TextLayout(text, bigBold, frc); final Rectangle2D bounds = layout.getBounds(); final int w = (int) Math.ceil(bounds.getWidth()); final int h = (int) Math.ceil(bounds.getHeight()); final BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); final Graphics2D g = image.createGraphics(); g.setColor(Color.WHITE);/*w ww . j a v a 2 s. c o m*/ g.fillRect(0, 0, w, h); g.setColor(Color.RED); g.setFont(bigBold); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF); g.drawString(text, (float) -bounds.getX(), (float) -bounds.getY()); g.dispose(); return image; }