/*
 *	Modulname:	TypeNasa
 *	Autor:		Eyer Leander
 *	Datum:		06.06.2006
 *
 *	(c) Copyright 2005
 */
package survey.model;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class TypeNasa extends QuestionType {

	private int value = Integer.MIN_VALUE;

	private int min;
	private int max;
	private String leftLabel = "";
	private String rightLabel = "";


	/**
	 * Constructor
	 */
	public TypeNasa(Question question, Element xmlRoot) {
		super(question);
		parseFromXML(xmlRoot);
	}

	/** Create the element from the information in the xml definition */
	private void parseFromXML(Element nasaRoot) {
		if (nasaRoot.hasAttribute("leftlabel")) {
			leftLabel = nasaRoot.getAttribute("leftlabel");
		}
		if (nasaRoot.hasAttribute("rightlabel")) {
			rightLabel = nasaRoot.getAttribute("rightlabel");
		}

		min = Integer.parseInt(nasaRoot.getAttribute("min"));
		max = Integer.parseInt(nasaRoot.getAttribute("max"));
	}


	/**
	 * Return true if an answer has been set for this question
	 */
	public boolean hasBeenAnswered() {
		return value != Integer.MIN_VALUE;
	}

	/**
	 * Set the answer of the question
	 */
	public void setAnswer(Object newValue) {
		value = Integer.parseInt(newValue.toString());
		getQuestion().fireStateChagned();
	}

	/**
	 * Read the answer of the question
	 */
	public Object getAnswer() {
		return Integer.toString(value);
	}

	public int getMin() {
		return min;
	}

	public int getMax() {
		return max;
	}

	public String getLeftLabel() {
		return leftLabel;
	}

	public String getRightLabel() {
		return rightLabel;
	}
}

