List of usage examples for java.awt.geom Rectangle2D getY
public abstract double getY();
From source file:FontTest.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; String message = "Hello, World!"; Font f = new Font("Serif", Font.BOLD, 36); g2.setFont(f);/*from w ww .j a v a 2 s . c o m*/ // measure the size of the message FontRenderContext context = g2.getFontRenderContext(); Rectangle2D bounds = f.getStringBounds(message, context); // set (x,y) = top left corner of text double x = (getWidth() - bounds.getWidth()) / 2; double y = (getHeight() - bounds.getHeight()) / 2; // add ascent to y to reach the baseline double ascent = -bounds.getY(); double baseY = y + ascent; // draw the message g2.drawString(message, (int) x, (int) baseY); g2.setPaint(Color.LIGHT_GRAY); // draw the baseline g2.draw(new Line2D.Double(x, baseY, x + bounds.getWidth(), baseY)); // draw the enclosing rectangle Rectangle2D rect = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight()); g2.draw(rect); }
From source file:com.epiq.bitshark.ui.FrequencyDomainMouseMarker.java
/** * Draws the marker/*w ww . j a va 2 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:grafix.telas.MolduraAreaDados.java
protected void descartarEvento(final java.awt.event.MouseEvent evt) { Rectangle2D areaDados = getAreaData(); evt.translatePoint(arred(areaDados.getX()), arred(areaDados.getY())); // this.getPanelMolduras().dispatchEvent(evt); Controle.getJanelaAtiva().getPanelGraficos().dispatchEvent(evt); // Em teste }
From source file:net.sourceforge.processdash.ui.lib.chart.PaddedAxisHelper.java
public Rectangle2D removePadding(Rectangle2D area, RectangleEdge edge) { boolean inverted = axis.isInverted(); if (RectangleEdge.isTopOrBottom(edge)) { double xPad = inverted ? upperPad : lowerPad; double width = area.getWidth() - upperPad - lowerPad; return new Rectangle2D.Double(area.getX() + xPad, area.getY(), width, area.getHeight()); } else {/* ww w . j av a 2 s . com*/ double yPad = inverted ? lowerPad : upperPad; double height = area.getHeight() - upperPad - lowerPad; return new Rectangle2D.Double(area.getX(), area.getY() + yPad, area.getWidth(), height); } }
From source file:org.jfree.demo.TextBlockPanel.java
/** * Paints the panel.//from w w w . java 2 s. c o m * * @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); }
From source file:net.sf.jasperreports.engine.JRImageRenderer.java
@Override public void render(JasperReportsContext jasperReportsContext, Graphics2D grx, Rectangle2D rectangle) throws JRException { Image img = getImage(jasperReportsContext); grx.drawImage(img, (int) rectangle.getX(), (int) rectangle.getY(), (int) rectangle.getWidth(), (int) rectangle.getHeight(), null); }
From source file:XMLWriteTest.java
/** * Writers an SVG document of the current drawing. * @param writer the document destination *//*from www . j a v a 2 s . c o m*/ public void writeDocument(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartDocument(); writer.writeDTD("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20000802//EN\" " + "\"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd\">"); writer.writeStartElement("svg"); writer.writeAttribute("width", "" + getWidth()); writer.writeAttribute("height", "" + getHeight()); for (int i = 0; i < rects.size(); i++) { Color c = colors.get(i); Rectangle2D r = rects.get(i); writer.writeEmptyElement("rect"); writer.writeAttribute("x", "" + r.getX()); writer.writeAttribute("y", "" + r.getY()); writer.writeAttribute("width", "" + r.getWidth()); writer.writeAttribute("height", "" + r.getHeight()); writer.writeAttribute("fill", colorToString(c)); } writer.writeEndDocument(); // closes svg element }
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 ww. j av a 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:XMLWriteTest.java
/** * Creates an SVG document of the current drawing. * @return the DOM tree of the SVG document *///from w w w . java2 s .co m public Document buildDocument() { Document doc = builder.newDocument(); Element svgElement = doc.createElement("svg"); doc.appendChild(svgElement); svgElement.setAttribute("width", "" + getWidth()); svgElement.setAttribute("height", "" + getHeight()); for (int i = 0; i < rects.size(); i++) { Color c = colors.get(i); Rectangle2D r = rects.get(i); Element rectElement = doc.createElement("rect"); rectElement.setAttribute("x", "" + r.getX()); rectElement.setAttribute("y", "" + r.getY()); rectElement.setAttribute("width", "" + r.getWidth()); rectElement.setAttribute("height", "" + r.getHeight()); rectElement.setAttribute("fill", colorToString(c)); svgElement.appendChild(rectElement); } return doc; }
From source file:Clip.java
/** * Set the clip contents, and set the status to valid and in use. * @param r the clip contents to copy//from ww w .j a v a 2s. co m */ public void setClip(Rectangle2D r) { setClip(r.getX(), r.getY(), r.getWidth(), r.getHeight()); }