// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) space 
// Source File Name:   StringablePropertyEditor.java

package lt.ktu.gmj.propertySheet;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JComponent;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;

// Referenced classes of package lt.ktu.gmj.propertySheet:
//            PropertyEditor, PropertyNotifier, PropertyEnStringer, PropertyDeStringer, 
//            InvalidPropertyException, NotifierTextField, PropertyStringer, PropertyObserver

public class StringablePropertyEditor
    implements PropertyEditor
{

    public void setStringer(PropertyStringer propertystringer)
    {
        stringer = propertystringer;
        stringer.addObserver(this);
        refreshed();
    }

    public void refreshed()
    {
        editor.setText(stringer.getAsString());
        editor.setBackground(normalBackground);
        editor.setForeground(normalForeground);
    }

    public void fieldChanged()
    {
        try
        {
            stringer.setAsString(editor.getText());
            editor.setBackground(normalBackground);
            editor.setForeground(normalForeground);
        }
        catch (InvalidPropertyException invalidpropertyexception)
        {
            editor.setBackground(Color.red);
            editor.setForeground(Color.black);
        }
    }

    public JComponent component()
    {
        return (JComponent)editor;
    }

    public void refresh()
    {
    }

    public void addObserver(PropertyObserver propertyobserver)
    {
    }

    public StringablePropertyEditor(PropertyStringer propertystringer)
    {
        this();
        setStringer(propertystringer);
    }

    public StringablePropertyEditor()
    {
        stringer = null;
        editor = new NotifierTextField(this);
        normalBackground = editor.getBackground();
        normalForeground = editor.getForeground();
    }

    private PropertyStringer stringer;
    private JTextField editor;
    private Color normalBackground;
    private Color normalForeground;
}
