package com.approximatrix.draco.application.plugin;

public class PluginSimpleOption {

	public static final int INTEGER = 0;
	public static final int FLOAT = 1;
	public static final int STRING = 2;
	public static final int VARIABLE = 3;
	public static final int CONSTANT = 4;
	public static final int CHECKBOX = 5;
	public static final int RADIOBUTTONS = 6;
	
	private String label = null;
	private int type = INTEGER;
	private String value = null;
	
	public PluginSimpleOption(String label, int type, String def_value) {
		this.label = label;
		this.type = type;
		this.value = def_value;
	}

    public String getLabel() {
        return label;
    }

    public void setString(String value) {
        this.value = value;
    }
    
    public int getType() {
        return type;
    }
    
    public String getString() {
        return value;
    }
    
    public boolean getBoolean() {
    	return new Boolean(value).booleanValue();
    }
    
    public int getInteger() {
        return getNumber().intValue();
    }
    
    public double getFloat() {
        return getNumber().doubleValue();
    }
    
    public Object getObject() {
    	switch(type) {
	    	case FLOAT:
	    	case INTEGER:
	    		return getNumber();
	    	case CHECKBOX:
	    		return new Boolean(getBoolean());
	    	default:
	    		return value;
    	}
    }
    
    public boolean setObject(Object value) {
    	switch(type) {
    		case FLOAT:
    	}
    	
    	return true;
    }
    
    private Number getNumber() {
        try {
            switch(type) {
                case FLOAT:
                    return new Double(value);
                case INTEGER:
                    return new Integer(value);
                case CHECKBOX:
                    return getBoolean() ? new Integer(1) : new Integer(0);
                default:
                    return new Integer(0);
            }
        } catch(NumberFormatException nfe) {
            return new Integer(0);
        }    
    }
	
}
