Example usage for org.jfree.ui TextAnchor CENTER_LEFT

List of usage examples for org.jfree.ui TextAnchor CENTER_LEFT

Introduction

In this page you can find the example usage for org.jfree.ui TextAnchor CENTER_LEFT.

Prototype

TextAnchor CENTER_LEFT

To view the source code for org.jfree.ui TextAnchor CENTER_LEFT.

Click Source Link

Document

Middle/left.

Usage

From source file:com.bwc.ora.views.LabelPopupMenu.java

private void initMenu() {
    //determine if the point clicked already has an annotation
    boolean hasAnnotationAlready = hasAnnoationAlready();

    if (hasAnnotationAlready) {
        //add label to allow users to deselect the label for a given peak
        JMenuItem nonItem = new JMenuItem("Remove Label");
        nonItem.addActionListener(e -> {
            removeAnnotation();//from ww w . jav a  2 s .  co  m
            lrp.setAnnotations(LrpDisplayFrame.getInstance().getAnnotations());
        });
        add(nonItem);
    }

    //add list of possible labels for a point to the popup menu
    Arrays.stream(RetinalBand.values()).map(RetinalBand::toString).map(label -> {
        XYPointerAnnotation pointer = new XYPointerAnnotation(label,
                item.getDataset().getXValue(item.getSeriesIndex(), item.getItem()),
                item.getDataset().getYValue(item.getSeriesIndex(), item.getItem()), 0);
        pointer.setBaseRadius(35.0);
        pointer.setTipRadius(10.0);
        pointer.setFont(new Font("SansSerif", Font.PLAIN, 9));
        pointer.setPaint(Color.blue);
        pointer.setTextAnchor(TextAnchor.CENTER_LEFT);
        JMenuItem l = new JMenuItem(label);
        l.addActionListener(e -> {
            if (hasAnnotationAlready) {
                removeAnnotation();
            }
            chartPanel.getChart().getXYPlot().addAnnotation(pointer);
            lrp.setAnnotations(LrpDisplayFrame.getInstance().getAnnotations());
        });
        return l;
    }).forEach(this::add);
}

From source file:com.epiq.bitshark.ui.FrequencyAxis.java

/**
 * //from  w w  w  .ja  v a2  s.co  m
 * @param g2
 * @param state
 * @param dataArea
 * @param edge
 * @return
 */
@Override
public List refreshTicks(java.awt.Graphics2D g2, AxisState state, java.awt.geom.Rectangle2D dataArea,
        org.jfree.ui.RectangleEdge edge) {

    List<NumberTick> tickList = new ArrayList<NumberTick>();

    // start
    tickList.add(new NumberTick(0, toMhzString(center - (rate / 2.0)), TextAnchor.CENTER_LEFT,
            TextAnchor.CENTER, 0));

    // half down
    tickList.add(new NumberTick((FMCUartClient.BLOCK_SIZE - 1) * .25, toMhzString(center - (rate / 4.0)),
            TextAnchor.CENTER, TextAnchor.CENTER, 0));

    // center
    tickList.add(new NumberTick((FMCUartClient.BLOCK_SIZE - 1) * .5, toMhzString(center), TextAnchor.CENTER,
            TextAnchor.CENTER, 0));

    // half up
    tickList.add(new NumberTick((FMCUartClient.BLOCK_SIZE - 1) * .75, toMhzString(center + (rate / 4.0)),
            TextAnchor.CENTER, TextAnchor.CENTER, 0));

    // end
    tickList.add(new NumberTick(FMCUartClient.BLOCK_SIZE - 1, toMhzString(center + (rate / 2.0)),
            TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, 0));

    return tickList;
}

From source file:edu.coeia.charts.BarChartPanel.java

private JFreeChart createChart(final CategoryDataset dataset, String str) {
    final JFreeChart chart = ChartFactory.createBarChart3D(str, // chart title
            "Names", // domain axis label
            "Values(%)", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );/*from  w  ww  .j a  v  a2s.  co m*/

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(1.0f);

    // left align the category labels...
    final CategoryAxis axis = plot.getDomainAxis();
    final CategoryLabelPositions p = axis.getCategoryLabelPositions();

    final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT,
            TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f);
    axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(from, to);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    return chart;
}

From source file:org.jfree.chart.demo.XYSeriesDemo3.java

/**
 * Creates a sample chart./*from  w w  w. ja va 2s .  co m*/
 * 
 * @param dataset  the dataset.
 * 
 * @return A sample chart.
 */
private JFreeChart createChart(IntervalXYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYBarChart("XY Series Demo", "X", false, "Y", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    final IntervalMarker target = new IntervalMarker(400.0, 700.0);
    target.setLabel("Target Range");
    target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    target.setLabelAnchor(RectangleAnchor.LEFT);
    target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    target.setPaint(new Color(222, 222, 255, 128));
    plot.addRangeMarker(target, Layer.BACKGROUND);
    return chart;
}

From source file:org.jfree.chart.demo.NormalDistributionDemo2.java

public static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Normal Distribution Demo 2", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainZeroBaselineVisible(true);
    xyplot.setRangeZeroBaselineVisible(true);
    xyplot.setDomainPannable(true);//from  w ww.  j a v  a2 s .  c  o m
    xyplot.setRangePannable(true);
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setLowerMargin(0.0D);
    valueaxis.setUpperMargin(0.0D);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setDrawSeriesLineAsPath(true);
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(1.5F));
    xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 6F, 4F }, 0.0F));
    xylineandshaperenderer.setSeriesStroke(2,
            new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 6F, 4F, 3F, 3F }, 0.0F));
    xylineandshaperenderer.setSeriesStroke(3, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 4F, 4F }, 0.0F));
    XYPointerAnnotation xypointerannotation = new XYPointerAnnotation(" = -2.0, \262 = 0.5", -2D,
            0.56399999999999995D, 3.9269908169872414D);
    xypointerannotation.setLabelOffset(4D);
    xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT);
    xypointerannotation.setBackgroundPaint(Color.yellow);
    xyplot.addAnnotation(xypointerannotation);
    XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation(" = 0.0, \262 = 0.2",
            0.22500000000000001D, 0.80000000000000004D, 0.0D);
    xypointerannotation1.setLabelOffset(4D);
    xypointerannotation1.setTextAnchor(TextAnchor.CENTER_LEFT);
    xypointerannotation1.setBackgroundPaint(new Color(0, 0, 255, 63));
    xyplot.addAnnotation(xypointerannotation1);
    XYPointerAnnotation xypointerannotation2 = new XYPointerAnnotation(" = 0.0, \262 = 1.0", 0.75D,
            0.29999999999999999D, 5.497787143782138D);
    xypointerannotation2.setLabelOffset(4D);
    xypointerannotation2.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xypointerannotation2.setBackgroundPaint(new Color(255, 0, 0, 63));
    xyplot.addAnnotation(xypointerannotation2);
    XYPointerAnnotation xypointerannotation3 = new XYPointerAnnotation(" = 0.0, \262 = 5.0", 3D,
            0.074999999999999997D, 4.7123889803846897D);
    xypointerannotation3.setLabelOffset(4D);
    xypointerannotation3.setTextAnchor(TextAnchor.BOTTOM_CENTER);
    xypointerannotation3.setBackgroundPaint(new Color(0, 255, 0, 63));
    xyplot.addAnnotation(xypointerannotation3);
    return jfreechart;
}

From source file:sernet.gs.ui.rcp.main.bsi.views.chart.RealisierungLineChart.java

private JFreeChart createProgressChart(Object dataset) {
    final double plotGap = 10.0;
    final int axisUpperBoundPadding = 50;
    final int labelFontSize = 10;
    XYDataset data1 = (XYDataset) dataset;
    XYItemRenderer renderer1 = new StandardXYItemRenderer();
    NumberAxis rangeAxis1 = new NumberAxis(Messages.RealisierungLineChart_1);
    XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis(Messages.RealisierungLineChart_2));
    plot.setGap(plotGap);//ww w . j av  a2s . c o m

    plot.add(subplot1, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);

    CountMassnahmen command = new CountMassnahmen();
    try {
        command = ServiceFactory.lookupCommandService().executeCommand(command);
    } catch (CommandException e) {
        ExceptionUtil.log(e, Messages.RealisierungLineChart_3);
    }
    int totalNum = command.getTotalCount();

    NumberAxis axis = (NumberAxis) subplot1.getRangeAxis();
    axis.setUpperBound(totalNum + axisUpperBoundPadding);

    ValueMarker bst = new ValueMarker(totalNum);
    bst.setPaint(Color.GREEN);
    bst.setLabel(Messages.RealisierungLineChart_4);
    bst.setLabelAnchor(RectangleAnchor.LEFT);
    bst.setLabelFont(new Font("SansSerif", Font.ITALIC + Font.BOLD, labelFontSize)); //$NON-NLS-1$
    bst.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    subplot1.addRangeMarker(bst, Layer.BACKGROUND);

    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart(Messages.RealisierungLineChart_6, JFreeChart.DEFAULT_TITLE_FONT, plot,
            true);
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:edu.jhuapl.graphs.jfreechart.utils.RotatedTickDateAxis.java

@SuppressWarnings("unchecked")
@Override/*from w  w  w . j  a  v  a2 s  . c  o  m*/
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    double rotationAngleInRad = Math.toRadians(tickLabelAngle);
    //Template types are specified here for additional type safety.
    List<Tick> ticks = (List<Tick>) super.refreshTicksHorizontal(g2, dataArea, edge);
    List<Tick> ret = new ArrayList<Tick>();
    for (Tick tick : ticks) {
        if (tick instanceof DateTick) {
            DateTick dateTick = (DateTick) tick;

            //The anchor used depends on the label angle, as follows:
            TextAnchor textAnchor, rotationAnchor;

            double modRadians = rotationAngleInRad % (2 * Math.PI);
            //Handle case where user provided a negative angle value.
            if (modRadians < 0) {
                modRadians += 2 * Math.PI;
            }

            //For angles between 0-180 degrees:
            if (modRadians <= Math.PI) {
                textAnchor = TextAnchor.CENTER_LEFT;
                rotationAnchor = TextAnchor.CENTER_LEFT;
            }
            //For angles between 180-360 degrees:
            else {
                textAnchor = TextAnchor.CENTER_RIGHT;
                rotationAnchor = TextAnchor.CENTER_RIGHT;
            }
            ret.add(new DateTick(dateTick.getDate(), dateTick.getText(), textAnchor, rotationAnchor,
                    rotationAngleInRad));
        } else {
            ret.add(tick);
        }
    }

    return ret;
}

From source file:org.jstockchart.axis.TimeseriesNumberAxis.java

public List<Tick> refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    TextAnchor anchor = null;// www . j av a2s .c om
    TextAnchor rotationAnchor = null;
    double angle = 0.0;
    if (isVerticalTickLabels()) {
        anchor = TextAnchor.BOTTOM_CENTER;
        rotationAnchor = TextAnchor.BOTTOM_CENTER;
        if (edge == RectangleEdge.LEFT) {
            angle = -Math.PI / 2.0;
        } else {
            angle = Math.PI / 2.0;
        }
    } else {
        if (edge == RectangleEdge.LEFT) {
            anchor = TextAnchor.CENTER_RIGHT;
            rotationAnchor = TextAnchor.CENTER_RIGHT;
        } else {
            anchor = TextAnchor.CENTER_LEFT;
            rotationAnchor = TextAnchor.CENTER_LEFT;
        }
    }
    return createTicks(logicTicks, anchor, rotationAnchor, angle);
}

From source file:edu.ucla.stat.SOCR.chart.demo.BarChart3DDemo2.java

/**
 * Creates a chart./* ww w.  j  a  v  a  2s  . com*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createBarChart3D(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(1.0f);

    // left align the category labels...
    CategoryAxis axis = plot.getDomainAxis();
    CategoryLabelPositions p = axis.getCategoryLabelPositions();

    CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT,
            TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f);
    axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));

    BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());
    setCategorySummary(dataset);
    return chart;

}

From source file:eu.cassandra.training.utils.ChartUtils.java

/**
 * This function is used for the visualization of a Comparative Response Model
 * Histogram.// w w w.j a v a2s . co m
 * 
 * @param title
 *          The title of the chart.
 * @param x
 *          The unit on the X axis of the chart.
 * @param y
 *          The unit on the Y axis of the chart.
 * @param dataBefore
 *          The array of values before the response.
 * @param dataAfter
 *          The array of values after the response.
 * @return a chart panel with the graphical representation.
 */
public static ChartPanel createDailyResponseHistogram(String title, String x, String y, double[] dataBefore,
        double[] dataAfter) {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (int i = 0; i < dataBefore.length; i++) {
        dataset.addValue(dataBefore[i], "Basic Scheme", "" + i + "");
        if (i < dataAfter.length)
            dataset.addValue(dataAfter[i], "New Scheme", "" + i + "");
        else
            dataset.addValue(0, "New Scheme", "" + i + "");
    }

    JFreeChart chart = ChartFactory.createBarChart3D(title, // chart title
            x, // domain axis label
            y, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setForegroundAlpha(1.0f);

    // left align the category labels...
    final CategoryAxis axis = plot.getDomainAxis();
    final CategoryLabelPositions p = axis.getCategoryLabelPositions();

    final CategoryLabelPosition left = new CategoryLabelPosition(RectangleAnchor.LEFT,
            TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0, CategoryLabelWidthType.RANGE, 0.30f);
    axis.setCategoryLabelPositions(CategoryLabelPositions.replaceLeftPosition(p, left));

    return new ChartPanel(chart);
}