use of edu.cmu.cs.hcii.cogtool.util.RcvrIOLoadException in project cogtool by cogtool.
the class Controller method open.
/**
* Prompts for and opens a file.
*
* @throws RcvrIOLoadException if the open fails
*/
protected boolean open(DoublePoint loc, File[] openLocs) {
try {
// If the open dialog was canceled, do nothing.
if (openLocs != null) {
Interaction interaction = getUI().getStandardInteraction();
// Otherwise, open all of the selected projects.
for (int i = 0; i < openLocs.length; i++) {
String statusMsg = null;
if (!openLocs[i].exists()) {
interaction.protestFileNotFound(openLocs[i].getName());
continue;
}
Project proj = null;
try {
proj = (Project) persist.isLoaded(openLocs[i]);
if (proj != null) {
if (UndoManager.isAtSavePoint(proj)) {
statusMsg = L10N.get("AC.OpenNotModified", "Project already open and not modified");
} else {
boolean revert = interaction.askRevertBeforeOpen(proj.getName());
if (revert) {
closeProject(proj, false);
} else {
continue;
}
}
}
proj = (Project) persist.load(openLocs[i]);
} catch (RuntimeException e) {
// format
throw new RcvrIOLoadException(("Error loading project: " + e.getMessage()), e);
}
CogToolPref.setRecent(openLocs[i].getCanonicalPath());
// Reset the project name in case the file was renamed
String name = openLocs[i].getName();
// Remove the .cgt, if it is there.
int periodIndex = name.lastIndexOf('.');
if (periodIndex > 0) {
name = name.substring(0, periodIndex);
}
proj.setName(name);
// Create a window; the project is not yet registered
// and is unmodified.
ProjectController c = ProjectController.openController(proj, false, true);
UI ui = getUI();
if ((loc != null) && (ui != null)) {
c.getUI().setLocation(loc);
}
if (statusMsg != null) {
c.interaction.setStatusMessage(statusMsg);
}
}
return true;
}
return false;
} catch (IOException e) {
throw new RcvrIOLoadException("Error loading project: " + e.getMessage(), e);
} catch (GraphicsUtil.ImageException e) {
throw new RcvrImageException("Error loading image from project: " + e.getMessage(), e);
}
}
Aggregations