package com.uvigo.mhp.ui;

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

public class BackgroundImageModeEditor extends PropertyEditorSupport
{
    private int mode;
    
    public void setValue(Object o)
    {
        mode = ((Integer)o).intValue();
        firePropertyChange();
    }
    
    public Object getValue()
    {
        return new Integer(mode);
    }
    
    public String getAsText()
    {
        switch (mode)
        {
            case HPanel.IMAGE_DONT_SHOW:
                return "DONT_SHOW";
            case HPanel.IMAGE_SINGLE:
                return "SINGLE";
            case HPanel.IMAGE_TILE:
                return "TILE";
            default: //HPanel.BACKGROUND_FILL
                return "STRETCH";
        }
    }
    
    public void setAsText(String s) throws IllegalArgumentException
    {
        if (s.equalsIgnoreCase("DONT_SHOW"))
            mode = HPanel.IMAGE_DONT_SHOW;
        else if (s.equalsIgnoreCase("SINGLE"))
            mode = HPanel.IMAGE_SINGLE;
        else if (s.equalsIgnoreCase("TILE"))
            mode = HPanel.IMAGE_TILE;
        else
            mode = HPanel.IMAGE_STRETCH;
        firePropertyChange();
    }
    
    public String[] getTags()
    {
        return new String[]
        {"DONT_SHOW", "SINGLE", "TILE", "STRETCH"};
    }
    
    public String getJavaInitializationString()
    {
        return "com.uvigo.mhp.ui.HPanel.IMAGE_"+getAsText();
    }
}
