package com.uvigo.mhp.ui;

import java.beans.*;
import org.havi.ui.*;

public class Colour extends PropertyEditorSupport
{
    private int mode;
    
    public void setValue(Object o)
    {
        mode = ((Integer)o).intValue();
        System.out.println("cuando me llaman en el colour valego "+mode);
        firePropertyChange();
    }
    
    public Object getValue()
    {
        return new Integer(mode);
    }
    
    public String getAsText()
    {
        switch (mode)
        {
            case HPanel.COLOUR_NONE:
                return "NONE";
            case HPanel.COLOUR_RED:
                return "RED";
            case HPanel.COLOUR_GREEN:
                return "GREEN";
                case HPanel.COLOUR_YELLOW:
                return "YELLOW";
            default: //HPanel.BACKGROUND_FILL
                return "BLUE";
        }
    }
    
    public void setAsText(String s) throws IllegalArgumentException
    {
        if (s.equalsIgnoreCase("NONE"))
            mode = HPanel.COLOUR_NONE;
        else if (s.equalsIgnoreCase("RED"))
            mode = HPanel.COLOUR_RED;
        else if (s.equalsIgnoreCase("GREEN"))
            mode = HPanel.COLOUR_GREEN;
         else if (s.equalsIgnoreCase("YELLOW"))
            mode = HPanel.COLOUR_YELLOW;
        else
            mode = HPanel.COLOUR_BLUE;
        firePropertyChange();
    }
    
    public String[] getTags()
    {
        return new String[]
        {"NONE", "RED", "GREEN", "YELLOW", "BLUE"};
    }
    
    public String getJavaInitializationString()
    {
        return "com.uvigo.mhp.ui.HPanel.COLOUR_"+getAsText();
    }
}
