package com.uvigo.mhp.ui;

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

public class HScrollBarOrientationEditor extends PropertyEditorSupport
{
    private int orientation;
    
    public static final String LEFT_TO_RIGHT="LEFT_TO_RIGHT";
    public static final String RIGHT_TO_LEFT="RIGHT_TO_LEFT";
    public static final String TOP_TO_BOTTOM="TOP_TO_BOTTOM";
    public static final String BOTTOM_TO_TOP="BOTTOM_TO_TOP";
    
    public void setValue(Object o)
    {
        orientation=((Integer)o).intValue();
        firePropertyChange();
    }
    
    public Object getValue()
    {
        return new Integer(orientation);
    }
    
    public String getAsText()
    {
        switch (orientation)
        {
            case HOrientable.ORIENT_LEFT_TO_RIGHT:
                return LEFT_TO_RIGHT;
            case HOrientable.ORIENT_RIGHT_TO_LEFT:
                return RIGHT_TO_LEFT;
            case HOrientable.ORIENT_TOP_TO_BOTTOM:
                return TOP_TO_BOTTOM;
            default:
                return BOTTOM_TO_TOP;
        }
    }
    
    public void setAsText(String s) throws IllegalArgumentException
    {
        if (s.equalsIgnoreCase(LEFT_TO_RIGHT))
            orientation = HOrientable.ORIENT_LEFT_TO_RIGHT;
        else if (s.equalsIgnoreCase(RIGHT_TO_LEFT))
            orientation = HOrientable.ORIENT_RIGHT_TO_LEFT;
        else if (s.equalsIgnoreCase(TOP_TO_BOTTOM))
            orientation = HOrientable.ORIENT_TOP_TO_BOTTOM;
        else
            orientation = HOrientable.ORIENT_BOTTOM_TO_TOP;
        firePropertyChange();
    }
    
    public String[] getTags()
    {
        return new String[]
        {LEFT_TO_RIGHT, RIGHT_TO_LEFT, TOP_TO_BOTTOM, BOTTOM_TO_TOP};
    }
    
    public String getJavaInitializationString()
    {
        return "org.havi.ui.HOrientable.ORIENT_"+getAsText();
    }
}
