Java Code Examples for org.jfree.chart.util.Size2D#getWidth()

The following examples show how to use org.jfree.chart.util.Size2D#getWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextLine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
    }

}
 
Example 2
Source File: CategoryAxis.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A utility method for determining the height of a text block.
 *
 * @param block  the text block.
 * @param position  the label position.
 * @param g2  the graphics device.
 *
 * @return The height.
 */
protected double calculateTextBlockHeight(TextBlock block,
                                          CategoryLabelPosition position,
                                          Graphics2D g2) {

    RectangleInsets insets = getTickLabelInsets();
    Size2D size = block.calculateDimensions(g2);
    Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(),
            size.getHeight());
    Shape rotatedBox = ShapeUtilities.rotateShape(box, position.getAngle(),
            0.0f, 0.0f);
    double h = rotatedBox.getBounds2D().getHeight()
               + insets.getTop() + insets.getBottom();
    return h;

}
 
Example 3
Source File: TextLine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
    }

}
 
Example 4
Source File: CategoryAxis.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A utility method for determining the width of a text block.
 *
 * @param block  the text block.
 * @param position  the position.
 * @param g2  the graphics device.
 *
 * @return The width.
 */
protected double calculateTextBlockWidth(TextBlock block, 
                                         CategoryLabelPosition position, 
                                         Graphics2D g2) {
                                                
    RectangleInsets insets = getTickLabelInsets();
    Size2D size = block.calculateDimensions(g2);
    Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(), 
            size.getHeight());
    Shape rotatedBox = ShapeUtilities.rotateShape(box, position.getAngle(),
            0.0f, 0.0f);
    double w = rotatedBox.getBounds2D().getWidth() + insets.getTop() 
            + insets.getBottom();
    return w;
    
}
 
Example 5
Source File: CategoryAxis.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A utility method for determining the height of a text block.
 *
 * @param block  the text block.
 * @param position  the label position.
 * @param g2  the graphics device.
 *
 * @return The height.
 */
protected double calculateTextBlockHeight(TextBlock block, 
                                          CategoryLabelPosition position, 
                                          Graphics2D g2) {
                                                
    RectangleInsets insets = getTickLabelInsets();
    Size2D size = block.calculateDimensions(g2);
    Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(), 
            size.getHeight());
    Shape rotatedBox = ShapeUtilities.rotateShape(box, position.getAngle(),
            0.0f, 0.0f);
    double h = rotatedBox.getBounds2D().getHeight() 
               + insets.getTop() + insets.getBottom();
    return h;
    
}
 
Example 6
Source File: TextBlock.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the bounds of the text block.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param anchorX  the x-coordinate for the anchor point.
 * @param anchorY  the y-coordinate for the anchor point.
 * @param anchor  the text block anchor (<code>null</code> not permitted).
 * @param rotateX  the x-coordinate for the rotation point.
 * @param rotateY  the y-coordinate for the rotation point.
 * @param angle  the rotation angle.
 *
 * @return The bounds.
 */
public Shape calculateBounds(Graphics2D g2, float anchorX, float anchorY,
        TextBlockAnchor anchor, float rotateX, float rotateY,
        double angle) {

    Size2D d = calculateDimensions(g2);
    float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
    Rectangle2D bounds = new Rectangle2D.Double(anchorX + offsets[0],
            anchorY + offsets[1], d.getWidth(), d.getHeight());
    Shape rotatedBounds = ShapeUtilities.rotateShape(bounds, angle,
            rotateX, rotateY);
    return rotatedBounds;

}
 
Example 7
Source File: TextBlock.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws the text block, aligning it with the specified anchor point and
 * rotating it about the specified rotation point.
 *
 * @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 block that is aligned to the
 *                anchor point.
 * @param rotateX  the x-coordinate for the rotation point.
 * @param rotateY  the x-coordinate for the rotation point.
 * @param angle  the rotation (in radians).
 */
public void draw(Graphics2D g2, float anchorX, float anchorY,
                 TextBlockAnchor anchor, float rotateX, float rotateY,
                 double angle) {

    Size2D d = calculateDimensions(g2);
    float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
    Iterator iterator = this.lines.iterator();
    float yCursor = 0.0f;
    while (iterator.hasNext()) {
        TextLine line = (TextLine) iterator.next();
        Size2D dimension = line.calculateDimensions(g2);
        float lineOffset = 0.0f;
        if (this.lineAlignment == HorizontalAlignment.CENTER) {
            lineOffset = (float) (d.getWidth() - dimension.getWidth())
                / 2.0f;
        }
        else if (this.lineAlignment == HorizontalAlignment.RIGHT) {
            lineOffset = (float) (d.getWidth() - dimension.getWidth());
        }
        line.draw(g2, anchorX + offsets[0] + lineOffset, anchorY
                + offsets[1] + yCursor, TextAnchor.TOP_LEFT, rotateX,
                rotateY, angle);
        yCursor = yCursor + (float) dimension.getHeight();
    }

}
 
Example 8
Source File: TextLine.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 9
Source File: CategoryAxis.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A utility method for determining the width of a text block.
 *
 * @param block  the text block.
 * @param position  the position.
 * @param g2  the graphics device.
 *
 * @return The width.
 */
protected double calculateTextBlockWidth(TextBlock block,
        CategoryLabelPosition position, Graphics2D g2) {

    RectangleInsets insets = getTickLabelInsets();
    Size2D size = block.calculateDimensions(g2);
    Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(),
            size.getHeight());
    Shape rotatedBox = ShapeUtilities.rotateShape(box, position.getAngle(),
            0.0f, 0.0f);
    double w = rotatedBox.getBounds2D().getWidth() + insets.getLeft()
            + insets.getRight();
    return w;

}
 
Example 10
Source File: TextBlock.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the bounds of the text block.
 * 
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param anchorX  the x-coordinate for the anchor point.
 * @param anchorY  the y-coordinate for the anchor point.
 * @param anchor  the text block anchor (<code>null</code> not permitted).
 * @param rotateX  the x-coordinate for the rotation point.
 * @param rotateY  the y-coordinate for the rotation point.
 * @param angle  the rotation angle.
 * 
 * @return The bounds.
 */
public Shape calculateBounds(Graphics2D g2, float anchorX, float anchorY, 
        TextBlockAnchor anchor, float rotateX, float rotateY, 
        double angle) {
    
    Size2D d = calculateDimensions(g2);
    float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
    Rectangle2D bounds = new Rectangle2D.Double(anchorX + offsets[0], 
            anchorY + offsets[1], d.getWidth(), d.getHeight());
    Shape rotatedBounds = ShapeUtilities.rotateShape(bounds, angle, 
            rotateX, rotateY);
    return rotatedBounds;   
    
}
 
Example 11
Source File: TextBlock.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws the text block, aligning it with the specified anchor point and 
 * rotating it about the specified rotation point.
 * 
 * @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 block that is aligned to the 
 *                anchor point.
 * @param rotateX  the x-coordinate for the rotation point.
 * @param rotateY  the x-coordinate for the rotation point.
 * @param angle  the rotation (in radians).
 */
public void draw(Graphics2D g2, float anchorX, float anchorY, 
                 TextBlockAnchor anchor, float rotateX, float rotateY, 
                 double angle) {

    Size2D d = calculateDimensions(g2);
    float[] offsets = calculateOffsets(anchor, d.getWidth(), d.getHeight());
    Iterator iterator = this.lines.iterator();
    float yCursor = 0.0f;
    while (iterator.hasNext()) {
        TextLine line = (TextLine) iterator.next();
        Size2D dimension = line.calculateDimensions(g2);
        float lineOffset = 0.0f;
        if (this.lineAlignment == HorizontalAlignment.CENTER) {
            lineOffset = (float) (d.getWidth() - dimension.getWidth()) 
                / 2.0f;   
        }
        else if (this.lineAlignment == HorizontalAlignment.RIGHT) {
            lineOffset = (float) (d.getWidth() - dimension.getWidth());   
        }
        line.draw(g2, anchorX + offsets[0] + lineOffset, anchorY 
                + offsets[1] + yCursor, TextAnchor.TOP_LEFT, rotateX, 
                rotateY, angle);
        yCursor = yCursor + (float) dimension.getHeight();
    }
    
}
 
Example 12
Source File: TextLine.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}