Example usage for org.jfree.chart.title LegendTitle getPosition

List of usage examples for org.jfree.chart.title LegendTitle getPosition

Introduction

In this page you can find the example usage for org.jfree.chart.title LegendTitle getPosition.

Prototype

public RectangleEdge getPosition() 

Source Link

Document

Returns the position of the title.

Usage

From source file:net.sf.dynamicreports.test.jasper.chart.ChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);//from   w  ww . j  a  v a 2  s.  c  o m

    chartCountTest("summary.chart1", 1);
    JFreeChart chart = getChart("summary.chart1", 0);

    TextTitle title = chart.getTitle();
    Assert.assertEquals("title", "title", title.getText());
    Assert.assertEquals("title color", Color.BLUE, title.getPaint());
    Assert.assertEquals("title font", new Font("Arial", Font.BOLD, 10), title.getFont());
    Assert.assertEquals("title position", RectangleEdge.RIGHT, title.getPosition());

    TextTitle subtitle = (TextTitle) chart.getSubtitle(1);
    Assert.assertEquals("subtitle", "subtitle", subtitle.getText());
    Assert.assertEquals("subtitle color", Color.CYAN, subtitle.getPaint());
    Assert.assertEquals("subtitle font", new Font("Arial", Font.PLAIN, 10), subtitle.getFont());

    LegendTitle legend = (LegendTitle) chart.getSubtitle(0);
    Assert.assertEquals("legend color", Color.BLUE, legend.getItemPaint());
    Assert.assertEquals("legend backgroundcolor", Color.LIGHT_GRAY, legend.getBackgroundPaint());
    Assert.assertEquals("legend font", new Font("Courier New", Font.PLAIN, 10), legend.getItemFont());
    Assert.assertEquals("legend position", RectangleEdge.LEFT, legend.getPosition());

    chartCountTest("summary.chart2", 1);
    chart = getChart("summary.chart2", 0);
    Assert.assertNull("legend", chart.getLegend());
    Assert.assertEquals("plot orientation", PlotOrientation.HORIZONTAL,
            chart.getCategoryPlot().getOrientation());
    Assert.assertEquals("plot series colors", Color.BLUE, chart.getPlot().getDrawingSupplier().getNextPaint());
    Assert.assertEquals("plot series colors", Color.GREEN, chart.getPlot().getDrawingSupplier().getNextPaint());
    Assert.assertEquals("plot series colors", Color.RED, chart.getPlot().getDrawingSupplier().getNextPaint());
}

From source file:org.gumtree.vis.core.internal.SWTChartComposite.java

@Override
protected Menu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom) {
    Menu result = super.createPopupMenu(properties, save, print, zoom);

    LegendTitle legend = getChart().getLegend();
    if (legend != null) {
        boolean isVisable = legend.isVisible();
        RectangleEdge location = legend.getPosition();

        new MenuItem(result, SWT.SEPARATOR);
        Menu legendMenu = new Menu(result);
        MenuItem legendMenuGroup = new MenuItem(result, SWT.CASCADE);
        legendMenuGroup.setMenu(legendMenu);
        legendMenuGroup.setText("Legend");
        legendButtomMenuItem = new MenuItem(legendMenu, SWT.RADIO);
        legendButtomMenuItem.setText("Bottom");
        legendButtomMenuItem.setData(LEGEND_BOTTOM_COMMAND);
        legendButtomMenuItem.addSelectionListener(this);
        if (isVisable && location.equals(RectangleEdge.BOTTOM)) {
            legendButtomMenuItem.setSelection(true);
        }//  ww  w  . j  a  v a2s. c o  m

        legendRightMenuItem = new MenuItem(legendMenu, SWT.RADIO);
        legendRightMenuItem.setText("Right");
        legendRightMenuItem.setData(LEGEND_RIGHT_COMMAND);
        legendRightMenuItem.addSelectionListener(this);
        if (isVisable && location.equals(RectangleEdge.RIGHT)) {
            legendRightMenuItem.setSelection(true);
        }

        //          new MenuItem(legendMenu, SWT.SEPARATOR);
        legendNoneMenuItem = new MenuItem(legendMenu, SWT.RADIO);
        legendNoneMenuItem.setText("None");
        legendNoneMenuItem.setData(LEGEND_NONE_COMMAND);
        legendNoneMenuItem.addSelectionListener(this);
        if (!isVisible()) {
            legendNoneMenuItem.setSelection(true);
        }
    }
    new MenuItem(result, SWT.SEPARATOR);
    copyMenuItem = new MenuItem(result, SWT.NONE);
    copyMenuItem.setText("Copy");
    copyMenuItem.setData(COPY_COMMAND);
    copyMenuItem.addSelectionListener(this);
    return result;
}

From source file:org.gumtree.vis.awt.time.TimePlotPanel.java

@Override
protected void displayPopupMenu(int x, int y) {
    LegendTitle legend = getChart().getLegend();
    if (legend != null) {
        boolean isVisable = legend.isVisible();
        RectangleEdge location = legend.getPosition();
        if (isVisable) {
            if (location.equals(RectangleEdge.BOTTOM)) {
                legendBottom.setSelected(true);
                legendNone.setSelected(false);
                legendRight.setSelected(false);
            } else if (isVisable && location.equals(RectangleEdge.RIGHT)) {
                legendRight.setSelected(true);
                legendNone.setSelected(false);
                legendBottom.setSelected(false);
            }/*  w ww . ja  v a2 s .c om*/
        } else {
            legendNone.setSelected(true);
            legendRight.setSelected(false);
            legendBottom.setSelected(false);
        }
    }
    curveManagementMenu.removeAll();
    curveResetMenu.removeAll();
    if (getXYPlot().getDatasetCount() > 0) {
        curveManagementMenu.setEnabled(true);
        curveResetMenu.setEnabled(true);

        JMenuItem focusNoneCurveItem = new JRadioButtonMenuItem();
        focusNoneCurveItem.setText("None");
        focusNoneCurveItem.setActionCommand(UNFOCUS_CURVE_COMMAND);
        focusNoneCurveItem.addActionListener(this);
        curveManagementMenu.add(focusNoneCurveItem);

        JMenuItem resetAllCurveItem = new JMenuItem();
        resetAllCurveItem.setText("RESET ALL");
        resetAllCurveItem.setActionCommand(RESET_ALL_CURVE_COMMAND);
        resetAllCurveItem.addActionListener(this);
        curveResetMenu.add(resetAllCurveItem);

        boolean isCurveFocused = false;
        for (int j = 0; j < getXYPlot().getDatasetCount(); j++) {
            XYDataset dataset = getChart().getXYPlot().getDataset(j);
            if (dataset != null) {
                for (int i = 0; i < dataset.getSeriesCount(); i++) {
                    String seriesKey = (String) dataset.getSeriesKey(i);
                    JMenuItem focusOnCurveItem = new JRadioButtonMenuItem();
                    focusOnCurveItem.setText(seriesKey);
                    focusOnCurveItem.setActionCommand(FOCUS_ON_COMMAND + "-" + seriesKey);
                    focusOnCurveItem.addActionListener(this);
                    curveManagementMenu.add(focusOnCurveItem);
                    if (dataset == selectedDataset && i == selectedSeriesIndex) {
                        focusOnCurveItem.setSelected(true);
                        isCurveFocused = true;
                    }

                    JMenuItem resetCurveItem = new JMenuItem();
                    resetCurveItem.setText("Reset " + seriesKey);
                    resetCurveItem.setActionCommand(RESET_CURVE_COMMAND + "-" + seriesKey);
                    resetCurveItem.addActionListener(this);
                    curveResetMenu.add(resetCurveItem);

                }
            }
        }
        if (!isCurveFocused) {
            focusNoneCurveItem.setSelected(true);
        }
    } else {
        curveManagementMenu.setEnabled(false);
        curveResetMenu.setEnabled(false);
    }

    showMultiAxesMenuItem.setSelected(isShowMultiaxes());

    if (isPaused) {
        pauseMenuItem.setText("Paused");
    } else {
        pauseMenuItem.setText("Click to Pause");
    }
    pauseMenuItem.setSelected(isPaused);
    super.displayPopupMenu(x, y);
}

From source file:userinterface.graph.Histogram.java

/**
 * Update the settings of the graph if the settings changed
 *///from   w  w  w .  j  av  a 2 s  .  co m
public void updateGraph() {

    /* Update title if necessary. */
    if (!this.chart.getTitle().equals(graphTitle)) {
        this.chart.setTitle(graphTitle.getStringValue());
    }

    /* Update title font if necessary. */
    if (!titleFont.getFontColorValue().f.equals(this.chart.getTitle().getFont())) {
        this.chart.getTitle().setFont(titleFont.getFontColorValue().f);
    }

    /* Update title colour if necessary. */
    if (!titleFont.getFontColorValue().c.equals(this.chart.getTitle().getPaint())) {
        this.chart.getTitle().setPaint(titleFont.getFontColorValue().c);
    }

    if (legendVisible.getBooleanValue() != (this.chart.getLegend() != null)) {
        if (!legendVisible.getBooleanValue()) {
            this.chart.removeLegend();
        } else {
            LegendTitle legend = new LegendTitle(plot.getRenderer());
            legend.setBackgroundPaint(Color.white);
            legend.setBorder(1, 1, 1, 1);

            this.chart.addLegend(legend);
        }
    }

    if (this.chart.getLegend() != null) {
        LegendTitle legend = this.chart.getLegend();

        /* Put legend on the left if appropriate. */
        if ((legendPosition.getCurrentIndex() == Graph.LEFT)
                && !legend.getPosition().equals(RectangleEdge.LEFT)) {
            legend.setPosition(RectangleEdge.LEFT);
        }
        /* Put legend on the right if appropriate. */
        if ((legendPosition.getCurrentIndex() == Graph.RIGHT)
                && !legend.getPosition().equals(RectangleEdge.RIGHT)) {
            legend.setPosition(RectangleEdge.RIGHT);
        }
        /* Put legend on the top if appropriate. */
        if ((legendPosition.getCurrentIndex() == Graph.TOP)
                && !legend.getPosition().equals(RectangleEdge.TOP)) {
            legend.setPosition(RectangleEdge.TOP);
        }
        /* Put legend on the bottom if appropriate. */
        if ((legendPosition.getCurrentIndex() == Graph.BOTTOM)
                && !legend.getPosition().equals(RectangleEdge.BOTTOM)) {
            legend.setPosition(RectangleEdge.BOTTOM);
        }

        /* Set legend font. */
        if (!legend.getItemFont().equals(legendFont.getFontColorValue().f)) {
            legend.setItemFont(legendFont.getFontColorValue().f);
        }
        /* Set legend font colour. */
        if (!legend.getItemPaint().equals(legendFont.getFontColorValue().c)) {
            legend.setItemPaint(legendFont.getFontColorValue().c);
        }
    }

    super.repaint();
    doEnables();
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

@Override
public LegendPosition getLegendPosition() {
    if (isInternalLegendEnabled) {
        return LegendPosition.INTERNAL;
    } else {/*  ww  w.j  a  v  a  2s.  co  m*/
        LegendTitle legend = getChart().getLegend();
        if (legend != null) {
            if (legend.isVisible()) {
                if (legend.getPosition() == RectangleEdge.TOP) {
                    return LegendPosition.TOP;
                } else if (legend.getPosition() == RectangleEdge.BOTTOM) {
                    return LegendPosition.BOTTOM;
                } else if (legend.getPosition() == RectangleEdge.RIGHT) {
                    return LegendPosition.RIGHT;
                } else if (legend.getPosition() == RectangleEdge.LEFT) {
                    return LegendPosition.LEFT;
                }
            }
        }
    }
    return LegendPosition.NONE;
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

@Override
protected void displayPopupMenu(int x, int y) {
    LegendTitle legend = getChart().getLegend();
    if (legend != null) {
        boolean isVisable = legend.isVisible();
        RectangleEdge location = legend.getPosition();
        if (isVisable) {
            if (location.equals(RectangleEdge.BOTTOM)) {
                legendBottom.setSelected(true);
                legendNone.setSelected(false);
                legendInternal.setSelected(false);
                legendRight.setSelected(false);
            } else if (isVisable && location.equals(RectangleEdge.RIGHT)) {
                legendRight.setSelected(true);
                legendNone.setSelected(false);
                legendInternal.setSelected(false);
                legendBottom.setSelected(false);
            }/*w  ww. j av  a  2s .c  o  m*/
        } else {
            if (isInternalLegendEnabled) {
                legendNone.setSelected(false);
                legendInternal.setSelected(true);
                legendRight.setSelected(false);
                legendBottom.setSelected(false);
            } else {
                legendNone.setSelected(true);
                legendInternal.setSelected(false);
                legendRight.setSelected(false);
                legendBottom.setSelected(false);
            }
        }
    }
    XYDataset dataset = getChart().getXYPlot().getDataset();
    curveManagementMenu.removeAll();
    if (dataset.getSeriesCount() > 0) {
        curveManagementMenu.setEnabled(true);
        JMenuItem focusNoneCurveItem = new JRadioButtonMenuItem();
        focusNoneCurveItem.setText("None");
        focusNoneCurveItem.setActionCommand(UNFOCUS_CURVE_COMMAND);
        focusNoneCurveItem.addActionListener(this);
        curveManagementMenu.add(focusNoneCurveItem);
        boolean isCurveFocused = false;
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            String seriesKey = (String) dataset.getSeriesKey(i);
            JMenuItem focusOnCurveItem = new JRadioButtonMenuItem();
            focusOnCurveItem.setText(seriesKey);
            focusOnCurveItem.setActionCommand(FOCUS_ON_COMMAND + "-" + seriesKey);
            focusOnCurveItem.addActionListener(this);
            curveManagementMenu.add(focusOnCurveItem);
            if (i == selectedSeriesIndex) {
                focusOnCurveItem.setSelected(true);
                isCurveFocused = true;
            }
        }
        if (!isCurveFocused) {
            focusNoneCurveItem.setSelected(true);
        }
    } else {
        curveManagementMenu.setEnabled(false);
    }
    //        addMaskMenu(x, y);
    super.displayPopupMenu(x, y);
}

From source file:userinterface.graph.Graph.java

private void updateGraph() {
    /* Update title if necessary. */
    if (!this.chart.getTitle().equals(graphTitle)) {
        this.chart.setTitle(graphTitle.getStringValue());
    }/*  w  ww .ja v a2  s  .c  om*/

    /* Update title font if necessary. */
    if (!titleFont.getFontColorValue().f.equals(this.chart.getTitle().getFont())) {
        this.chart.getTitle().setFont(titleFont.getFontColorValue().f);
    }

    /* Update title colour if necessary. */
    if (!titleFont.getFontColorValue().c.equals(this.chart.getTitle().getPaint())) {
        this.chart.getTitle().setPaint(titleFont.getFontColorValue().c);
    }

    if (legendVisible.getBooleanValue() != (this.chart.getLegend() != null)) {
        if (!legendVisible.getBooleanValue()) {
            this.chart.removeLegend();
        } else {
            LegendTitle legend = new LegendTitle(plot.getRenderer());
            legend.setBackgroundPaint(Color.white);
            legend.setBorder(1, 1, 1, 1);

            this.chart.addLegend(legend);
        }
    }

    if (this.chart.getLegend() != null) {
        LegendTitle legend = this.chart.getLegend();

        /* Put legend on the left if appropriate. */
        if ((legendPosition.getCurrentIndex() == LEFT) && !legend.getPosition().equals(RectangleEdge.LEFT)) {
            legend.setPosition(RectangleEdge.LEFT);
        }
        /* Put legend on the right if appropriate. */
        if ((legendPosition.getCurrentIndex() == RIGHT) && !legend.getPosition().equals(RectangleEdge.RIGHT)) {
            legend.setPosition(RectangleEdge.RIGHT);
        }
        /* Put legend on the top if appropriate. */
        if ((legendPosition.getCurrentIndex() == TOP) && !legend.getPosition().equals(RectangleEdge.TOP)) {
            legend.setPosition(RectangleEdge.TOP);
        }
        /* Put legend on the bottom if appropriate. */
        if ((legendPosition.getCurrentIndex() == BOTTOM)
                && !legend.getPosition().equals(RectangleEdge.BOTTOM)) {
            legend.setPosition(RectangleEdge.BOTTOM);
        }

        /* Set legend font. */
        if (!legend.getItemFont().equals(legendFont.getFontColorValue().f)) {
            legend.setItemFont(legendFont.getFontColorValue().f);
        }
        /* Set legend font colour. */
        if (!legend.getItemPaint().equals(legendFont.getFontColorValue().c)) {
            legend.setItemPaint(legendFont.getFontColorValue().c);
        }
    }

    super.repaint();
    doEnables();
}