Example usage for org.jfree.text TextBlockAnchor CENTER_RIGHT

List of usage examples for org.jfree.text TextBlockAnchor CENTER_RIGHT

Introduction

In this page you can find the example usage for org.jfree.text TextBlockAnchor CENTER_RIGHT.

Prototype

TextBlockAnchor CENTER_RIGHT

To view the source code for org.jfree.text TextBlockAnchor CENTER_RIGHT.

Click Source Link

Document

Middle/right.

Usage

From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpressionTest.java

@Test
public void testCreateUpRotationCategoryLabelPosition() {
    TestableCategoricalChartExpression e = new TestableCategoricalChartExpression();
    {//from  w  w w . j  a v  a 2  s .c o m
        CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM, 0.0);
        Assert.assertEquals(RectangleAnchor.TOP, c.getCategoryAnchor());
        Assert.assertEquals(TextBlockAnchor.TOP_CENTER, c.getLabelAnchor());
        Assert.assertEquals(TextAnchor.TOP_CENTER, c.getRotationAnchor());
    }
    {
        CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM,
                90.0 * Math.PI / 180.0);
        Assert.assertEquals(RectangleAnchor.TOP, c.getCategoryAnchor());
        Assert.assertEquals(TextBlockAnchor.CENTER_RIGHT, c.getLabelAnchor());
        Assert.assertEquals(TextAnchor.CENTER_RIGHT, c.getRotationAnchor());
    }
    {
        CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM,
                -90.0 * Math.PI / 180.0);
        Assert.assertEquals(RectangleAnchor.TOP, c.getCategoryAnchor());
        Assert.assertEquals(TextBlockAnchor.CENTER_LEFT, c.getLabelAnchor());
        Assert.assertEquals(TextAnchor.CENTER_LEFT, c.getRotationAnchor());
    }
    {
        CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM,
                180.0 * Math.PI / 180.0);
        Assert.assertEquals(RectangleAnchor.TOP, c.getCategoryAnchor());
        Assert.assertEquals(TextBlockAnchor.BOTTOM_CENTER, c.getLabelAnchor());
        Assert.assertEquals(TextAnchor.BOTTOM_CENTER, c.getRotationAnchor());
    }

    {
        CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.LEFT, 0.0);
        Assert.assertEquals(RectangleAnchor.RIGHT, c.getCategoryAnchor());
        Assert.assertEquals(TextBlockAnchor.CENTER_RIGHT, c.getLabelAnchor());
        Assert.assertEquals(TextAnchor.CENTER_RIGHT, c.getRotationAnchor());
    }
    {
        CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.LEFT,
                90.0 * Math.PI / 180.0);
        Assert.assertEquals(RectangleAnchor.RIGHT, c.getCategoryAnchor());
        Assert.assertEquals(TextBlockAnchor.BOTTOM_CENTER, c.getLabelAnchor());
        Assert.assertEquals(TextAnchor.BOTTOM_CENTER, c.getRotationAnchor());
    }
    {
        CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.LEFT,
                -90.0 * Math.PI / 180.0);
        Assert.assertEquals(RectangleAnchor.RIGHT, c.getCategoryAnchor());
        Assert.assertEquals(TextBlockAnchor.TOP_CENTER, c.getLabelAnchor());
        Assert.assertEquals(TextAnchor.TOP_CENTER, c.getRotationAnchor());
    }
    {
        CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.LEFT,
                180.0 * Math.PI / 180.0);
        Assert.assertEquals(RectangleAnchor.RIGHT, c.getCategoryAnchor());
        Assert.assertEquals(TextBlockAnchor.CENTER_LEFT, c.getLabelAnchor());
        Assert.assertEquals(TextAnchor.CENTER_LEFT, c.getRotationAnchor());
    }

    {
        CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.TOP, 0.0);
        Assert.assertEquals(RectangleAnchor.BOTTOM, c.getCategoryAnchor());
        Assert.assertEquals(TextBlockAnchor.BOTTOM_CENTER, c.getLabelAnchor());
        Assert.assertEquals(TextAnchor.BOTTOM_CENTER, c.getRotationAnchor());
    }
    {
        CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.TOP,
                90.0 * Math.PI / 180.0);
        Assert.assertEquals(RectangleAnchor.BOTTOM, c.getCategoryAnchor());
        Assert.assertEquals(TextBlockAnchor.CENTER_LEFT, c.getLabelAnchor());
        Assert.assertEquals(TextAnchor.CENTER_LEFT, c.getRotationAnchor());
    }

    {
        CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.RIGHT, 0.0);
        Assert.assertEquals(RectangleAnchor.LEFT, c.getCategoryAnchor());
        Assert.assertEquals(TextBlockAnchor.CENTER_LEFT, c.getLabelAnchor());
        Assert.assertEquals(TextAnchor.CENTER_LEFT, c.getRotationAnchor());
    }
    {
        CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.RIGHT,
                90.0 * Math.PI / 180.0);
        Assert.assertEquals(RectangleAnchor.LEFT, c.getCategoryAnchor());
        Assert.assertEquals(TextBlockAnchor.TOP_CENTER, c.getLabelAnchor());
        Assert.assertEquals(TextAnchor.TOP_CENTER, c.getRotationAnchor());
    }
}

From source file:hr.restart.util.chart.ChartXY.java

/**
 * Creates a BAR CHART/*from w  w w . ja  va  2  s.  c o m*/
 * @param dataset The org.jfree.data.CategoryDataset
 * @param title The title
 * @return org.jfree.chart.JFreeChart
 */
private JFreeChart createBarChart(final CategoryDataset dataset, String title, PlotOrientation orientation) {

    final JFreeChart chart = ChartFactory.createBarChart(title, // chart title
            "", // domain axis label
            "", // range axis label
            dataset, // data
            orientation, // the plot orientation
            false, // include legend
            true, false);

    chart.setBackgroundPaint(Color.white);

    // the subtitle from the combobox        
    if (jcb != null)
        chart.addSubtitle(new TextTitle(jcb.getSelectedItem().toString()));

    //subtitles setted by the user.
    if (getSubtitles() != null)
        for (int i = 0; i < getSubtitles().size(); i++) {
            chart.addSubtitle(new TextTitle(getSubtitles().get(i).toString()));
        }

    final Plot plot = chart.getPlot();

    // get a reference to the plot for further customisation...
    final CategoryPlot categoryPlot = (CategoryPlot) plot;

    categoryPlot.setNoDataMessage("NO DATA!");

    categoryPlot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    final CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { Color.red, Color.blue, Color.green,
            Color.yellow, Color.orange, Color.cyan, Color.magenta, Color.blue });
    categoryPlot.setRenderer(renderer);

    renderer.setLabelGenerator(new StandardCategoryLabelGenerator());
    renderer.setItemLabelsVisible(true);

    // inside
    //renderer.setBaseItemLabelPaint(Color.white);
    Font font = new Font("SansSerif", Font.PLAIN, 7);
    Font derive = font.deriveFont(Font.BOLD);
    renderer.setBaseItemLabelFont(derive);

    // margin
    final CategoryAxis domainAxis = categoryPlot.getDomainAxis();
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    //domainAxis.setBottomCategoryLabelPosition(new CategoryLabelPosition(RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_CENTER));
    domainAxis.setCategoryLabelPositions(new CategoryLabelPositions(
            new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_CENTER), // TOP
            new CategoryLabelPosition(RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_CENTER), // BOTTOM
            new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
                    CategoryLabelWidthType.RANGE, 0.30f), // LEFT
            new CategoryLabelPosition(RectangleAnchor.RIGHT, TextBlockAnchor.CENTER_RIGHT,
                    CategoryLabelWidthType.RANGE, 0.30f) // RIGHT) 
    ));

    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 0.0);
    renderer.setPositiveItemLabelPosition(p);

    if (comboBoxOrientation != null) {
        if (comboBoxOrientation.getSelectedItem() == "Vertikalni") {

            domainAxis.setCategoryLabelPositions(
                    CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0));
        }
    }

    return chart;

}