use of edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep in project cogtool by cogtool.
the class SEDemoController method assignActions.
@Override
public void assignActions() {
super.assignActions();
ui.setAction(SEDemoLID.Undo, new UndoController.UndoAction(undoMgr, interaction));
ui.setAction(SEDemoLID.Redo, new UndoController.RedoAction(undoMgr, interaction));
ui.setAction(SEDemoLID.SetMouseHand, createSetMouseHandAction());
ui.setAction(SEDemoLID.SetHandLocation, createSetHandLocationAction());
ui.setAction(SEDemoLID.PerformTransition, createPerformTransitionAction());
ui.setAction(SEDemoLID.InsertThink, new IListenerAction() {
public Class<?> getParameterClass() {
return SEDemoSelectionState.class;
}
public boolean performAction(Object prms) {
SEDemoSelectionState selection = (SEDemoSelectionState) prms;
return performInsertThink(selection);
}
});
ui.setAction(SEDemoLID.ChangeThinkProperties, new IListenerAction() {
public Class<?> getParameterClass() {
return SEDemoSelectionState.class;
}
public boolean performAction(Object prms) {
SEDemoSelectionState selection = (SEDemoSelectionState) prms;
return performChangeThink(selection);
}
});
ui.setAction(SEDemoLID.InsertDelay, new IListenerAction() {
public Class<?> getParameterClass() {
return SEDemoSelectionState.class;
}
public boolean performAction(Object prms) {
SEDemoSelectionState selection = (SEDemoSelectionState) prms;
return performInsertDelay(selection);
}
});
ui.setAction(SEDemoLID.ChangeWaitProperties, new IListenerAction() {
public Class<?> getParameterClass() {
return SEDemoSelectionState.class;
}
public boolean performAction(Object prms) {
SEDemoSelectionState selection = (SEDemoSelectionState) prms;
return performChangeDelay(selection);
}
});
ui.setAction(SEDemoLID.Edit, new IListenerAction() {
public Class<?> getParameterClass() {
return SEDemoSelectionState.class;
}
public boolean performAction(Object prms) {
SEDemoSelectionState selection = (SEDemoSelectionState) prms;
DefaultModelGeneratorState selectedState = selection.getSelectedState();
if (selectedState == null) {
interaction.protestNoStep();
return false;
}
AScriptStep step = selectedState.getScriptStep();
if (step instanceof ThinkScriptStep) {
return performChangeThink(selection);
}
if (step instanceof DelayScriptStep) {
return performChangeDelay(selection);
}
if ((step instanceof ActionScriptStep) && step.isDemonstrated() && step.isInsertedByUser()) {
return performEditSelfTransition((ActionScriptStep) step);
}
step = step.getOwner();
if ((step instanceof ActionScriptStep) && step.isDemonstrated() && step.isInsertedByUser()) {
return performEditSelfTransition((ActionScriptStep) step);
}
interaction.protestNotEditable();
return false;
}
});
ui.setAction(SEDemoLID.InsertDrive, new IListenerAction() {
public Class<?> getParameterClass() {
return SEDemoSelectionState.class;
}
public boolean performAction(Object prms) {
SEDemoSelectionState selection = (SEDemoSelectionState) prms;
return performInsertDrive(selection);
}
});
ui.setAction(SEDemoLID.InsertLookAt, new IListenerAction() {
public Class<?> getParameterClass() {
return SEDemoUI.LookAtTransition.class;
}
public boolean performAction(Object prms) {
SEDemoUI.LookAtTransition lookAt = (SEDemoUI.LookAtTransition) prms;
return performInsertLookAt(lookAt.selection, lookAt.target);
}
});
ui.setAction(SEDemoLID.InsertSelfTransition, createInsertSelfTransitionAction());
ui.setAction(SEDemoLID.Delete, new IListenerAction() {
public Class<?> getParameterClass() {
return SEDemoSelectionState.class;
}
public boolean performAction(Object prms) {
// If not the "most recent" step state, warn
// the user that this will remove all
// items after as well, unless it's a think,
// look-at or other non-transitioning item.
SEDemoSelectionState selection = (SEDemoSelectionState) prms;
return deleteScriptStep(selection);
}
});
ui.setAction(SEDemoLID.RegenerateScript, createRegenerateScriptAction());
ui.setAction(SEDemoLID.RecomputeScript, createSaveScriptChangesAction());
ui.setAction(SEDemoLID.ExportScriptToCSV, createExportScriptToCSVAction());
ui.setAction(DesignEditorLID.EditFrame, createEditFrameAction());
ui.setAction(SEDemoLID.ShowModelVisualization, createShowModelVisualizationAction());
}
use of edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep in project cogtool by cogtool.
the class SEDemoController method deleteScriptStep.
// createInsertSelfTransitionAction
/**
* Perform the operations needed to DELETE a script Action
*
* @param selection
* @return
*/
protected boolean deleteScriptStep(SEDemoSelectionState selection) {
// In case we need to go back to edit initial state.
final CognitiveModelGenerator modelGen = script.getModelGenerator();
final Demonstration demo = script.getDemonstration();
final TaskApplication taskApp = demo.getTaskApplication();
// If there is no selected action, try to delete the last item
DefaultModelGeneratorState selectedState = selection.getSelectedState();
final DefaultModelGeneratorState stateToDelete = getValidStepState(selectedState);
IUndoableEdit edit;
// If no states, go back to edit initial state
if ((stateToDelete == null) || stateToDelete.getScriptStep().isInitiallyGenerated()) {
closeWindow(false);
demo.setStartFrameChosen(false);
SEFrameChooserController.openController(taskApp, modelGen, project);
edit = new AUndoableEdit(SEDemoLID.Delete) {
protected DemoScriptCmd.ComputationUndoRedo computeUndoRedo = new DemoScriptCmd.ComputationUndoRedo(script);
@Override
public String getPresentationName() {
return CHANGE_START_FRAME;
}
@Override
public void redo() {
super.redo();
DefaultController seDemoController = ControllerRegistry.ONLY.findOpenController(script);
if (seDemoController != null) {
seDemoController.closeWindow(false);
}
demo.setStartFrameChosen(false);
SEFrameChooserController.openController(taskApp, modelGen, project);
computeUndoRedo.redoChanges();
}
@Override
public void undo() {
super.undo();
if (demo.getStartFrame() != null) {
demo.setStartFrameChosen(true);
// Close the frame chooser window.
DefaultController frameChooserController = ControllerRegistry.ONLY.findOpenController(taskApp);
if (frameChooserController != null) {
frameChooserController.closeWindow(false);
}
// Open the new demo view window
try {
SEDemoController.openController(taskApp, modelGen, project);
} catch (GraphicsUtil.ImageException ex) {
interaction.protestInvalidImageFile();
}
computeUndoRedo.undoChanges();
}
}
};
UndoManager seFrameMgr = UndoManager.getUndoManager(taskApp, project);
seFrameMgr.addEdit(edit);
undoMgr.addEdit(edit);
return true;
}
AScriptStep step = stateToDelete.getScriptStep();
// If a generated think step, simply delete
if ((step instanceof ThinkScriptStep) && !step.isInsertedByUser()) {
edit = new AUndoableEdit(SEDemoLID.Delete) {
protected int scriptIndex = script.removeState(stateToDelete);
protected DemoScriptCmd.ComputationUndoRedo computeUndoRedo = new DemoScriptCmd.ComputationUndoRedo(script);
@Override
public String getPresentationName() {
return DELETE_STEP;
}
@Override
public void redo() {
super.redo();
script.removeState(scriptIndex);
computeUndoRedo.redoChanges();
}
@Override
public void undo() {
super.undo();
script.insertState(stateToDelete, scriptIndex);
computeUndoRedo.undoChanges();
}
};
} else {
final AScriptStep demoStep = step.getOwner();
// There are no "new" steps to replace with when deleting
Set<AScriptStep> emptyDemoSteps = new HashSet<AScriptStep>();
if (demoStep.getCurrentFrame() == demoStep.getDestinationFrame()) {
final int atIndex = demo.removeStep(demoStep);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, demoStep, interaction);
Set<AScriptStep> oldDemoSteps = Collections.singleton(demoStep);
edit = new DemoStateManager.ADemoUndoableEdit(SEDemoLID.Delete, demo, emptyDemoSteps, oldDemoSteps, demoStateMgr) {
@Override
public String getPresentationName() {
return DELETE_STEP;
}
@Override
public void redo() {
super.redo();
demo.removeStep(atIndex);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
demo.insertStep(demoStep, atIndex);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
} else {
if ((selectedState != null) && (demoStep != demo.getLastStep()) && !interaction.confirmDeleteScriptStep()) {
return false;
}
Set<AScriptStep> oldDemoSteps = new LinkedHashSet<AScriptStep>();
final int atIndex = demo.replaceSteps(demoStep, emptyDemoSteps, oldDemoSteps);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, demoStep, interaction);
edit = new DemoStateManager.ADemoUndoableEdit(SEDemoLID.Delete, demo, emptyDemoSteps, oldDemoSteps, demoStateMgr) {
@Override
public String getPresentationName() {
return DELETE_STEP;
}
@Override
public void redo() {
super.redo();
demo.replaceSteps(atIndex, redoDemoSteps);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
demo.replaceSteps(atIndex, undoDemoSteps);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
}
}
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(DELETE_STEP, SEDemoLID.Delete);
editSequence.addEdit(edit);
if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateScripts(project, demo, demoStateMgr, interaction, editSequence);
}
editSequence.end();
undoMgr.addEdit(editSequence);
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep in project cogtool by cogtool.
the class SEDemoUI method addSelectionChangeListeners.
/**
* Add the selection Change event listeners.
*/
protected void addSelectionChangeListeners() {
SWTselectionChangeHandler = new SelectionListener() {
public void widgetSelected(SelectionEvent evt) {
SWTList swtList = view.getScriptEditorList();
TableItem[] selectedItems = swtList.getSelectionObject();
for (TableItem selectedItem : selectedItems) {
// TODO: Currently supports only single selection.
Object data = selectedItem.getData();
if (data instanceof Frame) {
selection.setSelectedState(null);
} else {
// should be instanceof DefaultModelGeneratorState!!!
AScriptStep step = ((DefaultModelGeneratorState) data).getScriptStep();
if (step instanceof HearScriptStep) {
if (interaction.askEditFrame()) {
Frame f = step.getCurrentFrame();
performAction(DesignEditorLID.EditFrame, f);
}
TableItem previousSelectedRow = swtList.getRowItem(selection.getPreviousSelection());
selection.setSelectedState(previousSelectedRow);
} else {
selection.setSelectedState(selectedItem);
}
}
}
centerSelectedRegion();
setViewEnabledState(selection, ListenerIdentifierMap.NORMAL);
// Let selection change handle changing the frame
}
public void widgetDefaultSelected(SelectionEvent evt) {
SWTList swtList = view.getScriptEditorList();
TableItem[] selectedItems = swtList.getSelectionObject();
// TODO: Currently supports only single selection.
for (TableItem selectedItem : selectedItems) {
Object data = selectedItem.getData();
if (data instanceof DefaultModelGeneratorState) {
DefaultModelGeneratorState stepState = (DefaultModelGeneratorState) data;
AScriptStep step = stepState.getScriptStep();
// In case we need this; not a context selection
// in truth, but we can re-use the structure.
contextSelection.setSelectedState(stepState);
if (editable) {
if (step instanceof DelayScriptStep) {
performAction(SEDemoLID.ChangeWaitProperties, contextSelection);
} else if (step instanceof ThinkScriptStep) {
performAction(SEDemoLID.ChangeThinkProperties, contextSelection);
} else if (isEditable(step)) {
performAction(SEDemoLID.Edit, contextSelection);
}
}
}
}
}
};
view.addSWTListSelectionHandler(SWTselectionChangeHandler);
AlertHandler selectionChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
SEDemoSelectionState.StepStateSelectionChange event = (SEDemoSelectionState.StepStateSelectionChange) alert;
if (event != null) {
if (event.selected) {
DefaultModelGeneratorState stepState = event.changedState;
uiModel.setCurrentOverride(script, script.getPreviousState(stepState));
Frame resultFrame = null;
if (stepState != null) {
resultFrame = stepState.getScriptStep().getCurrentFrame();
} else {
resultFrame = script.getDemonstration().getResultFrame();
}
try {
setCurrentFrame(resultFrame);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Changing current demonstration frame", ex);
}
} else {
// deselect item.
uiModel.setCurrentOverride(script, script.getLastState());
}
}
}
};
selection.addHandler(this, SEDemoSelectionState.StepStateSelectionChange.class, selectionChangeHandler);
}
use of edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep in project cogtool by cogtool.
the class HCIPACmd method setFunctionName.
public static void setFunctionName(Project project, final AUndertaking renamedTask, final String newName, CognitiveModelGenerator modelGen, final String undoRenameLabel, IUndoableEditSequence editSeq) {
final TaskGroup parentTask = renamedTask.getTaskGroup();
final String oldName = renamedTask.getName();
final Object oldAttr = parentTask.getAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR);
final String newAttr = parseFunctionName(newName);
renamedTask.setName(newName);
parentTask.setAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR, newAttr);
CompoundUndoableEdit edits = new CompoundUndoableEdit(undoRenameLabel, ProjectLID.HCIPARenameTask);
edits.addEdit(new AUndoableEdit(ProjectLID.HCIPARenameTask) {
@Override
public String getPresentationName() {
return undoRenameLabel;
}
@Override
public void redo() {
super.redo();
renamedTask.setName(newName);
parentTask.setAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR, newAttr);
}
@Override
public void undo() {
super.undo();
renamedTask.setName(oldName);
parentTask.setAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR, oldAttr);
}
});
// change the task's think step label
Iterator<Design> designs = project.getDesigns().iterator();
while (designs.hasNext()) {
final ThinkScriptStep thinkStep = chgFnName(project, renamedTask, designs.next(), modelGen, DECIDE_TO_USE + newAttr);
// Create undo/redo step and add to undo manager
if (thinkStep != null) {
IUndoableEdit edit = new AUndoableEdit(ProjectLID.HCIPARenameTask) {
@Override
public String getPresentationName() {
return undoRenameLabel;
}
@Override
public void redo() {
super.redo();
thinkStep.setLabel(DECIDE_TO_USE + newAttr);
}
@Override
public void undo() {
super.undo();
thinkStep.setLabel(DECIDE_TO_USE + oldAttr);
}
};
edits.addEdit(edit);
}
}
edits.end();
editSeq.addEdit(edits);
}
use of edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep in project cogtool by cogtool.
the class SEDemoController method performInsertThink.
// insertStep
protected boolean performInsertThink(SEDemoSelectionState selection) {
SEDemoInteraction.TimedActionData data = getTimedActionData(ThinkScriptStep.DEFAULT_KLM_THINK_DURATION, ThinkScriptStep.DEFAULT_THINK_LABEL, IS_THINK);
// Check to see if the user canceled the operation.
if (data != null) {
AScriptStep beforeStep = getDemoStep(selection);
// a Delay, if so ask the user about it.
if ((beforeStep != null) && (beforeStep instanceof DelayScriptStep)) {
Boolean reposition = interaction.confirmNewThinkLocation();
if (reposition == null) {
// Break out; the user canceled
return false;
}
if (reposition.booleanValue()) {
// We want to insert it AFTER the delay step
beforeStep = script.getDemonstration().getNextStep(beforeStep);
}
// O.w., the user confirmed they wanted it where they put it.
}
AScriptStep thinkStep = new ThinkScriptStep(getCurrentFrame(beforeStep), data.duration, data.labelString);
return insertStep(thinkStep, beforeStep, SEDemoLID.InsertThink, INSERT_THINK);
}
// Cannot complete action / was canceled
return false;
}
Aggregations