Package org.jfree.text

Examples of org.jfree.text.TextBlock


    public float getPreferredHeight(Graphics2D g2, float width) {
        float result = 0.0f;
        if (this.text != null && !this.text.equals("")) {
            g2.setFont(this.font);
            float textWidth = (float) getSpacer().trimWidth(width);
            TextBlock title = TextUtilities.createTextBlock(
                this.text, this.font, this.paint, textWidth, new G2TextMeasurer(g2)
            );
            Size2D d = title.calculateDimensions(g2);
            result = (float) getSpacer().getAdjustedHeight(d.getHeight());
        }
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Title preferred height = " + result);  
        }
View Full Code Here


    protected void drawHorizontal(Graphics2D g2, Rectangle2D area) {
        Rectangle2D titleArea = (Rectangle2D) area.clone();
        getSpacer().trim(titleArea);
        g2.setFont(this.font);
        g2.setPaint(this.paint);
        TextBlock title = TextUtilities.createTextBlock(
            this.text, this.font, this.paint, (float) titleArea.getWidth(), new G2TextMeasurer(g2)
        );
        TextBlockAnchor anchor = null;
        float x = 0.0f;
        HorizontalAlignment horizontalAlignment = getHorizontalAlignment();
        if (horizontalAlignment == HorizontalAlignment.LEFT) {
            x = (float) titleArea.getX();
            anchor = TextBlockAnchor.TOP_LEFT;
        }
        else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
            x = (float) titleArea.getMaxX();
            anchor = TextBlockAnchor.TOP_RIGHT;
        }
        else if (horizontalAlignment == HorizontalAlignment.CENTER) {
            x = (float) titleArea.getCenterX();
            anchor = TextBlockAnchor.TOP_CENTER;
        }
        float y = 0.0f;
        RectangleEdge position = getPosition();
        if (position == RectangleEdge.TOP) {
            y = (float) titleArea.getY();
        }
        else if (position == RectangleEdge.BOTTOM) {
            y = (float) titleArea.getMaxY();
            if (horizontalAlignment == HorizontalAlignment.LEFT) {
                anchor = TextBlockAnchor.BOTTOM_LEFT;
            }
            else if (horizontalAlignment == HorizontalAlignment.CENTER) {
                anchor = TextBlockAnchor.BOTTOM_CENTER;
            }
            else if (horizontalAlignment == HorizontalAlignment.RIGHT) {
                anchor = TextBlockAnchor.BOTTOM_RIGHT;
            }
        }
        title.draw(g2, x, y, anchor);
    }
View Full Code Here

    protected void drawVertical(Graphics2D g2, Rectangle2D area) {
        Rectangle2D titleArea = (Rectangle2D) area.clone();
        getSpacer().trim(titleArea);
        g2.setFont(this.font);
        g2.setPaint(this.paint);
        TextBlock title = TextUtilities.createTextBlock(
            this.text, this.font, this.paint, (float) titleArea.getHeight(), new G2TextMeasurer(g2)
        );
        TextBlockAnchor anchor = null;
        float y = 0.0f;
        VerticalAlignment verticalAlignment = getVerticalAlignment();
        if (verticalAlignment == VerticalAlignment.TOP) {
            y = (float) titleArea.getY();
            anchor = TextBlockAnchor.TOP_RIGHT;
        }
        else if (verticalAlignment == VerticalAlignment.BOTTOM) {
            y = (float) titleArea.getMaxY();
            anchor = TextBlockAnchor.TOP_LEFT;
        }
        else if (verticalAlignment == VerticalAlignment.CENTER) {
            y = (float) titleArea.getCenterY();
            anchor = TextBlockAnchor.TOP_CENTER;
        }
        float x = 0.0f;
        RectangleEdge position = getPosition();
        if (position == RectangleEdge.LEFT) {
            x = (float) titleArea.getX();
        }
        else if (position == RectangleEdge.RIGHT) {
            x = (float) titleArea.getMaxX();
            if (verticalAlignment == VerticalAlignment.TOP) {
                anchor = TextBlockAnchor.BOTTOM_RIGHT;
            }
            else if (verticalAlignment == VerticalAlignment.CENTER) {
                anchor = TextBlockAnchor.BOTTOM_CENTER;
            }
            else if (verticalAlignment == VerticalAlignment.BOTTOM) {
                anchor = TextBlockAnchor.BOTTOM_LEFT;
            }
        }
        title.draw(g2, x, y, anchor, x, y, -Math.PI / 2.0);
    }
View Full Code Here

     *
     * @return a label.
     */
    protected TextBlock createLabel(Comparable category, float width,
                                    RectangleEdge edge, Graphics2D g2) {
        TextBlock label = super.createLabel(category, width, edge, g2);  
        String s = (String) this.sublabels.get(category);
        if (s != null) {
            if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
                TextLine line = new TextLine(s, this.sublabelFont, this.sublabelPaint);
                label.addLine(line);
            }
            else if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) {
                TextLine line = label.getLastLine();
                if (line != null) {
                    line.addFragment(
                        new TextFragment("  " + s, this.sublabelFont, this.sublabelPaint)
                    );
                }
View Full Code Here

//            FontMetrics fm = g2.getFontMetrics(this.noDataMessageFont);
//            Rectangle2D bounds = TextUtilities.getTextBounds(message, g2, fm);
//            float x = (float) (area.getX() + area.getWidth() / 2 - bounds.getWidth() / 2);
//            float y = (float) (area.getMinY() + (area.getHeight() / 2) - (bounds.getHeight() / 2));
//            g2.drawString(message, x, y);
            TextBlock block = TextUtilities.createTextBlock(
                this.noDataMessage, this.noDataMessageFont, this.noDataMessagePaint,
                0.9f * (float) area.getWidth(), new G2TextMeasurer(g2)
            );
            block.draw(
                g2, (float) area.getCenterX(), (float) area.getCenterY(), TextBlockAnchor.CENTER
            );
        }
        g2.setClip(savedClip);

View Full Code Here

                }
                Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0),
                        (y1 - y0));
                Point2D anchorPoint = RectangleAnchor.coordinates(area,
                        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(),
                        (float) anchorPoint.getY(), position.getAngle());
                if (plotState != null && plotState.getOwner() != null) {
                    EntityCollection entities
View Full Code Here

            }
            int categoryIndex = 0;
            Iterator iterator = categories.iterator();
            while (iterator.hasNext()) {
                Comparable category = (Comparable) iterator.next();
                TextBlock label = createLabel(category, l * r, edge, g2);
                if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) {
                    max = Math.max(max, calculateTextBlockHeight(label,
                            position, g2));
                }
                else if (edge == RectangleEdge.LEFT
View Full Code Here

     *
     * @return A label.
     */
    protected TextBlock createLabel(Comparable category, float width,
                                    RectangleEdge edge, Graphics2D g2) {
        TextBlock label = TextUtilities.createTextBlock(category.toString(),
                getTickLabelFont(category), getTickLabelPaint(category), width,
                this.maximumCategoryLabelLines, new G2TextMeasurer(g2))
        return label;
    }
View Full Code Here

     */
    public void testEquals() {
       
        Comparable c1 = "C1";
        Comparable c2 = "C2";
        TextBlock tb1 = new TextBlock();
        tb1.addLine(new TextLine("Block 1"));
        TextBlock tb2 = new TextBlock();
        tb1.addLine(new TextLine("Block 2"));
        TextBlockAnchor tba1 = TextBlockAnchor.CENTER;
        TextBlockAnchor tba2 = TextBlockAnchor.BOTTOM_CENTER;
        TextAnchor ta1 = TextAnchor.CENTER;
        TextAnchor ta2 = TextAnchor.BASELINE_LEFT;
View Full Code Here

    /**
     * Two objects that are equal are required to return the same hashCode.
     */
    public void testHashCode() {
        Comparable c1 = "C1";
        TextBlock tb1 = new TextBlock();
        tb1.addLine(new TextLine("Block 1"));
        tb1.addLine(new TextLine("Block 2"));
        TextBlockAnchor tba1 = TextBlockAnchor.CENTER;
        TextAnchor ta1 = TextAnchor.CENTER;
       
        CategoryTick t1 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
        CategoryTick t2 = new CategoryTick(c1, tb1, tba1, ta1, 1.0f);
View Full Code Here

TOP

Related Classes of org.jfree.text.TextBlock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.