List of usage examples for java.awt.geom Rectangle2D getX
public abstract double getX();
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// w w w .ja v a2 s. co 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:Main.java
/** * Creates and returns image from the given text. * @param text input text/* w w w . j av a 2s. co m*/ * @param font text font * @return image with input text */ public static BufferedImage createImageFromText(String text, Font font) { //You may want to change these setting, or make them parameters boolean isAntiAliased = true; boolean usesFractionalMetrics = false; FontRenderContext frc = new FontRenderContext(null, isAntiAliased, usesFractionalMetrics); TextLayout layout = new TextLayout(text, font, frc); Rectangle2D bounds = layout.getBounds(); int w = (int) Math.ceil(bounds.getWidth()); int h = (int) Math.ceil(bounds.getHeight()) + 2; BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); //for example; Graphics2D g = image.createGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, w, h); g.setColor(Color.BLACK); g.setFont(font); Object antiAliased = isAntiAliased ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF; g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, antiAliased); Object fractionalMetrics = usesFractionalMetrics ? RenderingHints.VALUE_FRACTIONALMETRICS_ON : RenderingHints.VALUE_FRACTIONALMETRICS_OFF; g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, fractionalMetrics); g.drawString(text, (float) -bounds.getX(), (float) -bounds.getY()); g.dispose(); return image; }
From source file:edu.ucla.stat.SOCR.chart.gui.CircleDrawer.java
/** * Draws the circle./*from ww w . j ava2s . c o m*/ * * @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: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:org.jfree.chart.demo.CircleDrawer.java
/** * Draws the circle.// w ww . ja v a 2 s. c om * * @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); }
From source file:com.rapidminer.gui.plotter.charts.WeightBasedSymbolAxis.java
/** * Draws the grid bands for the axis when it is at the top or bottom of the plot. * //from w ww.j a v a2 s.c om * @param g2 * the graphics device. * @param drawArea * the area within which the chart should be drawn. * @param plotArea * the area within which the plot should be drawn (a subset of the drawArea). * @param firstGridBandIsDark * True: the first grid band takes the color of <CODE>gridBandPaint<CODE>. * False: the second grid band takes the * color of <CODE>gridBandPaint<CODE>. * @param ticks * a list of ticks. */ @Override protected void drawGridBandsVertical(Graphics2D g2, Rectangle2D drawArea, Rectangle2D plotArea, boolean firstGridBandIsDark, List ticks) { double xx = plotArea.getX(); double yy1, yy2; // gets the outline stroke width of the plot double outlineStrokeWidth; Stroke outlineStroke = getPlot().getOutlineStroke(); if (outlineStroke != null && outlineStroke instanceof BasicStroke) { outlineStrokeWidth = ((BasicStroke) outlineStroke).getLineWidth(); } else { outlineStrokeWidth = 1d; } Iterator iterator = ticks.iterator(); ValueTick tick; Rectangle2D band; while (iterator.hasNext()) { tick = (ValueTick) iterator.next(); int weightIndex = (int) tick.getValue(); yy1 = valueToJava2D(tick.getValue() + 0.5d, plotArea, RectangleEdge.LEFT); yy2 = valueToJava2D(tick.getValue() - 0.5d, plotArea, RectangleEdge.LEFT); g2.setColor(PlotterAdapter.getWeightColor(this.weights[weightIndex], this.maxWeight)); band = new Rectangle2D.Double(xx + outlineStrokeWidth, yy1, plotArea.getMaxX() - xx - outlineStrokeWidth, yy2 - yy1); g2.fill(band); } g2.setPaintMode(); }
From source file:grafix.telas.MolduraAreaDados.java
public void setPosicao(Rectangle2D rect) { this.setLocation((int) rect.getX(), (int) rect.getY()); this.setSize((int) rect.getWidth(), (int) rect.getHeight()); }
From source file:edu.uci.ics.jung.visualization.util.VertexShapeFactory.java
/** * Returns a <code>RoundRectangle2D</code> whose width and * height are defined by this instance's size and * aspect ratio functions for this vertex. The arc size is * set to be half the minimum of the height and width of the frame. *//*from ww w .j ava 2s .c o m*/ public RoundRectangle2D getRoundRectangle(V v) { Rectangle2D frame = getRectangle(v); float arc_size = (float) Math.min(frame.getHeight(), frame.getWidth()) / 2; theRoundRectangle.setRoundRect(frame.getX(), frame.getY(), frame.getWidth(), frame.getHeight(), arc_size, arc_size); return theRoundRectangle; }
From source file:com.epiq.bitshark.ui.FrequencyDomainMouseMarker.java
/** * Draws the marker// www.ja va2 s . c o m * @param g2 * @param rect */ public void draw(Graphics2D g2, Rectangle2D rect) { g2.setColor(outlineColor); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.fillOval((int) Math.round(rect.getX()), (int) Math.round(rect.getY()), (int) Math.round(rect.getWidth()), (int) Math.round(rect.getHeight())); }
From source file:org.jfree.demo.TextBlockPanel.java
/** * Paints the panel.// w w w . j ava2s . c om * * @param g the graphics device. */ public void paintComponent(final Graphics g) { super.paintComponent(g); final Graphics2D g2 = (Graphics2D) g; final Dimension size = getSize(); final Insets insets = getInsets(); final Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); final double x = available.getX(); final double y = available.getY(); final float width = (float) available.getWidth(); final TextBlock block = TextUtilities.createTextBlock(this.text, this.font, Color.black, width, new G2TextMeasurer(g2)); g2.setPaint(Color.black); block.draw(g2, (float) x, (float) y, TextBlockAnchor.TOP_LEFT, 0.0f, 0.0f, 0.0); }