Search in sources :

Example 1 with Library

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);
        }
    }
}
Also used : Library(com.cburch.logisim.tools.Library) Base(com.cburch.logisim.std.base.Base) Tool(com.cburch.logisim.tools.Tool)

Example 2 with Library

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;
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) ArrayList(java.util.ArrayList) Wire(com.cburch.logisim.circuit.Wire) LogisimFile(com.cburch.logisim.file.LogisimFile) AttributeSet(com.cburch.logisim.data.AttributeSet) Library(com.cburch.logisim.tools.Library) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 3 with Library

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;
}
Also used : Element(org.w3c.dom.Element) Circuit(com.cburch.logisim.circuit.Circuit) Library(com.cburch.logisim.tools.Library)

Example 4 with Library

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

Example 5 with Library

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

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