use of edu.cmu.cs.hcii.cogtool.model.DeviceType in project cogtool by cogtool.
the class SEDemoMouseState method doTransitionAction.
protected boolean doTransitionAction(TransitionSource source, int button, int state, int clickState) {
AAction action = null;
Set<DeviceType> deviceTypes = ui.design.getDeviceTypes();
if (deviceTypes.contains(DeviceType.Mouse)) {
MousePressType pt = null;
switch(clickState) {
case UP:
pt = MousePressType.Up;
break;
case DOWN:
pt = MousePressType.Down;
break;
case CLICK:
pt = MousePressType.Click;
break;
case DOUBLE:
pt = MousePressType.Double;
break;
case TRIPLE:
pt = MousePressType.Triple;
break;
default:
throw new IllegalArgumentException("Invalid click state received");
}
action = new ButtonAction(getActionButtonButton(button), pt, getActionButtonModifier(state));
} else if (deviceTypes.contains(DeviceType.Touchscreen)) {
TapPressType tt = null;
switch(clickState) {
case UP:
tt = TapPressType.Up;
break;
case DOWN:
tt = TapPressType.Down;
break;
case CLICK:
tt = TapPressType.Tap;
break;
case DOUBLE:
tt = TapPressType.DoubleTap;
break;
case TRIPLE:
tt = TapPressType.TripleTap;
break;
default:
throw new IllegalArgumentException("Invalid ClickState received");
}
action = new TapAction(tt);
}
if (clickState == CLICK) {
if (source.getTransition(action) == null) {
// Check to see if a doubleclick/doubletap is in the set of
// transitions
Iterator<AAction> iter = source.getTransitions().keySet().iterator();
while (iter.hasNext()) {
AAction act = iter.next();
if ((act.getType() == ActionType.ButtonPress) && deviceTypes.contains(DeviceType.Mouse)) {
} else if ((act.getType() == ActionType.Tap) && deviceTypes.contains(DeviceType.Touchscreen)) {
}
}
if ((source instanceof IWidget) && ((IWidget) source).isStandard() && deviceTypes.contains(DeviceType.Mouse)) {
WidgetType type = ((IWidget) source).getWidgetType();
Object toggle = source.getAttribute(WidgetAttributes.IS_TOGGLEABLE_ATTR);
Object isSep = source.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if ((type == WidgetType.Check) || (type == WidgetType.Radio) || ((type == WidgetType.PullDownItem) && NullSafe.equals(WidgetAttributes.NON_SEPARATOR, isSep)) || ((type == WidgetType.Button) && NullSafe.equals(WidgetAttributes.IS_TOGGLEABLE, toggle))) {
if (type == WidgetType.PullDownItem) {
ui.hideAllChildren();
}
AAction a = new ButtonAction(MouseButtonState.Left, MousePressType.Click, 0);
SEDemoUI.SelfTransition prms = new SEDemoUI.SelfTransition(ui.selection, source, a);
ui.performAction(SEDemoLID.InsertSelfTransition, prms);
return true;
}
}
ui.showContextMenu(source);
}
}
Transition transition = source.getTransition(action);
if (transition != null) {
SEDemoUI.FollowTransition prms = new SEDemoUI.FollowTransition(ui.selection, transition);
ui.performAction(SEDemoLID.PerformTransition, prms);
return true;
}
return false;
}
use of edu.cmu.cs.hcii.cogtool.model.DeviceType 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.DeviceType in project cogtool by cogtool.
the class ProjectController method createNewDesignForImport.
// createNewDesignAction
// Action for NewDesign2, createNewDesignForImport
protected IListenerAction createNewDesignForImport() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignSelectionState.class;
// return Class.class;
}
public boolean performAction(Object prms) {
//call convert on the converter file
Class<ImportConverter> translatorClass = CogToolLID.NewDesignFromImport.getClassAttribute();
//CogToolLID.NewDesignFromImport.setClassAttribute(null);
Object converter = null;
try {
converter = translatorClass.newInstance();
} catch (InstantiationException e) {
throw new RcvrImportException("Translator class cannot be instantiated.");
} catch (IllegalAccessException e) {
throw new RcvrImportException("The translator class is not accessible.");
}
Design design = null;
Method isInputFileDirectory = null;
try {
isInputFileDirectory = translatorClass.getMethod("isInputFileDirectory", new Class[0]);
} catch (SecurityException e) {
throw new RcvrImportException("The security manager does not allow access to this method.");
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
throw new RcvrImportException("isInputFileDirectory does not exist in the converter file.");
}
boolean reqDir = false;
try {
reqDir = (Boolean) isInputFileDirectory.invoke(converter);
} catch (IllegalArgumentException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IllegalAccessException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (InvocationTargetException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
//parameters needed to be passed to importDesign. A file and design are passed.
Class<?>[] parameters = new Class<?>[2];
parameters[0] = File.class;
parameters[1] = Design.class;
Method importDesignMethod = null;
try {
importDesignMethod = translatorClass.getMethod("importDesign", parameters);
} catch (SecurityException e) {
throw new RcvrImportException("The security manager does not allow access to this method.");
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String designName = "";
/*Instead of a inputFile, a directory was specified. Every file in the directory
needs to be parsed */
Method allowedExtsMethod = null;
try {
allowedExtsMethod = translatorClass.getMethod("allowedExtensions", new Class[0]);
} catch (SecurityException e) {
throw new RcvrImportException("The security manager does not allow access to this method.");
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] extensions = null;
try {
extensions = (String[]) allowedExtsMethod.invoke(converter);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (reqDir) {
/*TODO: Need to confirm that directory name is guaranteed to only accept a directory*/
String directoryName = interaction.askUserForDirectory("Choose a directory of files", "This directory contains the files that you wish to import.");
if (directoryName != null) {
File directory = new File(directoryName);
if (directory != null) {
//TODO: What to do about importing it twice, designName [2];
designName = directory.getName();
Set<DeviceType> deviceTypeSet = new HashSet<DeviceType>();
Method selectedDevicesMethod = null;
try {
selectedDevicesMethod = translatorClass.getMethod("selectedDevices", new Class[0]);
} catch (SecurityException e) {
throw new RcvrImportException("The security manager does not allow access to this method.");
} catch (NoSuchMethodException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
deviceTypeSet = (Set<DeviceType>) selectedDevicesMethod.invoke(converter);
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InvocationTargetException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ProjectInteraction.DesignRequestData requestData = new ProjectInteraction.DesignRequestData();
requestData.designName = designName;
requestData.deviceTypes = deviceTypeSet;
//TODO: may need to keep checking the value that this returns
interaction.requestNewDesignName(requestData, false, project, false);
design = new Design(requestData.designName, requestData.deviceTypes);
makeDesignNameUnique(design);
// Collection<DeviceType> deviceTypes = (Collection<DeviceType>)
// designLoader.createCollection(design, Design.deviceTypesVAR, 1);
// Collection<?> frames =
//designLoader.createCollection(design, Design.framesVAR, 1);
File[] directoryContents = directory.listFiles();
for (File file : directoryContents) {
String fileName = file.getName();
//If there is no extension then null is the file extension
String fileExt = (fileName.lastIndexOf(".") == -1) ? null : fileName.substring(fileName.lastIndexOf('.'));
//Example: ".txt" will now be "txt" and . will now be ""
if (fileExt != null) {
fileExt = (fileExt.length()) > 1 ? fileExt = fileExt.substring(1) : "";
}
for (String extension : extensions) {
if (extension == null || extension.equalsIgnoreCase(fileExt)) {
try {
importDesignMethod.invoke(converter, file, design);
break;
/* Break is needed if the converter author placed the same
* extension in the array twice then this conversion will
* not occur more than once. */
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
//throw new RcvrImportXmlException("Not a valid XML file to parse.");
//ignore
System.out.println("fileName " + fileName);
break;
}
}
}
}
}
}
} else {
File importFile = interaction.selectFile(true, null, extensions);
try {
designName = importFile.getName();
//TODO: ask user for design name since it can be different from the filename
Set<DeviceType> deviceTypeSet = new HashSet<DeviceType>();
design = new Design(designName, deviceTypeSet);
makeDesignNameUnique(design);
//Collection<DeviceType> deviceTypes = (Collection<DeviceType>)
//designLoader.createCollection(design, Design.deviceTypesVAR, 1);
//Collection<?> frames =
// designLoader.createCollection(design, Design.framesVAR, 1);
System.out.println("design " + design.getName());
importDesignMethod.invoke(converter, importFile, design);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//change inputfile to the specific file
}
if (design != null) {
ProjectCmd.addNewDesign(project, design, ((DesignSelectionState) prms).getSelectedDesign(), NEW_DESIGN, undoMgr);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.DeviceType 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.DeviceType in project cogtool by cogtool.
the class DesignEditorUI method getDefaultProperties.
public void getDefaultProperties(TransitionSource source, ActionProperties properties) {
view.getDefaultProperties(properties);
ActionType transitionType = getCurrentActionType();
Set<DeviceType> deviceTypes = uiModel.getDesign().getDeviceTypes();
properties.setInitialActionType(source, transitionType, deviceTypes);
}
Aggregations