Search in sources :

Example 1 with Frame

use of com.cburch.logisim.gui.main.Frame in project logisim-evolution by reds-heig.

the class Project method setFrame.

public void setFrame(Frame value) {
    if (frame == value)
        return;
    Frame oldValue = frame;
    frame = value;
    Projects.windowCreated(this, oldValue, value);
    value.getCanvas().getSelection().addListener(myListener);
}
Also used : LogFrame(com.cburch.logisim.gui.log.LogFrame) TestFrame(com.cburch.logisim.gui.test.TestFrame) Frame(com.cburch.logisim.gui.main.Frame) OptionsFrame(com.cburch.logisim.gui.opts.OptionsFrame) ChronoFrame(com.hepia.logisim.chronogui.ChronoFrame)

Example 2 with Frame

use of com.cburch.logisim.gui.main.Frame in project logisim-evolution by reds-heig.

the class ProjectActions method doNew.

public static Project doNew(Project baseProject) {
    LogisimFile file = createNewFile(baseProject);
    Project newProj = new Project(file);
    Frame frame = createFrame(baseProject, newProj);
    frame.setVisible(true);
    frame.getCanvas().requestFocus();
    newProj.getLogisimFile().getLoader().setParent(frame);
    updatecircs(file, newProj);
    return newProj;
}
Also used : LogisimFile(com.cburch.logisim.file.LogisimFile) Frame(com.cburch.logisim.gui.main.Frame)

Example 3 with Frame

use of com.cburch.logisim.gui.main.Frame in project logisim-evolution by reds-heig.

the class ProjectActions method createFrame.

private static Frame createFrame(Project sourceProject, Project newProject) {
    if (sourceProject != null) {
        Frame frame = sourceProject.getFrame();
        if (frame != null) {
            frame.savePreferences();
        }
    }
    Frame newFrame = new Frame(newProject);
    newProject.setFrame(newFrame);
    return newFrame;
}
Also used : Frame(com.cburch.logisim.gui.main.Frame)

Example 4 with Frame

use of com.cburch.logisim.gui.main.Frame in project logisim-evolution by reds-heig.

the class MenuFile method actionPerformed.

public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    Project proj = menubar.getProject();
    if (src == newi) {
        ProjectActions.doNew(proj);
    } else if (src == merge) {
        ProjectActions.doMerge(proj == null ? null : proj.getFrame().getCanvas(), proj);
    } else if (src == open) {
        ProjectActions.doOpen(proj == null ? null : proj.getFrame().getCanvas(), proj);
    } else if (src == close) {
        int result = 0;
        Frame frame = proj.getFrame();
        if (proj.isFileDirty()) {
            /* Must use hardcoded strings here, because the string management is rotten */
            String message = "What should happen to your unsaved changes to " + proj.getLogisimFile().getName();
            String[] options = { "Save", "Discard", "Cancel" };
            result = JOptionPane.showOptionDialog(JOptionPane.getFrameForComponent(this), message, "Confirm Close", 0, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
            if (result == 0) {
                ProjectActions.doSave(proj);
            }
        }
        /* If "cancel" pressed do nothing, otherwise dispose the window, opening one if this was the last opened window */
        if (result != 2) {
            // Get the list of open projects
            List<Project> pl = Projects.getOpenProjects();
            if (pl.size() == 1) {
                // Since we have a single window open, before closing the
                // current
                // project open a new empty one
                ProjectActions.doNew(proj);
            }
            // Close the current project
            frame.dispose();
            OptionsFrame f = proj.getOptionsFrame(false);
            if (f != null)
                f.dispose();
        }
    } else if (src == save) {
        ProjectActions.doSave(proj);
    } else if (src == saveAs) {
        ProjectActions.doSaveAs(proj);
    } else if (src == prefs) {
        PreferencesFrame.showPreferences();
    } else if (src == quit) {
        ProjectActions.doQuit();
    }
}
Also used : Project(com.cburch.logisim.proj.Project) OptionsFrame(com.cburch.logisim.gui.opts.OptionsFrame) Frame(com.cburch.logisim.gui.main.Frame) PreferencesFrame(com.cburch.logisim.gui.prefs.PreferencesFrame) List(java.util.List) OptionsFrame(com.cburch.logisim.gui.opts.OptionsFrame)

Example 5 with Frame

use of com.cburch.logisim.gui.main.Frame 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

Frame (com.cburch.logisim.gui.main.Frame)7 LogisimFile (com.cburch.logisim.file.LogisimFile)2 OptionsFrame (com.cburch.logisim.gui.opts.OptionsFrame)2 LoadFailedException (com.cburch.logisim.file.LoadFailedException)1 LoadedLibrary (com.cburch.logisim.file.LoadedLibrary)1 Loader (com.cburch.logisim.file.Loader)1 LogFrame (com.cburch.logisim.gui.log.LogFrame)1 PreferencesFrame (com.cburch.logisim.gui.prefs.PreferencesFrame)1 TestFrame (com.cburch.logisim.gui.test.TestFrame)1 Project (com.cburch.logisim.proj.Project)1 Library (com.cburch.logisim.tools.Library)1 ChronoFrame (com.hepia.logisim.chronogui.ChronoFrame)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1