use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method createSetRemoteLabelTextAction.
// createUngroupElementsAction
private IListenerAction createSetRemoteLabelTextAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorUI.SetRemoteLabelTextParms.class;
}
public boolean performAction(Object prms) {
FrameEditorUI.SetRemoteLabelTextParms p = (FrameEditorUI.SetRemoteLabelTextParms) prms;
// Check p.selectedElement; must be an FrameElementGroup
// or an IWidget of WidgetType Button, PullDownList, Graffiti,
// or TextBox (whether IS_STANDARD or IS_CUSTOM) or an IWidget
// of WidgetType Radio, Check, or ListBoxItem if IS_STANDARD
// (in which case, the label belongs to the parent SimpleWidgetGroup)
FrameElement owningElt = p.selectedElement.getRemoteLabelOwner();
if (owningElt == null) {
interaction.protestUnsupportedLabelOwnerType();
return false;
}
IWidget remoteLabel = (IWidget) owningElt.getAttribute(WidgetAttributes.REMOTE_LABEL_ATTR);
// Already has a label; simply update
if (remoteLabel != null) {
changeTitleProperty(FrameEditorLID.SetRemoteLabelText, SET_REMOTE_LABEL, remoteLabel, p.newText, // not a separator!
false, undoMgr);
} else if ((p.newText != null) && !p.newText.equals("")) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(SET_REMOTE_LABEL, FrameEditorLID.SetRemoteLabelText);
final double INITIAL_WIDTH = 100.0;
final double INITIAL_HEIGHT = 16.0;
final double MIN_MARGIN = 5.0;
final double EXTRA_MARGIN = 10.0;
DoubleRectangle eltBds = owningElt.getEltBounds();
double maxY = eltBds.y - INITIAL_HEIGHT - MIN_MARGIN;
DoubleRectangle labelBds;
if (0.0 <= maxY) {
labelBds = new DoubleRectangle(eltBds.x, Math.max(0.0, maxY - EXTRA_MARGIN), INITIAL_WIDTH, INITIAL_HEIGHT);
} else {
double maxX = Math.max(0.0, eltBds.x - INITIAL_WIDTH - MIN_MARGIN);
labelBds = new DoubleRectangle(Math.max(0.0, maxX - EXTRA_MARGIN), eltBds.y, INITIAL_WIDTH, INITIAL_HEIGHT);
}
remoteLabel = new Widget(labelBds, WidgetType.Text);
DefaultCmd.setAttribute(owningElt, demoStateMgr, WidgetAttributes.REMOTE_LABEL_ATTR, remoteLabel, interaction, editSequence);
remoteLabel.setAttribute(WidgetAttributes.IS_STANDARD_ATTR, WidgetAttributes.IS_CUSTOM);
remoteLabel.setAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR, owningElt);
remoteLabel.setName(generateUniqueWidgetName());
remoteLabel.setTitle(p.newText);
// Add the new widget to the undo system and to the model
editSequence.addEdit(addWidget(remoteLabel));
// Commit the edit
editSequence.end();
// Only add this edit if it is significant
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class DictEntryGenerator method generateEntries.
// TODO This whole mishmash of different flavors of progress bars, and
// Cancelables/Stoppables/Pausables is a mess. We shouldn't be using
// the type hierarchy to fiddle this stuff. Instead we should have a
// single interface for control of a background operation, subsuming
// all of Cancelable, Stoppable and Pausable, and a single ProgressBar
// type that takes a bunch of flags indicating what buttons it should
// display.
public void generateEntries(String goal, ITermSimilarity alg, Cancelable cancelable, Stoppable stoppable, boolean computeAll, List<String> computeErrors, ProgressCallback progressCallback) {
// TODO figure out how to deal with this for real, long term
// goal = clean(goal);
ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if (NullSafe.equals(dict, WidgetAttributes.NO_DICTIONARY)) {
dict = new SimilarityDictionary();
design.setAttribute(WidgetAttributes.DICTIONARY_ATTR, dict);
}
int initialSize = dict.size();
ITermSimilarity.Continuable cont = new ITermSimilarity.Continuable(cancelable, stoppable);
Iterator<Frame> frames = design.getFrames().iterator();
while (frames.hasNext() && cont.isContinuing()) {
Frame f = frames.next();
generateOneEntry(f.getSpeakerText(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
Set<SimpleWidgetGroup> swGrps = new HashSet<SimpleWidgetGroup>();
Iterator<IWidget> widgets = f.getWidgets().iterator();
while (widgets.hasNext() && cont.isContinuing()) {
IWidget w = widgets.next();
generateOneEntry(w.getTitle(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
if (!cont.isContinuing()) {
break;
}
generateOneEntry(w.getTextualCue(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
SimpleWidgetGroup swg = w.getParentGroup();
if (swg != null) {
swGrps.add(swg);
}
}
Iterator<FrameElementGroup> groups = f.getEltGroups().iterator();
while (groups.hasNext() && cont.isContinuing()) {
generateOneEntry(groups.next().getTextualCue(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
}
Iterator<SimpleWidgetGroup> swgIter = swGrps.iterator();
while (swgIter.hasNext() && cont.isContinuing()) {
generateOneEntry(swgIter.next().getTextualCue(), goal, alg, cont, dict, computeAll, computeErrors, progressCallback);
}
}
if (stoppable.isStopped()) {
// Clean out the last entry if we were stopped, as it may not be
// correct. But only if we've added something.
int n = dict.size();
if (n > initialSize) {
dict.removeEntry(n - 1);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget 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;
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method renderChildren.
private void renderChildren(AParentWidget parent, boolean rendered, boolean oldRendered, CompoundUndoableEdit edit) {
if (parent.hasChildren()) {
Iterator<IWidget> children = parent.getChildren().iterator();
while (children.hasNext()) {
IWidget w = children.next();
if (w instanceof AParentWidget) {
renderChildren((AParentWidget) w, rendered, oldRendered, edit);
}
renderWidget(w, rendered, oldRendered, edit);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method createInitiateRelabelAction.
private IListenerAction createInitiateRelabelAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorSelectionState.class;
}
public boolean performAction(Object prms) {
FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
int selectedWidgetCount = selection.getWidgetSelectionCount();
if (selectedWidgetCount == 1) {
IWidget w = selection.getSelectedIWidgets()[0];
ui.initiateWidgetRetitle(w);
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
Aggregations