ValueEditorsRegistry.java :  » Swing-Library » autoui » com » thekirschners » uitoys » autoui » editors » Java Open Source

Java Open Source » Swing Library » autoui 
autoui » com » thekirschners » uitoys » autoui » editors » ValueEditorsRegistry.java
/************************************************************************
Copyright 2004 Emil Kirschner

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
************************************************************************/

package com.thekirschners.uitoys.autoui.editors;

import java.util.HashMap;

public class ValueEditorsRegistry {
    private static ValueEditorsRegistry ourInstance = new ValueEditorsRegistry();

    public static ValueEditorsRegistry getInstance() {
        return ourInstance;
    }

    private ValueEditorsRegistry() {
        editors = new HashMap<Class, Class>();

        editors.put(String.class, DefaultStringEditor.class);

        editors.put(Boolean.class, DefaultBooleanEditor.class);
        editors.put(boolean.class, DefaultBooleanEditor.class);

        editors.put(Integer.class, DefaultIntegerEditor.class);
        editors.put(int.class, DefaultIntegerEditor.class);
        editors.put(Long.class, DefaultIntegerEditor.class);
        editors.put(long.class, DefaultIntegerEditor.class);
    }

    public ValueEditor getValueEditor(Class cls) {
        Class editorClass = editors.get(cls);
        assert editorClass != null : "unable to find editor class for type: " + cls.getName();
        assert ValueEditor.class.isAssignableFrom(editorClass);

        ValueEditor ve = null;
        try {
            ve = (ValueEditor) editorClass.newInstance();
        } catch (InstantiationException e) {
            assert false : "unable to instantiate editor class";
        } catch (IllegalAccessException e) {
            assert false : "unable to instantiate editor class - can't access constructor";
        }

        return ve;
    }

    private HashMap<Class,Class> editors = new HashMap<Class, Class>();
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.