use of com.cburch.logisim.tools.AddTool in project logisim-evolution by reds-heig.
the class FileStatistics method sortCounts.
private static List<Count> sortCounts(Map<ComponentFactory, Count> counts, LogisimFile file) {
List<Count> ret = new ArrayList<Count>();
for (AddTool tool : file.getTools()) {
ComponentFactory factory = tool.getFactory();
Count count = counts.get(factory);
if (count != null) {
count.library = file;
ret.add(count);
}
}
for (Library lib : file.getLibraries()) {
for (Tool tool : lib.getTools()) {
if (tool instanceof AddTool) {
ComponentFactory factory = ((AddTool) tool).getFactory();
Count count = counts.get(factory);
if (count != null) {
count.library = lib;
ret.add(count);
}
}
}
}
return ret;
}
use of com.cburch.logisim.tools.AddTool in project logisim-evolution by reds-heig.
the class LoadedLibrary method resolveChanges.
private void resolveChanges(Library old) {
if (listeners.isEmpty())
return;
if (!base.getDisplayName().equals(old.getDisplayName())) {
fireLibraryEvent(LibraryEvent.SET_NAME, base.getDisplayName());
}
HashSet<Library> changes = new HashSet<Library>(old.getLibraries());
changes.removeAll(base.getLibraries());
for (Library lib : changes) {
fireLibraryEvent(LibraryEvent.REMOVE_LIBRARY, lib);
}
changes.clear();
changes.addAll(base.getLibraries());
changes.removeAll(old.getLibraries());
for (Library lib : changes) {
fireLibraryEvent(LibraryEvent.ADD_LIBRARY, lib);
}
HashMap<ComponentFactory, ComponentFactory> componentMap;
HashMap<Tool, Tool> toolMap;
componentMap = new HashMap<ComponentFactory, ComponentFactory>();
toolMap = new HashMap<Tool, Tool>();
for (Tool oldTool : old.getTools()) {
Tool newTool = base.getTool(oldTool.getName());
toolMap.put(oldTool, newTool);
if (oldTool instanceof AddTool) {
ComponentFactory oldFactory = ((AddTool) oldTool).getFactory();
if (newTool != null && newTool instanceof AddTool) {
ComponentFactory newFactory = ((AddTool) newTool).getFactory();
componentMap.put(oldFactory, newFactory);
} else {
componentMap.put(oldFactory, null);
}
}
}
replaceAll(componentMap, toolMap);
HashSet<Tool> toolChanges = new HashSet<Tool>(old.getTools());
toolChanges.removeAll(toolMap.keySet());
for (Tool tool : toolChanges) {
fireLibraryEvent(LibraryEvent.REMOVE_TOOL, tool);
}
toolChanges = new HashSet<Tool>(base.getTools());
toolChanges.removeAll(toolMap.values());
for (Tool tool : toolChanges) {
fireLibraryEvent(LibraryEvent.ADD_TOOL, tool);
}
}
use of com.cburch.logisim.tools.AddTool in project logisim-evolution by reds-heig.
the class LogisimFile method removeCircuit.
public void removeCircuit(Circuit circuit) {
if (tools.size() <= 1) {
throw new RuntimeException("Cannot remove last circuit");
}
int index = getCircuits().indexOf(circuit);
if (index >= 0) {
Tool circuitTool = tools.remove(index);
if (main == circuit) {
AddTool dflt_tool = tools.get(0);
SubcircuitFactory factory = (SubcircuitFactory) dflt_tool.getFactory();
setMainCircuit(factory.getSubcircuit());
}
fireEvent(LibraryEvent.REMOVE_TOOL, circuitTool);
}
}
use of com.cburch.logisim.tools.AddTool in project logisim-evolution by reds-heig.
the class MouseMappings method replaceAll.
//
// package-protected methods
//
void replaceAll(Map<Tool, Tool> toolMap) {
boolean changed = false;
for (Map.Entry<Integer, Tool> entry : map.entrySet()) {
Integer key = entry.getKey();
Tool tool = entry.getValue();
if (tool instanceof AddTool) {
ComponentFactory factory = ((AddTool) tool).getFactory();
if (toolMap.containsKey(factory)) {
changed = true;
Tool newTool = toolMap.get(factory);
if (newTool == null) {
map.remove(key);
} else {
Tool clone = newTool.cloneTool();
LoadedLibrary.copyAttributes(clone.getAttributeSet(), tool.getAttributeSet());
map.put(key, clone);
}
}
} else {
if (toolMap.containsKey(tool)) {
changed = true;
Tool newTool = toolMap.get(tool);
if (newTool == null) {
map.remove(key);
} else {
Tool clone = newTool.cloneTool();
LoadedLibrary.copyAttributes(clone.getAttributeSet(), tool.getAttributeSet());
map.put(key, clone);
}
}
}
}
if (changed)
fireMouseMappingsChanged();
}
use of com.cburch.logisim.tools.AddTool 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));
}
}
}
Aggregations