Search in sources :

Example 26 with Library

use of com.cburch.logisim.tools.Library in project logisim-evolution by reds-heig.

the class XmlCircuitReader method getComponent.

/**
 * Get a circuit's component from a read XML file. If the component has a
 * non-null "trackercomp" field, it means that it is tracked, therefore it
 * is skipped in the non-tracked version to avoid errors.
 *
 * @param elt
 *            XML element to parse
 * @param reader
 *            XML file reader
 * @return the component built from its XML description
 * @throws XmlReaderException
 */
static Component getComponent(Element elt, XmlReader.ReadContext reader) throws XmlReaderException {
    if (elt.getAttribute("trackercomp") != "" && !Main.VERSION.hasTracker()) {
        return (null);
    }
    // Determine the factory that creates this element
    String name = elt.getAttribute("name");
    if (name == null || name.equals("")) {
        throw new XmlReaderException(Strings.get("compNameMissingError"));
    }
    String libName = elt.getAttribute("lib");
    Library lib = reader.findLibrary(libName);
    if (lib == null) {
        throw new XmlReaderException(Strings.get("compUnknownError", "no-lib"));
    }
    Tool tool = lib.getTool(name);
    if (tool == null || !(tool instanceof AddTool)) {
        if (libName == null || libName.equals("")) {
            throw new XmlReaderException(Strings.get("compUnknownError", name));
        } else {
            throw new XmlReaderException(Strings.get("compAbsentError", name, libName));
        }
    }
    ComponentFactory source = ((AddTool) tool).getFactory();
    // Determine attributes
    String loc_str = elt.getAttribute("loc");
    AttributeSet attrs = source.createAttributeSet();
    reader.initAttributeSet(elt, attrs, source);
    // Create component if location known
    if (loc_str == null || loc_str.equals("")) {
        throw new XmlReaderException(Strings.get("compLocMissingError", source.getName()));
    } else {
        try {
            Location loc = Location.parse(loc_str);
            return source.createComponent(loc, attrs);
        } catch (NumberFormatException e) {
            throw new XmlReaderException(Strings.get("compLocInvalidError", source.getName(), loc_str));
        }
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Library(com.cburch.logisim.tools.Library) AddTool(com.cburch.logisim.tools.AddTool) Tool(com.cburch.logisim.tools.Tool) AddTool(com.cburch.logisim.tools.AddTool) Location(com.cburch.logisim.data.Location)

Aggregations

Library (com.cburch.logisim.tools.Library)26 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)8 Tool (com.cburch.logisim.tools.Tool)7 LogisimFile (com.cburch.logisim.file.LogisimFile)6 AddTool (com.cburch.logisim.tools.AddTool)6 File (java.io.File)5 ArrayList (java.util.ArrayList)4 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)3 Loader (com.cburch.logisim.file.Loader)3 ProjectExplorerToolNode (com.cburch.logisim.gui.generic.ProjectExplorerToolNode)3 IOException (java.io.IOException)3 JScrollPane (javax.swing.JScrollPane)3 Element (org.w3c.dom.Element)3 Circuit (com.cburch.logisim.circuit.Circuit)2 AttributeSet (com.cburch.logisim.data.AttributeSet)2 Location (com.cburch.logisim.data.Location)2 LoadedLibrary (com.cburch.logisim.file.LoadedLibrary)2 ProjectExplorerLibraryNode (com.cburch.logisim.gui.generic.ProjectExplorerLibraryNode)2 Base (com.cburch.logisim.std.base.Base)2 HashSet (java.util.HashSet)2