use of edu.cmu.cs.hcii.cogtool.util.IUndoableEdit 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.util.IUndoableEdit 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.util.IUndoableEdit in project cogtool by cogtool.
the class SEDemoController method performTransition.
/**
* Take the transition, and perform the action
*
* @param transition
*/
protected boolean performTransition(SEDemoSelectionState selection, Transition transition, CogToolLID lid) {
AScriptStep stepToReplace = getDemoStep(selection);
if (stepToReplace != null) {
Frame currentFrame = stepToReplace.getCurrentFrame();
if (transition.getDestination() == currentFrame) {
return insertStep(new TransitionScriptStep(transition), stepToReplace, lid, PERFORM_TRANSITION);
}
if (!interaction.confirmDestructiveInsert()) {
return false;
}
}
AScriptStep newDemoStep = new TransitionScriptStep(transition);
TransitionSource source = transition.getSource();
if (source.getFrame() == transition.getDestination() && (source instanceof IWidget)) {
toggleIfGermane((IWidget) source, newDemoStep, transition.getAction());
}
Set<AScriptStep> newDemoSteps = Collections.singleton(newDemoStep);
Set<AScriptStep> oldDemoSteps = new LinkedHashSet<AScriptStep>();
Demonstration demo = script.getDemonstration();
final int atIndex = demo.replaceSteps(stepToReplace, newDemoSteps, oldDemoSteps);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, stepToReplace, interaction);
IUndoableEdit edit = new DemoStateManager.ADemoUndoableEdit(lid, demo, newDemoSteps, oldDemoSteps, demoStateMgr) {
@Override
public String getPresentationName() {
return PERFORM_TRANSITION;
}
@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(PERFORM_TRANSITION, lid);
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.util.IUndoableEdit in project cogtool by cogtool.
the class SEDemoController method insertStep.
protected boolean insertStep(final AScriptStep newDemoStep, AScriptStep beforeStep, CogToolLID lid, final String presentationName) {
Set<AScriptStep> newDemoSteps = Collections.singleton(newDemoStep);
Set<AScriptStep> emptyDemoSteps = // None are being replaced!
new HashSet<AScriptStep>();
Demonstration demo = script.getDemonstration();
final int atIndex = demo.insertStep(newDemoStep, beforeStep);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, beforeStep, interaction);
if (CogToolPref.HCIPA.getBoolean()) {
TaskApplication ta = script.getDemonstration().getTaskApplication();
AUndertaking t = ta.getTask();
Design d = ta.getDesign();
// Starting with the script after t, update all of the scripts in
// the task group to reflect the new state
TaskGroup grp = t.getTaskGroup();
if (grp != null) {
List<AUndertaking> tasks = grp.getUndertakings();
int startIndex = tasks.indexOf(t);
Script prevScript = script;
for (int i = startIndex + 1; i < tasks.size(); i++) {
t = tasks.get(i);
ta = project.getTaskApplication(t, d);
if (ta == null) {
continue;
}
Script s = ta.getScript(script.getModelGenerator());
Demonstration curDemo = s.getDemonstration();
HCIPACmd.copyState(prevScript, curDemo);
scriptsUndoRedos.addAll(DemoScriptCmd.regenerateScripts(curDemo, 0, curDemo.getStepAt(0), interaction));
prevScript = s;
}
}
}
IUndoableEdit edit = new DemoStateManager.ADemoUndoableEdit(lid, demo, newDemoSteps, emptyDemoSteps, demoStateMgr) {
@Override
public String getPresentationName() {
return presentationName;
}
@Override
public void redo() {
super.redo();
demo.insertStep(newDemoStep, atIndex);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
demo.removeStep(atIndex);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(presentationName, lid);
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.util.IUndoableEdit in project cogtool by cogtool.
the class SEFrameChooserController method createOpenDemonstrationWindowAction.
/**
* Create the window for demonstrating the entire script.
*/
protected IListenerAction createOpenDemonstrationWindowAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
// Ensure there is a selected start frame.
final Demonstration demo = taskApp.getDemonstration();
final Script script = taskApp.getScript(modelGen);
if (demo.getStartFrame() != null) {
demo.setStartFrameChosen(true);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, 0, demo.getStepAt(0), interaction);
// Close the current window.
closeWindow(false);
// Open the new demo view window
try {
SEDemoController.openController(taskApp, modelGen, project);
} catch (GraphicsUtil.ImageException ex) {
interaction.protestInvalidImageFile();
}
IUndoableEdit edit = new AUndoableEdit(SEFrameChooserLID.OpenScriptEditor) {
@Override
public String getPresentationName() {
return startDemonstrating;
}
@Override
public void redo() {
super.redo();
if (demo.getStartFrame() != null) {
demo.setStartFrameChosen(true);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
// Close the frame chooser window.
DefaultController frameController = ControllerRegistry.ONLY.findOpenController(taskApp);
if (frameController != null) {
frameController.closeWindow(false);
}
// Open the new demo view window
try {
SEDemoController.openController(taskApp, modelGen, project);
} catch (GraphicsUtil.ImageException ex) {
interaction.protestInvalidImageFile();
}
}
}
@Override
public void undo() {
super.undo();
DefaultController seDemoController = ControllerRegistry.ONLY.findOpenController(script);
if (seDemoController != null) {
seDemoController.closeWindow(false);
}
demo.setStartFrameChosen(false);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
SEFrameChooserController.openController(taskApp, modelGen, project);
}
};
UndoManager scriptUndoMgr = UndoManager.getUndoManager(script, project);
scriptUndoMgr.addEdit(edit);
undoMgr.addEdit(edit);
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
Aggregations