use of com.cburch.logisim.tools.Library in project logisim-evolution by reds-heig.
the class LogisimFile method removeLibrary.
public boolean removeLibrary(String Name) {
int index = -1;
for (Library lib : libraries) if (lib.getName().equals(Name))
index = libraries.indexOf(lib);
if (index < 0)
return false;
libraries.remove(index);
return true;
}
use of com.cburch.logisim.tools.Library 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.tools.Library in project logisim-evolution by reds-heig.
the class LayoutEditHandler method computeEnabled.
@Override
public void computeEnabled() {
Project proj = frame.getProject();
Selection sel = proj == null ? null : proj.getSelection();
boolean selEmpty = (sel == null ? true : sel.isEmpty());
boolean canChange = proj != null && proj.getLogisimFile().contains(proj.getCurrentCircuit());
boolean selectAvailable = false;
for (Library lib : proj.getLogisimFile().getLibraries()) {
if (lib instanceof Base)
selectAvailable = true;
}
setEnabled(LogisimMenuBar.CUT, !selEmpty && selectAvailable && canChange);
setEnabled(LogisimMenuBar.COPY, !selEmpty && selectAvailable);
setEnabled(LogisimMenuBar.PASTE, selectAvailable && canChange && !Clipboard.isEmpty());
setEnabled(LogisimMenuBar.DELETE, !selEmpty && selectAvailable && canChange);
setEnabled(LogisimMenuBar.DUPLICATE, !selEmpty && selectAvailable && canChange);
setEnabled(LogisimMenuBar.SELECT_ALL, selectAvailable);
setEnabled(LogisimMenuBar.RAISE, false);
setEnabled(LogisimMenuBar.LOWER, false);
setEnabled(LogisimMenuBar.RAISE_TOP, false);
setEnabled(LogisimMenuBar.LOWER_BOTTOM, false);
setEnabled(LogisimMenuBar.ADD_CONTROL, false);
setEnabled(LogisimMenuBar.REMOVE_CONTROL, false);
}
use of com.cburch.logisim.tools.Library in project logisim-evolution by reds-heig.
the class XmlWriter method fromTool.
Element fromTool(Tool tool) {
Library lib = findLibrary(tool);
String lib_name;
if (lib == null) {
loader.showError(StringUtil.format("tool `%s' not found", tool.getDisplayName()));
return null;
} else if (lib == file) {
lib_name = null;
} else {
lib_name = libs.get(lib);
if (lib_name == null) {
loader.showError("unknown library within file");
return null;
}
}
Element elt = doc.createElement("tool");
if (lib_name != null)
elt.setAttribute("lib", lib_name);
elt.setAttribute("name", tool.getName());
addAttributeSetContent(elt, tool.getAttributeSet(), tool);
return elt;
}
use of com.cburch.logisim.tools.Library in project logisim-evolution by reds-heig.
the class XmlWriter method fromComponent.
Element fromComponent(Component comp) {
ComponentFactory source = comp.getFactory();
Library lib = findLibrary(source);
String lib_name;
if (lib == null) {
loader.showError(source.getName() + " component not found");
return null;
} else if (lib == file) {
lib_name = null;
} else {
lib_name = libs.get(lib);
if (lib_name == null) {
loader.showError("unknown library within file");
return null;
}
}
Element ret = doc.createElement("comp");
if (lib_name != null)
ret.setAttribute("lib", lib_name);
ret.setAttribute("name", source.getName());
ret.setAttribute("loc", comp.getLocation().toString());
addAttributeSetContent(ret, comp.getAttributeSet(), comp.getFactory());
return ret;
}
Aggregations