Search in sources :

Example 46 with Size2D

use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.

the class TextBox method draw.

/**
 * Draws the text box.
 *
 * @param g2  the graphics device.
 * @param x  the x-coordinate.
 * @param y  the y-coordinate.
 * @param anchor  the anchor point.
 */
public void draw(Graphics2D g2, float x, float y, RectangleAnchor anchor) {
    Size2D d1 = this.textBlock.calculateDimensions(g2);
    double w = this.interiorGap.extendWidth(d1.getWidth());
    double h = this.interiorGap.extendHeight(d1.getHeight());
    Size2D d2 = new Size2D(w, h);
    Rectangle2D bounds = RectangleAnchor.createRectangle(d2, x, y, anchor);
    double xx = bounds.getX();
    double yy = bounds.getY();
    if (this.shadowPaint != null) {
        Rectangle2D shadow = new Rectangle2D.Double(xx + this.shadowXOffset, yy + this.shadowYOffset, bounds.getWidth(), bounds.getHeight());
        g2.setPaint(this.shadowPaint);
        g2.fill(shadow);
    }
    if (this.backgroundPaint != null) {
        g2.setPaint(this.backgroundPaint);
        g2.fill(bounds);
    }
    if (this.outlinePaint != null && this.outlineStroke != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.outlineStroke);
        g2.draw(bounds);
    }
    this.textBlock.draw(g2, (float) (xx + this.interiorGap.calculateLeftInset(w)), (float) (yy + this.interiorGap.calculateTopInset(h)), TextBlockAnchor.TOP_LEFT);
}
Also used : Size2D(org.jfree.chart.util.Size2D) Rectangle2D(java.awt.geom.Rectangle2D)

Example 47 with Size2D

use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.

the class TextFragment method calculateDimensions.

/**
 * Calculates the dimensions of the text fragment.
 *
 * @param g2  the graphics device.
 *
 * @return The width and height of the text.
 */
public Size2D calculateDimensions(Graphics2D g2) {
    FontMetrics fm = g2.getFontMetrics(this.font);
    Rectangle2D bounds = TextUtilities.getTextBounds(this.text, g2, fm);
    Size2D result = new Size2D(bounds.getWidth(), bounds.getHeight());
    return result;
}
Also used : Size2D(org.jfree.chart.util.Size2D) FontMetrics(java.awt.FontMetrics) Rectangle2D(java.awt.geom.Rectangle2D)

Example 48 with Size2D

use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.

the class TextLine method calculateDimensions.

/**
 * Calculates the width and height of the text line.
 *
 * @param g2  the graphics device.
 *
 * @return The width and height.
 */
public Size2D calculateDimensions(Graphics2D g2) {
    double width = 0.0;
    double height = 0.0;
    Iterator iterator = this.fragments.iterator();
    while (iterator.hasNext()) {
        TextFragment fragment = (TextFragment) iterator.next();
        Size2D dimension = fragment.calculateDimensions(g2);
        width = width + dimension.getWidth();
        height = Math.max(height, dimension.getHeight());
    }
    return new Size2D(width, height);
}
Also used : Size2D(org.jfree.chart.util.Size2D) Iterator(java.util.Iterator)

Example 49 with Size2D

use of org.jfree.chart.util.Size2D in project graphcode2vec by graphcode2vec.

the class TextLine method draw.

/**
 * Draws the text line.
 *
 * @param g2  the graphics device.
 * @param anchorX  the x-coordinate for the anchor point.
 * @param anchorY  the y-coordinate for the anchor point.
 * @param anchor  the point on the text line that is aligned to the anchor
 *                point.
 * @param rotateX  the x-coordinate for the rotation point.
 * @param rotateY  the y-coordinate for the rotation point.
 * @param angle  the rotation angle (in radians).
 */
public void draw(Graphics2D g2, float anchorX, float anchorY, TextAnchor anchor, float rotateX, float rotateY, double angle) {
    float x = anchorX;
    float yOffset = calculateBaselineOffset(g2, anchor);
    Iterator iterator = this.fragments.iterator();
    while (iterator.hasNext()) {
        TextFragment fragment = (TextFragment) iterator.next();
        Size2D d = fragment.calculateDimensions(g2);
        fragment.draw(g2, x, anchorY + yOffset, TextAnchor.BASELINE_LEFT, rotateX, rotateY, angle);
        x = x + (float) d.getWidth();
    }
}
Also used : Size2D(org.jfree.chart.util.Size2D) Iterator(java.util.Iterator)

Aggregations

Size2D (org.jfree.chart.util.Size2D)49 Rectangle2D (java.awt.geom.Rectangle2D)21 List (java.util.List)10 RectangleConstraint (org.jfree.chart.block.RectangleConstraint)8 Iterator (java.util.Iterator)5 RectangleEdge (org.jfree.chart.util.RectangleEdge)5 Range (org.jfree.data.Range)5 FontMetrics (java.awt.FontMetrics)4 Shape (java.awt.Shape)4 ArrayList (java.util.ArrayList)4 LengthConstraintType (org.jfree.chart.block.LengthConstraintType)4 RectangleInsets (org.jfree.chart.util.RectangleInsets)4 Point2D (java.awt.geom.Point2D)2 BlockParams (org.jfree.chart.block.BlockParams)2 EntityBlockResult (org.jfree.chart.block.EntityBlockResult)2 G2TextMeasurer (org.jfree.chart.text.G2TextMeasurer)2 Arc2D (java.awt.geom.Arc2D)1 AxisLocation (org.jfree.chart.axis.AxisLocation)1 AxisSpace (org.jfree.chart.axis.AxisSpace)1 BlockContainer (org.jfree.chart.block.BlockContainer)1