Search in sources :

Example 36 with ComponentFactory

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);
        }
    }
}
Also used : KeyConfigurationResult(com.cburch.logisim.tools.key.KeyConfigurationResult) Action(com.cburch.logisim.proj.Action) ToolAttributeAction(com.cburch.logisim.gui.main.ToolAttributeAction) AttributeSet(com.cburch.logisim.data.AttributeSet) KeyConfigurationEvent(com.cburch.logisim.tools.key.KeyConfigurationEvent) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) KeyConfigurator(com.cburch.logisim.tools.key.KeyConfigurator)

Example 37 with ComponentFactory

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;
    }
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory)

Aggregations

ComponentFactory (com.cburch.logisim.comp.ComponentFactory)37 AttributeSet (com.cburch.logisim.data.AttributeSet)16 AddTool (com.cburch.logisim.tools.AddTool)9 Tool (com.cburch.logisim.tools.Tool)9 Circuit (com.cburch.logisim.circuit.Circuit)8 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)8 Component (com.cburch.logisim.comp.Component)8 Library (com.cburch.logisim.tools.Library)8 ArrayList (java.util.ArrayList)6 Wire (com.cburch.logisim.circuit.Wire)4 Location (com.cburch.logisim.data.Location)4 ProjectExplorerToolNode (com.cburch.logisim.gui.generic.ProjectExplorerToolNode)4 HashSet (java.util.HashSet)4 Attribute (com.cburch.logisim.data.Attribute)3 Bounds (com.cburch.logisim.data.Bounds)3 ToolAttributeAction (com.cburch.logisim.gui.main.ToolAttributeAction)3 Action (com.cburch.logisim.proj.Action)3 HashMap (java.util.HashMap)3 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)2 Direction (com.cburch.logisim.data.Direction)2