use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class ChoiceWireRenderer method updateData.
@Override
public void updateData() {
GraphicalWidget<?> gw = (GraphicalWidget<?>) getParent();
IWidget attributed = gw.getModel();
if (kind == CHECK) {
selected = RendererSupport.isSelected(attributed, attrOverride);
} else {
selected = RendererSupport.isRadioSelected(attributed, attrOverride);
}
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class SEDemoController method performTransition.
/**
* Take the transition, and perform the action
*
* @param transition
*/
protected boolean performTransition(SEDemoSelectionState selection, Transition transition, CogToolLID lid) {
AScriptStep stepToReplace = getDemoStep(selection);
if (stepToReplace != null) {
Frame currentFrame = stepToReplace.getCurrentFrame();
if (transition.getDestination() == currentFrame) {
return insertStep(new TransitionScriptStep(transition), stepToReplace, lid, PERFORM_TRANSITION);
}
if (!interaction.confirmDestructiveInsert()) {
return false;
}
}
AScriptStep newDemoStep = new TransitionScriptStep(transition);
TransitionSource source = transition.getSource();
if (source.getFrame() == transition.getDestination() && (source instanceof IWidget)) {
toggleIfGermane((IWidget) source, newDemoStep, transition.getAction());
}
Set<AScriptStep> newDemoSteps = Collections.singleton(newDemoStep);
Set<AScriptStep> oldDemoSteps = new LinkedHashSet<AScriptStep>();
Demonstration demo = script.getDemonstration();
final int atIndex = demo.replaceSteps(stepToReplace, newDemoSteps, oldDemoSteps);
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, stepToReplace, interaction);
IUndoableEdit edit = new DemoStateManager.ADemoUndoableEdit(lid, demo, newDemoSteps, oldDemoSteps, demoStateMgr) {
@Override
public String getPresentationName() {
return PERFORM_TRANSITION;
}
@Override
public void redo() {
super.redo();
demo.replaceSteps(atIndex, redoDemoSteps);
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
demo.replaceSteps(atIndex, undoDemoSteps);
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(PERFORM_TRANSITION, lid);
editSequence.addEdit(edit);
if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateScripts(project, demo, demoStateMgr, interaction, editSequence);
}
editSequence.end();
undoMgr.addEdit(editSequence);
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget 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.IWidget in project cogtool by cogtool.
the class ImportWebCrawlThread method doneCallback.
/**
* For each page visited and parsed, create a corresponding Frame.
* For each child link, create a corresponding Widget and Transition.
*/
@Override
public void doneCallback() {
// Performed by the main UI thread
try {
// If an exception was thrown during the import, display error here
if (RcvrExceptionHandler.recoverWorkThread(this, interaction)) {
return;
}
if (isCanceled()) {
return;
}
DemoStateManager demoStateMgr = DemoStateManager.getStateManager(project, design);
if (isPaused()) {
DefaultCmd.setAttribute(design, demoStateMgr, WidgetAttributes.PAUSED_WEB_CRAWL_ATTR, importWeb.getURLsToCrawl(), interaction, editSequence);
}
// -1 means that the design already is part of the project
if (insertBeforeIndex != EXISTING_DESIGN) {
ProjectCmd.addNewDesign(project, design, insertBeforeIndex, IMPORT_WEB_DESIGN, editSequence);
}
Collection<PageInfo> crawledURLs = importWeb.getCrawledURLs();
Iterator<PageInfo> pagesVisited = crawledURLs.iterator();
Set<DeviceType> deviceTypes = design.getDeviceTypes();
// Map (Link) IWidget to URL
Map<IWidget, String> neededTransitions = new HashMap<IWidget, String>();
int minFrameWidth = DesignUtil.getFrameMinWidth();
int minFrameHeight = DesignUtil.getFrameMinHeight();
double frameScale = DesignUtil.getFrameScaleFactor();
DesignUtil.IFrameSituator frameSituator = new DesignUtil.ByRowFrameSituator(0.0, 0.0, 16.0, 16.0, minFrameWidth, minFrameHeight, CogToolPref.FRAMES_PER_ROW.getInt(), frameScale);
while (pagesVisited.hasNext()) {
ImportWebURL.ImportPageInfo page = (ImportWebURL.ImportPageInfo) pagesVisited.next();
Frame newFrame = new Frame(page.url, deviceTypes);
knownFrames.put(page.url, newFrame);
if (page.background != null) {
DoubleRectangle bds = new DoubleRectangle(page.bkgImageX, page.bkgImageY, page.bkgImageWidth, page.bkgImageHeight);
newFrame.setBackgroundImage(page.background, bds);
}
int linkCount = 0;
Iterator<URLLabeledLink> links = page.links.iterator();
while (links.hasNext()) {
URLPositionedLink link = (URLPositionedLink) links.next();
// of the page)
if ((Math.round(link.width) == 0.0) || (Math.round(link.height) == 0.0)) {
continue;
}
IWidget linkWidget = new Widget(new DoubleRectangle(link.left, link.top, link.width, link.height), WidgetType.Link);
linkWidget.setName("Widget " + Integer.toString(++linkCount));
linkWidget.setTitle(StringUtil.trimWhitespace(link.getLabel()));
newFrame.addWidget(linkWidget);
if (deviceTypes.contains(DeviceType.Mouse)) {
String linkURL = link.getURL();
Frame targetFrame = knownFrames.get(linkURL);
if (targetFrame != null) {
Transition t = new Transition(linkWidget, targetFrame, buildLinkAction());
IUndoableEdit edit = DesignEditorCmd.addTransition(demoStateMgr, t);
editSequence.addEdit(edit);
} else {
// Have to handle this in the second pass
neededTransitions.put(linkWidget, linkURL);
}
}
}
Frame oldFrame = design.getFrame(newFrame.getName());
if (pruneSameURLs) {
if (oldFrame != null) {
makeFrameNameUnique(newFrame);
}
} else {
// If oldFrame exists, remove but keep incident transitions
if (oldFrame != null) {
Set<Transition> transitions = oldFrame.getIncidentTransitions();
synchronized (transitions) {
// them without upsetting the iterator
for (Transition transition : new ArrayList<Transition>(transitions)) {
DesignEditorCmd.changeTransitionTarget(demoStateMgr, transition, newFrame, editSequence);
}
//transitions=transitions2;
// Can't delete the transitive closure from here...sigh
DesignEditorCmd.deleteFrame(project, design, demoStateMgr, oldFrame, ProjectLID.ImportWebCrawl, editSequence);
}
}
}
frameSituator.situateNextFrame(newFrame);
DesignEditorCmd.addFrame(project, design, demoStateMgr, newFrame, editSequence);
}
// Each entry is IWidget --> URL string
for (Map.Entry<IWidget, String> checkTransition : neededTransitions.entrySet()) {
String transitionURL = checkTransition.getValue();
Frame targetFrame = knownFrames.get(transitionURL);
// processing is done (i.e., added during background processing).
if (targetFrame == null) {
targetFrame = design.getFrame(transitionURL);
}
// May just not be there; can't link if it's not there!
if (targetFrame != null) {
IWidget linkWidget = checkTransition.getKey();
Transition t = new Transition(linkWidget, targetFrame, buildLinkAction());
IUndoableEdit edit = DesignEditorCmd.addTransition(demoStateMgr, t);
editSequence.addEdit(edit);
}
}
editSequence.end();
undoMgr.addEdit(editSequence);
} finally {
// Recover resources.
importWeb.dispose();
super.doneCallback();
}
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method duplicateWidgetsAction.
// duplicateFrameEltGroup
private IListenerAction duplicateWidgetsAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorUI.DuplicateParameters.class;
}
public boolean performAction(Object prms) {
FrameEditorUI.DuplicateParameters parameters = (FrameEditorUI.DuplicateParameters) prms;
int elementCount = parameters.selection.getElementSelectionCount();
// If selection is non zero, copy widgets
if (elementCount > 0) {
Map<IWidget, IWidget> widgetCopies = new LinkedHashMap<IWidget, IWidget>();
final Map<FrameElementGroup, FrameElementGroup> groupCopies = new LinkedHashMap<FrameElementGroup, FrameElementGroup>();
widgetSituator.reset(widgetCopies, groupCopies);
Set<FrameElement> selectedElements = getSelectedElements(parameters.selection, elementLevelComparator);
Iterator<FrameElement> elements = selectedElements.iterator();
// Iterate through the widgets and duplicate.
while (elements.hasNext()) {
FrameElement elt = elements.next();
if (elt instanceof IWidget) {
duplicateWidget((IWidget) elt, parameters.selection, parameters.moveByX, parameters.moveByY);
} else if (elt instanceof FrameElementGroup) {
duplicateFrameEltGroup((FrameElementGroup) elt, parameters.moveByX, parameters.moveByY);
}
}
widgetSituator.completeWork();
final Iterable<? extends IWidget> widgetDuplicates = new ReadOnlyList<IWidget>(new ArrayList<IWidget>(widgetCopies.values()));
Iterator<? extends IWidget> copiedWidgets = widgetDuplicates.iterator();
Set<GridButtonGroup> dupGridGroups = new HashSet<GridButtonGroup>();
while (copiedWidgets.hasNext()) {
IWidget widgetCopy = copiedWidgets.next();
// Warning: it is important that each widget be added
// to the frame *before* we make the next widget name
// unique or we can end up with non-unique names.
makeWidgetNameUnique(widgetCopy);
model.addWidget(widgetCopy);
if (widgetCopy instanceof GridButton) {
GridButtonGroup gbg = (GridButtonGroup) widgetCopy.getParentGroup();
// for each grid button group
if (!dupGridGroups.contains(gbg)) {
gbg.recalculateOffsets();
dupGridGroups.add(gbg);
}
}
}
Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
while (copiedGroups.hasNext()) {
FrameElementGroup copiedGroup = copiedGroups.next();
// Ensure name is unique, then add to frame immediately
// Otherwise, it would be possible to generate presumed
// unique names that weren't.
makeEltGroupNameUnique(copiedGroup);
model.addEltGroup(copiedGroup);
}
DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(FrameEditorLID.Duplicate, demoStateMgr) {
@Override
public String getPresentationName() {
return DUPLICATE_WIDGETS;
}
@Override
public void redo() {
super.redo();
Iterator<? extends IWidget> addCopies = widgetDuplicates.iterator();
while (addCopies.hasNext()) {
IWidget widgetCopy = addCopies.next();
model.addWidget(widgetCopy);
}
Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
while (copiedGroups.hasNext()) {
model.addEltGroup(copiedGroups.next());
}
demoStateMgr.noteWidgetsEdit(widgetDuplicates, this);
}
@Override
public void undo() {
super.undo();
Iterator<? extends IWidget> removeCopies = widgetDuplicates.iterator();
while (removeCopies.hasNext()) {
IWidget widgetCopy = removeCopies.next();
model.removeWidget(widgetCopy);
}
Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
while (copiedGroups.hasNext()) {
model.removeEltGroup(copiedGroups.next());
}
demoStateMgr.noteWidgetsEdit(widgetDuplicates, this);
}
};
demoStateMgr.noteWidgetsEdit(widgetDuplicates, edit);
undoMgr.addEdit(edit);
return true;
}
// tell user to select something.
interaction.protestNoSelection();
return false;
}
};
}
Aggregations