use of edu.cmu.cs.hcii.cogtool.model.Transition in project cogtool by cogtool.
the class EditActionCmd method ensureActionIsUnique.
/**
* Check that the given action is not the same as that of another
* transition from the given source, where the other transition is
* different from the given transition. Thus, if checking when creating
* a new transition, the given currentTransition will be <code>null</code>.
* Otherwise, when modifying the action of an existing transition,
* currentTransition should be that transition.
*
* @param source the transition source widget/device in which the new
* action must be unique
* @param action the initial action value to test
* @param propertiess the default values for the interaction dialog box for
* specifying action property changes
* @param deviceTypes the device types currently available to allow
* for different action possibilities when not unique
* @param limitMode the limit on which device types can actually be used for
* selecting different action possibilities when not unique
* @param currentTransition the transition that the new action value should
* be attached to; use <code>null</code> when
* creating a new transition
* @param interaction the way to interact with the user
* @return the created action that is not in conflict, or <code>null</code>
* if the user requests a cancel of the current operation
* @author mlh
*/
public static AAction ensureActionIsUnique(TransitionSource source, AAction action, ActionProperties properties, int deviceTypes, int limitMode, Transition currentTransition, ActionInteraction interaction) {
// Check if given action has a transition on the given source
Transition actionTransition = source.getTransition(action);
// or must be the (existing) transition for the given action.
while ((actionTransition != null) && (actionTransition != currentTransition)) {
if (!interaction.determineNewAction(properties, deviceTypes, limitMode, action, source, currentTransition, L10N.get("DE.ChangeActionType", "Change Action Type"))) {
// user canceled operation
return null;
}
// Not canceled; build the action specified
action = buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
// the user may have requested a cancel; if so, propagate.
if (action == null) {
return null;
}
// A "legal" Action successfully created;
// check for uniqueness again!
actionTransition = source.getTransition(action);
}
// A "legal" and non-conflicting action was created; return!
return action;
}
use of edu.cmu.cs.hcii.cogtool.model.Transition in project cogtool by cogtool.
the class DesignEditorController method createDuplicateFramesEdit.
protected IUndoableEdit createDuplicateFramesEdit(final Frame[] frames) {
// Based on the code in deleteFrames
return new DemoStateManager.InvalidatingEdit(DesignEditorLID.DuplicateFrame, demoStateMgr) {
protected Transition[][] incidentTransitions = null;
protected boolean recoverMgrs = false;
@Override
public String getPresentationName() {
return (frames.length > 1) ? duplicateFrames : duplicateFrame;
}
@Override
public void redo() {
super.redo();
recoverMgrs = false;
for (int i = frames.length - 1; i >= 0; i--) {
design.addFrame(frames[i]);
}
for (int i = frames.length - 1; i >= 0; i--) {
DesignEditorCmd.addIncidentTransitions(incidentTransitions[i]);
}
stateMgr.noteFramesEdit(frames, this);
}
@Override
public void undo() {
super.undo();
recoverMgrs = true;
if (incidentTransitions == null) {
incidentTransitions = new Transition[frames.length][];
for (int i = 0; i < frames.length; i++) {
// Remove Transition instances for each Frame
incidentTransitions[i] = frames[i].removeIncidentTransitions();
}
for (Frame frame : frames) {
design.removeFrame(frame);
}
} else {
for (Frame frame : frames) {
frame.removeIncidentTransitions();
}
for (Frame frame : frames) {
design.removeFrame(frame);
}
}
stateMgr.noteFramesEdit(frames, this);
}
@Override
public void die() {
super.die();
if (recoverMgrs) {
for (Frame frame : frames) {
recoverManagers(frame);
}
}
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Transition in project cogtool by cogtool.
the class DesignEditorCmd method addIncidentTransitions.
public static void addIncidentTransitions(Transition[] transitions) {
// Maps Transition to the IWidget that is its source.
for (Transition transition : transitions) {
TransitionSource sourceWidget = transition.getSource();
sourceWidget.addTransition(transition);
}
}
use of edu.cmu.cs.hcii.cogtool.model.Transition in project cogtool by cogtool.
the class DesignExportToHTML method getMenuMap.
/**
* Return an array of three strings, corresponding to the three possible
* mouse buttons, representing either the name of the frame transitioned to
* by that button, or 'null'.
* NOTE: Hover and multiple-click transitions don't work with menu items.
*/
protected String getMenuMap(MenuItem child) {
String result = "[";
// TODO: onmouseup doesn't work for middle clicks...except
// sometimes it does, may be related to focus?
// Always use onmouseup instead of onclick because we need to check
// for double click here too
String[] mouseUpDests = new String[4];
mouseUpDests[0] = "null";
int mouseUpButton = 0;
Iterator<Transition> transitions = child.getTransitions().values().iterator();
while (transitions.hasNext()) {
Transition transition = transitions.next();
AAction action = transition.getAction();
if (action instanceof ButtonAction) {
ButtonAction bAction = (ButtonAction) action;
MouseButtonState buttonState = bAction.getButton();
MousePressType pressType = bAction.getPressType();
int button = -1;
String destName = getFrameURL(transition.getDestination(), ".html");
if (!MousePressType.Hover.equals(pressType)) {
if (MouseButtonState.Left.equals(buttonState)) {
button = LEFT_MOUSE;
} else if (MouseButtonState.Middle.equals(buttonState)) {
button = MIDDLE_MOUSE;
} else if (MouseButtonState.Right.equals(buttonState)) {
button = RIGHT_MOUSE;
}
/*if (MousePressType.Click.equals(pressType) &&
(button == LEFT_MOUSE))
{
//onAction = "onclick";
// clickDest = "'" + destName + "'";
mouseUpButton = button;
mouseUpDests[mouseUpButton] = "'" + destName + "'";
}
else */
if (MousePressType.Up.equals(pressType) || MousePressType.Click.equals(pressType)) {
//onAction = "onmouseup";
mouseUpButton = button;
mouseUpDests[mouseUpButton] = "'" + destName + "'";
}
// else if (MousePressType.Double.equals(pressType)) {
// //onAction = "ondblclick";
// dblClickButton = button;
// dblClickDests[dblClickButton] = "'" + destName + "'";
// }
// else if (MousePressType.Down.equals(pressType)) {
// onAction = "onmousedown";
// }
}
} else if (action instanceof TapAction) {
TapAction bAction = (TapAction) action;
TapPressType pressType = bAction.getTapPressType();
String destName = getFrameURL(transition.getDestination(), ".html");
if (!TapPressType.Hover.equals(pressType)) {
if (TapPressType.Tap.equals(pressType)) {
// TODO: Behavior is undefined if both a left-click and
// tap transition are created from the same widget!
//onAction = "onclick";
// clickDest = "'" + destName + "'";
mouseUpButton = LEFT_MOUSE;
mouseUpDests[mouseUpButton] = "'" + destName + "'";
}
// else if (TapPressType.Up.equals(pressType)) {
// onAction = "onmouseup";
// }
// else if (TapPressType.DoubleTap.equals(pressType)) {
// //onAction = "ondblclick";
// // TODO see tap
// dblClickButton = LEFT_MOUSE;
// dblClickDests[dblClickButton] = "'" + destName + "'";
// }
// else if (TapPressType.Down.equals(pressType)) {
// //onAction = "onmousedown";
// }
}
}
}
for (int i = 1; i < mouseUpDests.length; i++) {
if (mouseUpDests[i] == null) {
mouseUpDests[i] = "null";
}
// if (dblClickDests[i] == null) {
// dblClickDests[i] = "null";
// }
result += mouseUpDests[i];
if (i < 3) {
result += ", ";
}
}
result += "]";
return result;
}
use of edu.cmu.cs.hcii.cogtool.model.Transition in project cogtool by cogtool.
the class DesignExportToHTML method buildKeyTransitionMap.
/**
* Outputs a Javascript function that makes a map from the transition
* string to the name of the destination frame
* (treats Graffiti transitions as keyboard transitions)
*/
protected String buildKeyTransitionMap(Collection<InputDevice> devices, Collection<IWidget> widgets) {
StringBuilder html = new StringBuilder();
Iterator<InputDevice> deviceIterator = devices.iterator();
while (deviceIterator.hasNext()) {
InputDevice device = deviceIterator.next();
if (DeviceType.Keyboard.equals(device.getDeviceType()) || DeviceType.Touchscreen.equals(device.getDeviceType())) {
// first save all transitions from the device
Iterator<Transition> transitions = device.getTransitions().values().iterator();
while (transitions.hasNext()) {
Transition transition = transitions.next();
AAction action = transition.getAction();
if (action instanceof TextAction) {
String text = cleanup(((TextAction) action).getText());
html.append("keyTransitionMap[\"" + text + "\"]");
html.append(" = \'");
html.append(getFrameURL(transition.getDestination(), ".html"));
html.append("\';\n");
}
}
}
}
Iterator<IWidget> widgetIterator = widgets.iterator();
// NOTE: does not work with list box items or any menus
while (widgetIterator.hasNext()) {
IWidget w = widgetIterator.next();
String name = "\"" + w.getName() + "\"";
Iterator<Transition> wTransitions = w.getTransitions().values().iterator();
boolean foundKeyTransition = false;
while (wTransitions.hasNext()) {
Transition transition = wTransitions.next();
AAction action = transition.getAction();
if (action instanceof TextAction) {
if (!foundKeyTransition) {
foundKeyTransition = true;
html.append("focusTransitionMaps[" + name + "] = new Object();\n");
}
String key = "\"" + cleanup(((TextAction) action).getText()) + "\"";
String dest = "'" + getFrameURL(transition.getDestination(), ".html") + "'";
html.append("focusTransitionMaps[" + name + "][");
html.append(key + "] = " + dest + ";\n");
}
}
}
return html.toString();
}
Aggregations