forked from LupusNobilis/java-org.hwo
63 lines
1.4 KiB
Java
63 lines
1.4 KiB
Java
package org.hwo.interactiveobjects;
|
|
|
|
import java.util.Hashtable;
|
|
|
|
public class InteractiveObjectHelper {
|
|
|
|
|
|
private static Hashtable<Object, IInteractiveObjectEditor> p_editors = new Hashtable<Object, IInteractiveObjectEditor>();
|
|
|
|
private static InteractiveObject getInteractiveObject(Class<?> clazz)
|
|
{
|
|
InteractiveObject io = clazz.getAnnotation(InteractiveObject.class);
|
|
if (io != null)
|
|
return io;
|
|
if (clazz.getSuperclass() != null)
|
|
return getInteractiveObject(clazz.getSuperclass());
|
|
return null;
|
|
}
|
|
|
|
private static InteractiveObject getInteractiveObject(Object item)
|
|
{
|
|
Class<?> clazz = item.getClass();
|
|
return getInteractiveObject(clazz);
|
|
}
|
|
|
|
public static boolean isInteractiveObject(Class<?> clazz)
|
|
{
|
|
return (getInteractiveObject(clazz)!=null);
|
|
}
|
|
|
|
public static IInteractiveObjectEditor getEditor(Object item)
|
|
{
|
|
InteractiveObject io = getInteractiveObject(item);
|
|
|
|
if (io != null)
|
|
{
|
|
if (!p_editors.containsKey(item))
|
|
{
|
|
try
|
|
{
|
|
IInteractiveObjectEditor editor = io.editor().newInstance();
|
|
p_editors.put(item, editor);
|
|
} catch (Exception ex)
|
|
{
|
|
System.err.println(ex.toString());
|
|
ex.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
return p_editors.get(item);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static void showEditor(Object o)
|
|
{
|
|
IInteractiveObjectEditor editor = getEditor(o);
|
|
editor.setInteractiveObject(o);
|
|
editor.setVisible(true);
|
|
}
|
|
|
|
}
|