package cnp.ew.charts;

import java.awt.*;
import cnp.ew.util.*;
import java.util.*;

public class CpDataSeries extends CpDefaultObservable
{
    // TBD: make this more general, with a converter.
    String labelObject;
    double [] values;
    Color color;
    // Pattern pattern;
    boolean showLabel=false;

    public static final int CHANGED_VALUE=0;
    public static final int CHANGED_COLOR=1;
    public static final int CHANGED_LABEL=2;

    public CpDataSeries(double [] newValues, Color newColor, String newLabel)
    {
        values = newValues;
        color = newColor;
        labelObject = newLabel;
    }

    public void dumpValues()
    {
        for (int i = 0; i < values.length; i++) {
            System.out.print("    value[" + i + "]: " + values[i]);
        }
        System.out.println("");
    }


    public double getValueForIndex(int index)
    {
        return values[index];
    }

    public int getValueCount()
    {
        return values.length;
    }

    public void setValueForIndex(int index, double value)
    {
        boolean notify = value != values[index];
        values[index] = value;
        if (notify) {
            notifyObservers(CHANGED_VALUE, this);
        }
    }

    public Color getColor()
    {
        return color;
    }

    public void setColor(Color newColor)
    {
        boolean notify = color != newColor;
        color = newColor;
        if (notify) {
            notifyObservers(CHANGED_COLOR, this);
        }
    }

    public String getLabelObject()
    {
        return labelObject;
    }

    public void setLabelObject(String o)
    {
        boolean notify = o != labelObject;
        labelObject = o;
        if (notify) {
            notifyObservers(CHANGED_LABEL, labelObject);
        }
    }

}