use of edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState in project cogtool by cogtool.
the class ScriptViewerUI 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 {
selection.setSelectedState(selectedItem);
}
}
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) {
Script s = (Script) selectedItem.getData(SWTListGroupScript.SCRIPT_DATA_KEY);
DefaultModelGeneratorState stepState = (DefaultModelGeneratorState) data;
// In case we need this; not a context selection
// in truth, but we can re-use the structure.
contextSelection.setSelectedState(stepState);
performAction(ProjectLID.EditScript, s);
}
}
}
};
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;
Frame resultFrame = null;
Script script = getSelectedScript(stepState);
AUndertaking t = script.getDemonstration().getTaskApplication().getTask();
if (stepState != null) {
resultFrame = stepState.getScriptStep().getCurrentFrame();
} else if (script != null) {
resultFrame = script.getDemonstration().getResultFrame();
}
DefaultModelGeneratorState overrideState = script.getPreviousState(stepState);
if (overrideState == null) {
TaskGroup group = (TaskGroup) task;
List<AUndertaking> siblingTasks = group.getUndertakings();
int currentTaskIndex = siblingTasks.indexOf(t);
CognitiveModelGenerator modelGen = script.getModelGenerator();
while ((overrideState == null) && (0 <= --currentTaskIndex)) {
AUndertaking prevSibling = siblingTasks.get(currentTaskIndex);
TaskApplication ta = project.getTaskApplication(prevSibling, design);
if (ta != null) {
script = ta.getScript(modelGen);
if (script != null) {
overrideState = script.getLastState();
}
}
}
}
uiModel.setCurrentOverride(script, overrideState);
try {
setCurrentFrame(resultFrame);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Changing current demonstration frame", ex);
}
}
}
}
};
selection.addHandler(this, SEDemoSelectionState.StepStateSelectionChange.class, selectionChangeHandler);
}
use of edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState in project cogtool by cogtool.
the class ScriptViewerUI method showSelectionContextMenu.
/**
* Mouse event occurred on the table, use the selected item to
* display an appropriate menu.
*
*/
public void showSelectionContextMenu(int x, int y) {
contextSelection.deselectAll();
Table historyTable = view.getHistoryTable();
org.eclipse.swt.graphics.Point atPoint = historyTable.toControl(x, y);
TableItem ti = historyTable.getItem(atPoint);
if ((ti != null) && (ti.getData() instanceof DefaultModelGeneratorState)) {
contextSelection.setSelectedState((DefaultModelGeneratorState) ti.getData());
} else {
// this is the result Step, so no selection
historyTable.select(historyTable.getItemCount() - 1);
}
showContextMenu(contextSelection, true);
}
use of edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState in project cogtool by cogtool.
the class SEDemoController method setMouseHandAction.
// resetComputations
protected void setMouseHandAction(final boolean mouseHand) {
final Demonstration demo = script.getDemonstration();
final boolean oldMouseHand = demo.getMouseHand();
final DefaultModelGeneratorState initialState = demo.getInitialState();
final HandLocation mouseHandLoc = initialState.getHandLocation(oldMouseHand);
final DemoStateManager.IConformanceUndoRedo conformanceUndoRedo = demoStateMgr.restoreConformance(demo);
demo.setMouseHand(mouseHand);
initialState.setHandLocation(mouseHand, mouseHandLoc);
initialState.setHandLocation(!mouseHand, HandLocation.OnKeyboard);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, 0, demo.getStepAt(0), interaction);
IUndoableEdit edit = new AUndoableEdit(SEDemoLID.SetMouseHand) {
@Override
public String getPresentationName() {
return SET_MOUSE_HAND;
}
@Override
public void redo() {
super.redo();
conformanceUndoRedo.redo();
initialState.setHandLocation(mouseHand, mouseHandLoc);
initialState.setHandLocation(!mouseHand, HandLocation.OnKeyboard);
// Do this last as it will alert
demo.setMouseHand(mouseHand);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
conformanceUndoRedo.undo();
initialState.setHandLocation(oldMouseHand, mouseHandLoc);
initialState.setHandLocation(!oldMouseHand, HandLocation.OnKeyboard);
// Do this last as it will alert
demo.setMouseHand(oldMouseHand);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
undoMgr.addEdit(edit);
}
use of edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState in project cogtool by cogtool.
the class SEDemoController method performChangeThink.
// performInsertThink
protected boolean performChangeThink(SEDemoSelectionState selection) {
DefaultModelGeneratorState selectedState = selection.getSelectedState();
if ((selectedState == null) || !(selectedState.getScriptStep() instanceof ThinkScriptStep)) {
interaction.protestNotThinkStep();
return false;
}
final ThinkScriptStep thinkStep = (ThinkScriptStep) selectedState.getScriptStep();
final double oldDuration = thinkStep.getThinkDuration();
final String oldLabel = thinkStep.getLabel();
final SEDemoInteraction.TimedActionData data = getTimedActionData(oldDuration, oldLabel, IS_THINK);
if (data == null) {
return false;
}
thinkStep.setThinkDuration(data.duration);
thinkStep.setLabel(data.labelString);
final Collection<ComputationUndoRedo> computeUndoRedos = resetComputations();
IUndoableEdit edit = new AUndoableEdit(SEDemoLID.ChangeThinkProperties) {
@Override
public String getPresentationName() {
return CHG_THINK_PROPERTIES;
}
@Override
public void redo() {
super.redo();
thinkStep.setThinkDuration(data.duration);
thinkStep.setLabel(data.labelString);
DemoScriptCmd.redoAllChanges(computeUndoRedos);
}
@Override
public void undo() {
super.undo();
thinkStep.setThinkDuration(oldDuration);
thinkStep.setLabel(oldLabel);
DemoScriptCmd.undoAllChanges(computeUndoRedos);
}
};
undoMgr.addEdit(edit);
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState in project cogtool by cogtool.
the class HCIPACmd method initHCIPATaskDesign.
// For each design
protected static void initHCIPATaskDesign(Project project, String taskName, AUndertaking[] subtasks, Design design, CognitiveModelGenerator modelGen) {
Frame f = getStartFrame(design);
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
TaskApplication ta = DemoStateManager.ensureTaskApplication(project, subtasks[0], design, modelGen, demoMgr);
Script script = ta.getScript(modelGen);
Demonstration demo = script.getDemonstration();
demo.setStartFrame(f);
demo.setStartFrameChosen(true);
IPredictionAlgo computeAlg = ta.determineActiveAlgorithm(project);
ThinkScriptStep thinkStep = new ThinkScriptStep(f, RECOGNIZE_NEED + taskName);
demo.appendStep(thinkStep);
List<String> warnings = new ArrayList<String>();
List<DefaultModelGeneratorState> states = modelGen.generateScriptSteps(thinkStep, demo.getInitialState(), warnings);
script.replaceStepStates(0, states);
APredictionResult result = ComputePredictionCmd.computePrediction(computeAlg, script);
ta.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(result));
ta = DemoStateManager.ensureTaskApplication(project, subtasks[1], design, modelGen, demoMgr);
script = ta.getScript(modelGen);
demo = ta.getDemonstration();
demo.setStartFrame(f);
demo.setStartFrameChosen(true);
thinkStep = new ThinkScriptStep(f, "Select Function Step");
demo.appendStep(thinkStep);
states = modelGen.generateScriptSteps(thinkStep, demo.getInitialState(), warnings);
script.replaceStepStates(0, states);
result = ComputePredictionCmd.computePrediction(computeAlg, script);
ta.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(result));
}
Aggregations