Example usage for org.jfree.data.xy XYSeriesCollection indexOf

List of usage examples for org.jfree.data.xy XYSeriesCollection indexOf

Introduction

In this page you can find the example usage for org.jfree.data.xy XYSeriesCollection indexOf.

Prototype

public int indexOf(XYSeries series) 

Source Link

Document

Returns the index of the specified series, or -1 if that series is not present in the dataset.

Usage

From source file:com.ivli.roim.controls.ChartView.java

@Override
public void OverlayChanged(OverlayChangeEvent anEvt) {
    LOG.debug(anEvt);/*from w w w.j  av a  2s.  com*/

    if (anEvt.getObject() instanceof ROI) {
        XYSeriesCollection col = ((XYSeriesCollection) iPlot.getDataset());
        final OverlayManager mgr = (OverlayManager) anEvt.getSource();

        switch (anEvt.getCode()) {
        case CREATED: {
            assert (0 > col.indexOf(anEvt.getObject().getName()));

            final XYSeries s = new XYSeries(anEvt.getObject().getName(), true, false);
            final ISeries c = ((ROI) anEvt.getObject()).getSeries(Measurement.DENSITY);

            IMultiframeImage img = mgr.getImage();

            assert (c.size() == img.getTimeSliceVector().getNumFrames());

            for (int n = 0; n < c.size(); ++n)
                s.add(img.getTimeSliceVector().getSlices().get(n) / 1000., c.get(n));

            ((XYSeriesCollection) iPlot.getDataset()).addSeries(s);
            iPlot.getRenderer().setSeriesPaint(col.indexOf(anEvt.getObject().getName()),
                    ((ROI) anEvt.getObject()).getColor());
        }
            break;

        case DELETED: {
            final int ndx = col.indexOf(anEvt.getObject().getName());
            col.removeSeries(ndx);
        }
            break;

        case MOVED: {//fall-through                                                                      
            final int ndx = col.indexOf(anEvt.getObject().getName());
            ISeries c = ((ROI) anEvt.getObject()).getSeries(Measurement.DENSITY);
            XYSeries s = col.getSeries(ndx);
            s.setNotify(false);
            s.clear();

            for (int n = 0; n < c.size(); ++n) {
                long dur = mgr.getImage().getTimeSliceVector().getSlices().get(n) / 1000;
                s.add(dur, c.get(n));
            }
            s.setNotify(true);
            //s.fireSeriesChanged();

        }
            break;

        case COLOR_CHANGED: {
            assert (anEvt.getExtra() instanceof java.awt.Color);
            final int ndx = col.indexOf(anEvt.getObject().getName());
            iPlot.getRenderer().setSeriesPaint(ndx, ((ROI) anEvt.getObject()).getColor());
        }
            break;

        case NAME_CHANGED: {
            assert (anEvt.getExtra() instanceof String);
            LOG.debug("ROI" + (String) anEvt.getExtra() + "name changed to " + anEvt.getObject().getName());

            final int ndx = col.indexOf(((String) anEvt.getExtra()));

            col.getSeries(ndx).setKey(anEvt.getObject().getName());
            /* this is a work-around the case when two or more ROI have the same names (user mistakenly renamed) 
             * when this mistake is corrected it might happen the colors of curves does not match colors of corresponding ROI 
             */
            iPlot.getRenderer().setSeriesPaint(ndx, ((ROI) anEvt.getObject()).getColor());

        }
            break;

        default:
            ///throw new java.lang.IllegalArgumentException();    
            break;
        }
    }
}

From source file:org.jfree.data.xy.junit.XYSeriesCollectionTest.java

/**
 * Some tests for the indexOf() method./*from   w w w  .  java2 s.co  m*/
 */
public void testIndexOf() {
    XYSeries s1 = new XYSeries("S1");
    XYSeries s2 = new XYSeries("S2");
    XYSeriesCollection dataset = new XYSeriesCollection();
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));

    dataset.addSeries(s1);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));

    dataset.addSeries(s2);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(1, dataset.indexOf(s2));

    dataset.removeSeries(s1);
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(0, dataset.indexOf(s2));

    XYSeries s2b = new XYSeries("S2");
    assertEquals(0, dataset.indexOf(s2b));
}

From source file:org.jfree.data.xy.XYSeriesCollectionTest.java

/**
 * Some tests for the indexOf() method.//from  w  ww. j av  a  2  s  .co m
 */
@Test
public void testIndexOf() {
    XYSeries s1 = new XYSeries("S1");
    XYSeries s2 = new XYSeries("S2");
    XYSeriesCollection dataset = new XYSeriesCollection();
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));

    dataset.addSeries(s1);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(-1, dataset.indexOf(s2));

    dataset.addSeries(s2);
    assertEquals(0, dataset.indexOf(s1));
    assertEquals(1, dataset.indexOf(s2));

    dataset.removeSeries(s1);
    assertEquals(-1, dataset.indexOf(s1));
    assertEquals(0, dataset.indexOf(s2));

    XYSeries s2b = new XYSeries("S2");
    assertEquals(0, dataset.indexOf(s2b));
}