use of com.cburch.logisim.tools.Library in project logisim-evolution by reds-heig.
the class LayoutEditHandler method selectSelectTool.
private void selectSelectTool(Project proj) {
for (Library sub : proj.getLogisimFile().getLibraries()) {
if (sub instanceof Base) {
Base base = (Base) sub;
Tool tool = base.getTool("Edit Tool");
if (tool != null)
proj.setTool(tool);
}
}
}
use of com.cburch.logisim.tools.Library in project logisim-evolution by reds-heig.
the class SelectionActions method getReplacementMap.
private static HashMap<Component, Component> getReplacementMap(Project proj) {
HashMap<Component, Component> replMap;
replMap = new HashMap<Component, Component>();
LogisimFile file = proj.getLogisimFile();
ArrayList<Library> libs = new ArrayList<Library>();
libs.add(file);
libs.addAll(file.getLibraries());
ArrayList<String> dropped = null;
Clipboard clip = Clipboard.get();
Collection<Component> comps = clip.getComponents();
HashMap<ComponentFactory, ComponentFactory> factoryReplacements;
factoryReplacements = new HashMap<ComponentFactory, ComponentFactory>();
for (Component comp : comps) {
if (comp instanceof Wire)
continue;
ComponentFactory compFactory = comp.getFactory();
ComponentFactory copyFactory = findComponentFactory(compFactory, libs, false);
if (factoryReplacements.containsKey(compFactory)) {
copyFactory = factoryReplacements.get(compFactory);
} else if (copyFactory == null) {
ComponentFactory candidate = findComponentFactory(compFactory, libs, true);
if (candidate == null) {
if (dropped == null) {
dropped = new ArrayList<String>();
}
dropped.add(compFactory.getDisplayName());
} else {
String msg = Strings.get("pasteCloneQuery", compFactory.getName());
Object[] opts = { Strings.get("pasteCloneReplace"), Strings.get("pasteCloneIgnore"), Strings.get("pasteCloneCancel") };
int select = JOptionPane.showOptionDialog(proj.getFrame(), msg, Strings.get("pasteCloneTitle"), 0, JOptionPane.QUESTION_MESSAGE, null, opts, opts[0]);
if (select == 0) {
copyFactory = candidate;
} else if (select == 1) {
copyFactory = null;
} else {
return null;
}
factoryReplacements.put(compFactory, copyFactory);
}
}
if (copyFactory == null) {
replMap.put(comp, null);
} else if (copyFactory != compFactory) {
Location copyLoc = comp.getLocation();
AttributeSet copyAttrs = (AttributeSet) comp.getAttributeSet().clone();
Component copy = copyFactory.createComponent(copyLoc, copyAttrs);
replMap.put(comp, copy);
}
}
if (dropped != null) {
Collections.sort(dropped);
StringBuilder droppedStr = new StringBuilder();
droppedStr.append(Strings.get("pasteDropMessage"));
String curName = dropped.get(0);
int curCount = 1;
int lines = 1;
for (int i = 1; i <= dropped.size(); i++) {
String nextName = i == dropped.size() ? "" : dropped.get(i);
if (nextName.equals(curName)) {
curCount++;
} else {
lines++;
droppedStr.append("\n ");
droppedStr.append(curName);
if (curCount > 1) {
droppedStr.append(" \u00d7 " + curCount);
}
curName = nextName;
curCount = 1;
}
}
lines = Math.max(3, Math.min(7, lines));
JTextArea area = new JTextArea(lines, 60);
area.setEditable(false);
area.setText(droppedStr.toString());
area.setCaretPosition(0);
JScrollPane areaPane = new JScrollPane(area);
JOptionPane.showMessageDialog(proj.getFrame(), areaPane, Strings.get("pasteDropTitle"), JOptionPane.WARNING_MESSAGE);
}
return replMap;
}
use of com.cburch.logisim.tools.Library in project logisim-evolution by reds-heig.
the class XmlWriter method fromLogisimFile.
Element fromLogisimFile() {
Element ret = doc.createElement("project");
doc.appendChild(ret);
ret.appendChild(doc.createTextNode("\nThis file is intended to be " + "loaded by Logisim-evolution (https://github.com/reds-heig/logisim-evolution).\n"));
ret.setAttribute("version", "1.0");
ret.setAttribute("source", Main.VERSION_NAME);
for (Library lib : file.getLibraries()) {
Element elt = fromLibrary(lib);
if (elt != null)
ret.appendChild(elt);
}
if (file.getMainCircuit() != null) {
Element mainElt = doc.createElement("main");
mainElt.setAttribute("name", file.getMainCircuit().getName());
ret.appendChild(mainElt);
}
ret.appendChild(fromOptions());
ret.appendChild(fromMouseMappings());
ret.appendChild(fromToolbarData());
for (Circuit circ : file.getCircuits()) {
ret.appendChild(fromCircuit(circ));
}
return ret;
}
use of com.cburch.logisim.tools.Library in project logisim-evolution by reds-heig.
the class ProjectExplorerLibraryNode method buildChildren.
private void buildChildren() {
Library lib = getValue();
if (lib != null) {
buildChildren(new ProjectExplorerToolNode(getModel(), null), lib.getTools(), 0);
buildChildren(new ProjectExplorerLibraryNode(getModel(), null), lib.getLibraries(), lib.getTools().size());
}
}
use of com.cburch.logisim.tools.Library in project logisim-evolution by reds-heig.
the class LibraryManager method findReference.
public Library findReference(LogisimFile file, File query) {
for (Library lib : file.getLibraries()) {
LibraryDescriptor desc = invMap.get(lib);
if (desc != null && desc.concernsFile(query)) {
return lib;
}
if (lib instanceof LoadedLibrary) {
LoadedLibrary loadedLib = (LoadedLibrary) lib;
if (loadedLib.getBase() instanceof LogisimFile) {
LogisimFile loadedProj = (LogisimFile) loadedLib.getBase();
Library ret = findReference(loadedProj, query);
if (ret != null)
return lib;
}
}
}
return null;
}
Aggregations