// (C)2007 Attila Kovacs <attila@submm.caltech.edu>


import nom.tam.fits.*;
import nom.tam.util.*;

import java.text.*;
import java.util.*;

//Add visualizable...

public class CoordinateAxis implements Cloneable {
	public String label;
	public String wcsName; // TODO newly added...
	public NumberFormat format;
	public boolean reverse = false;
	public double reverseFrom = 0.0;
	
	public Unit unit; // TODO newly added...

	public Vector<Unit> tickUnits = new Vector<Unit>();
	public double[] multiples; // The multiples of the fundamental tickunits that can be used.
	public boolean magnitudeScaling = true; // If the ticks can be scaled by powers of 10 also.
	public double majorTick, minorTick; // The actual ticks.
	
	public CoordinateAxis() { this("unspecified axis");}

	public CoordinateAxis(String text) { 
		defaults();
		setLabel(text); 
	}
	
	public CoordinateAxis(String text, String fitsID) { 
		this(text);
		wcsName = fitsID;
	}
	
	public void copy(CoordinateAxis axis) {
		label = axis.label;
		wcsName = axis.wcsName;
		format = axis.format;
		unit = axis.unit;
	}
	
	public Object clone() { 
		try { return super.clone(); }
		catch(CloneNotSupportedException e) { return null; }
	}
	
	public void defaults() {
		tickUnits.clear();
		tickUnits.add(Unit.unity);
		reverse = false;
		multiples = new double[] { 1.0, 2.0, 5.0 }; // The multiples of the fundamental tickunits that can be used.
		magnitudeScaling = true;
	}

	public void setTickUnits(double[] unit) {}

	public Vector<Unit> getTickUnits() { return tickUnits; }

	public void setLabel(String text) { label = text; }

	public String getLabel() { return label; }

	public void setFormat(NumberFormat nf) { format = nf; }
	
	public NumberFormat getFormat() { return format; }
	
	public void setReverse(boolean value) { setReverse(value, 0.0); }
	
	public void setReverse(boolean value, double from) { reverse = value; reverseFrom = from; }
	
	public boolean isReverse() { return reverse; }
	
	public String format(double value) { return format.format(reverse ? reverseFrom - value : value); }
	
	public void edit(Cursor cursor, String id) throws HeaderCardException {
		cursor.add(new HeaderCard("CTYPE" + id, wcsName, "Description of coordinate axis."));
		cursor.add(new HeaderCard("CUNIT" + id, unit.name, "Coordinate units used."));	
	}
	
	// TODO
	// does not read label and format information...
	// should use getDefaults("wcsName")?
	public void parse(Header header, String id) {
		wcsName = header.getStringValue("CTYPE" + id);
		unit = Unit.get("CUNIT" + "id");
		if(unit == null) unit = Unit.unity;
	}
	
}

