Search in sources :

Example 11 with LogisimFile

use of com.cburch.logisim.file.LogisimFile in project logisim-evolution by reds-heig.

the class ProjectLibraryActions method doLoadBuiltinLibrary.

public static void doLoadBuiltinLibrary(Project proj) {
    LogisimFile file = proj.getLogisimFile();
    List<Library> baseBuilt = file.getLoader().getBuiltin().getLibraries();
    ArrayList<Library> builtins = new ArrayList<Library>(baseBuilt);
    builtins.removeAll(file.getLibraries());
    if (builtins.isEmpty()) {
        JOptionPane.showMessageDialog(proj.getFrame(), Strings.get("loadBuiltinNoneError"), Strings.get("loadBuiltinErrorTitle"), JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    LibraryJList list = new LibraryJList(builtins);
    JScrollPane listPane = new JScrollPane(list);
    int action = JOptionPane.showConfirmDialog(proj.getFrame(), listPane, Strings.get("loadBuiltinDialogTitle"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (action == JOptionPane.OK_OPTION) {
        Library[] libs = list.getSelectedLibraries();
        if (libs != null)
            proj.doAction(LogisimFileActions.loadLibraries(libs, proj.getLogisimFile()));
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) LogisimFile(com.cburch.logisim.file.LogisimFile) ArrayList(java.util.ArrayList) Library(com.cburch.logisim.tools.Library)

Example 12 with LogisimFile

use of com.cburch.logisim.file.LogisimFile in project logisim-evolution by reds-heig.

the class ProjectLibraryActions method doUnloadLibraries.

public static void doUnloadLibraries(Project proj) {
    LogisimFile file = proj.getLogisimFile();
    ArrayList<Library> canUnload = new ArrayList<Library>();
    for (Library lib : file.getLibraries()) {
        String message = file.getUnloadLibraryMessage(lib);
        if (message == null)
            canUnload.add(lib);
    }
    if (canUnload.isEmpty()) {
        JOptionPane.showMessageDialog(proj.getFrame(), Strings.get("unloadNoneError"), Strings.get("unloadErrorTitle"), JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    LibraryJList list = new LibraryJList(canUnload);
    JScrollPane listPane = new JScrollPane(list);
    int action = JOptionPane.showConfirmDialog(proj.getFrame(), listPane, Strings.get("unloadLibrariesDialogTitle"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (action == JOptionPane.OK_OPTION) {
        Library[] libs = list.getSelectedLibraries();
        if (libs != null)
            proj.doAction(LogisimFileActions.unloadLibraries(libs));
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) LogisimFile(com.cburch.logisim.file.LogisimFile) ArrayList(java.util.ArrayList) Library(com.cburch.logisim.tools.Library)

Example 13 with LogisimFile

use of com.cburch.logisim.file.LogisimFile 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 14 with LogisimFile

use of com.cburch.logisim.file.LogisimFile in project logisim-evolution by reds-heig.

the class ProjectActions method doOpen.

public static Project doOpen(SplashScreen monitor, File source, Map<File, File> substitutions) throws LoadFailedException {
    if (monitor != null)
        monitor.setProgress(SplashScreen.FILE_LOAD);
    Loader loader = new Loader(monitor);
    LogisimFile file = loader.openLogisimFile(source, substitutions);
    AppPreferences.updateRecentFile(source);
    return completeProject(monitor, loader, file, false);
}
Also used : LogisimFile(com.cburch.logisim.file.LogisimFile) Loader(com.cburch.logisim.file.Loader)

Example 15 with LogisimFile

use of com.cburch.logisim.file.LogisimFile in project logisim-evolution by reds-heig.

the class ProjectActions method createEmptyFile.

private static LogisimFile createEmptyFile(Loader loader, Project proj) {
    InputStream templReader = AppPreferences.getEmptyTemplate().createStream();
    LogisimFile file;
    try {
        file = loader.openLogisimFile(templReader);
    } catch (Exception t) {
        file = LogisimFile.createNew(loader, proj);
        file.addCircuit(new Circuit("main", file, proj));
    } finally {
        try {
            templReader.close();
        } catch (IOException e) {
        }
    }
    return file;
}
Also used : LogisimFile(com.cburch.logisim.file.LogisimFile) InputStream(java.io.InputStream) Circuit(com.cburch.logisim.circuit.Circuit) IOException(java.io.IOException) IOException(java.io.IOException) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Aggregations

LogisimFile (com.cburch.logisim.file.LogisimFile)18 Loader (com.cburch.logisim.file.Loader)7 Circuit (com.cburch.logisim.circuit.Circuit)6 LoadFailedException (com.cburch.logisim.file.LoadFailedException)6 ArrayList (java.util.ArrayList)6 Library (com.cburch.logisim.tools.Library)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)3 JScrollPane (javax.swing.JScrollPane)3 CircuitState (com.cburch.logisim.circuit.CircuitState)2 Component (com.cburch.logisim.comp.Component)2 LoadedLibrary (com.cburch.logisim.file.LoadedLibrary)2 Frame (com.cburch.logisim.gui.main.Frame)2 File (java.io.File)2 Netlist (com.bfh.logisim.designrulecheck.Netlist)1 AbstractHDLGeneratorFactory (com.bfh.logisim.hdlgenerator.AbstractHDLGeneratorFactory)1 HDLGeneratorFactory (com.bfh.logisim.hdlgenerator.HDLGeneratorFactory)1 TickComponentHDLGeneratorFactory (com.bfh.logisim.hdlgenerator.TickComponentHDLGeneratorFactory)1 ToplevelHDLGeneratorFactory (com.bfh.logisim.hdlgenerator.ToplevelHDLGeneratorFactory)1 Wire (com.cburch.logisim.circuit.Wire)1