List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * calculates the correct height with multiple iterations Domain and Range axes need to share the * same unit (e.g. mm)/*w w w .jav a 2 s . c o m*/ * * @param myChart * @param copyToNewPanel * @param dataWidth width of data * @param axis for width calculation * @return */ public static double calcHeightToWidth(ChartPanel myChart, double chartWidth, double estimatedHeight, int iterations, boolean copyToNewPanel) { // if(myChart.getChartRenderingInfo()==null || // myChart.getChartRenderingInfo().getChartArea()==null || // myChart.getChartRenderingInfo().getChartArea().getWidth()==0) // result double height = estimatedHeight; double lastH = height; makeChartResizable(myChart); // paint on a ghost panel JPanel parent = (JPanel) myChart.getParent(); JPanel p = copyToNewPanel ? new JPanel() : parent; if (copyToNewPanel) p.add(myChart, BorderLayout.CENTER); try { for (int i = 0; i < iterations; i++) { // paint on ghost panel with estimated height (if copy panel==true) myChart.setSize((int) chartWidth, (int) estimatedHeight); myChart.paintImmediately(myChart.getBounds()); XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ChartRenderingInfo info = myChart.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); Rectangle2D chartArea = info.getChartArea(); // calc title space: will be added later to the right plot size double titleWidth = chartArea.getWidth() - dataArea.getWidth(); double titleHeight = chartArea.getHeight() - dataArea.getHeight(); // calc right plot size with axis dim. // real plot width is given by factor; double realPW = chartWidth - titleWidth; // ranges ValueAxis domainAxis = plot.getDomainAxis(); org.jfree.data.Range x = domainAxis.getRange(); ValueAxis rangeAxis = plot.getRangeAxis(); org.jfree.data.Range y = rangeAxis.getRange(); // real plot height can be calculated by double realPH = realPW / x.getLength() * y.getLength(); // the real height height = realPH + titleHeight; // for next iteration estimatedHeight = height; if ((int) lastH == (int) height) break; else lastH = height; } } catch (Exception ex) { ex.printStackTrace(); } if (copyToNewPanel) { // reset to frame p.removeAll(); parent.add(myChart); } return height; }
From source file:org.apache.xmlgraphics.ps.PSImageUtils.java
/** * Places an EPS file in the PostScript stream. * @param in the InputStream that contains the EPS stream * @param name name for the EPS document * @param viewport the viewport in points in which to place the EPS * @param bbox the EPS bounding box in points * @param gen the PS generator// ww w .j ava 2 s. c o m * @throws IOException in case an I/O error happens during output */ public static void renderEPS(InputStream in, String name, Rectangle2D viewport, Rectangle2D bbox, PSGenerator gen) throws IOException { gen.getResourceTracker().notifyResourceUsageOnPage(PSProcSets.EPS_PROCSET); gen.writeln("%AXGBeginEPS: " + name); gen.writeln("BeginEPSF"); gen.writeln(gen.formatDouble(viewport.getX()) + " " + gen.formatDouble(viewport.getY()) + " translate"); gen.writeln("0 " + gen.formatDouble(viewport.getHeight()) + " translate"); gen.writeln("1 -1 scale"); double sx = viewport.getWidth() / bbox.getWidth(); double sy = viewport.getHeight() / bbox.getHeight(); if (sx != 1 || sy != 1) { gen.writeln(gen.formatDouble(sx) + " " + gen.formatDouble(sy) + " scale"); } if (bbox.getX() != 0 || bbox.getY() != 0) { gen.writeln(gen.formatDouble(-bbox.getX()) + " " + gen.formatDouble(-bbox.getY()) + " translate"); } gen.writeln(gen.formatDouble(bbox.getX()) + " " + gen.formatDouble(bbox.getY()) + " " + gen.formatDouble(bbox.getWidth()) + " " + gen.formatDouble(bbox.getHeight()) + " re clip"); gen.writeln("newpath"); PSResource res = new PSResource(PSResource.TYPE_FILE, name); gen.getResourceTracker().registerSuppliedResource(res); gen.getResourceTracker().notifyResourceUsageOnPage(res); gen.writeDSCComment(DSCConstants.BEGIN_DOCUMENT, res.getName()); IOUtils.copy(in, gen.getOutputStream()); gen.newLine(); gen.writeDSCComment(DSCConstants.END_DOCUMENT); gen.writeln("EndEPSF"); gen.writeln("%AXGEndEPS"); }
From source file:ca.sqlpower.wabit.swingui.chart.WabitJFreeChartPanel.java
private float getXaxisBaseline() { Rectangle2D dataArea = getScreenDataArea(); return (float) (dataArea.getY() + dataArea.getHeight()); }
From source file:ShowOff.java
protected float drawBoxedString(Graphics2D g2, String s, Color c1, Color c2, double x) { FontRenderContext frc = g2.getFontRenderContext(); TextLayout subLayout = new TextLayout(s, mFont, frc); float advance = subLayout.getAdvance(); GradientPaint gradient = new GradientPaint((float) x, 0, c1, (float) (x + advance), 0, c2); g2.setPaint(gradient);//from w w w. j av a 2 s .com Rectangle2D bounds = mLayout.getBounds(); Rectangle2D back = new Rectangle2D.Double(x, 0, advance, bounds.getHeight()); g2.fill(back); g2.setPaint(Color.white); g2.setFont(mFont); g2.drawString(s, (float) x, (float) -bounds.getY()); return advance; }
From source file:edu.ucla.stat.SOCR.chart.gui.CircleDrawer.java
/** * Draws the circle.// w w w . ja v a 2 s.com * * @param g2 the graphics device. * @param area the area in which to draw. */ public void draw(Graphics2D g2, Rectangle2D area) { Ellipse2D ellipse = new Ellipse2D.Double(area.getX(), area.getY(), area.getWidth(), area.getHeight()); if (this.fillPaint != null) { g2.setPaint(this.fillPaint); g2.fill(ellipse); } if (this.outlinePaint != null && this.outlineStroke != null) { g2.setPaint(this.outlinePaint); g2.setStroke(this.outlineStroke); g2.draw(ellipse); } g2.setPaint(Color.black); g2.setStroke(new BasicStroke(1.0f)); Line2D line1 = new Line2D.Double(area.getCenterX(), area.getMinY(), area.getCenterX(), area.getMaxY()); Line2D line2 = new Line2D.Double(area.getMinX(), area.getCenterY(), area.getMaxX(), area.getCenterY()); g2.draw(line1); g2.draw(line2); }
From source file:ImageLabel.java
public void paint(Graphics g) { /*// ww w . ja v a 2 s . c o m * Draw the image stretched to exactly cover the size of the drawing area. */ Dimension size = getSize(); g.drawImage(img, 0, 0, size.width, size.height, 0, 0, img.getWidth(null), img.getHeight(null), null); /* * Fill a rounded rectangle centered in the drawing area. Calculate the size * of the rectangle from the size of the text */ g.setFont(font); FontRenderContext frc = ((Graphics2D) g).getFontRenderContext(); Rectangle2D bounds = font.getStringBounds(text, frc); int wText = (int) bounds.getWidth(); int hText = (int) bounds.getHeight(); int rX = (size.width - wText) / 2; int rY = (size.height - hText) / 2; g.setColor(Color.yellow); g.fillRoundRect(rX, rY, wText, hText, hText / 2, hText / 2); /* * Draw text positioned in the rectangle. Since the rectangle is sized based * on the bounds of the String we can position it using those bounds. */ int xText = rX - (int) bounds.getX(); int yText = rY - (int) bounds.getY(); g.setColor(Color.black); g.setFont(font); g.drawString(text, xText, yText); }
From source file:ShowOff.java
protected void drawText(Graphics2D g2) { FontRenderContext frc = g2.getFontRenderContext(); mLayout = new TextLayout(mMessage, mFont, frc); int width = getSize().width; int height = getSize().height; Rectangle2D bounds = mLayout.getBounds(); double x = (width - bounds.getWidth()) / 2; double y = height - bounds.getHeight(); drawString(g2, x, y, 0);/*www.j a v a2s. c o m*/ drawString(g2, width - bounds.getHeight(), y, -Math.PI / 2); }
From source file:net.sf.jasperreports.customizers.shape.LineDotShapeCustomizer.java
@Override protected Point getOffset(Rectangle2D bounds) { return new Point((int) (bounds.getWidth() / 2 + bounds.getX()), (int) (bounds.getHeight() / 2 + bounds.getY())); }
From source file:edu.umn.ecology.populus.plot.ChartRendererWithOrientatedShapes.java
@Override protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis, CrosshairState crosshairState, EntityCollection entities) {/*from w w w . j a v a 2 s . com*/ //Orient the shapes first double graphicsRatio = dataArea.getHeight() / dataArea.getWidth(); double dataRatio = plot.getRangeAxis().getRange().getLength() / plot.getDomainAxis().getRange().getLength(); double ratio = graphicsRatio / dataRatio; bpInfo.updateDirectedSymbolsJFC(this, ratio); //Now call this to do the rest super.drawSecondaryPass(g2, plot, dataset, pass, series, item, domainAxis, dataArea, rangeAxis, crosshairState, entities); }
From source file:org.jfree.chart.demo.CircleDrawer.java
/** * Draws the circle.//from ww w . java 2 s . c o m * * @param g2 the graphics device. * @param area the area in which to draw. */ public void draw(final Graphics2D g2, final Rectangle2D area) { final Ellipse2D ellipse = new Ellipse2D.Double(area.getX(), area.getY(), area.getWidth(), area.getHeight()); if (this.fillPaint != null) { g2.setPaint(this.fillPaint); g2.fill(ellipse); } if (this.outlinePaint != null && this.outlineStroke != null) { g2.setPaint(this.outlinePaint); g2.setStroke(this.outlineStroke); g2.draw(ellipse); } g2.setPaint(Color.black); g2.setStroke(new BasicStroke(1.0f)); final Line2D line1 = new Line2D.Double(area.getCenterX(), area.getMinY(), area.getCenterX(), area.getMaxY()); final Line2D line2 = new Line2D.Double(area.getMinX(), area.getCenterY(), area.getMaxX(), area.getCenterY()); g2.draw(line1); g2.draw(line2); }