use of edu.cmu.cs.hcii.cogtool.model.Frame 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.model.Frame in project cogtool by cogtool.
the class UndoManagerRecovery method recoverManagers.
/**
* Recover UndoManagers for the given design and its associated
* task applications. Also recovers for the design's frames and widgets.
*
* @param project the project containing the model objects
* @param design design whose ITaskApplications to recover managers for
* @param associatedTAs maps ITaskDesign to TaskApplication
*/
public static void recoverManagers(Project project, Design design, Map<ITaskDesign, TaskApplication> associatedTAs) {
DemoStateManager.removeStateManager(project, design);
// Recover UndoManagers for design's frames
// (used by FrameEditorControllers)
Iterator<Frame> frames = design.getFrames().iterator();
while (frames.hasNext()) {
Frame frame = frames.next();
recoverManagers(project, frame);
}
recoverScriptManagers(project, associatedTAs, false);
// Recover UndoManager for design's dictionary, if one exists
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (!NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
recoverManagers(project, dict);
}
// Recover UndoManager for design (used by DesignEditorController)
recoverManagers(project, design);
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorMouseState method handleMousePressed.
// dealWithMouseDoubleClicked
protected void handleMousePressed(int filter) {
if (filter == StructureViewUIModel.NO_LABEL) {
ResizeThumb thumb = ui.getResizeAtXY(mouseDownX, mouseDownY);
if (thumb != null) {
hitTransition = (DesignEditorTransition) thumb.getData();
selection.setSelectedTransition(hitTransition);
if (thumb.thumbType == DesignEditorUI.SOURCE) {
setMouseState(PotentialChangeSource);
} else {
setMouseState(PotentialChangeTarget);
}
return;
}
}
IFigure target = ui.structureView.getFigureAtXY(mouseDownX, mouseDownY, filter);
if (target instanceof DesignEditorTransition) {
hitTransition = (DesignEditorTransition) target;
if ((mouseDownState & InputEvent.SHIFT) != 0) {
setMouseState(PotentialToggleTransition);
} else {
setMouseState(PotentialSelectTransition);
}
} else if (target instanceof GraphicalSource<?>) {
potentialTransitionSource = (GraphicalSource<?>) target;
setMouseState(PotentialCreatingTransition);
// drag creates arrow
} else if (target instanceof DesignEditorFrame) {
DesignEditorFrame frameFigure = (DesignEditorFrame) target;
Frame frame = frameFigure.getFrame();
if ((mouseDownState & InputEvent.SHIFT) != 0) {
setMouseState(PotentialTogglingSelection);
} else if ((mouseDownState & platformDuplicateModifierKey()) != 0) {
if (!selection.isFrameSelected(frame)) {
selection.setSelectedFrame(frameFigure);
}
setMouseState(PotentialDuplicatingFrame);
} else {
if (selection.isFrameSelected(frame)) {
setMouseState(PotentialMovingSelection);
} else {
selection.setSelectedFrame(frameFigure);
setMouseState(PotentialMovingFrame);
}
}
} else {
// out in space
if ((mouseDownState & InputEvent.SHIFT) != 0) {
setMouseState(PotentialTogglingSelection);
} else {
selection.deselectAll();
setMouseState(PotentialSelectingFrames);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorMouseState method dealWithMouseReleased.
@Override
protected boolean dealWithMouseReleased(IFigure figure, int button, int x, int y, int state) {
boolean goForward = super.dealWithMouseReleased(figure, button, x, y, state);
// Clear any mouse drag timer, that may be running
stopMouseDragTimer = true;
if (goForward) {
// This must be done before the hideAllMenuItems!
IFigure figureAtXY = ui.structureView.getFigureAtXY(mouseDownX, mouseDownY, StructureViewUIModel.SOURCE_ONLY);
// Record the mouse down position.
// Convert mouse coordinates into model coordinates
double zoom = ui.getZoom();
double scaledMouseUpX = x / zoom;
double scaledMouseUpY = y / zoom;
DesignEditorFrame frameAtXY = ui.structureView.getFrameAtXY(mouseDownX, mouseDownY);
if (frameAtXY != null) {
frameAtXY.hideAllChildren();
ui.resetHiddenTransitionSources();
}
int leftX = PrecisionUtilities.round((scaledMouseUpX < scaledMouseDownX) ? scaledMouseUpX : scaledMouseDownX);
int topY = PrecisionUtilities.round((scaledMouseUpY < scaledMouseDownY) ? scaledMouseUpY : scaledMouseDownY);
int width = PrecisionUtilities.round((scaledMouseUpX < scaledMouseDownX) ? (scaledMouseDownX - scaledMouseUpX + 1) : (scaledMouseUpX - scaledMouseDownX + 1));
int height = PrecisionUtilities.round((scaledMouseUpY < scaledMouseDownY) ? (scaledMouseDownY - scaledMouseUpY + 1) : (scaledMouseUpY - scaledMouseDownY + 1));
Rectangle selectionBox = new Rectangle(leftX, topY, width, height);
switch(getMouseState()) {
case PotentialMovingFrame:
{
// set on mouse down.
break;
}
case PotentialMovingSelection:
{
DesignEditorFrame frameFig = ui.structureView.getFrameAtXY(mouseDownX, mouseDownY);
selection.setSelectedFrame(frameFig);
break;
}
case PotentialSelectingFrames:
{
break;
}
case PotentialCreatingTransition:
{
if (figureAtXY instanceof GraphicalParentWidget<?, ?>) {
GraphicalParentWidget<?, ?> parentToOpen = (GraphicalParentWidget<?, ?>) figureAtXY;
if (!parentToOpen.canHaveChildren()) {
parentToOpen = ((GraphicalChildWidget<?, ?>) parentToOpen).getParentFigure();
}
parentToOpen.openChildren();
ui.resetHiddenTransitionSources();
}
break;
}
case MovingFrames:
{
updateDynamicMove(x, y, true);
break;
}
case PotentialTogglingSelection:
{
dynamicSelectionArea.setVisible(false);
DesignEditorFrame frameFig = ui.structureView.getFrameAtXY(mouseDownX, mouseDownY);
if (frameFig != null) {
if (selection.isFrameSelected(frameFig.getFrame())) {
selection.deselectFrame(frameFig);
} else {
if (selection.getSelectedTransitionCount() > 0) {
selection.deselectAll();
}
selection.selectFrame(frameFig);
}
}
break;
}
case TogglingSelection:
{
dynamicSelectionArea.setVisible(false);
Iterator<DesignEditorFrame> frameFigures = ui.structureView.getAllFrameFigures();
while (frameFigures.hasNext()) {
DesignEditorFrame frameFig = frameFigures.next();
Frame frame = frameFig.getFrame();
if (frameFig.intersects(selectionBox)) {
if (selection.isFrameSelected(frame)) {
selection.deselectFrame(frameFig);
} else {
if (selection.getSelectedTransitionCount() > 0) {
selection.deselectAll();
}
selection.selectFrame(frameFig);
}
}
}
break;
}
case SelectingFrames:
{
dynamicSelectionArea.setVisible(false);
Iterator<DesignEditorFrame> frameFigures = ui.structureView.getAllFrameFigures();
while (frameFigures.hasNext()) {
DesignEditorFrame frameFig = frameFigures.next();
if (frameFig.intersects(selectionBox)) {
selection.selectFrame(frameFig);
}
}
break;
}
case CreatingTransition:
{
stopDynamicTransition();
if (potentialTarget != null) {
potentialTarget.dynamicHighlight(false);
potentialTarget = null;
}
if (potentialTransitionSource != null) {
DesignEditorFrame targetFigure = ui.structureView.getFrameAtXY(x, y);
TransitionSource source = potentialTransitionSource.getModel();
Frame target = (targetFigure != null) ? targetFigure.getFrame() : (Frame) null;
// Convert mouse coordinates into model coordinates
DesignEditorUI.NewTransitionParameters prms = new DesignEditorUI.NewTransitionParameters(source, target, scaledMouseUpX, scaledMouseUpY);
ui.performAction(DesignEditorLID.NewTransition, prms);
}
break;
}
case PotentialSelectTransition:
case PotentialChangeTarget:
case PotentialChangeSource:
{
selection.setSelectedTransition(hitTransition);
Transition transition = hitTransition.getTransition();
ui.getInteraction().setTransitionStatusMessage(transition);
hitTransition = null;
break;
}
case PotentialToggleTransition:
{
Transition transition = hitTransition.getTransition();
if (selection.isTransitionSelected(transition)) {
selection.deselectTransition(hitTransition);
} else {
if (selection.getSelectedFrameCount() > 0) {
selection.deselectAll();
}
selection.selectTransition(hitTransition);
}
hitTransition = null;
break;
}
case ChangingTarget:
{
stopDynamicTransition();
if (potentialTarget != null) {
potentialTarget.dynamicHighlight(false);
potentialTarget = null;
}
DesignEditorFrame newTargetFigure = ui.structureView.getFrameAtXY(x, y);
if (newTargetFigure != null) {
Transition transition = hitTransition.getTransition();
DesignEditorUI.ChangeTargetParameters prms = new DesignEditorUI.ChangeTargetParameters(transition, newTargetFigure.getFrame());
ui.performAction(DesignEditorLID.ChangeTarget, prms);
ui.getInteraction().setTransitionStatusMessage(transition);
}
hitTransition.setVisible(true);
break;
}
case ChangingSource:
{
stopDynamicTransition();
InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
drawLayer.setCursor(WindowUtil.getCursor(WindowUtil.SELECT_CURSOR));
GraphicalSource<?> newSourceFigure = ui.structureView.getSourceAtXY(x, y);
hitTransition.setVisible(true);
if (newSourceFigure != null) {
Transition transition = hitTransition.getTransition();
DesignEditorUI.ChangeSourceParameters prms = new DesignEditorUI.ChangeSourceParameters(transition, newSourceFigure.getModel());
ui.performAction(DesignEditorLID.ChangeSource, prms);
ui.getInteraction().setTransitionStatusMessage(transition);
}
hitTransition = null;
break;
}
case PotentialDuplicatingFrame:
{
DesignEditorFrame frameFig = ui.structureView.getFrameAtXY(mouseDownX, mouseDownY);
selection.setSelectedFrame(frameFig);
break;
}
case DuplicatingFrames:
{
double dx = scaledMouseUpX - scaledMouseDownX;
double dy = scaledMouseUpY - scaledMouseDownY;
// Remove all the rectangle figures from the display, clear the list
clearRectFigures();
DesignEditorUI.DuplicateParameters prm = new DesignEditorUI.DuplicateParameters(dx, dy, selection);
ui.performAction(DesignEditorLID.DuplicateFrame, prm);
break;
}
}
}
setMouseState(MouseUp);
mouseDown = false;
cleanup();
return goForward;
}
use of edu.cmu.cs.hcii.cogtool.model.Frame 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