Search in sources :

Example 26 with Tool

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

the class ToolbarData method move.

public Object move(int from, int to) {
    Tool moved = contents.remove(from);
    contents.add(to, moved);
    fireToolbarChanged();
    return moved;
}
Also used : Tool(com.cburch.logisim.tools.Tool)

Example 27 with Tool

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

the class ToolbarData method copyFrom.

// 
// modification methods
// 
public void copyFrom(ToolbarData other, LogisimFile file) {
    if (this == other)
        return;
    for (Tool tool : contents) {
        if (tool != null) {
            removeAttributeListeners(tool);
        }
    }
    this.contents.clear();
    for (Tool srcTool : other.contents) {
        if (srcTool == null) {
            this.addSeparator();
        } else {
            Tool toolCopy = file.findTool(srcTool);
            if (toolCopy != null) {
                Tool dstTool = toolCopy.cloneTool();
                AttributeSets.copy(srcTool.getAttributeSet(), dstTool.getAttributeSet());
                this.addTool(dstTool);
                addAttributeListeners(toolCopy);
            }
        }
    }
    fireToolbarChanged();
}
Also used : Tool(com.cburch.logisim.tools.Tool)

Example 28 with Tool

use of com.cburch.logisim.tools.Tool 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

Tool (com.cburch.logisim.tools.Tool)28 AddTool (com.cburch.logisim.tools.AddTool)16 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)9 Library (com.cburch.logisim.tools.Library)7 Circuit (com.cburch.logisim.circuit.Circuit)6 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)6 ProjectExplorerToolNode (com.cburch.logisim.gui.generic.ProjectExplorerToolNode)4 SelectTool (com.cburch.logisim.tools.SelectTool)4 Component (com.cburch.logisim.comp.Component)3 ArrayList (java.util.ArrayList)3 Element (org.w3c.dom.Element)3 AttributeSet (com.cburch.logisim.data.AttributeSet)2 ProjectExplorerLibraryNode (com.cburch.logisim.gui.generic.ProjectExplorerLibraryNode)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 ToolbarItem (com.cburch.draw.toolbar.ToolbarItem)1 ToolbarSeparator (com.cburch.draw.toolbar.ToolbarSeparator)1 CircuitState (com.cburch.logisim.circuit.CircuitState)1 ComponentDrawContext (com.cburch.logisim.comp.ComponentDrawContext)1