List of usage examples for org.jfree.ui Size2D Size2D
public Size2D(final double width, final double height)
From source file:gda.plots.BlockWrapper.java
/** * Usually this returns the Size2D that the object would like to have given the constraints applied - we just return * the width and height of our wrapped JComponent. * /* ww w.j a va 2 s . co m*/ * @param g2 * the Graphics2D into which the object will be drawn * @param constraint * a set of constraints (ignored here) * @return a Size2D that the object requires for successful drawing. */ @Override public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { logger.debug("BW constraint is " + constraint); Size2D rtrn = new Size2D(jc.getWidth(), jc.getHeight()); logger.debug("BW rtrn is " + rtrn); Dimension d = jc.getPreferredSize(); rtrn = new Size2D(d.getWidth(), d.getHeight()); logger.debug("BW rtrn is " + d); return rtrn; }
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). *///w w w .ja va 2s. com @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.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 . j a v a 2s.c om 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:com.hmsinc.epicenter.webapp.chart.SNColumnArrangement.java
/** * Calculates and sets the bounds of all the items in the specified * container, subject to the given constraint. The <code>Graphics2D</code> * can be used by some items (particularly items containing text) to * calculate sizing parameters./*from w w w .j av a 2s. co m*/ * * @param container * the container whose items are being arranged. * @param g2 * the graphics device. * @param constraint * the size constraint. * * @return The size of the container after arrangement of the contents. */ @SuppressWarnings("unchecked") public Size2D arrange(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { List<Block> blocks = container.getBlocks(); // calculate max width of entries double maxWidth = 0.0; double maxHeight = 0.0; for (Block block : blocks) { Size2D size = block.arrange(g2, RectangleConstraint.NONE); maxWidth = Math.max(maxWidth, size.width + this.horizontalGap); maxHeight = Math.max(maxHeight, size.height + this.verticalGap); } // calculate number of columns double width = 0.0; if (constraint.getWidthConstraintType() == LengthConstraintType.FIXED) { width = constraint.getWidth(); } else if (constraint.getWidthConstraintType() == LengthConstraintType.RANGE) { Range range = constraint.getWidthRange(); width = range.getUpperBound(); } else { throw new RuntimeException("Not implemented."); } int columns = (int) (Math.floor(width / maxWidth)); if (columns > 0) { columns--; } // for all columns int colx = -1; int coly = 0; for (Block block : blocks) { Size2D size = block.arrange(g2, RectangleConstraint.NONE); if (colx < columns) { colx++; } else { colx = 0; coly++; } double x = colx * maxWidth; double y = coly * maxHeight; block.setBounds(new Rectangle2D.Double(x, y, size.width, size.height)); } // calculate size of bounding double bWidth = (coly == 0) ? (colx + 1) * maxWidth : (columns + 1) * maxWidth; double bHeight = (coly + 1) * maxHeight; return new Size2D(bWidth, bHeight); }
From source file:org.jfree.experimental.chart.plot.dial.DialValueIndicator.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). *//*from www . ja v a2 s. c om*/ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius); Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // calculate the bounds of the template value FontMetrics fm = g2.getFontMetrics(this.font); String s = this.formatter.format(this.templateValue); 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.frameAnchor); // add the insets Rectangle2D fb = this.insets.createOutsetRectangle(bounds); // draw the background g2.setPaint(this.backgroundPaint); g2.fill(fb); // draw the border g2.setStroke(this.outlineStroke); g2.setPaint(this.outlinePaint); g2.draw(fb); // now find the text anchor point double value = plot.getValue(this.datasetIndex); String valueStr = this.formatter.format(value); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor); g2.setPaint(this.paint); g2.setFont(this.font); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor); }