use of edu.cmu.cs.hcii.cogtool.model.WidgetType in project cogtool by cogtool.
the class FrameEditorController method changeWidgetType.
private void changeWidgetType(ListenerIdentifier lid, final String presentation, final IWidget widget, final WidgetType newWidgetType, IUndoableEditSequence editSequence) {
final WidgetType oldWidgetType = widget.getWidgetType();
// Don't make a non-changing edit!
if (!oldWidgetType.equals(newWidgetType)) {
// Set the new widget type
widget.setWidgetType(newWidgetType);
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(lid, demoStateMgr) {
@Override
public String getPresentationName() {
return presentation;
}
@Override
public void redo() {
super.redo();
widget.setWidgetType(newWidgetType);
noteEditCheckRegenerate(widget, this);
}
@Override
public void undo() {
super.undo();
widget.setWidgetType(oldWidgetType);
noteEditCheckRegenerate(widget, this);
}
};
noteEditCheckRegenerate(widget, edit);
editSequence.addEdit(edit);
}
}
use of edu.cmu.cs.hcii.cogtool.model.WidgetType in project cogtool by cogtool.
the class SEDemoController method toggleIfGermane.
private boolean toggleIfGermane(IWidget widget, AScriptStep selfTransitionStep, AAction action) {
WidgetType widgetType = widget.getWidgetType();
ActionType actionType = action.getType();
if (widget.isStandard() && ((actionType == ActionType.Tap) || ((actionType == ActionType.ButtonPress) && (((ButtonAction) action).getButton() == MouseButtonState.Left)))) {
if (widgetType == WidgetType.Check) {
selfTransitionStep.overrideAttribute(widget, WidgetAttributes.IS_SELECTED_ATTR, WidgetAttributes.TOGGLE_SELECTION);
} else if (widgetType == WidgetType.Radio) {
selfTransitionStep.overrideAttribute(widget.getParentGroup(), WidgetAttributes.SELECTION_ATTR, widget);
} else if (widgetType == WidgetType.Button) {
// Override regardless of the button's "toggleability"
// because the user can always change this attribute in the
// frame
selfTransitionStep.overrideAttribute(widget, WidgetAttributes.IS_SELECTED_ATTR, WidgetAttributes.TOGGLE_SELECTION);
} else if (widgetType == WidgetType.PullDownItem) {
PullDownItem pdi = (PullDownItem) widget;
Object value = pdi.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if (NullSafe.equals(WidgetAttributes.NON_SEPARATOR, value)) {
selfTransitionStep.overrideAttribute(pdi.getParent(), WidgetAttributes.SELECTION_ATTR, widget);
}
}
return true;
} else {
return false;
}
}
use of edu.cmu.cs.hcii.cogtool.model.WidgetType in project cogtool by cogtool.
the class ActionProperties method setInitialActionType.
/**
* Base initial action type on given source
*/
public void setInitialActionType(TransitionSource source, Set<DeviceType> deviceTypes) {
if (source instanceof InputDevice) {
InputDevice device = (InputDevice) source;
DeviceType devType = device.getDeviceType();
if (devType == DeviceType.Keyboard) {
useWhichParts = USE_KEYBOARD;
} else if (devType == DeviceType.Mouse) {
useWhichParts = USE_MOUSE;
} else if (devType == DeviceType.Touchscreen) {
useWhichParts = USE_TOUCHSCREEN;
} else if (devType == DeviceType.Voice) {
useWhichParts = USE_VOICE;
}
} else if (source instanceof IWidget) {
IWidget widget = (IWidget) source;
WidgetType widgetType = widget.getWidgetType();
if (widgetType == WidgetType.Graffiti) {
useWhichParts = USE_GRAFFITI_WIDGET;
} else if (widgetType == WidgetType.TextBox) {
useWhichParts = USE_KEYBOARD;
} else {
setInitialActionType(source, BASE_ACTION_ON_SOURCE, deviceTypes);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.WidgetType in project cogtool by cogtool.
the class WidgetPropertiesPane method showAttributeWidgets.
public void showAttributeWidgets(IWidget widget) {
WidgetType type = widget.getWidgetType();
widgetTitle.setText(DISPLAYED_LABEL);
Object pathObj = widget.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
if (!NullSafe.equals(WidgetAttributes.NO_IMAGE, pathObj)) {
String imgPath = (String) pathObj;
imagePath.setVisible(true);
imagePathText.setVisible(true);
imagePathText.setText(imgPath);
imagePathText.setSelection(imgPath.length());
}
if ((type == WidgetType.MenuItem) || (type == WidgetType.PullDownItem) || (type == WidgetType.ListBoxItem)) {
isSeparator.setVisible(true);
Object value = widget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
boolean isSep = NullSafe.equals(WidgetAttributes.IS_SEPARATOR, value);
isSeparator.setSelection(isSep);
widgetTitleText.setEnabled(!isSep);
widgetAuxText.setEnabled(!isSep);
}
// Remote label support
// First check if this is a remote label
FrameElement remoteLabelOwner = (FrameElement) widget.getAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR);
if (remoteLabelOwner != null) {
String ownerWidgetName = remoteLabelOwner.getName();
if ((ownerWidgetName == null) || ownerWidgetName.equals("")) {
if (remoteLabelOwner instanceof RadioButtonGroup) {
ownerWidgetName = "[ anonymous radio button group ]";
} else if (remoteLabelOwner instanceof GridButtonGroup) {
ownerWidgetName = "[ anonymous checkbox group ]";
} else if (remoteLabelOwner instanceof SimpleWidgetGroup) {
ownerWidgetName = "[ anonymous widget group ]";
} else if (remoteLabelOwner instanceof SimpleWidgetGroup) {
ownerWidgetName = "[ unnamed element group ]";
} else {
ownerWidgetName = "[ unnamed widget ]";
}
}
this.remoteLabelOwner.setVisible(true);
remoteLabelOwnerName.setVisible(true);
remoteLabelOwnerName.setText("<a>" + ownerWidgetName + "</a>");
remoteLabelType.setVisible(true);
remoteLabelTypeCombo.setVisible(true);
selectCurrentValue(remoteLabelTypeCombo, widgetTypeChoices, widget.getWidgetType());
imagePath.setLayoutData(isRemoteLabelAlign);
} else {
// Otherwise, check if this widget has a remote label
remoteLabelOwner = widget.getRemoteLabelOwner();
// reset layout to eliminate space for the remote label
if (remoteLabelOwner == null) {
imagePath.setLayoutData(noRemoteLabelAlign);
} else {
IWidget remoteLabelWidget = (IWidget) remoteLabelOwner.getAttribute(WidgetAttributes.REMOTE_LABEL_ATTR);
if (remoteLabelWidget != null) {
remoteLabelText.setText(remoteLabelWidget.getTitle());
remoteLabelFind.setVisible(true);
} else {
// Display an empty remote label stuff to allow one to be set
remoteLabelText.setText("");
remoteLabelFind.setVisible(false);
}
remoteLabel.setVisible(true);
remoteLabelText.setVisible(true);
imagePath.setLayoutData(hasRemoteLabelAlign);
}
}
if (!widget.isStandard()) {
layout();
return;
}
if ((type == WidgetType.Menu) || (type == WidgetType.ContextMenu)) {
submenuActionLabel.setVisible(true);
submenuAction.setVisible(true);
submenuDelayLabel.setVisible(true);
submenuDelay.setVisible(true);
Integer submenuAction = (Integer) widget.getAttribute(WidgetAttributes.SUBMENU_ACTION_ATTR);
selectCurrentValue(this.submenuAction, submenuActions, submenuAction);
Double delay = (Double) widget.getAttribute(WidgetAttributes.SUBMENU_DELAY_ATTR);
if (NullSafe.equals(WidgetAttributes.NO_SUBMENU_DELAY, delay)) {
submenuDelay.select(0);
} else if (NullSafe.equals(WidgetAttributes.PC_SUBMENU_DELAY, delay)) {
submenuDelay.select(1);
} else {
submenuDelay.setText(delay.toString() + " s");
}
if (type == WidgetType.ContextMenu) {
contextMenuActionLabel.setVisible(true);
contextMenuAction.setVisible(true);
Integer contextAction = (Integer) widget.getAttribute(WidgetAttributes.CONTEXT_MENU_ACTION_ATTR);
selectCurrentValue(contextMenuAction, contextMenuActions, contextAction);
}
}
if (type == WidgetType.Check) {
isInitiallySelected.setVisible(true);
Boolean selected = (Boolean) widget.getAttribute(WidgetAttributes.IS_SELECTED_ATTR);
isInitiallySelected.setSelection(selected.booleanValue());
} else if (type == WidgetType.Button) {
// TODO: "clicked-on" for Link?
isToggleable.setVisible(true);
Boolean selected = (Boolean) widget.getAttribute(WidgetAttributes.IS_TOGGLEABLE_ATTR);
isToggleable.setSelection(selected.booleanValue());
isButtonSelected.setEnabled(selected.booleanValue());
isButtonSelected.setVisible(true);
selected = (Boolean) widget.getAttribute(WidgetAttributes.IS_SELECTED_ATTR);
isButtonSelected.setSelection(selected.booleanValue());
} else if (type == WidgetType.TextBox) {
// this.isMultiLine.setVisible(true);
//
// Boolean multi =
// (Boolean) widget.getAttribute(WidgetType.IS_MULTILINE_ATTR);
//
// this.isMultiLine.setSelection(multi.booleanValue());
widgetTitle.setText(TEXT_CONTENTS);
} else if (type == WidgetType.Radio) {
selectLabel.setVisible(true);
initiallySelected.setVisible(true);
initiallySelected.removeAll();
initiallySelected.add(SELECT_NONE);
RadioButtonGroup group = (RadioButtonGroup) widget.getParentGroup();
if (group != null) {
Iterator<IWidget> widgets = group.iterator();
IWidget[] map = new IWidget[group.size()];
int i = 0;
while (widgets.hasNext()) {
IWidget curWidget = widgets.next();
map[i++] = curWidget;
String name = curWidget.getNameLabel();
initiallySelected.add(name);
}
// This works because null isn't in the list so indexOf
// returns -1 if SELECT_NONE is chosen
int index = group.indexOf(group.getSelection()) + 1;
initiallySelected.select(index);
selectionAttrListener.setAttributeHelper(RADIO_HELPER, map);
}
} else if (type == WidgetType.PullDownList) {
selectLabel.setVisible(true);
initiallySelected.setVisible(true);
initiallySelected.removeAll();
initiallySelected.add(SELECT_NONE);
initiallySelected.select(0);
SimpleWidgetGroup group = ((AParentWidget) widget).getChildren();
Iterator<IWidget> widgets = group.iterator();
IWidget[] map = new IWidget[group.size()];
int i = 0;
Widget selected = (Widget) widget.getAttribute(WidgetAttributes.SELECTION_ATTR);
while (widgets.hasNext()) {
IWidget curWidget = widgets.next();
Object isSep = curWidget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if (NullSafe.equals(WidgetAttributes.NON_SEPARATOR, isSep)) {
String name = curWidget.getNameLabel();
initiallySelected.add(name);
if (curWidget == selected) {
initiallySelected.select(i + 1);
}
map[i++] = curWidget;
}
}
selectionAttrListener.setAttributeHelper(PULLDOWN_HELPER, map);
}
// TODO implement list box support
// else if (type == WidgetType.ListBoxItem) {
// this.selectLabel.setVisible(true);
// this.initiallySelected.setVisible(true);
// this.initiallySelected.removeAll();
// this.initiallySelected.add(SELECT_NONE);
// this.visibleLabel.setVisible(true);
// this.firstVisible.setVisible(true);
// this.firstVisible.removeAll();
// this.numVisibleLabel.setVisible(true);
// this.numVisible.setVisible(true);
//
// SimpleWidgetGroup group = widget.getParentGroup();
//
// Integer num =
// (Integer) group.getAttribute(WidgetType.NUM_VISIBLE_ATTR);
// this.numVisible.setSelection(num.intValue());
//
// Iterator<IWidget> widgets = group.getAllWidgets();
// while (widgets.hasNext()) {
// IWidget curWidget = widgets.next();
// String name = curWidget.getDisplayLabel();
// this.initiallySelected.add(name);
// this.firstVisible.add(name);
// }
//
// IWidget init =
// (IWidget) group.getAttribute(WidgetType.SELECTION_ATTR);
// int ind = group.indexOf(init) + 1;
// this.initiallySelected.select(ind);
// init = (IWidget) group.getAttribute(WidgetType.FIRST_VISIBLE_ATTR);
// ind = group.indexOf(init);
// this.firstVisible.select(ind);
// }
layout();
}
use of edu.cmu.cs.hcii.cogtool.model.WidgetType in project cogtool by cogtool.
the class WidgetPropertiesPane method createWidgets.
protected void createWidgets() {
// set up widgets, set disabled for launch
widgetName = new DisplayLabel(this, SWT.NONE);
widgetName.setText(L10N.get("FE.WidgetNameCaption", "Widget Name") + ":");
widgetNameText = new WidgetChangeText(this, SWT.SINGLE | SWT.BORDER, FrameEditorLID.ChangeNameProperty, view);
widgetTitle = new DisplayLabel(this, SWT.NONE);
widgetTitle.setText(DISPLAYED_LABEL);
widgetTitleText = new WidgetChangeText(this, SWT.SINGLE | SWT.BORDER, FrameEditorLID.ChangeTitleProperty, view);
widgetAux = new DisplayLabel(this, SWT.NONE);
widgetAux.setText(AUX_TEXT_LABEL);
widgetAuxText = new WidgetChangeText(this, SWT.SINGLE | SWT.BORDER, FrameEditorLID.ChangeAuxTextProperty, view);
widgetType = new DisplayLabel(this, SWT.NONE);
widgetType.setText(L10N.get("FE.WidgetTypeCaption", "Type") + ":");
widgetTypeLabel = new Label(this, SWT.NONE);
widgetMode = new DisplayLabel(this, SWT.NONE);
widgetMode.setText(L10N.get("FE.WidgetModeCaption", "Mode") + ":");
widgetModeValue = new Label(this, SWT.NONE);
widgetRender = new Button(this, SWT.CHECK);
widgetRender.setText(L10N.get("FE.WidgetRenderedCaption", "Render Widget Skin"));
// Add listener to the rendered widget property
widgetRender.addSelectionListener(view.createWidgetChgHandler(FrameEditorLID.SetRenderSkin));
remoteLabel = new DisplayLabel(this, SWT.NONE);
remoteLabel.setText(L10N.get("FE.RemoteLabelCaption", "Remote Label") + ":");
remoteLabelFind = new Link(this, SWT.NONE);
remoteLabelFind.setText(L10N.get("FE.RemoteLabelFind", "<a>Find</a>"));
remoteLabelFind.setFont(FontUtils.getAdjustedFont(remoteLabelFind.getFont(), 8, SWT.BOLD));
remoteLabelText = new WidgetChangeText(this, SWT.SINGLE | SWT.BORDER, FrameEditorLID.SetRemoteLabelText, view);
remoteLabelOwner = new DisplayLabel(this, SWT.NONE);
remoteLabelOwner.setText(L10N.get("FE.RemoteLabelOwnerCaption", "Remote Label Owner") + ":");
remoteLabelOwnerName = new Link(this, SWT.NONE);
remoteLabelType = new DisplayLabel(this, SWT.NONE);
remoteLabelType.setText(L10N.get("FE.RemoteLabelTypeCaption", "Remote Label Type") + ":");
remoteLabelTypeCombo = new View.PerformActionCombo(this, SWT.DROP_DOWN | SWT.READ_ONLY) {
@Override
protected boolean doChangeAction() {
int selectedType = remoteLabelTypeCombo.getSelectionIndex();
FrameEditorUI.SetRemoteLabelTypeParms setTypeParms = new FrameEditorUI.SetRemoteLabelTypeParms(widgetTypeChoices[selectedType], view.selection.getSelectedIWidgets()[0]);
return view.performAction(FrameEditorLID.SetRemoteLabelType, setTypeParms, true);
}
};
for (WidgetType widgetTypeChoice : widgetTypeChoices) {
remoteLabelTypeCombo.add(widgetTypeChoice.toString());
}
imagePath = new DisplayLabel(this, SWT.NONE);
imagePath.setText(IMAGE_PATH);
imagePathText = new TextWithEnableFix(this, SWT.SINGLE | SWT.READ_ONLY);
isInitiallySelected = new Button(this, SWT.CHECK);
isInitiallySelected.setText(L10N.get("FE.InitiallySelected", "Initially Selected"));
WidgetAttributeListener listener = new WidgetAttributeListener(WidgetAttributes.IS_SELECTED_ATTR) {
@Override
public Object getValue() {
return new Boolean(isInitiallySelected.getSelection());
}
};
isInitiallySelected.addSelectionListener(listener);
isButtonSelected = new Button(this, SWT.CHECK);
isButtonSelected.setText(L10N.get("FE.InitiallySelected", "Initially Selected"));
isButtonSelected.setEnabled(false);
listener = new WidgetAttributeListener(WidgetAttributes.IS_SELECTED_ATTR) {
@Override
public Object getValue() {
return new Boolean(isButtonSelected.getSelection());
}
};
isButtonSelected.addSelectionListener(listener);
isToggleable = new Button(this, SWT.CHECK);
isToggleable.setText(L10N.get("FE.Togglable", "Can be toggled"));
listener = new WidgetAttributeListener(WidgetAttributes.IS_TOGGLEABLE_ATTR) {
@Override
public Object getValue() {
boolean sel = isToggleable.getSelection();
isButtonSelected.setEnabled(sel);
return new Boolean(sel);
}
};
isToggleable.addSelectionListener(listener);
/*this.isMultiLine = new Button(parent, SWT.CHECK);
this.isMultiLine.setText(L10N.get("FE.MultiLine", "Multiple Lined"));
listener = new WidgetAttributeListener(WidgetType.IS_MULTILINE_ATTR) {
@Override
public Object getValue() {
return new Boolean(isMultiLine.getSelection());
}
};
this.isMultiLine.addSelectionListener(listener);*/
selectLabel = new DisplayLabel(this, SWT.NONE);
selectLabel.setText(L10N.get("FE.ComboSelectCaption", "Initially Selected Item") + ":");
initiallySelected = new ComboWithEnableFix(this, SWT.DROP_DOWN | SWT.READ_ONLY);
initiallySelected.setVisibleItemCount(8);
initiallySelected.addSelectionListener(selectionAttrListener);
isSeparator = new Button(this, SWT.CHECK);
isSeparator.setText(L10N.get("FE.Separator", "Separator"));
listener = new WidgetAttributeListener(WidgetAttributes.IS_SEPARATOR_ATTR) {
@Override
public Object getValue() {
return (isSeparator.getSelection()) ? WidgetAttributes.IS_SEPARATOR : WidgetAttributes.NON_SEPARATOR;
}
};
isSeparator.addSelectionListener(listener);
isSeparator.moveAbove(widgetTypeLabel);
submenuActionLabel = new DisplayLabel(this, SWT.NONE);
submenuActionLabel.setText(L10N.get("FE.SubmenuActionLabel", "Submenu transition action") + ":");
submenuAction = new ComboWithEnableFix(this, SWT.DROP_DOWN | SWT.READ_ONLY);
// Maximize the possible set of values.
submenuActions = new Integer[] { WidgetAttributes.HOVER_SUBMENU_ACTION, null, null };
submenuAction.add(L10N.get("FE.HoverSubmenuAction", "Hover"));
listener = new WidgetAttributeListener(WidgetAttributes.SUBMENU_ACTION_ATTR) {
@Override
public Object getValue() {
Object a = submenuActions[submenuAction.getSelectionIndex()];
submenuDelay.setEnabled(a == WidgetAttributes.HOVER_SUBMENU_ACTION);
return a;
}
};
submenuAction.addSelectionListener(listener);
submenuDelayLabel = new DisplayLabel(this, SWT.NONE);
submenuDelayLabel.setText(L10N.get("FE.SubmenuDelay", "Submenu transition delay") + ":");
// TODO: remove READ_ONLY when editing allowed (check exception in setSubmenuDelayAttr)
submenuDelay = new ComboWithEnableFix(this, SWT.DROP_DOWN | SWT.READ_ONLY);
submenuDelay.add("0.0 s (" + L10N.get("FE.TypicalForMac", "typical for a Mac") + ")");
submenuDelay.add("0.5 s (" + L10N.get("FE.TypicalForPC", "typical for a PC") + ")");
listener = new WidgetAttributeListener(WidgetAttributes.SUBMENU_DELAY_ATTR) {
@Override
public Object getValue() {
switch(submenuDelay.getSelectionIndex()) {
case 0:
{
return WidgetAttributes.NO_SUBMENU_DELAY;
}
case 1:
{
return WidgetAttributes.PC_SUBMENU_DELAY;
}
}
// should be the current value!
return null;
}
@Override
public void widgetDefaultSelected(SelectionEvent evt) {
view.setSubmenuDelayAttr(view.selection.getSelectedIWidgets()[0], submenuDelay.getText());
}
};
submenuDelay.addSelectionListener(listener);
submenuDelay.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent evt) {
/*
* We can allow certain types of characters here:
* Control characters (arrow keys, etc): Character.CONTROL
* Numerics: Character.DECIMAL_DIGIT_NUMBER
* Decimal Point: keycodes 46 and 16777262
*
* Disallow anything else
*/
int characterType = Character.getType(evt.character);
if ((characterType == Character.CONTROL) || (characterType == Character.DECIMAL_DIGIT_NUMBER) || (evt.keyCode == 46) || (evt.keyCode == 16777262)) {
evt.doit = true;
} else {
evt.doit = false;
}
}
// listen for the enter key on the number pad for OS X
public void keyReleased(KeyEvent evt) {
if (OSUtils.MACOSX) {
if (evt.keyCode == SWT.KEYPAD_CR) {
view.setSubmenuDelayAttr(view.selection.getSelectedIWidgets()[0], submenuDelay.getText());
}
}
}
});
contextMenuActionLabel = new DisplayLabel(this, SWT.NONE);
contextMenuActionLabel.setText(L10N.get("FE.ContextMenuAction", "Context Menu Action") + ":");
// Maximize the possible set of values.
contextMenuActions = new Integer[] { null, null, null };
contextMenuAction = new ComboWithEnableFix(this, SWT.DROP_DOWN | SWT.READ_ONLY);
//TODO: this.contextMenuAction.add(L10N.get("FE.MenuKeyPress", "Menu Key Press"));
listener = new WidgetAttributeListener(WidgetAttributes.CONTEXT_MENU_ACTION_ATTR) {
@Override
public Object getValue() {
return contextMenuActions[contextMenuAction.getSelectionIndex()];
}
};
contextMenuAction.addSelectionListener(listener);
// Set initial selection
//widgetShapeCombo.select(0);
widgetTypeLabel.setText(N_A);
widgetModeValue.setText(N_A);
}
Aggregations