List of usage examples for java.awt.geom Rectangle2D.Double Rectangle2D.Double
public Double(double x, double y, double w, double h)
From source file:sim.util.media.chart.ScatterPlotSeriesAttributes.java
static Shape[] buildShapes() { Shape[] s = new Shape[7]; GeneralPath g = null;//from w w w .j av a 2 s. c o m // Circle s[0] = new Ellipse2D.Double(-3, -3, 6, 6); // Rectangle Rectangle2D.Double r = new Rectangle2D.Double(-3, -3, 6, 6); s[1] = r; // Diamond s[2] = AffineTransform.getRotateInstance(Math.PI / 4.0).createTransformedShape(r); // Cross + g = new GeneralPath(); g.moveTo(-0.5f, -3); g.lineTo(-0.5f, -0.5f); g.lineTo(-3, -0.5f); g.lineTo(-3, 0.5f); g.lineTo(-0.5f, 0.5f); g.lineTo(-0.5f, 3); g.lineTo(0.5f, 3); g.lineTo(0.5f, 0.5f); g.lineTo(3, 0.5f); g.lineTo(3, -0.5f); g.lineTo(0.5f, -0.5f); g.lineTo(0.5f, -3); g.closePath(); s[3] = g; // X s[4] = g.createTransformedShape(AffineTransform.getRotateInstance(Math.PI / 4.0)); // Up Triangle g = new GeneralPath(); g.moveTo(0f, -3); g.lineTo(-3, 3); g.lineTo(3, 3); g.closePath(); s[5] = g; // Down Triangle s[6] = g.createTransformedShape(AffineTransform.getRotateInstance(Math.PI)); return s; }
From source file:sim.util.media.PDFEncoder.java
public static void generatePDF(JFreeChart chart, int width, int height, File file) { try {// w ww . ja va 2 s . co m Document document = new Document(new com.lowagie.text.Rectangle(width, height)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.addAuthor("MASON"); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height); chart.draw(g2, rectangle2D); g2.dispose(); cb.addTemplate(tp, 0, 0); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:GraphicsUtil.java
public static Rectangle2D expand(RectangularShape rect, double amountX, double amountY) { return new Rectangle2D.Double(rect.getX() - amountX, rect.getY() - amountY, rect.getWidth() + (2 * amountX), rect.getHeight() + (2 * amountY)); }
From source file:GraphicsUtil.java
public static Rectangle2D contract(RectangularShape rect, double amountX, double amountY) { return new Rectangle2D.Double(rect.getX() + amountX, rect.getY() + amountY, rect.getWidth() - (2 * amountX), rect.getHeight() - (2 * amountY)); }
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.// ww w. j av a 2 s . com @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:DrawingApplet.java
public Shape createRectangle(double x, double y, double w, double h) { return new Rectangle2D.Double(x, y, w, h); }
From source file:Chart.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; // compute the minimum and maximum values if (values == null) return; double minValue = 0; double maxValue = 0; for (double v : values) {// w w w .j a va 2s . c om if (minValue > v) minValue = v; if (maxValue < v) maxValue = v; } if (maxValue == minValue) return; int panelWidth = getWidth(); int panelHeight = getHeight(); Font titleFont = new Font("SansSerif", Font.BOLD, 20); Font labelFont = new Font("SansSerif", Font.PLAIN, 10); // compute the extent of the title FontRenderContext context = g2.getFontRenderContext(); Rectangle2D titleBounds = titleFont.getStringBounds(title, context); double titleWidth = titleBounds.getWidth(); double top = titleBounds.getHeight(); // draw the title double y = -titleBounds.getY(); // ascent double x = (panelWidth - titleWidth) / 2; g2.setFont(titleFont); g2.drawString(title, (float) x, (float) y); // compute the extent of the bar labels LineMetrics labelMetrics = labelFont.getLineMetrics("", context); double bottom = labelMetrics.getHeight(); y = panelHeight - labelMetrics.getDescent(); g2.setFont(labelFont); // get the scale factor and width for the bars double scale = (panelHeight - top - bottom) / (maxValue - minValue); int barWidth = panelWidth / values.length; // draw the bars for (int i = 0; i < values.length; i++) { // get the coordinates of the bar rectangle double x1 = i * barWidth + 1; double y1 = top; double height = values[i] * scale; if (values[i] >= 0) y1 += (maxValue - values[i]) * scale; else { y1 += maxValue * scale; height = -height; } // fill the bar and draw the bar outline Rectangle2D rect = new Rectangle2D.Double(x1, y1, barWidth - 2, height); g2.setPaint(Color.RED); g2.fill(rect); g2.setPaint(Color.BLACK); g2.draw(rect); // draw the centered label below the bar Rectangle2D labelBounds = labelFont.getStringBounds(names[i], context); double labelWidth = labelBounds.getWidth(); x = x1 + (barWidth - labelWidth) / 2; g2.drawString(names[i], (float) x, (float) y); } }
From source file:ucar.unidata.idv.control.chart.MyTimeSeriesPlot.java
/** * Override this method because it gets called after the graphics clip * has been reset./* ww w. j a va 2s .c o m*/ * TODO: We end up drawing the annotations twice. Figure something out to * only draw once. * * @param g2 the graphics * @param dataArea the data area */ public void drawOutline(Graphics2D g2, Rectangle2D dataArea) { super.drawOutline(g2, dataArea); Shape originalClip = g2.getClip(); double y = dataArea.getY(); Rectangle2D.Double newClip = new Rectangle2D.Double(dataArea.getX(), 0, dataArea.getWidth(), dataArea.getHeight() + y); g2.clip(newClip); drawAnnotations(g2, dataArea, null); g2.clip(originalClip); }
From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java
@Override public void drawBackground(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea) { float x0 = (float) dataArea.getX(); float x1 = x0 + (float) Math.abs(getXOffset()); float x3 = (float) dataArea.getMaxX(); float x2 = x3 - (float) Math.abs(getXOffset()); float y0 = (float) dataArea.getMaxY(); float y1 = y0 - (float) Math.abs(getYOffset()); float y3 = (float) dataArea.getMinY(); float y2 = y3 + (float) Math.abs(getYOffset()); GeneralPath clip = new GeneralPath(); clip.moveTo(x0, y0);/*from www. j a va 2 s.c o m*/ clip.lineTo(x0, y2); clip.lineTo(x1, y3); clip.lineTo(x3, y3); clip.lineTo(x3, y1); clip.lineTo(x2, y0); clip.closePath(); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, plot.getBackgroundAlpha())); // fill background... Paint backgroundPaint = plot.getBackgroundPaint(); if (backgroundPaint != null) { g2.setPaint(backgroundPaint); g2.fill(clip); } GeneralPath bottomWall = new GeneralPath(); bottomWall.moveTo(x0, y0); bottomWall.lineTo(x1, y1); bottomWall.lineTo(x3, y1); bottomWall.lineTo(x2, y0); bottomWall.closePath(); g2.setPaint(getWallPaint()); g2.fill(bottomWall); // draw background image, if there is one... Image backgroundImage = plot.getBackgroundImage(); if (backgroundImage != null) { Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX() + getXOffset(), dataArea.getY(), dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset()); plot.drawBackgroundImage(g2, adjusted); } g2.setComposite(originalComposite); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
public Rectangle2D computeSizeData(AnnotationObject a) { // compute bbox theGlycanRenderer.getGraphicOptions().setScale(theOptions.SCALE_GLYCANS * theDocument.getScale(a)); Rectangle bbox = theGlycanRenderer.computeBoundingBoxes(a.getStructures(), false, false, new PositionManager(), new BBoxManager(), false); // compute text bbox DecimalFormat mz_df = new DecimalFormat("0.0"); String mz_text = mz_df.format(a.getPeakPoint().getX()); Dimension mz_dim = textBounds(mz_text, theOptions.ANNOTATION_MZ_FONT, theOptions.ANNOTATION_MZ_SIZE); // update bbox double width = Math.max(bbox.getWidth(), mz_dim.getWidth()); double height = bbox.getHeight() + theOptions.ANNOTATION_MARGIN + theOptions.ANNOTATION_MZ_SIZE; return new Rectangle2D.Double(0, 0, screenToDataX(width), screenToDataY(height)); }