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