package framework.parameters;

import java.util.Observable;

import framework.editors.ParameterEditor;

/**
 * Generic abstract class to represent any kind of parameter.
 */
public abstract class Parameter<T> extends Observable {
    /**
     * Create a Parameter object.
     * @param  n the name of the parameter
     * @param  v the initial value of the parameter
     */
    public Parameter(String n, T v) {
        name    = n;
        value   = v;
    }

    /**
     * Parse the value to see if it fits the requirements.
     * @param  v the value to be tested
     * @return   the value or null if it doesn't fit
     */
    public abstract T parseValue(T v);

    /**
     * Parse the value from a String and see if it fits the requirements.
     * @param  s the String to parse
     * @return   the value or null if it doesn't fit
     */
    public abstract T parseValue(String s);

    /**
     * Attach a new ParameterEditor to the Parameter object.
     * @return the ParameterEditor newly attached
     */
    public ParameterEditor attachEditor() {
        ParameterEditor editor = new ParameterEditor(this);
        addObserver(editor);
        return editor;
    }

    /**
     * Get the current value of the Parameter object.
     * @return the value
     */
    public T getValue() {
        return value;
    }

    /**
     * Set a new value in the Parameter object.
     * @param  v the new value
     * @return   true if the value has been updated, false otherwise
     */
    public boolean setValue(T v) {
        // If the value is correct
        // Informs the modifier that the parameter changed
        if(parseValue(v) != null) {
            value = parseValue(v);
            setChanged();
            notifyObservers();
            return true;
        }
        return false;
    }

    /**
     * Get the name of the Parameter (clearer than toString() for this purpose).
     * @return the name of the Parameter
     */
    public String getName() {
        return toString();
    }

    public String toString() {
        return name;
    }

    private String  name;
    private T       value;
}
@@ -1405,25 +1405,36 @@
   v the 
-new
+value possibly
  val
-ue
+id
 %0A     * 
@@ -1664,24 +1664,24 @@
  != null) %7B%0A
-
             
@@ -1816,32 +1816,457 @@
 n false;%0A    %7D%0A%0A
+    /**%0A     * Set a new value in the Parameter object.%0A     * @param  s the string possibly containing a new value%0A     * @return   true if the value has been updated, false otherwise%0A     */%0A    public boolean setValue(String s) %7B%0A        if(parseValue(s) != null) %7B%0A            value = parseValue(s);%0A            setChanged();%0A            notifyObservers();%0A            return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A
     /**%0A     * G

Add a new setValue method taking a String has argument.