/*
 * File:     AbstractTSTrack.java
 * Project:  MPI Linguistic Application
 * Date:     03 April 2006
 *
 * Copyright (C) 2001-2006  Max Planck Institute for Psycholinguistics
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package mpi.eudico.client.annotator.timeseries;

import java.awt.Color;


/**
 * Abstract time series track.
 *
 * @author Han Sloetjes
 */
public abstract class AbstractTSTrack implements TimeSeriesTrack {
    protected Color color;
    protected float[] range;
    protected int datatype;
    protected String units;
    protected String name;
    protected String description;
    protected String source;
    protected int timeOffset;
    protected int derivativeLevel;

    /**
     * Creates a new AbstractTSTrack instance
     */
    public AbstractTSTrack() {
        this("nk", "-");
    }

    /**
     * Creates a new AbstractTSTrack instance
     *
     * @param name the name of the track
     * @param description the description
     */
    public AbstractTSTrack(String name, String description) {
        this(name, description, TimeSeriesTrack.VALUES_FLOAT_ARRAY);
    }

    /**
     * Creates a new AbstractTSTrack instance
     *
     * @param name the name of the track
     * @param description the description
     * @param type the type of the track data
     */
    public AbstractTSTrack(String name, String description, int type) {
        this.name = name;
        this.description = description;
        this.datatype = type;
    }

    /**
     * Returns the color used for rendering.
     *
     * @return the color
     */
    public Color getColor() {
        return color;
    }

    /**
     * Sets the color.
     *
     * @param color the color
     */
    public void setColor(Color color) {
        this.color = color;
    }

    /**
     * Returns the name /id of the track.
     *
     * @return the name /id of the track
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name /id of the track
     *
     * @param name the name /id of the track
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Returns the description of this track.
     *
     * @return the description of this track
     */
    public String getDescription() {
        return description;
    }

    /**
     * Sets the description of this track
     *
     * @param description the description of this track
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * Returns the (estimated or calculated) range of this track.
     *
     * @return the range, float array of size 2; min, max
     */
    public float[] getRange() {
        return range;
    }

    /**
     * Sets the (estimated or calculated) range of this track.
     *
     * @param range the new range, float array of size 2
     */
    public void setRange(float[] range) {
        this.range = range;
    }

    /**
     * A String representation of the source this track has been extracted
     * from.
     *
     * @return the source of the track
     */
    public String getSource() {
        return source;
    }

    /**
     * Sets the source for the track data.
     *
     * @param source the source
     */
    public void setSource(String source) {
        this.source = source;
    }

    /**
     * Returns the level of a derivation in case the data in this track is
     * a derivative of the data in the samples.
     *
     * @return the level of derivation, 0 means no derivation (the raw data from the file)
     */
    public int getDerivativeLevel() {
        return derivativeLevel;
    }

    /**
     * Sets the level of a derivation for the data in this track.
     *
     * @param int the level of derivation, 0 means no derivation
     */
    public void setDerivativeLevel(int level) {
        derivativeLevel = level;
    }

    /**
     * Returns a String representation of the ruler's units, like m/s.
     *
     * @return a String representation of the ruler's units
     */
    public String getUnitString() {
        return units;
    }

    /**
     * Sets the String representation of the ruler's units.
     *
     * @param unitString the String representation of the ruler's units
     */
    public void setUnitString(String unitString) {
        units = unitString;
    }

    /**
     * Returns the type, one of the constants in TimeSeriesTrack.
     *
     * @return the type of track data
     */
    public int getType() {
        return datatype;
    }

    /**
     * Sets the data type of this track, one of the constants in TimeSeriesTrack.
     *
     * @param type the type
     */
    public void setType(int type) {
        datatype = type;
    }

    /**
     * Returns the time offset into the data stream (point zero).
     *
     * @return the offset
     */
    public int getTimeOffset() {
        return timeOffset;
    }

    /**
     * Set the time offset.
     *
     * @param timeOffset the time offset
     */
    public void setTimeOffset(int timeOffset) {
        this.timeOffset = timeOffset;
    }

    /**
     * Returns the index of the value for the specified time, rounded down.
     *
     * @param time the time
     * @return the index of the value for the specified time, rounded down
     */
    public abstract int getIndexForTime(long time);

    /**
     * Returns the begin time of the sample at the given sample index.
     * The value is rounded down.
     * As a result time - sample comparisons are begin time inclusive, end
     * time exclusive. e.g. if each sample has a duration of 40 ms sample 0
     * is from 0 - 39 ms, sample 1 from 40 - 79 ms etc.
     *
     * @param index the sample index
     * @return the time value for the sample, i.e. the begin time of the sample
     * interval
     */
    public abstract long getTimeForIndex(int index);
}
