package org.okip.okifunc.dictionary.impl;

public class ResourceDictionaryPanel
extends mit.swing.xJPanel
implements mit.event.Listener
        ,  mit.swing.event.LocaleChangedRaiser
{
    private org.okip.okifunc.dictionary.api.Factory factory = new org.okip.okifunc.dictionary.impl.Factory();
    private org.okip.okifunc.dictionary.api.ResourceDictionary dictionary = factory.createResourceDictionary();

    public void addNotify()
    {
        super.addNotify();
        try
        {
            getAdapter().addHandled(mit.swing.event.ChangeLocaleEvent.class);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }        
    }
    
    public void eventRaised( mit.event.Event e )
    {
        if( e instanceof mit.swing.event.ChangeLocaleEvent )
        {
            HandleChangeLocaleEvent( ( mit.swing.event.ChangeLocaleEvent ) e ) ;
        }
    }

    public void HandleChangeLocaleEvent( mit.swing.event.ChangeLocaleEvent e )
    {
        mit.swing.event.ChangeLocaleRaiser raiser = ( mit.swing.event.ChangeLocaleRaiser )e.getSource();
        try
        {
            dictionary.setDefaultLocale(raiser.getNewLocale());
            new mit.swing.event.LocaleChangedEvent( this ).raise();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
    
    public java.util.Locale getCurrentLocale()
    {
        java.util.Locale locale = null;
        try
        {
            locale = dictionary.getDefaultLocale();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return locale;
    }
}