/** * Receives notification that the key for one of the series in the * collection has changed, and vetos it if the key is already present in * the collection. * * @param e the event. * * @since 1.0.14 */ @Override public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException { // if it is not the series name, then we have no interest if (!"Key".equals(e.getPropertyName())) { return; } // to be defensive, let's check that the source series does in fact // belong to this collection Series s = (Series) e.getSource(); if (getSeriesIndex(s.getKey()) == -1) { throw new IllegalStateException("Receiving events from a series " + "that does not belong to this collection."); } // check if the new series name already exists for another series Comparable key = (Comparable) e.getNewValue(); if (getSeriesIndex(key) >= 0) { throw new PropertyVetoException("Duplicate key2", e); } }
/** * Add a series to the chart. * * @param series populated series * @param color display color * @param displayShapes true to display a shape at each item */ public void add (XYSeries series, Color color, boolean displayShapes) { dataset.addSeries(series); final int index = dataset.getSeriesIndex(series.getKey()); renderer.setSeriesPaint(index, color); renderer.setSeriesShapesVisible(index, displayShapes); }
/** * Adds a series to the collection and sends a {@link DatasetChangeEvent} * to all registered listeners. * * @param series the series ({@code null} not permitted). * * @throws IllegalArgumentException if the key for the series is null or * not unique within the dataset. */ public void addSeries(XYSeries series) { Args.nullNotPermitted(series, "series"); if (getSeriesIndex(series.getKey()) >= 0) { throw new IllegalArgumentException( "This dataset already contains a series with the key " + series.getKey()); } this.data.add(series); series.addChangeListener(this); series.addVetoableChangeListener(this); fireDatasetChanged(); }