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);
}
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;
}
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;
}
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();
}
}
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;
}
Aggregations