use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method duplicateFrameEltGroup.
// duplicateWidget
private FrameElementGroup duplicateFrameEltGroup(FrameElementGroup grp, double moveByX, double moveByY) {
// Temporarily assign the same name; when added to the Frame
// we will ensure the name is then unique
FrameElementGroup newEltGrp = grp.twin();
Iterator<FrameElement> eltsToDup = grp.iterator();
while (eltsToDup.hasNext()) {
FrameElement elt = eltsToDup.next();
FrameElement eltCopy = null;
if (elt instanceof IWidget) {
IWidget widget = (IWidget) elt;
duplicateWidget(widget, null, moveByX, moveByY);
eltCopy = widgetSituator.getDuplicate(widget);
} else if (elt instanceof SimpleWidgetGroup) {
SimpleWidgetGroup group = (SimpleWidgetGroup) elt;
SimpleWidgetGroup groupCopy = widgetSituator.getGroup(group);
Iterator<IWidget> groupWidgets = group.iterator();
while (groupWidgets.hasNext()) {
duplicateGroupMember(groupWidgets.next(), null, moveByX, moveByY);
}
Frame.duplicateRemoteLabel(group, groupCopy, lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
eltCopy = groupCopy;
} else if (elt instanceof FrameElementGroup) {
eltCopy = duplicateFrameEltGroup((FrameElementGroup) elt, moveByX, moveByY);
}
if (eltCopy != null) {
newEltGrp.add(eltCopy);
}
}
widgetSituator.setGroupDuplicate(grp, newEltGrp);
Frame.duplicateRemoteLabel(grp, newEltGrp, lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
return newEltGrp;
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method updateWidgetName.
/**
* Update the widget's name.
* The name must be unique.
*
* @param widget
* @param newName
* @return
*/
private boolean updateWidgetName(final IWidget widget, String tryName) {
final String oldName = widget.getName();
boolean notDone = true;
do {
if (tryName.length() == 0) {
tryName = interaction.protestNameCannotBeEmpty(DEFAULT_WIDGET_PREFIX);
// If canceled, indicate so; otherwise, test again
if (tryName == null) {
return false;
}
} else {
IWidget widgetForName = model.getWidget(tryName);
// then no change is necessary!
if (widgetForName == widget) {
notDone = false;
} else if (widgetForName != null) {
// A non-null widget for the tryName indicates a collision
tryName = interaction.protestNameCollision(DEFAULT_WIDGET_PREFIX);
// If canceled, indicate so; otherwise, test again
if (tryName == null) {
return false;
}
} else {
// Not canceled, not empty, and not a collision
notDone = false;
final String newName = tryName;
model.setWidgetName(newName, widget);
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.ChangeNameProperty, demoStateMgr) {
@Override
public String getPresentationName() {
return CHG_WIDGET_NAME;
}
@Override
public void redo() {
super.redo();
model.setWidgetName(newName, widget);
noteEditCheckRegenerate(widget, this);
}
@Override
public void undo() {
super.undo();
model.setWidgetName(oldName, widget);
noteEditCheckRegenerate(widget, this);
}
};
noteEditCheckRegenerate(widget, edit);
undoMgr.addEdit(edit);
}
}
} while (notDone);
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method changeAuxTextProperty.
// createChangeTitlePropertyAction
private void changeAuxTextProperty(ListenerIdentifier lid, final String presentation, FrameElement elt, final String newText, IUndoableEditSequence editSequence) {
if (elt instanceof IWidget) {
final IWidget widget = (IWidget) elt;
final String oldText = widget.getAuxiliaryText();
if (!oldText.equals(newText)) {
widget.setAuxiliaryText(newText);
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(lid, demoStateMgr) {
@Override
public String getPresentationName() {
return presentation;
}
@Override
public void redo() {
// Redo the set auxiliary text
super.redo();
widget.setAuxiliaryText(newText);
noteEditCheckRegenerate(widget, this);
}
@Override
public void undo() {
// Go back to old auxiliary text
super.undo();
widget.setAuxiliaryText(oldText);
noteEditCheckRegenerate(widget, this);
}
};
noteEditCheckRegenerate(widget, edit);
editSequence.addEdit(edit);
}
} else if (elt instanceof FrameElementGroup) {
final FrameElementGroup eltGroup = (FrameElementGroup) elt;
final String oldText = eltGroup.getAuxiliaryText();
if (!oldText.equals(newText)) {
eltGroup.setAuxiliaryText(newText);
IUndoableEdit edit = new DemoStateManager.ObsoletingEdit(lid, demoStateMgr) {
@Override
public String getPresentationName() {
return presentation;
}
@Override
public void redo() {
// Redo the set auxiliary text
super.redo();
eltGroup.setAuxiliaryText(newText);
}
@Override
public void undo() {
// Go back to old auxiliary text
super.undo();
eltGroup.setAuxiliaryText(oldText);
}
};
editSequence.addEdit(edit);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method renderGroup.
private void renderGroup(SimpleWidgetGroup group, boolean rendered, boolean oldRendered, CompoundUndoableEdit edit) {
Iterator<IWidget> children = group.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 getSelectedWidgets.
/**
* Fetch all widgets referenced by the given selection sorted by
* the given comparison function.
*/
private IWidget[] getSelectedWidgets(FrameEditorSelectionState seln, Comparator<? super IWidget> c) {
IWidget[] widgets;
Set<IWidget> allWidgets = new HashSet<IWidget>();
Iterator<FrameElement> s = seln.getSelectedElementsIterator();
while (s.hasNext()) {
FrameElement elt = s.next();
if (elt instanceof IWidget) {
IWidget w = (IWidget) elt;
SimpleWidgetGroup group = w.getParentGroup();
if (group != null) {
Iterator<IWidget> mbrs = group.iterator();
while (mbrs.hasNext()) {
allWidgets.add(mbrs.next());
}
} else {
allWidgets.add(w);
}
} else if (elt instanceof FrameElementGroup) {
Iterator<IWidget> eltGrpWidgets = new ElementAllWidgetIterator((FrameElementGroup) elt);
while (eltGrpWidgets.hasNext()) {
allWidgets.add(eltGrpWidgets.next());
}
}
}
widgets = new IWidget[allWidgets.size()];
allWidgets.toArray(widgets);
Arrays.sort(widgets, c);
return widgets;
}
Aggregations