Search in sources :

Example 11 with CategoryItemRenderer

use of org.jfree.chart.renderer.category.CategoryItemRenderer in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testRangeMarkerIndices.

@Test
public void testRangeMarkerIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    // add a second dataset, plotted against a second axis
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset);
    NumberAxis yAxis2 = new NumberAxis("Y2");
    plot.setRangeAxis(1, yAxis2);
    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    plot.mapDatasetToRangeAxis(99, 1);
    ValueMarker yMarker1 = new ValueMarker(123);
    plot.addRangeMarker(99, yMarker1, Layer.FOREGROUND);
    assertTrue(plot.getRangeMarkers(99, Layer.FOREGROUND).contains(yMarker1));
}
Also used : LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Test(org.junit.Test)

Example 12 with CategoryItemRenderer

use of org.jfree.chart.renderer.category.CategoryItemRenderer in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testGetDomainAxisForDataset.

/**
 * Some tests for the getDomainAxisForDataset() method.
 */
@Test
public void testGetDomainAxisForDataset() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    assertEquals(xAxis, plot.getDomainAxisForDataset(0));
    // should get IllegalArgumentException for negative index
    boolean pass = false;
    try {
        plot.getDomainAxisForDataset(-1);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
    // if multiple axes are mapped, the first in the list should be
    // returned...
    CategoryAxis xAxis2 = new CategoryAxis("X2");
    plot.setDomainAxis(1, xAxis2);
    assertEquals(xAxis, plot.getDomainAxisForDataset(0));
    plot.mapDatasetToDomainAxis(0, 1);
    assertEquals(xAxis2, plot.getDomainAxisForDataset(0));
    List axisIndices = Arrays.asList(new Integer[] { new Integer(0), new Integer(1) });
    plot.mapDatasetToDomainAxes(0, axisIndices);
    assertEquals(xAxis, plot.getDomainAxisForDataset(0));
    axisIndices = Arrays.asList(new Integer[] { new Integer(1), new Integer(2) });
    plot.mapDatasetToDomainAxes(0, axisIndices);
    assertEquals(xAxis2, plot.getDomainAxisForDataset(0));
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) List(java.util.List) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Test(org.junit.Test)

Example 13 with CategoryItemRenderer

use of org.jfree.chart.renderer.category.CategoryItemRenderer in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testGetRangeAxisForDataset.

/**
 * Some tests for the getRangeAxisForDataset() method.
 */
@Test
public void testGetRangeAxisForDataset() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new DefaultCategoryItemRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    assertEquals(yAxis, plot.getRangeAxisForDataset(0));
    // should get IllegalArgumentException for negative index
    boolean pass = false;
    try {
        plot.getRangeAxisForDataset(-1);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
    // if multiple axes are mapped, the first in the list should be
    // returned...
    NumberAxis yAxis2 = new NumberAxis("Y2");
    plot.setRangeAxis(1, yAxis2);
    assertEquals(yAxis, plot.getRangeAxisForDataset(0));
    plot.mapDatasetToRangeAxis(0, 1);
    assertEquals(yAxis2, plot.getRangeAxisForDataset(0));
    List axisIndices = Arrays.asList(new Integer[] { new Integer(0), new Integer(1) });
    plot.mapDatasetToRangeAxes(0, axisIndices);
    assertEquals(yAxis, plot.getRangeAxisForDataset(0));
    axisIndices = Arrays.asList(new Integer[] { new Integer(1), new Integer(2) });
    plot.mapDatasetToRangeAxes(0, axisIndices);
    assertEquals(yAxis2, plot.getRangeAxisForDataset(0));
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) List(java.util.List) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Test(org.junit.Test)

Example 14 with CategoryItemRenderer

use of org.jfree.chart.renderer.category.CategoryItemRenderer in project SIMVA-SoS by SESoS.

the class DefaultPlotEditor method createPlotPanel.

protected JPanel createPlotPanel(Plot plot) {
    this.plotInsets = plot.getInsets();
    this.backgroundPaintSample = new PaintSample(plot.getBackgroundPaint());
    this.outlineStrokeSample = new StrokeSample(plot.getOutlineStroke());
    this.outlinePaintSample = new PaintSample(plot.getOutlinePaint());
    if (plot instanceof CategoryPlot) {
        this.plotOrientation = ((CategoryPlot) plot).getOrientation();
    } else if (plot instanceof XYPlot) {
        this.plotOrientation = ((XYPlot) plot).getOrientation();
    }
    if (plot instanceof CategoryPlot) {
        CategoryItemRenderer renderer = ((CategoryPlot) plot).getRenderer();
        if (renderer instanceof LineAndShapeRenderer) {
            LineAndShapeRenderer r = (LineAndShapeRenderer) renderer;
            this.drawLines = BooleanUtilities.valueOf(r.getBaseLinesVisible());
            this.drawShapes = BooleanUtilities.valueOf(r.getBaseShapesVisible());
        }
    } else if (plot instanceof XYPlot) {
        XYItemRenderer renderer = ((XYPlot) plot).getRenderer();
        if (renderer instanceof StandardXYItemRenderer) {
            StandardXYItemRenderer r = (StandardXYItemRenderer) renderer;
            this.drawLines = BooleanUtilities.valueOf(r.getPlotLines());
            this.drawShapes = BooleanUtilities.valueOf(r.getBaseShapesVisible());
        }
    }
    setLayout(new BorderLayout());
    this.availableStrokeSamples = new StrokeSample[4];
    this.availableStrokeSamples[0] = new StrokeSample(null);
    this.availableStrokeSamples[1] = new StrokeSample(new BasicStroke(1.0f));
    this.availableStrokeSamples[2] = new StrokeSample(new BasicStroke(2.0f));
    this.availableStrokeSamples[3] = new StrokeSample(new BasicStroke(3.0f));
    // create a panel for the settings...
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), plot.getPlotType() + localizationResources.getString(":")));
    JPanel general = new JPanel(new BorderLayout());
    general.setBorder(BorderFactory.createTitledBorder(localizationResources.getString("General")));
    JPanel interior = new JPanel(new LCBLayout(7));
    interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    // interior.add(new JLabel(localizationResources.getString("Insets")));
    // JButton button = new JButton(
    // localizationResources.getString("Edit...")
    // );
    // button.setActionCommand("Insets");
    // button.addActionListener(this);
    // 
    // this.insetsTextField = new InsetsTextField(this.plotInsets);
    // this.insetsTextField.setEnabled(false);
    // interior.add(this.insetsTextField);
    // interior.add(button);
    interior.add(new JLabel(localizationResources.getString("Outline_stroke")));
    JButton button = new JButton(localizationResources.getString("Select..."));
    button.setActionCommand("OutlineStroke");
    button.addActionListener(this);
    interior.add(this.outlineStrokeSample);
    interior.add(button);
    interior.add(new JLabel(localizationResources.getString("Outline_Paint")));
    button = new JButton(localizationResources.getString("Select..."));
    button.setActionCommand("OutlinePaint");
    button.addActionListener(this);
    interior.add(this.outlinePaintSample);
    interior.add(button);
    interior.add(new JLabel(localizationResources.getString("Background_paint")));
    button = new JButton(localizationResources.getString("Select..."));
    button.setActionCommand("BackgroundPaint");
    button.addActionListener(this);
    interior.add(this.backgroundPaintSample);
    interior.add(button);
    if (this.plotOrientation != null) {
        boolean isVertical = this.plotOrientation.equals(PlotOrientation.VERTICAL);
        int index = isVertical ? ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL;
        interior.add(new JLabel(localizationResources.getString("Orientation")));
        this.orientationCombo = new JComboBox(orientationNames);
        this.orientationCombo.setSelectedIndex(index);
        this.orientationCombo.setActionCommand("Orientation");
        this.orientationCombo.addActionListener(this);
        interior.add(new JPanel());
        interior.add(this.orientationCombo);
    }
    if (this.drawLines != null) {
        interior.add(new JLabel(localizationResources.getString("Draw_lines")));
        this.drawLinesCheckBox = new JCheckBox();
        this.drawLinesCheckBox.setSelected(this.drawLines.booleanValue());
        this.drawLinesCheckBox.setActionCommand("DrawLines");
        this.drawLinesCheckBox.addActionListener(this);
        interior.add(new JPanel());
        interior.add(this.drawLinesCheckBox);
    }
    if (this.drawShapes != null) {
        interior.add(new JLabel(localizationResources.getString("Draw_shapes")));
        this.drawShapesCheckBox = new JCheckBox();
        this.drawShapesCheckBox.setSelected(this.drawShapes.booleanValue());
        this.drawShapesCheckBox.setActionCommand("DrawShapes");
        this.drawShapesCheckBox.addActionListener(this);
        interior.add(new JPanel());
        interior.add(this.drawShapesCheckBox);
    }
    general.add(interior, BorderLayout.NORTH);
    JPanel appearance = new JPanel(new BorderLayout());
    appearance.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    appearance.add(general, BorderLayout.NORTH);
    JTabbedPane tabs = createPlotTabs(plot);
    tabs.add(localizationResources.getString("Appearance"), appearance);
    panel.add(tabs);
    return panel;
}
Also used : BasicStroke(java.awt.BasicStroke) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) JPanel(javax.swing.JPanel) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) JComboBox(javax.swing.JComboBox) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Paint(java.awt.Paint) LCBLayout(org.jfree.layout.LCBLayout) JCheckBox(javax.swing.JCheckBox) XYPlot(org.jfree.chart.plot.XYPlot) BorderLayout(java.awt.BorderLayout) PaintSample(org.jfree.ui.PaintSample) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) StrokeSample(org.jfree.ui.StrokeSample) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer)

Example 15 with CategoryItemRenderer

use of org.jfree.chart.renderer.category.CategoryItemRenderer in project SIMVA-SoS by SESoS.

the class BarChartTest method testSetSeriesToolTipGenerator.

/**
 * Check that setting a tool tip generator for a series does override the
 * default generator.
 */
@Test
public void testSetSeriesToolTipGenerator() {
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    CategoryItemRenderer renderer = plot.getRenderer();
    StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator();
    renderer.setSeriesToolTipGenerator(0, tt);
    CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0);
    assertTrue(tt2 == tt);
}
Also used : CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) CategoryToolTipGenerator(org.jfree.chart.labels.CategoryToolTipGenerator) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Test(org.junit.Test)

Aggregations

CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)70 CategoryPlot (org.jfree.chart.plot.CategoryPlot)36 Test (org.junit.Test)32 CategoryAxis (org.jfree.chart.axis.CategoryAxis)23 CategoryDataset (org.jfree.data.category.CategoryDataset)20 AbstractCategoryItemRenderer (org.jfree.chart.renderer.category.AbstractCategoryItemRenderer)14 Paint (java.awt.Paint)13 NumberAxis (org.jfree.chart.axis.NumberAxis)13 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)13 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)12 DefaultCategoryItemRenderer (org.jfree.chart.renderer.category.DefaultCategoryItemRenderer)12 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)12 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)11 ValueAxis (org.jfree.chart.axis.ValueAxis)10 CategoryToolTipGenerator (org.jfree.chart.labels.CategoryToolTipGenerator)10 CategoryURLGenerator (org.jfree.chart.urls.CategoryURLGenerator)10 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)9 JFreeChart (org.jfree.chart.JFreeChart)6 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)5 Rectangle2D (java.awt.geom.Rectangle2D)4