Search in sources :

Example 21 with Library

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

the class LogisimFile method removeLibrary.

public boolean removeLibrary(String Name) {
    int index = -1;
    for (Library lib : libraries) if (lib.getName().equals(Name))
        index = libraries.indexOf(lib);
    if (index < 0)
        return false;
    libraries.remove(index);
    return true;
}
Also used : Library(com.cburch.logisim.tools.Library)

Example 22 with Library

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

the class ProjectActions method doOpen.

public static Project doOpen(Component parent, Project baseProject, File f) {
    Project proj = Projects.findProjectFor(f);
    Loader loader = null;
    if (proj != null) {
        proj.getFrame().toFront();
        loader = proj.getLogisimFile().getLoader();
        if (proj.isFileDirty()) {
            String message = StringUtil.format(Strings.get("openAlreadyMessage"), proj.getLogisimFile().getName());
            String[] options = { Strings.get("openAlreadyLoseChangesOption"), Strings.get("openAlreadyNewWindowOption"), Strings.get("openAlreadyCancelOption") };
            int result = JOptionPane.showOptionDialog(proj.getFrame(), message, Strings.get("openAlreadyTitle"), 0, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
            if (result == 0) {
                // keep proj as is, so that load happens into the window
                ;
            } else if (result == 1) {
                // we'll create a new project
                proj = null;
            } else {
                return proj;
            }
        }
    }
    if (proj == null && baseProject != null && baseProject.isStartupScreen()) {
        proj = baseProject;
        proj.setStartupScreen(false);
        loader = baseProject.getLogisimFile().getLoader();
    } else {
        loader = new Loader(baseProject == null ? parent : baseProject.getFrame());
    }
    try {
        LogisimFile lib = loader.openLogisimFile(f);
        AppPreferences.updateRecentFile(f);
        if (lib == null)
            return null;
        LibraryTools.RemovePresentLibraries(lib, new HashMap<String, Library>(), true);
        if (proj == null) {
            proj = new Project(lib);
            updatecircs(lib, proj);
        } else {
            updatecircs(lib, proj);
            proj.setLogisimFile(lib);
        }
    } catch (LoadFailedException ex) {
        if (!ex.isShown()) {
            JOptionPane.showMessageDialog(parent, StringUtil.format(Strings.get("fileOpenError"), ex.toString()), Strings.get("fileOpenErrorTitle"), JOptionPane.ERROR_MESSAGE);
        }
        return null;
    }
    Frame frame = proj.getFrame();
    if (frame == null) {
        frame = createFrame(baseProject, proj);
    }
    frame.setVisible(true);
    frame.toFront();
    frame.getCanvas().requestFocus();
    proj.getLogisimFile().getLoader().setParent(frame);
    return proj;
}
Also used : LogisimFile(com.cburch.logisim.file.LogisimFile) Frame(com.cburch.logisim.gui.main.Frame) Loader(com.cburch.logisim.file.Loader) LoadedLibrary(com.cburch.logisim.file.LoadedLibrary) Library(com.cburch.logisim.tools.Library) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Example 23 with Library

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

the class LayoutEditHandler method computeEnabled.

@Override
public void computeEnabled() {
    Project proj = frame.getProject();
    Selection sel = proj == null ? null : proj.getSelection();
    boolean selEmpty = (sel == null ? true : sel.isEmpty());
    boolean canChange = proj != null && proj.getLogisimFile().contains(proj.getCurrentCircuit());
    boolean selectAvailable = false;
    for (Library lib : proj.getLogisimFile().getLibraries()) {
        if (lib instanceof Base)
            selectAvailable = true;
    }
    setEnabled(LogisimMenuBar.CUT, !selEmpty && selectAvailable && canChange);
    setEnabled(LogisimMenuBar.COPY, !selEmpty && selectAvailable);
    setEnabled(LogisimMenuBar.PASTE, selectAvailable && canChange && !Clipboard.isEmpty());
    setEnabled(LogisimMenuBar.DELETE, !selEmpty && selectAvailable && canChange);
    setEnabled(LogisimMenuBar.DUPLICATE, !selEmpty && selectAvailable && canChange);
    setEnabled(LogisimMenuBar.SELECT_ALL, selectAvailable);
    setEnabled(LogisimMenuBar.RAISE, false);
    setEnabled(LogisimMenuBar.LOWER, false);
    setEnabled(LogisimMenuBar.RAISE_TOP, false);
    setEnabled(LogisimMenuBar.LOWER_BOTTOM, false);
    setEnabled(LogisimMenuBar.ADD_CONTROL, false);
    setEnabled(LogisimMenuBar.REMOVE_CONTROL, false);
}
Also used : Project(com.cburch.logisim.proj.Project) Library(com.cburch.logisim.tools.Library) Base(com.cburch.logisim.std.base.Base)

Example 24 with Library

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

the class XmlWriter method fromTool.

Element fromTool(Tool tool) {
    Library lib = findLibrary(tool);
    String lib_name;
    if (lib == null) {
        loader.showError(StringUtil.format("tool `%s' not found", tool.getDisplayName()));
        return null;
    } else if (lib == file) {
        lib_name = null;
    } else {
        lib_name = libs.get(lib);
        if (lib_name == null) {
            loader.showError("unknown library within file");
            return null;
        }
    }
    Element elt = doc.createElement("tool");
    if (lib_name != null)
        elt.setAttribute("lib", lib_name);
    elt.setAttribute("name", tool.getName());
    addAttributeSetContent(elt, tool.getAttributeSet(), tool);
    return elt;
}
Also used : Element(org.w3c.dom.Element) Library(com.cburch.logisim.tools.Library)

Example 25 with Library

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

the class XmlWriter method fromComponent.

Element fromComponent(Component comp) {
    ComponentFactory source = comp.getFactory();
    Library lib = findLibrary(source);
    String lib_name;
    if (lib == null) {
        loader.showError(source.getName() + " component not found");
        return null;
    } else if (lib == file) {
        lib_name = null;
    } else {
        lib_name = libs.get(lib);
        if (lib_name == null) {
            loader.showError("unknown library within file");
            return null;
        }
    }
    Element ret = doc.createElement("comp");
    if (lib_name != null)
        ret.setAttribute("lib", lib_name);
    ret.setAttribute("name", source.getName());
    ret.setAttribute("loc", comp.getLocation().toString());
    addAttributeSetContent(ret, comp.getAttributeSet(), comp.getFactory());
    return ret;
}
Also used : ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Element(org.w3c.dom.Element) 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