Search in sources :

Example 26 with LegendItemCollection

use of org.jfree.chart.LegendItemCollection in project SIMVA-SoS by SESoS.

the class PolarPlotTest method testEquals.

/**
 * Some checks for the equals() method.
 */
@Test
public void testEquals() {
    PolarPlot plot1 = new PolarPlot();
    PolarPlot plot2 = new PolarPlot();
    assertTrue(plot1.equals(plot2));
    assertTrue(plot2.equals(plot1));
    plot1.setAngleGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertFalse(plot1.equals(plot2));
    plot2.setAngleGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertTrue(plot1.equals(plot2));
    Stroke s = new BasicStroke(1.23f);
    plot1.setAngleGridlineStroke(s);
    assertFalse(plot1.equals(plot2));
    plot2.setAngleGridlineStroke(s);
    assertTrue(plot1.equals(plot2));
    plot1.setAngleTickUnit(new NumberTickUnit(11.0));
    assertFalse(plot1.equals(plot2));
    plot2.setAngleTickUnit(new NumberTickUnit(11.0));
    assertTrue(plot1.equals(plot2));
    plot1.setAngleGridlinesVisible(false);
    assertFalse(plot1.equals(plot2));
    plot2.setAngleGridlinesVisible(false);
    assertTrue(plot1.equals(plot2));
    plot1.setAngleLabelFont(new Font("Serif", Font.PLAIN, 9));
    assertFalse(plot1.equals(plot2));
    plot2.setAngleLabelFont(new Font("Serif", Font.PLAIN, 9));
    assertTrue(plot1.equals(plot2));
    plot1.setAngleLabelPaint(new GradientPaint(9.0f, 8.0f, Color.blue, 7.0f, 6.0f, Color.red));
    assertFalse(plot1.equals(plot2));
    plot2.setAngleLabelPaint(new GradientPaint(9.0f, 8.0f, Color.blue, 7.0f, 6.0f, Color.red));
    assertTrue(plot1.equals(plot2));
    plot1.setAngleLabelsVisible(false);
    assertFalse(plot1.equals(plot2));
    plot2.setAngleLabelsVisible(false);
    assertTrue(plot1.equals(plot2));
    plot1.setAxis(new NumberAxis("Test"));
    assertFalse(plot1.equals(plot2));
    plot2.setAxis(new NumberAxis("Test"));
    assertTrue(plot1.equals(plot2));
    plot1.setRadiusGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.black));
    assertFalse(plot1.equals(plot2));
    plot2.setRadiusGridlinePaint(new GradientPaint(1.0f, 2.0f, Color.white, 3.0f, 4.0f, Color.black));
    assertTrue(plot1.equals(plot2));
    plot1.setRadiusGridlineStroke(s);
    assertFalse(plot1.equals(plot2));
    plot2.setRadiusGridlineStroke(s);
    assertTrue(plot1.equals(plot2));
    plot1.setRadiusGridlinesVisible(false);
    assertFalse(plot1.equals(plot2));
    plot2.setRadiusGridlinesVisible(false);
    assertTrue(plot1.equals(plot2));
    plot1.setRadiusMinorGridlinesVisible(false);
    assertFalse(plot1.equals(plot2));
    plot2.setRadiusMinorGridlinesVisible(false);
    assertTrue(plot1.equals(plot2));
    plot1.addCornerTextItem("XYZ");
    assertFalse(plot1.equals(plot2));
    plot2.addCornerTextItem("XYZ");
    assertTrue(plot1.equals(plot2));
    plot1.setMargin(6);
    assertFalse(plot1.equals(plot2));
    plot2.setMargin(6);
    assertTrue(plot1.equals(plot2));
    LegendItemCollection lic1 = new LegendItemCollection();
    lic1.add(new LegendItem("XYZ", Color.red));
    plot1.setFixedLegendItems(lic1);
    assertFalse(plot1.equals(plot2));
    LegendItemCollection lic2 = new LegendItemCollection();
    lic2.add(new LegendItem("XYZ", Color.red));
    plot2.setFixedLegendItems(lic2);
    assertTrue(plot1.equals(plot2));
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) NumberAxis(org.jfree.chart.axis.NumberAxis) LegendItem(org.jfree.chart.LegendItem) LegendItemCollection(org.jfree.chart.LegendItemCollection) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font) NumberTickUnit(org.jfree.chart.axis.NumberTickUnit) Test(org.junit.Test)

Example 27 with LegendItemCollection

use of org.jfree.chart.LegendItemCollection in project SIMVA-SoS by SESoS.

the class AbstractCategoryItemRendererTest method test2947660.

/**
 * A test that reproduces the problem reported in bug 2947660.
 */
@Test
public void test2947660() {
    AbstractCategoryItemRenderer r = new LineAndShapeRenderer();
    assertNotNull(r.getLegendItems());
    assertEquals(0, r.getLegendItems().getItemCount());
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset);
    plot.setRenderer(r);
    assertEquals(0, r.getLegendItems().getItemCount());
    dataset.addValue(1.0, "S1", "C1");
    LegendItemCollection lic = r.getLegendItems();
    assertEquals(1, lic.getItemCount());
    assertEquals("S1", lic.get(0).getLabel());
}
Also used : LegendItemCollection(org.jfree.chart.LegendItemCollection) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Test(org.junit.Test)

Example 28 with LegendItemCollection

use of org.jfree.chart.LegendItemCollection in project SIMVA-SoS by SESoS.

the class SpiderWebPlotTest method testGetLegendItems.

/**
 * Fetches the legend items and checks the values.
 */
@Test
public void testGetLegendItems() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(35.0, "S1", "C1");
    dataset.addValue(45.0, "S1", "C2");
    dataset.addValue(55.0, "S2", "C1");
    dataset.addValue(15.0, "S2", "C2");
    SpiderWebPlot plot = new SpiderWebPlot(dataset);
    JFreeChart chart = new JFreeChart(plot);
    LegendItemCollection legendItems = plot.getLegendItems();
    assertEquals(2, legendItems.getItemCount());
    LegendItem item1 = legendItems.get(0);
    assertEquals("S1", item1.getLabel());
    assertEquals("S1", item1.getSeriesKey());
    assertEquals(0, item1.getSeriesIndex());
    assertEquals(dataset, item1.getDataset());
    assertEquals(0, item1.getDatasetIndex());
    LegendItem item2 = legendItems.get(1);
    assertEquals("S2", item2.getLabel());
    assertEquals("S2", item2.getSeriesKey());
    assertEquals(1, item2.getSeriesIndex());
    assertEquals(dataset, item2.getDataset());
    assertEquals(0, item2.getDatasetIndex());
}
Also used : LegendItem(org.jfree.chart.LegendItem) LegendItemCollection(org.jfree.chart.LegendItemCollection) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Example 29 with LegendItemCollection

use of org.jfree.chart.LegendItemCollection in project SIMVA-SoS by SESoS.

the class MultiplePiePlotTest method testGetLegendItems.

/**
 * Fetches the legend items and checks the values.
 */
@Test
public void testGetLegendItems() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(35.0, "S1", "C1");
    dataset.addValue(45.0, "S1", "C2");
    dataset.addValue(55.0, "S2", "C1");
    dataset.addValue(15.0, "S2", "C2");
    MultiplePiePlot plot = new MultiplePiePlot(dataset);
    JFreeChart chart = new JFreeChart(plot);
    LegendItemCollection legendItems = plot.getLegendItems();
    assertEquals(2, legendItems.getItemCount());
    LegendItem item1 = legendItems.get(0);
    assertEquals("S1", item1.getLabel());
    assertEquals("S1", item1.getSeriesKey());
    assertEquals(0, item1.getSeriesIndex());
    assertEquals(dataset, item1.getDataset());
    assertEquals(0, item1.getDatasetIndex());
    LegendItem item2 = legendItems.get(1);
    assertEquals("S2", item2.getLabel());
    assertEquals("S2", item2.getSeriesKey());
    assertEquals(1, item2.getSeriesIndex());
    assertEquals(dataset, item2.getDataset());
    assertEquals(0, item2.getDatasetIndex());
}
Also used : LegendItem(org.jfree.chart.LegendItem) LegendItemCollection(org.jfree.chart.LegendItemCollection) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Example 30 with LegendItemCollection

use of org.jfree.chart.LegendItemCollection in project mzmine2 by mzmine.

the class MsMsVisualizerWindow method actionPerformed.

/**
 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 */
public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();
    if (command.equals("SHOW_SPECTRUM")) {
        CursorPosition pos = getCursorPosition();
        if (pos != null) {
            SpectraVisualizerModule.showNewSpectrumWindow(pos.getDataFile(), pos.getScanNumber());
        }
    }
    if (command.equals("SETUP_AXES")) {
        AxesSetupDialog dialog = new AxesSetupDialog(this, IDAPlot.getXYPlot());
        dialog.setVisible(true);
    }
    if (command.equals("SHOW_DATA_POINTS")) {
        IDAPlot.switchDataPointsVisible();
    }
    if (command.equals("SWITCH_TOOLTIPS")) {
        if (tooltipMode) {
            IDAPlot.showPeaksTooltips(false);
            toolBar.setTooltipButton(false);
            tooltipMode = false;
        } else {
            IDAPlot.showPeaksTooltips(true);
            toolBar.setTooltipButton(true);
            tooltipMode = true;
        }
    }
    if (command.equals("FIND_SPECTRA")) {
        // Parameters
        final DoubleParameter inputMZ = new DoubleParameter("Ion m/z", "m/z value of ion to search for.");
        final MZToleranceParameter inputMZTolerance = new MZToleranceParameter();
        final DoubleParameter inputIntensity = new DoubleParameter("Min. ion intensity", "Only ions with intensities above this value will be searched for.");
        final BooleanParameter inputNL = new BooleanParameter("Neutral Loss", "If selected, the ion to be searched for will be a neutral loss ion.\nIn this case, only ions above the min. intensity will be examined.", false);
        final ComboParameter<Colors> inputColors = new ComboParameter<Colors>("Color", "The color which the data points will be marked with.", Colors.values());
        Parameter<?>[] parameters = new Parameter<?>[5];
        parameters[0] = inputMZ;
        parameters[1] = inputMZTolerance;
        parameters[2] = inputIntensity;
        parameters[3] = inputNL;
        parameters[4] = inputColors;
        final ParameterSet parametersSearch = new SimpleParameterSet(parameters);
        ExitCode exitCode = parametersSearch.showSetupDialog(this, true);
        if (exitCode != ExitCode.OK)
            return;
        double searchMZ = parametersSearch.getParameter(inputMZ).getValue();
        MZTolerance searchMZTolerance = parametersSearch.getParameter(inputMZTolerance).getValue();
        double minIntensity = parametersSearch.getParameter(inputIntensity).getValue();
        boolean neutralLoss = parametersSearch.getParameter(inputNL).getValue();
        Color highligtColor = Color.red;
        ;
        if (parametersSearch.getParameter(inputColors).getValue().equals(Colors.green)) {
            highligtColor = Color.green;
        }
        if (parametersSearch.getParameter(inputColors).getValue().equals(Colors.blue)) {
            highligtColor = Color.blue;
        }
        // Find and highlight spectra with specific ion
        dataset.highlightSpectra(searchMZ, searchMZTolerance, minIntensity, neutralLoss, highligtColor);
        // Add legend entry
        LegendItemCollection chartLegend = IDAPlot.getXYPlot().getLegendItems();
        chartLegend.add(new LegendItem("Ion: " + searchMZ, "", "MS/MS spectra which contain the " + searchMZ + " ion\nTolerance: " + searchMZTolerance.toString() + "\nMin intensity: " + minIntensity, "", new Ellipse2D.Double(0, 0, 7, 7), highligtColor));
        IDAPlot.getXYPlot().setFixedLegendItems(chartLegend);
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) MZToleranceParameter(net.sf.mzmine.parameters.parametertypes.tolerances.MZToleranceParameter) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) LegendItemCollection(org.jfree.chart.LegendItemCollection) ExitCode(net.sf.mzmine.util.ExitCode) Color(java.awt.Color) BooleanParameter(net.sf.mzmine.parameters.parametertypes.BooleanParameter) AxesSetupDialog(net.sf.mzmine.util.dialogs.AxesSetupDialog) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter) LegendItem(org.jfree.chart.LegendItem) Parameter(net.sf.mzmine.parameters.Parameter) WindowSettingsParameter(net.sf.mzmine.parameters.parametertypes.WindowSettingsParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter) BooleanParameter(net.sf.mzmine.parameters.parametertypes.BooleanParameter) MZToleranceParameter(net.sf.mzmine.parameters.parametertypes.tolerances.MZToleranceParameter) CursorPosition(net.sf.mzmine.modules.visualization.tic.CursorPosition)

Aggregations

LegendItemCollection (org.jfree.chart.LegendItemCollection)30 LegendItem (org.jfree.chart.LegendItem)19 Paint (java.awt.Paint)12 Test (org.junit.Test)12 Iterator (java.util.Iterator)9 BasicStroke (java.awt.BasicStroke)6 Stroke (java.awt.Stroke)6 GradientPaint (java.awt.GradientPaint)5 NumberAxis (org.jfree.chart.axis.NumberAxis)5 List (java.util.List)4 XYDataset (org.jfree.data.xy.XYDataset)4 Shape (java.awt.Shape)3 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)3 Color (java.awt.Color)2 Font (java.awt.Font)2 HashSet (java.util.HashSet)2 JFreeChart (org.jfree.chart.JFreeChart)2 DefaultPolarItemRenderer (org.jfree.chart.renderer.DefaultPolarItemRenderer)2 DefaultXYItemRenderer (org.jfree.chart.renderer.xy.DefaultXYItemRenderer)2 LegendTitle (org.jfree.chart.title.LegendTitle)2