Example usage for org.jfree.text TextBlock setLineAlignment

List of usage examples for org.jfree.text TextBlock setLineAlignment

Introduction

In this page you can find the example usage for org.jfree.text TextBlock setLineAlignment.

Prototype

public void setLineAlignment(HorizontalAlignment alignment) 

Source Link

Document

Sets the alignment of the lines of text within the block.

Usage

From source file:org.jboss.weld.benchmark.charts.Chart.java

/**
 * Saving a chart to hard disk as png image
 *
 * @param path absolute path/*  www.jav  a2 s .com*/
 * @return true if no errors occurred
 */
public Boolean saveImageTo(String path) {
    try {
        JFreeChart lineChartObject = ChartFactory.createBarChart(NAME, X_AXIS_NAME, Y_AXIS_NAME,
                lineChartDataset, PlotOrientation.VERTICAL, true, true, false);

        CategoryPlot plot = (CategoryPlot) lineChartObject.getPlot();

        plot.setDomainAxis(new CategoryAxis() {
            private static final long serialVersionUID = 1L;

            @Override
            protected TextBlock createLabel(@SuppressWarnings("rawtypes") Comparable category, float width,
                    RectangleEdge edge, Graphics2D g2) {
                TextBlock label = TextUtilities.createTextBlock(category.toString(), getTickLabelFont(category),
                        getTickLabelPaint(category), ONE_PART_WIDTH - 30, 2, new G2TextMeasurer(g2));

                label.setLineAlignment(HorizontalAlignment.LEFT);
                return label;
            }
        });

        File lineChart = new File(path, NAME + ".png");
        ChartUtilities.saveChartAsPNG(lineChart, lineChartObject,
                ONE_PART_WIDTH * lineChartDataset.getColumnCount(), GRAPH_HEIGHT);
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}