use of edu.cmu.cs.hcii.cogtool.model.Project in project cogtool by cogtool.
the class CogTool method main.
public static void main(String[] args) {
// Do a clean exit if running on a machine with an old JRE.
if (!OSUtils.supportCogTool()) {
System.out.println("JRE 1.5 or later is required to run CogTool");
// TODO: add simple window with message?
System.exit(1024);
}
if (revision == null) {
// we're running under the development environment; get the revision
// dynamically, and also make our subprocesses echo what's going
// on to stdout
revision = getRevisionAtRuntime();
Subprocess.setDebug(true);
}
// Insert the two phases into the delayed work manager, selection
// first and repaint second, since selection can cause repaint requests
delayedWorkMgr.addDelayedWork(selectionPhase);
delayedWorkMgr.addDelayedWork(repaintPhase);
try {
if (OSUtils.MACOSX) {
if (!OSUtils.isIntelMac()) {
System.out.println("CogTool no longer runs on PowerPC");
System.exit(16);
}
// we need to create the RootController, but will never
// actually need to interact with it programmatically
rootCtl = new RootController();
}
// TODO temporary kludge until we update the preference dialog to supply
// a UI for turning this on and off
CogToolPref.IS_LOGGING.setBoolean(true);
enableLogging(CogToolPref.IS_LOGGING.getBoolean());
OptionParser parser = new OptionParser("f:i:re:s:qQ");
// The psn is supplied on MacOS when a GUI application is double-clicked;
// we just ignore it, but need to recognize it so we can ignore it.
parser.accepts("psn", "process serial number (ignored)").withRequiredArg();
OptionSet opts = parser.parse(args);
if (opts.has("Q")) {
quietCommands = true;
}
List<String> filesToLoad = new ArrayList<String>();
for (Object obj : opts.nonOptionArguments()) {
filesToLoad.add((String) obj);
}
List<RecoverableException> loadExceptions = new ArrayList<RecoverableException>();
ProjectController openedProject = null;
File file = null;
if (!filesToLoad.isEmpty()) {
ObjectPersister persister = ObjectPersister.ONLY;
for (String fn : filesToLoad) {
try {
file = new File(fn);
Project proj = (Project) persister.load(file);
openedProject = ProjectController.openController(proj, false, true);
} catch (Exception e) {
RecoverableException re = new RecoverableException("Error occurred while loading: " + fn, e);
RcvrExceptionHandler.recover(re, interaction);
}
}
}
if (opts.has("f")) {
openedProject = (new CommandFile((String) opts.valueOf("f"))).run();
} else {
if (opts.has("i")) {
openedProject = ProjectController.newProjectController();
openedProject.importFile = new File((String) opts.valueOf("i"));
openedProject.importFileComputes = opts.has("r");
openedProject.performAction(CogToolLID.ImportXML, new ProjectContextSelectionState(openedProject.getModel()));
}
if (openedProject != null && opts.has("e")) {
openedProject.exportFile = (String) opts.valueOf("e");
openedProject.exportResultsToCSV();
}
if (openedProject != null && opts.has("s")) {
openedProject.saveAsFilename((String) opts.valueOf("s"));
}
if (opts.has("q")) {
System.exit(0);
}
}
if (openedProject != null) {
if (System.getProperty("edu.cmu.cs.hcii.cogtool.ExportCSVKludge") != null) {
exportCSVKludgeDir = file.getAbsoluteFile().getParentFile();
openedProject.exportCSVKludge();
System.exit(0);
}
}
if (openedProject == null) {
// no project was opened successfully, or none were specified,
// so create a fresh project and use its Interaction to
// report load errors
ProjectController c = ProjectController.newProjectController();
c.setLocation(25.0, 25.0);
String response = c.getInteraction().createNewOrOpenExisting();
if (response == ProjectInteraction.CREATE) {
// Populate the empty project to avoid a "blank screen".
c.populateProject();
} else if (response == null) {
c.requestClose();
} else {
if (response == ProjectInteraction.OPEN) {
c.openExistingProject(c.getLocation());
} else {
c.performAction(CogToolLID.OpenProjectFile, response, false);
}
if (ControllerRegistry.ONLY.openControllerCount() > 1) {
c.requestClose();
}
}
}
// } else if (command.equals("export-csv")) {
// if (openedProject == null) {
// System.err.println(String.format(
// L10N.get("CT.NoFileForCSV",
// "Couldn't open %s for CSV export."),
// arguments.get(0)));
// System.exit(32);
// }
// exportCSVKludgeDir =
// file.getAbsoluteFile().getParentFile();
// openedProject.exportCSVKludge();
// System.exit(0);
// }
// Note that the following catches and does not rethrow any
// SWTExceptions. This means reportTopLevelException never gets
// a chance to report these to the user.
WindowUtil.interact();
} catch (RecoverableException e) {
RcvrExceptionHandler.recover(e, interaction);
} catch (Exception e) {
System.err.println("Catching exception...");
reportTopLevelAnomaly(e);
} catch (Error e) {
// Before trying to throw up a dialog it is important that we dump
// the trace to stderr, the same way as would happen if this went
// uncaught. At least that way if we are in so hosed a state that
// we can't even popup the dialog we've made the patient no worse
// than it would have been had we not caught this. We don't even
// wait for reportTopLevelAnomoly before printing it in case just
// that extra level of function call will make a difference in
// whether or not we succeed.
System.err.println("Catching error...");
e.printStackTrace();
reportTopLevelAnomaly(e);
} catch (Throwable e) {
// This shouldn't be possible -- the only unchecked Throwables
// are Errors and RuntimeExceptions, both of which should have
// been caught above. But just in case someone does something
// deeply bizarre and has something we call in this try able to
// throw a checked non-Exception Throwable, let's be extra paranoid.
System.err.println("Catching throwable...");
reportTopLevelAnomaly(new Exception(L10N.get("CT.UncaughtThrowable", ("Uncaught non-Exception, non-Error Throwable " + "propagated all the way to top-level.")), e));
}
// here.
if (!WindowUtil.GLOBAL_DISPLAY.isDisposed()) {
WindowUtil.GLOBAL_DISPLAY.close();
}
// Just calling the preceding is *not* sufficient to ensure we quit,
// in the rare case where we've thrown a non-recoverable Exception
// but left a background thread alive
System.exit(-1);
}
use of edu.cmu.cs.hcii.cogtool.model.Project 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);
}
}
use of edu.cmu.cs.hcii.cogtool.model.Project in project cogtool by cogtool.
the class Controller method createExitAction.
// The action for ExitApplication
protected IListenerAction createExitAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
// Take advantage of dual policy implementation; by
// temporarily ensuring that "project manages others", the user
// is presented with a ProjectController when asked to save
// each modified and unsaved project.
boolean oldProjectManagesOthers = CogTool.projectManagesOthers;
// Eliminate all windows where the associated
// ProjectController still exists.
CogTool.projectManagesOthers = true;
Set<Project> projectSet = CogTool.controllerNexus.getControllerNexuses();
Object[] projects = projectSet.toArray();
for (Object project : projects) {
Controller projectController = ControllerRegistry.ONLY.findOpenController(project);
// was canceled.
if ((projectController != null) && !projectController.requestClose()) {
// Restore the original policy
CogTool.projectManagesOthers = oldProjectManagesOthers;
return false;
}
}
// Restore the original policy
CogTool.projectManagesOthers = oldProjectManagesOthers;
// Find remaining open windows that are not ProjectControllers;
// Note we only get here if the current policy is that
// "projects do NOT manage others"!
projectSet = CogTool.controllerNexus.getControllerNexuses();
projects = projectSet.toArray();
// any modified but unsaved projects.
for (Object project2 : projects) {
Project project = (Project) project2;
if (!CogTool.controllerNexus.closeControllers(project, true)) {
return false;
}
}
// All the windows are closed (except possibly the "invisible"
// root window when executing on a Mac); time to exit!
System.exit(0);
// Kind of superfluous (Java!)
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Project in project cogtool by cogtool.
the class FrameEditorUI method init.
/**
* Set up this object for editing widgets.
* This method should be called from within the constructor.
*/
private void init() {
// Add listeners to the view
addEventListeners();
addSelectionChangeListeners();
// Add listeners to the model
addBackgroundImageHandler();
addFrameWidgetHandler();
addWidgetShapeChangeHandler();
project.addHandler(this, Project.DesignChange.class, new AlertHandler() {
public void handleAlert(EventObject alert) {
Project.DesignChange chg = (Project.DesignChange) alert;
if ((!chg.isAdd) && (chg.element == design)) {
closeOpenController();
}
}
});
design.addHandler(this, Design.FrameChange.class, new AlertHandler() {
public void handleAlert(EventObject alert) {
Design.FrameChange chg = (Design.FrameChange) alert;
if ((!chg.isAdd) && (chg.element == frame)) {
closeOpenController();
}
}
});
design.addHandler(this, Design.DeviceTypeChange.class, new AlertHandler() {
public void handleAlert(EventObject alert) {
Set<DeviceType> dts = design.getDeviceTypes();
int deviceTypes = DeviceType.buildDeviceSet(dts);
view.resetDeviceTypes(deviceTypes);
}
});
// Add listeners to rename events on project and design
frame.addHandler(this, NameChangeAlert.class, renameHandler);
design.addHandler(this, NameChangeAlert.class, renameHandler);
// Some items should always be enabled.
// Should be the last call in the constructor
setInitiallyEnabled(true);
}
Aggregations