use of edu.cmu.cs.hcii.cogtool.util.AListenerAction in project cogtool by cogtool.
the class SEDemoController method createShowModelVisualizationAction.
protected IListenerAction createShowModelVisualizationAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
CognitiveModelGenerator modelGen = script.getModelGenerator();
IPredictionAlgo activeAlgo = taskApplication.determineActiveAlgorithm(project);
if (taskApplication.getResult(modelGen, activeAlgo) != null) {
PERTChartController c = PERTChartController.openController(taskApplication, modelGen, activeAlgo, project, -1, interaction);
return (c != null);
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.AListenerAction 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.util.AListenerAction in project cogtool by cogtool.
the class DefaultController method assignActions.
/**
* Registers the set of <code>IListenerAction</code> instances
* that implement the semantic actions that are possible.
* <p>
* For this class, this consists of the actions that all CogTool
* model editing windows support.
*
* @author mlh
*/
@Override
protected void assignActions() {
super.assignActions();
UI ui = getUI();
final Interaction interaction = getUI().getStandardInteraction();
if (ui != null) {
// Set "save as" action
ui.setAction(CogToolLID.SaveProjectAs, new AListenerAction() {
public boolean performAction(Object prms) {
return saveAs();
}
});
// Set "save" action
ui.setAction(CogToolLID.SaveProject, new AListenerAction() {
public boolean performAction(Object prms) {
return forceSave();
}
});
ui.setAction(CogToolLID.CloseWindow, createCloseWindowAction());
ui.setAction(CogToolLID.CloseProject, new AListenerAction() {
public boolean performAction(Object prms) {
return closeProject(project, true);
}
});
ui.setAction(CogToolLID.Properties, new AListenerAction() {
public boolean performAction(Object prms) {
return showProperties();
}
});
ui.setAction(CogToolLID.SetAttribute, new IListenerAction() {
public Class<?> getParameterClass() {
return UI.SetAttributeParameters.class;
}
public boolean performAction(Object prms) {
UI.SetAttributeParameters p = (UI.SetAttributeParameters) prms;
return DefaultCmd.setAttribute(p.target, null, p.attrName, p.value, interaction, undoMgr);
}
});
}
}
use of edu.cmu.cs.hcii.cogtool.util.AListenerAction in project cogtool by cogtool.
the class DesignEditorController method createPasteAction.
protected IListenerAction createPasteAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
try {
Collection<Object> objects = CogToolClipboard.fetchCogToolObjects();
if ((objects != null) && (objects.size() > 0)) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(L10N.get("UNDO.Paste", "Paste"), DesignEditorLID.Paste);
Set<DeviceType> devTypes = design.getDeviceTypes();
int numPasted = 0;
Iterator<Object> objIt = objects.iterator();
while (objIt.hasNext()) {
Object o = objIt.next();
if (o instanceof Frame) {
Frame frame = (Frame) o;
makeFrameNameUnique(frame);
// Find an unoccupied starting position
// by cascading.
DoublePoint origin = frame.getFrameOrigin();
DesignUtil.findDistinctOrigin(design, origin, 16.0, 16.0);
// Union devices
Iterator<InputDevice> frameDevices = frame.getInputDevices().iterator();
while (frameDevices.hasNext()) {
InputDevice inputDevice = frameDevices.next();
DeviceType devType = inputDevice.getDeviceType();
if (!devTypes.contains(devType)) {
DesignCmd.addDevice(design, devType);
}
}
Iterator<DeviceType> designDevTypes = devTypes.iterator();
while (designDevTypes.hasNext()) {
DeviceType devType = designDevTypes.next();
if (frame.getInputDevice(devType) == null) {
frame.addInputDevice(devType);
}
}
addFrame(frame, editSequence);
numPasted++;
} else if (o instanceof Transition) {
Transition t = (Transition) o;
DeviceType device = t.getAction().getDefaultDeviceType();
if (!devTypes.contains(device)) {
DesignCmd.addDevice(design, device);
}
IUndoableEdit edit = DesignEditorCmd.addTransition(demoStateMgr, t);
editSequence.addEdit(edit);
numPasted++;
}
}
editSequence.end();
undoMgr.addEdit(editSequence);
interaction.setStatusMessage(numPasted + " " + pasteComplete);
} else {
interaction.setStatusMessage(nothingPasted);
}
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (ParserConfigurationException e) {
throw new RcvrClipboardException(e);
} catch (SAXException e) {
throw new RcvrClipboardException(e);
} catch (ClipboardUtil.ClipboardException e) {
throw new RcvrClipboardException(e);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.AListenerAction in project cogtool by cogtool.
the class DesignEditorController method createExportDesignToXMLAction.
protected IListenerAction createExportDesignToXMLAction() {
return new AListenerAction() {
public boolean performAction(Object actionParms) {
String defaultFilename = design.getName() + ".xml";
File exportFile = interaction.selectXMLFile(false, defaultFilename);
if (exportFile == null) {
return false;
}
OutputStream oStream = null;
try {
try {
oStream = new FileOutputStream(exportFile);
Writer xmlWriter = new BufferedWriter(new OutputStreamWriter(oStream, "UTF-8"));
Map<ITaskDesign, TaskApplication> designTAs = project.taskApplicationsForDesign(design);
ExportCogToolXML.exportXML(design, designTAs, xmlWriter, "UTF-8");
xmlWriter.flush();
} finally {
if (oStream != null) {
oStream.close();
}
}
} catch (IllegalArgumentException e) {
throw new RcvrIllegalStateException("Invalid argument exporting to XML", e);
} catch (IllegalStateException e) {
throw new RcvrIllegalStateException("Exporting to XML", e);
} catch (IOException e) {
throw new RcvrIOSaveException("Exporting to XML", e);
} catch (Exception e) {
throw new RecoverableException("Exporting to XML", e);
}
interaction.setStatusMessage(L10N.get("PC.DesignExportedToXML", "Design exported to XML:") + " " + exportFile.getName());
return true;
}
};
}
Aggregations