List of usage examples for java.awt.geom Rectangle2D getHeight
public abstract double getHeight();
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) {//ww w. j a v a2 s . c o m 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:net.sf.fspdfs.chartthemes.spring.ScaledDialValueIndicator.java
/** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). *//* w w w. ja va 2 s. c o m*/ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, getRadius(), this.getRadius()); Arc2D arc = new Arc2D.Double(f, this.getAngle(), 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // calculate the bounds of the template value FontMetrics fm = g2.getFontMetrics(this.getFont()); String s = this.getNumberFormat().format(this.getTemplateValue()); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(), this.getFrameAnchor()); // add the insets Rectangle2D fb = this.getInsets().createOutsetRectangle(bounds); // draw the background g2.setPaint(this.getBackgroundPaint()); g2.fill(fb); // draw the border g2.setStroke(this.getOutlineStroke()); g2.setPaint(this.getOutlinePaint()); g2.draw(fb); // now find the text anchor point String valueStr = this.getNumberFormat() .format(ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale)); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.getValueAnchor()); g2.setPaint(this.getPaint()); g2.setFont(this.getFont()); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.getTextAnchor()); }
From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialValueIndicator.java
/** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). */// ww w . java 2 s .co m @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, getRadius(), this.getRadius()); Arc2D arc = new Arc2D.Double(f, this.getAngle(), 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // calculate the bounds of the template value FontMetrics fm = g2.getFontMetrics(this.getFont()); String s = this.getNumberFormat().format(this.getTemplateValue()); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(tb.getWidth(), tb.getHeight()), pt.getX(), pt.getY(), this.getFrameAnchor()); // add the insets Rectangle2D fb = this.getInsets().createOutsetRectangle(bounds); // draw the background g2.setPaint(this.getBackgroundPaint()); g2.fill(fb); // draw the border g2.setStroke(this.getOutlineStroke()); g2.setPaint(this.getOutlinePaint()); g2.draw(fb); // now find the text anchor point String valueStr = this.getNumberFormat() .format(ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale)); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.getValueAnchor()); g2.setPaint(this.getPaint()); g2.setFont(this.getFont()); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.getTextAnchor()); }
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 {//from w ww .j a v a 2 s . c om 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:net.sf.jasperreports.charts.util.ImageChartRendererFactory.java
@Override public Renderable getRenderable(JasperReportsContext jasperReportsContext, JFreeChart chart, ChartHyperlinkProvider chartHyperlinkProvider, Rectangle2D rectangle) { int dpi = JRPropertiesUtil.getInstance(jasperReportsContext) .getIntegerProperty(Renderable.PROPERTY_IMAGE_DPI, 72); double scale = dpi / 72d; BufferedImage bi = new BufferedImage((int) (scale * (int) rectangle.getWidth()), (int) (scale * rectangle.getHeight()), BufferedImage.TYPE_INT_ARGB); List<JRPrintImageAreaHyperlink> areaHyperlinks = null; Graphics2D grx = bi.createGraphics(); try {// w ww. ja v a 2s . c o m grx.scale(scale, scale); if (chartHyperlinkProvider != null && chartHyperlinkProvider.hasHyperlinks()) { areaHyperlinks = ChartUtil.getImageAreaHyperlinks(chart, chartHyperlinkProvider, grx, rectangle); } else { chart.draw(grx, rectangle); } } finally { grx.dispose(); } try { return new SimpleDataRenderer( JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, ImageTypeEnum.PNG), areaHyperlinks); } catch (JRException e) { throw new JRRuntimeException(e); } }
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: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);/*from w w w .j ava 2 s. com*/ 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; }
From source file:com.projity.pm.graphic.xbs.XbsLayout.java
private void setShape(GraphicNode node, Rectangle2D ref, double centerX, double centerY) { TexturedShape texturedShape = findShape(node); if (texturedShape == null) return;/*from w w w . j a v a2 s .co m*/ GeneralPath shape = texturedShape.toGeneralPath(ref.getWidth(), ref.getHeight(), centerX - ref.getWidth() / 2, centerY, null); node.setXbsShape(shape, centerX, centerY); Rectangle.union(bounds, network.scale(shape.getBounds()), bounds); }
From source file:BookTest.java
/** * Gets the page count of this section./*from w ww . j a v a 2 s.c o m*/ * @param g2 the graphics context * @param pf the page format * @return the number of pages needed */ public int getPageCount(Graphics2D g2, PageFormat pf) { if (message.equals("")) return 0; FontRenderContext context = g2.getFontRenderContext(); Font f = new Font("Serif", Font.PLAIN, 72); Rectangle2D bounds = f.getStringBounds(message, context); scale = pf.getImageableHeight() / bounds.getHeight(); double width = scale * bounds.getWidth(); int pages = (int) Math.ceil(width / pf.getImageableWidth()); return pages; }
From source file:pl.edu.icm.visnow.system.main.VisNow.java
private static void renderSplashFrame(float progress, String loadText, String bottomTextUpperLine, String bottomTextLowerLine) { if (splash == null) { return;//from w w w. j a v a2 s. com } try { Graphics2D g = splash.createGraphics(); if (g == null) { return; } if (!splash.isVisible()) return; Rectangle bounds = splash.getBounds(); Font f = g.getFont(); FontMetrics fm = g.getFontMetrics(f); java.awt.geom.Rectangle2D rect = fm.getStringBounds(loadText, g); int texth = (int) Math.ceil(rect.getHeight()); g.setComposite(AlphaComposite.Clear); //g.setColor(Color.RED); g.fillRect(PROGRESS_TEXT_X_POSITION, bounds.height - PROGRESS_TEXT_Y_MARGIN - texth - 5, bounds.width - PROGRESS_TEXT_X_POSITION, texth + 10); g.setFont(lowerLineFont); fm = g.getFontMetrics(g.getFont()); rect = fm.getStringBounds(bottomTextLowerLine, g); int lowerLineTextHeight = (int) Math.ceil(rect.getHeight()); g.fillRect(BOTTOM_TEXT_X_MARGIN, bounds.height - BOTTOM_TEXT_Y_MARGIN - lowerLineTextHeight - 5, bounds.width - BOTTOM_TEXT_X_MARGIN, lowerLineTextHeight + 10); g.setFont(f); fm = g.getFontMetrics(g.getFont()); rect = fm.getStringBounds(bottomTextUpperLine, g); texth = (int) Math.ceil(rect.getHeight()); g.fillRect(BOTTOM_TEXT_X_MARGIN, bounds.height - lowerLineTextHeight - BOTTOM_TEXT_Y_MARGIN - texth - 5, bounds.width - BOTTOM_TEXT_X_MARGIN, lowerLineTextHeight + 10); g.setPaintMode(); // g.setColor(Color.BLACK); g.setColor(new Color(0, 75, 50)); g.drawString(loadText, PROGRESS_TEXT_X_POSITION, bounds.height - PROGRESS_TEXT_Y_MARGIN); g.drawString(bottomTextUpperLine, BOTTOM_TEXT_X_MARGIN, bounds.height - lowerLineTextHeight - BOTTOM_TEXT_Y_MARGIN); g.setFont(lowerLineFont); g.drawString(bottomTextLowerLine, BOTTOM_TEXT_X_MARGIN, bounds.height - BOTTOM_TEXT_Y_MARGIN); g.setFont(f); // g.setColor(Color.BLACK); g.setColor(new Color(0, 150, 100)); g.drawRect(PROGRESS_BAR_X_MARGIN, bounds.height - PROGRESS_BAR_Y_MARGIN, bounds.width - PROGRESS_BAR_X_MARGIN, PROGRESS_BAR_HEIGHT); int progressWidth = bounds.width - 2 * PROGRESS_BAR_X_MARGIN; int done = (int) (progressWidth * progress); g.fillRect(PROGRESS_BAR_X_MARGIN, bounds.height - PROGRESS_BAR_Y_MARGIN, PROGRESS_BAR_X_MARGIN + done, PROGRESS_BAR_HEIGHT); if (progress >= 1.0f) { g.fillRect(PROGRESS_BAR_X_MARGIN, bounds.height - PROGRESS_BAR_Y_MARGIN, bounds.width - PROGRESS_BAR_X_MARGIN, PROGRESS_BAR_HEIGHT); } splash.update(); } catch (IllegalStateException ex) { } }