Search in sources :

Example 6 with Loader

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

the class Startup method run.

public void run() {
    if (isTty) {
        try {
            TtyInterface.run(this);
            return;
        } catch (Exception t) {
            t.printStackTrace();
            System.exit(-1);
            return;
        }
    }
    // I loaded a large file.)
    if (showSplash) {
        try {
            monitor = new SplashScreen();
            monitor.setVisible(true);
        } catch (Exception t) {
            monitor = null;
            showSplash = false;
        }
    }
    Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.COMPONENT_EVENT_MASK | AWTEvent.CONTAINER_EVENT_MASK);
    // taken is shown separately in the progress bar.
    if (showSplash) {
        monitor.setProgress(SplashScreen.LIBRARIES);
    }
    Loader templLoader = new Loader(monitor);
    int count = templLoader.getBuiltin().getLibrary("Base").getTools().size() + templLoader.getBuiltin().getLibrary("Gates").getTools().size();
    if (count < 0) {
        // this will never happen, but the optimizer doesn't know that...
        // OK
        logger.error("FATAL ERROR - no components");
        System.exit(-1);
    }
    // load in template
    loadTemplate(templLoader, templFile, templEmpty);
    // interface initialization
    if (showSplash) {
        monitor.setProgress(SplashScreen.GUI_INIT);
    }
    WindowManagers.initialize();
    if (MacCompatibility.isSwingUsingScreenMenuBar()) {
        MacCompatibility.setFramelessJMenuBar(new LogisimMenuBar(null, null));
    } else {
        new LogisimMenuBar(null, null);
    // most of the time occupied here will be in loading menus, which
    // will occur eventually anyway; we might as well do it when the
    // monitor says we are
    }
    // if user has double-clicked a file to open, we'll
    // use that as the file to open now.
    initialized = true;
    // load file
    if (filesToOpen.isEmpty()) {
        Project proj = ProjectActions.doNew(monitor);
        proj.setStartupScreen(true);
        if (showSplash) {
            monitor.close();
        }
    } else {
        int numOpened = 0;
        boolean first = true;
        for (File fileToOpen : filesToOpen) {
            try {
                if (testVector != null) {
                    Project proj = ProjectActions.doOpenNoWindow(monitor, fileToOpen);
                    proj.doTestVector(testVector, circuitToTest);
                } else {
                    ProjectActions.doOpen(monitor, fileToOpen, substitutions);
                }
                numOpened++;
            } catch (LoadFailedException ex) {
                logger.error("{} : {}", fileToOpen.getName(), ex.getMessage());
            }
            if (first) {
                first = false;
                if (showSplash) {
                    monitor.close();
                }
                monitor = null;
            }
        }
        if (numOpened == 0)
            System.exit(-1);
    }
    for (File fileToPrint : filesToPrint) {
        doPrintFile(fileToPrint);
    }
    if (exitAfterStartup) {
        System.exit(0);
    }
}
Also used : Project(com.cburch.logisim.proj.Project) Loader(com.cburch.logisim.file.Loader) LogisimMenuBar(com.cburch.logisim.gui.menu.LogisimMenuBar) File(java.io.File) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) LoadFailedException(com.cburch.logisim.file.LoadFailedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Print(com.cburch.logisim.gui.main.Print) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Example 7 with Loader

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

the class ProjectLibraryActions method doLoadJarLibrary.

public static void doLoadJarLibrary(Project proj) {
    Loader loader = proj.getLogisimFile().getLoader();
    JFileChooser chooser = loader.createChooser();
    chooser.setDialogTitle(Strings.get("loadJarDialogTitle"));
    chooser.setFileFilter(Loader.JAR_FILTER);
    int check = chooser.showOpenDialog(proj.getFrame());
    if (check == JFileChooser.APPROVE_OPTION) {
        File f = chooser.getSelectedFile();
        String className = null;
        // try to retrieve the class name from the "Library-Class"
        // attribute in the manifest. This section of code was contributed
        // by Christophe Jacquet (Request Tracker #2024431).
        JarFile jarFile = null;
        try {
            jarFile = new JarFile(f);
            Manifest manifest = jarFile.getManifest();
            className = manifest.getMainAttributes().getValue("Library-Class");
        } catch (IOException e) {
        // if opening the JAR file failed, do nothing
        } finally {
            if (jarFile != null) {
                try {
                    jarFile.close();
                } catch (IOException e) {
                }
            }
        }
        // if the class name was not found, go back to the good old dialog
        if (className == null) {
            className = JOptionPane.showInputDialog(proj.getFrame(), Strings.get("jarClassNamePrompt"), Strings.get("jarClassNameTitle"), JOptionPane.QUESTION_MESSAGE);
            // if user canceled selection, abort
            if (className == null)
                return;
        }
        Library lib = loader.loadJarLibrary(f, className);
        if (lib != null) {
            proj.doAction(LogisimFileActions.loadLibrary(lib, proj.getLogisimFile()));
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) Loader(com.cburch.logisim.file.Loader) IOException(java.io.IOException) Library(com.cburch.logisim.tools.Library) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) LogisimFile(com.cburch.logisim.file.LogisimFile) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 8 with Loader

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

the class ProjectLibraryActions method doLoadLogisimLibrary.

public static void doLoadLogisimLibrary(Project proj) {
    Loader loader = proj.getLogisimFile().getLoader();
    JFileChooser chooser = loader.createChooser();
    chooser.setDialogTitle(Strings.get("loadLogisimDialogTitle"));
    chooser.setFileFilter(Loader.LOGISIM_FILTER);
    int check = chooser.showOpenDialog(proj.getFrame());
    if (check == JFileChooser.APPROVE_OPTION) {
        File f = chooser.getSelectedFile();
        Library lib = loader.loadLogisimLibrary(f);
        if (lib != null) {
            proj.doAction(LogisimFileActions.loadLibrary(lib, proj.getLogisimFile()));
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) Loader(com.cburch.logisim.file.Loader) Library(com.cburch.logisim.tools.Library) LogisimFile(com.cburch.logisim.file.LogisimFile) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 9 with Loader

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

the class TtyInterface method run.

public static void run(Startup args) {
    File fileToOpen = args.getFilesToOpen().get(0);
    Loader loader = new Loader(null);
    LogisimFile file;
    try {
        file = loader.openLogisimFile(fileToOpen, args.getSubstitutions());
    } catch (LoadFailedException e) {
        logger.error("{}", Strings.get("ttyLoadError", fileToOpen.getName()));
        System.exit(-1);
        return;
    }
    int format = args.getTtyFormat();
    if ((format & FORMAT_STATISTICS) != 0) {
        format &= ~FORMAT_STATISTICS;
        displayStatistics(file);
    }
    if (format == 0) {
        // no simulation remaining to perform, so just exit
        System.exit(0);
    }
    Project proj = new Project(file);
    Circuit circuit = file.getMainCircuit();
    Map<Instance, String> pinNames = Analyze.getPinLabels(circuit);
    ArrayList<Instance> outputPins = new ArrayList<Instance>();
    Instance haltPin = null;
    for (Map.Entry<Instance, String> entry : pinNames.entrySet()) {
        Instance pin = entry.getKey();
        String pinName = entry.getValue();
        if (!Pin.FACTORY.isInputPin(pin)) {
            outputPins.add(pin);
            if (pinName.equals("halt")) {
                haltPin = pin;
            }
        }
    }
    CircuitState circState = new CircuitState(proj, circuit);
    // we have to do our initial propagation before the simulation starts -
    // it's necessary to populate the circuit with substates.
    circState.getPropagator().propagate();
    if (args.getLoadFile() != null) {
        try {
            boolean loaded = loadRam(circState, args.getLoadFile());
            if (!loaded) {
                logger.error("{}", Strings.get("loadNoRamError"));
                System.exit(-1);
            }
        } catch (IOException e) {
            logger.error("{}: {}", Strings.get("loadIoError"), e.toString());
            System.exit(-1);
        }
    }
    int ttyFormat = args.getTtyFormat();
    int simCode = runSimulation(circState, outputPins, haltPin, ttyFormat);
    System.exit(simCode);
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) Instance(com.cburch.logisim.instance.Instance) ArrayList(java.util.ArrayList) Loader(com.cburch.logisim.file.Loader) Circuit(com.cburch.logisim.circuit.Circuit) IOException(java.io.IOException) Project(com.cburch.logisim.proj.Project) LogisimFile(com.cburch.logisim.file.LogisimFile) LogisimFile(com.cburch.logisim.file.LogisimFile) File(java.io.File) Map(java.util.Map) LoadFailedException(com.cburch.logisim.file.LoadFailedException)

Example 10 with Loader

use of com.cburch.logisim.file.Loader 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)

Aggregations

Loader (com.cburch.logisim.file.Loader)16 LogisimFile (com.cburch.logisim.file.LogisimFile)12 File (java.io.File)10 LoadFailedException (com.cburch.logisim.file.LoadFailedException)6 JFileChooser (javax.swing.JFileChooser)6 IOException (java.io.IOException)5 Library (com.cburch.logisim.tools.Library)3 Circuit (com.cburch.logisim.circuit.Circuit)2 Project (com.cburch.logisim.proj.Project)2 InputStream (java.io.InputStream)2 JarFile (java.util.jar.JarFile)2 CircuitState (com.cburch.logisim.circuit.CircuitState)1 LoadedLibrary (com.cburch.logisim.file.LoadedLibrary)1 Frame (com.cburch.logisim.gui.main.Frame)1 Print (com.cburch.logisim.gui.main.Print)1 LogisimMenuBar (com.cburch.logisim.gui.menu.LogisimMenuBar)1 Instance (com.cburch.logisim.instance.Instance)1 Tool (com.cburch.logisim.tools.Tool)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1