public Point textExtent( String text ) { String[] lines = text.split( Const.CR ); int maxWidth = 0; for ( String line : lines ) { Rectangle2D bounds = TextUtilities.getTextBounds( line, gc, gc.getFontMetrics() ); if ( bounds.getWidth() > maxWidth ) { maxWidth = (int) bounds.getWidth(); } } int height = gc.getFontMetrics().getHeight() * lines.length; return new Point( maxWidth, height ); }
public Point textExtent( String text ) { String[] lines = text.split( Const.CR ); int maxWidth = 0; for ( String line : lines ) { Rectangle2D bounds = TextUtilities.getTextBounds( line, gc, gc.getFontMetrics() ); if ( bounds.getWidth() > maxWidth ) { maxWidth = (int) bounds.getWidth(); } } int height = gc.getFontMetrics().getHeight() * lines.length; return new Point( maxWidth, height ); }
/** * Returns the string width. * * @param text the text. * @param start the index of the first character to measure. * @param end the index of the last character to measure. * * @return The string width. */ public float getStringWidth(final String text, final int start, final int end) { final FontMetrics fm = this.g2.getFontMetrics(); final Rectangle2D bounds = TextUtilities.getTextBounds( text.substring(start, end), this.g2, fm ); final float result = (float) bounds.getWidth(); return result; }
/** * Returns the string width. * * @param text the text. * @param start the index of the first character to measure. * @param end the index of the last character to measure. * * @return The string width. */ public float getStringWidth(final String text, final int start, final int end) { final FontMetrics fm = this.g2.getFontMetrics(); final Rectangle2D bounds = TextUtilities.getTextBounds( text.substring(start, end), this.g2, fm ); final float result = (float) bounds.getWidth(); return result; }
/** * Returns the string width. * * @param text the text. * @param start the index of the first character to measure. * @param end the index of the last character to measure. * * @return The string width. */ public float getStringWidth(final String text, final int start, final int end) { final FontMetrics fm = this.g2.getFontMetrics(); final Rectangle2D bounds = TextUtilities.getTextBounds( text.substring(start, end), this.g2, fm ); final float result = (float) bounds.getWidth(); return result; }
/** * Calculates the dimensions of the text fragment. * * @param g2 the graphics device. * * @return The width and height of the text. */ public Size2D calculateDimensions(final Graphics2D g2) { final FontMetrics fm = g2.getFontMetrics(this.font); final Rectangle2D bounds = TextUtilities.getTextBounds(this.text, g2, fm); final Size2D result = new Size2D(bounds.getWidth(), bounds.getHeight()); return result; }
/** * Calculates the dimensions of the text fragment. * * @param g2 the graphics device. * * @return The width and height of the text. */ public Size2D calculateDimensions(final Graphics2D g2) { final FontMetrics fm = g2.getFontMetrics(this.font); final Rectangle2D bounds = TextUtilities.getTextBounds(this.text, g2, fm); final Size2D result = new Size2D(bounds.getWidth(), bounds.getHeight()); return result; }
/** * Calculates the dimensions of the text fragment. * * @param g2 the graphics device. * * @return The width and height of the text. */ public Size2D calculateDimensions(final Graphics2D g2) { final FontMetrics fm = g2.getFontMetrics(this.font); final Rectangle2D bounds = TextUtilities.getTextBounds(this.text, g2, fm); final Size2D result = new Size2D(bounds.getWidth(), bounds.getHeight()); return result; }
String msg = (String) it.next(); FontMetrics fm = g2.getFontMetrics(); Rectangle2D bounds = TextUtilities.getTextBounds(msg, g2, fm); width = Math.max(width, bounds.getWidth()); height += bounds.getHeight(); for (Iterator it = this.cornerTextItems.iterator(); it.hasNext();) { String msg = (String) it.next(); Rectangle2D bounds = TextUtilities.getTextBounds(msg, g2, g2.getFontMetrics()); y += bounds.getHeight();
/** * Returns the maximum of the relevant dimension (height or width) of the * subcategory labels. * * @param g2 the graphics device. * @param edge the edge. * * @return The maximum dimension. */ private double getMaxDim(Graphics2D g2, RectangleEdge edge) { double result = 0.0; g2.setFont(this.subLabelFont); FontMetrics fm = g2.getFontMetrics(); Iterator iterator = this.subCategories.iterator(); while (iterator.hasNext()) { Comparable subcategory = (Comparable) iterator.next(); String label = subcategory.toString(); Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm); double dim = 0.0; if (RectangleEdge.isLeftOrRight(edge)) { dim = bounds.getWidth(); } else { // must be top or bottom dim = bounds.getHeight(); } result = Math.max(result, dim); } return result; }
final Rectangle2D bounds = TextUtilities.getTextBounds(text, g2, fm); final AffineTransform translate = AffineTransform.getTranslateInstance( textX, textY);
final Rectangle2D bounds = TextUtilities.getTextBounds(text, g2, fm); final AffineTransform translate = AffineTransform.getTranslateInstance( textX, textY);
Rectangle2D bounds = TextUtilities.getTextBounds(text, g2, fm); AffineTransform translate = AffineTransform.getTranslateInstance( textX, textY);
/** * A utility method that draws a string inside a rectangle. * * @param g2 the graphics device. * @param bounds the rectangle. * @param font the font. * @param text the text. */ private void drawStringInRect(Graphics2D g2, Rectangle2D bounds, Font font, String text) { g2.setFont(font); FontMetrics fm = g2.getFontMetrics(font); Rectangle2D r = TextUtilities.getTextBounds(text, g2, fm); double x = bounds.getX(); if (r.getWidth() < bounds.getWidth()) { x = x + (bounds.getWidth() - r.getWidth()) / 2; } LineMetrics metrics = font.getLineMetrics( text, g2.getFontRenderContext() ); g2.drawString( text, (float) x, (float) (bounds.getMaxY() - this.bottomInnerGap - metrics.getDescent()) ); }
/** * Arranges the content for this title assuming a fixed width and no bounds * on the height, and returns the required size. This will reflect the * fact that a text title positioned on the left or right of a chart will * be rotated by 90 degrees. * * @param g2 the graphics target. * @param w the width. * * @return The content size. */ protected Size2D arrangeFN(Graphics2D g2, double w) { g2.setFont(getFont()); FontMetrics fm = g2.getFontMetrics(getFont()); Rectangle2D bounds = TextUtilities.getTextBounds(getText(), g2, fm); if (bounds.getWidth() <= w) { return new Size2D(w, bounds.getHeight()); } else { return new Size2D(0.0, 0.0); } }
/** * Returns the content size for the title. * * @param g2 the graphics device. * @param widthRange the width range. * @param heightRange the height range. * * @return The content size. */ protected Size2D arrangeRR(Graphics2D g2, Range widthRange, Range heightRange) { g2.setFont(getFont()); FontMetrics fm = g2.getFontMetrics(getFont()); Rectangle2D bounds = TextUtilities.getTextBounds(getText(), g2, fm); if (bounds.getWidth() <= widthRange.getUpperBound() && bounds.getHeight() <= heightRange.getUpperBound()) { return new Size2D(bounds.getWidth(), bounds.getHeight()); } else { return new Size2D(0.0, 0.0); } }
/** * Returns a rectangle that encloses the axis label. This is typically * used for layout purposes (it gives the maximum dimensions of the label). * * @param g2 the graphics device. * @param edge the edge of the plot area along which the axis is measuring. * * @return The enclosing rectangle. */ protected Rectangle2D getLabelEnclosure(Graphics2D g2, RectangleEdge edge) { Rectangle2D result = new Rectangle2D.Double(); String axisLabel = getLabel(); if (axisLabel != null && !axisLabel.equals("")) { FontMetrics fm = g2.getFontMetrics(getLabelFont()); Rectangle2D bounds = TextUtilities.getTextBounds(axisLabel, g2, fm); RectangleInsets insets = getLabelInsets(); bounds = insets.createOutsetRectangle(bounds); double angle = getLabelAngle(); if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) { angle = angle - Math.PI / 2.0; } double x = bounds.getCenterX(); double y = bounds.getCenterY(); AffineTransform transformer = AffineTransform.getRotateInstance(angle, x, y); Shape labelBounds = transformer.createTransformedShape(bounds); result = labelBounds.getBounds2D(); } return result; }
while (iterator.hasNext()) { Tick tick = (Tick) iterator.next(); Rectangle2D labelBounds = TextUtilities.getTextBounds( tick.getText(), g2, fm); if (labelBounds.getWidth() + insets.getLeft()
while (iterator.hasNext()) { Tick tick = (Tick) iterator.next(); Rectangle2D labelBounds = TextUtilities.getTextBounds( tick.getText(), g2, fm); if (labelBounds.getWidth() + insets.getTop()
Rectangle2D r = TextUtilities.getTextBounds( this.internalMarkerCycleBoundTick.getText(), g2, fm );