use of edu.cmu.cs.hcii.cogtool.model.InputDevice in project cogtool by cogtool.
the class DefaultSEUIModel method updateDeviceDisplay.
public void updateDeviceDisplay() {
if ((currentFrame != null) && (devicesFooter != null)) {
Control[] deviceLabels = devicesFooter.getChildren();
double midIndex = 0.5 * (deviceLabels.length - 1);
for (int i = 0; i < deviceLabels.length; i++) {
DeviceType deviceType = (DeviceType) deviceLabels[i].getData(DEVICE_TYPE_KEY);
if (deviceType != null) {
Frame currentFrameModel = currentFrame.getFrame();
InputDevice inputDevice = currentFrameModel.getInputDevice(deviceType);
String text = AbstractGraphicalSource.buildToolTipText(inputDevice, deviceType.toString());
text = KeyDisplayUtil.convertActionToMenuText(text);
deviceLabels[i].setToolTipText(" " + text + " ");
deviceLabels[i].setData(inputDevice);
FormData formData = new FormData();
formData.top = new FormAttachment(0, 0);
formData.bottom = new FormAttachment(100, 0);
formData.width = DesignUtil.DEVICE_WIDTH;
double ii = i;
if (ii == (midIndex - 0.5)) {
formData.right = new FormAttachment(50, -(DEVICE_MARGIN / 2));
} else if (ii < midIndex) {
formData.right = new FormAttachment(deviceLabels[i + 1], -DEVICE_MARGIN, SWT.LEFT);
} else if (ii == midIndex) {
formData.left = new FormAttachment(50, -(DesignUtil.DEVICE_WIDTH / 2));
} else if (ii == (midIndex + 0.5)) {
formData.left = new FormAttachment(50, DEVICE_MARGIN / 2);
} else {
// ii > midIndex
formData.left = new FormAttachment(deviceLabels[i - 1], DEVICE_MARGIN, SWT.RIGHT);
}
deviceLabels[i].setLayoutData(formData);
}
}
devicesFooter.layout();
}
}
use of edu.cmu.cs.hcii.cogtool.model.InputDevice in project cogtool by cogtool.
the class StructureViewUIModel method installFrameTransitions.
/**
* Create the visible representations for all of the transitions
* emanating from all source objects (widgets/devices) of a frame.
* <p>
* The figures for transition sources and destination frames
* must be created/installed before attempting to create/install
* the visible representations for transitions.
*
* @param frame the frame containing the sources of the
* transitions to install
* @param sourceFrame the figure representing frame in the structure view
* @author mlh
*/
protected void installFrameTransitions(Frame frame, DesignEditorFrame sourceFrame) {
Iterator<IWidget> widgets = frame.getWidgets().iterator();
while (widgets.hasNext()) {
IWidget widget = widgets.next();
installSourceTransitions(sourceFrame, widget);
}
Iterator<InputDevice> devices = frame.getInputDevices().iterator();
while (devices.hasNext()) {
InputDevice device = devices.next();
installSourceTransitions(sourceFrame, device);
}
}
use of edu.cmu.cs.hcii.cogtool.model.InputDevice in project cogtool by cogtool.
the class ActionProperties method updateProperties.
public void updateProperties(TransitionDelay td, AAction action, TransitionSource transitionSource) {
delayInSecs = td.getDelayInSecs();
delayLabel = td.getDelayLabel();
Transition tr = transitionSource.getTransitions().get(action);
if (tr != null) {
// null if self-transition
transitionDestinationLabel = tr.getDestination().getName();
}
if (transitionSource instanceof IWidget) {
// TODO: Must modify this when text fields are added.
// Text fields may not use "ButtonAction"
AAction.ActionVisitor widgetActionVisitor = new AAction.ActionVisitor() {
@Override
public void visit(ButtonAction but) {
mouseButton = but.getButton();
buttonAction = but.getPressType();
if (buttonAction == MousePressType.Hover) {
mouseButton = null;
}
buttonState = but.getModifiers();
useWhichParts = ActionProperties.USE_MOUSE;
}
@Override
public void visit(TapAction tap) {
tapAction = tap.getTapPressType();
useWhichParts = ActionProperties.USE_TOUCHSCREEN;
}
@Override
public void visit(KeyAction key) {
keyboardString = key.getText();
keyboardIsCmd = key.isCommand();
keyboardAction = key.getPressType();
useWhichParts = ActionProperties.USE_KEYBOARD;
}
@Override
public void visit(GraffitiAction graffiti) {
graffitiString = graffiti.getText();
graffitiIsCmd = graffiti.isCommand();
useWhichParts = ActionProperties.USE_GRAFFITI_WIDGET;
}
@Override
public void visit(VoiceAction voice) {
voiceString = voice.getText();
voiceIsCmd = voice.isCommand();
useWhichParts = ActionProperties.USE_VOICE;
}
};
action.accept(widgetActionVisitor);
String t = ((IWidget) transitionSource).getTitle();
if (t.length() > 0) {
transitionSourceLabel = t + " in " + ((IWidget) transitionSource).getFrame().getName();
} else {
transitionSourceLabel = ((IWidget) transitionSource).getName() + " in " + ((IWidget) transitionSource).getFrame().getName();
}
} else {
InputDevice deviceSource = (InputDevice) transitionSource;
DeviceType type = deviceSource.getDeviceType();
if (type == DeviceType.Voice) {
VoiceAction voiceAction = (VoiceAction) action;
voiceString = voiceAction.getText();
voiceIsCmd = voiceAction.isCommand();
useWhichParts = ActionProperties.USE_VOICE;
} else {
KeyAction keyAction = (KeyAction) action;
keyboardString = keyAction.getText();
keyboardAction = keyAction.getPressType();
keyboardIsCmd = keyAction.isCommand();
useWhichParts = ActionProperties.USE_KEYBOARD;
}
transitionSourceLabel = "";
}
}
use of edu.cmu.cs.hcii.cogtool.model.InputDevice in project cogtool by cogtool.
the class DesignEditorController method createPasteAction.
protected IListenerAction createPasteAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
try {
Collection<Object> objects = CogToolClipboard.fetchCogToolObjects();
if ((objects != null) && (objects.size() > 0)) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(L10N.get("UNDO.Paste", "Paste"), DesignEditorLID.Paste);
Set<DeviceType> devTypes = design.getDeviceTypes();
int numPasted = 0;
Iterator<Object> objIt = objects.iterator();
while (objIt.hasNext()) {
Object o = objIt.next();
if (o instanceof Frame) {
Frame frame = (Frame) o;
makeFrameNameUnique(frame);
// Find an unoccupied starting position
// by cascading.
DoublePoint origin = frame.getFrameOrigin();
DesignUtil.findDistinctOrigin(design, origin, 16.0, 16.0);
// Union devices
Iterator<InputDevice> frameDevices = frame.getInputDevices().iterator();
while (frameDevices.hasNext()) {
InputDevice inputDevice = frameDevices.next();
DeviceType devType = inputDevice.getDeviceType();
if (!devTypes.contains(devType)) {
DesignCmd.addDevice(design, devType);
}
}
Iterator<DeviceType> designDevTypes = devTypes.iterator();
while (designDevTypes.hasNext()) {
DeviceType devType = designDevTypes.next();
if (frame.getInputDevice(devType) == null) {
frame.addInputDevice(devType);
}
}
addFrame(frame, editSequence);
numPasted++;
} else if (o instanceof Transition) {
Transition t = (Transition) o;
DeviceType device = t.getAction().getDefaultDeviceType();
if (!devTypes.contains(device)) {
DesignCmd.addDevice(design, device);
}
IUndoableEdit edit = DesignEditorCmd.addTransition(demoStateMgr, t);
editSequence.addEdit(edit);
numPasted++;
}
}
editSequence.end();
undoMgr.addEdit(editSequence);
interaction.setStatusMessage(numPasted + " " + pasteComplete);
} else {
interaction.setStatusMessage(nothingPasted);
}
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (ParserConfigurationException e) {
throw new RcvrClipboardException(e);
} catch (SAXException e) {
throw new RcvrClipboardException(e);
} catch (ClipboardUtil.ClipboardException e) {
throw new RcvrClipboardException(e);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.InputDevice in project cogtool by cogtool.
the class EditActionCmd method createDefaultAction.
// buildActionFromProperties
/**
* Based on the given transition source and/or the given type of transition
* to prefer, return a new action based on the current default settings.
* The current default settings are also copied into the controller's
* ActionProperties instance variable. If it is not possible to create
* the action, <code>null</code> is returned.
*
* @param source
* @return
*/
public static AAction createDefaultAction(Design design, TransitionSource source, ActionType desiredTransitionType, ActionProperties properties) {
if (source instanceof InputDevice) {
InputDevice device = (InputDevice) source;
DeviceType type = device.getDeviceType();
if (type == DeviceType.Keyboard) {
return properties.createKeyAction();
}
if (type == DeviceType.Voice) {
return properties.createVoiceAction();
}
}
// At this point, ensure source is an IWidget!
if (source instanceof IWidget) {
IWidget widget = (IWidget) source;
if (desiredTransitionType == ActionProperties.BASE_ACTION_ON_SOURCE) {
if (widget.getWidgetType() == WidgetType.Graffiti) {
return properties.createGraffitiAction();
}
Set<DeviceType> designDeviceTypes = design.getDeviceTypes();
// If both mouse and touchscreen exist, mouse has precedence
if (designDeviceTypes.contains(DeviceType.Mouse)) {
return properties.createMouseAction();
}
if (designDeviceTypes.contains(DeviceType.Touchscreen)) {
return properties.createTouchAction();
}
// Only other devices available should be Keyboard or Voice!
if (designDeviceTypes.contains(DeviceType.Keyboard)) {
return properties.createKeyAction();
}
if (designDeviceTypes.contains(DeviceType.Voice)) {
return properties.createVoiceAction();
}
} else {
// Base action on desiredTransitionType
if (desiredTransitionType == ActionType.ButtonPress) {
return properties.createMouseAction();
} else if (desiredTransitionType == ActionType.KeyPress) {
return properties.createKeyAction();
} else if (desiredTransitionType == ActionType.Tap) {
return properties.createTouchAction();
} else if (desiredTransitionType == ActionType.GraffitiStroke) {
return properties.createGraffitiAction();
} else if (desiredTransitionType == ActionType.Voice) {
return properties.createVoiceAction();
}
}
}
return null;
}
Aggregations