use of com.cburch.logisim.comp.ComponentFactory in project logisim-evolution by reds-heig.
the class AddTool method processKeyEvent.
private void processKeyEvent(Canvas canvas, KeyEvent event, int type) {
KeyConfigurator handler = keyHandler;
if (!keyHandlerTried) {
ComponentFactory source = getFactory();
AttributeSet baseAttrs = getBaseAttributes();
handler = (KeyConfigurator) source.getFeature(KeyConfigurator.class, baseAttrs);
keyHandler = handler;
keyHandlerTried = true;
}
if (handler != null) {
AttributeSet baseAttrs = getBaseAttributes();
KeyConfigurationEvent e = new KeyConfigurationEvent(type, baseAttrs, event, this);
KeyConfigurationResult r = handler.keyEventReceived(e);
if (r != null) {
Action act = ToolAttributeAction.create(r);
canvas.getProject().doAction(act);
}
}
}
use of com.cburch.logisim.comp.ComponentFactory in project logisim-evolution by reds-heig.
the class FactoryDescription method getFactory.
public ComponentFactory getFactory(Class<? extends Library> libraryClass) {
ComponentFactory ret = factory;
if (factory != null || factoryLoadAttempted) {
return ret;
} else {
String msg = "";
try {
msg = "getting class loader";
ClassLoader loader = libraryClass.getClassLoader();
msg = "getting package name";
String name;
Package pack = libraryClass.getPackage();
if (pack == null) {
name = factoryClassName;
} else {
name = pack.getName() + "." + factoryClassName;
}
msg = "loading class";
Class<?> factoryClass = loader.loadClass(name);
msg = "creating instance";
Object factoryValue = factoryClass.newInstance();
msg = "converting to factory";
if (factoryValue instanceof ComponentFactory) {
ret = (ComponentFactory) factoryValue;
factory = ret;
factoryLoadAttempted = true;
return ret;
}
} catch (Exception t) {
String name = t.getClass().getName();
String m = t.getMessage();
if (m != null)
msg = msg + ": " + name + ": " + m;
else
msg = msg + ": " + name;
}
logger.error("Error while {}", msg);
factory = null;
factoryLoadAttempted = true;
return null;
}
}
Aggregations