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 ); }
position.getCategoryAnchor()); TextBlock block = tick.getLabel(); block.draw(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle()); Shape bounds = block.calculateBounds(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(),
/** * Draws the text block at a specific location. * * @param g2 the graphics device. * @param x the x-coordinate for the anchor point. * @param y the y-coordinate for the anchor point. * @param anchor the anchor point. */ public void draw(final Graphics2D g2, final float x, final float y, final TextBlockAnchor anchor) { draw(g2, x, y, anchor, 0.0f, 0.0f, 0.0); }
/** * Creates a new label block. * * @param text the text for the label (<code>null</code> not permitted). * @param font the font (<code>null</code> not permitted). * @param paint the paint (<code>null</code> not permitted). */ public LabelBlock(String text, Font font, Paint paint) { this.text = text; this.paint = paint; this.label = TextUtilities.createTextBlock(text, font, this.paint); this.font = font; this.toolTipText = null; this.urlText = null; this.contentAlignmentPoint = TextBlockAnchor.CENTER; this.textAnchor = RectangleAnchor.CENTER; }
TextBlock notesBlock = TextUtilities.createTextBlock( someLongString, plainFont, g2.getPaint()); notesBlock.setLineAlignment(HorizontalAlignment.LEFT); notesBlock.draw(g2, indent, y, TextBlockAnchor.TOP_LEFT);
/** * A utility method for drawing rotated text. * <P> * A common rotation is -Math.PI/2 which draws text 'vertically' (with the * top of the characters on the left). * * @param text the text. * @param g2 the graphics device. * @param angle the angle of the (clockwise) rotation (in radians). * @param x the x-coordinate. * @param y the y-coordinate. */ public static void drawRotatedString(final String text, final Graphics2D g2, final double angle, final float x, final float y) { drawRotatedString(text, g2, x, y, angle, x, y); }
/** * Draws the text block at a specific location. * * @param g2 the graphics device. * @param x the x-coordinate for the anchor point. * @param y the y-coordinate for the anchor point. * @param anchor the anchor point. */ public void draw(final Graphics2D g2, final float x, final float y, final TextBlockAnchor anchor) { draw(g2, x, y, anchor, 0.0f, 0.0f, 0.0); }
/** * Creates a new text block from the given string, breaking the * text into lines so that the <code>maxWidth</code> value is * respected. * * @param text the text. * @param font the font. * @param paint the paint. * @param maxWidth the maximum width for each line. * @param measurer the text measurer. * * @return A text block. */ public static TextBlock createTextBlock(String text, Font font, Paint paint, float maxWidth, TextMeasurer measurer) { return createTextBlock(text, font, paint, maxWidth, Integer.MAX_VALUE, measurer); }
/** * A utility method for drawing rotated text. * <P> * A common rotation is -Math.PI/2 which draws text 'vertically' (with the * top of the characters on the left). * * @param text the text. * @param g2 the graphics device. * @param angle the angle of the (clockwise) rotation (in radians). * @param x the x-coordinate. * @param y the y-coordinate. */ public static void drawRotatedString(final String text, final Graphics2D g2, final double angle, final float x, final float y) { drawRotatedString(text, g2, x, y, angle, x, y); }
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 ); }
/** * Draws the text block at a specific location. * * @param g2 the graphics device. * @param x the x-coordinate for the anchor point. * @param y the y-coordinate for the anchor point. * @param anchor the anchor point. */ public void draw(final Graphics2D g2, final float x, final float y, final TextBlockAnchor anchor) { draw(g2, x, y, anchor, 0.0f, 0.0f, 0.0); }
/** * Creates a new text block from the given string, breaking the * text into lines so that the <code>maxWidth</code> value is * respected. * * @param text the text. * @param font the font. * @param paint the paint. * @param maxWidth the maximum width for each line. * @param measurer the text measurer. * * @return A text block. */ public static TextBlock createTextBlock(final String text, final Font font, final Paint paint, final float maxWidth, final TextMeasurer measurer) { return createTextBlock(text, font, paint, maxWidth, Integer.MAX_VALUE, measurer); }
/** * A utility method for drawing rotated text. * <P> * A common rotation is -Math.PI/2 which draws text 'vertically' (with the * top of the characters on the left). * * @param text the text. * @param g2 the graphics device. * @param angle the angle of the (clockwise) rotation (in radians). * @param x the x-coordinate. * @param y the y-coordinate. */ public static void drawRotatedString(String text, Graphics2D g2, double angle, float x, float y) { drawRotatedString(text, g2, x, y, angle, x, y); }
/** * Creates a new text block from the given string, breaking the * text into lines so that the <code>maxWidth</code> value is * respected. * * @param text the text. * @param font the font. * @param paint the paint. * @param maxWidth the maximum width for each line. * @param measurer the text measurer. * * @return A text block. */ public static TextBlock createTextBlock(final String text, final Font font, final Paint paint, final float maxWidth, final TextMeasurer measurer) { return createTextBlock(text, font, paint, maxWidth, Integer.MAX_VALUE, measurer); }
/** * Sets the font and regenerates the label. * * @param font the font (<code>null</code> not permitted). * * @see #getFont() */ public void setFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } this.font = font; this.label = TextUtilities.createTextBlock(this.text, font, this.paint); }
/** * Sets the paint and regenerates the label. * * @param paint the paint (<code>null</code> not permitted). * * @see #getPaint() */ public void setPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.paint = paint; this.label = TextUtilities.createTextBlock(this.text, this.font, this.paint); }