use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup in project cogtool by cogtool.
the class FrameEditorController method createGroupElementsAction.
private IListenerAction createGroupElementsAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorSelectionState.class;
}
public boolean performAction(Object prms) {
FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
int selectedEltCount = selection.getElementSelectionCount();
if (selectedEltCount > 1) {
final FrameElementGroup newGroup = new FrameElementGroup();
assignUniqueEltGroupName(newGroup);
Iterator<FrameElement> selectedElts = selection.getSelectedElementsIterator();
while (selectedElts.hasNext()) {
FrameElement rootElt = selectedElts.next().getRootElement();
// that the element is a member of the group
if (!newGroup.contains(rootElt)) {
newGroup.add(rootElt);
}
}
model.addEltGroup(newGroup);
IUndoableEdit edit = new AUndoableEdit(FrameEditorLID.Group) {
@Override
public String getPresentationName() {
return GROUP_ELEMENTS;
}
@Override
public void redo() {
super.redo();
Iterator<FrameElement> groupElts = newGroup.iterator();
// back to the frame
while (groupElts.hasNext()) {
groupElts.next().addToEltGroup(newGroup);
}
model.addEltGroup(newGroup);
}
@Override
public void undo() {
super.undo();
model.removeEltGroup(newGroup);
Iterator<FrameElement> groupElts = newGroup.iterator();
// association from the element.
while (groupElts.hasNext()) {
groupElts.next().removeFromEltGroup(newGroup);
}
}
};
undoMgr.addEdit(edit);
return true;
}
if (selectedEltCount == 1) {
interaction.protestTooFewWidgets();
} else {
interaction.protestNoSelection();
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup in project cogtool by cogtool.
the class FrameEditorController method deleteGroupMember.
private void deleteGroupMember(FrameElement elt, FrameElementGroup fromGroup, IUndoableEditSequence editSequence) {
if (elt instanceof IWidget) {
deleteWidget((IWidget) elt, false, fromGroup, editSequence);
} else if (elt instanceof FrameElementGroup) {
deleteFrameEltGroup((FrameElementGroup) elt, fromGroup, editSequence);
} else if (elt instanceof SimpleWidgetGroup) {
SimpleWidgetGroup parentGroup = (SimpleWidgetGroup) elt;
while (parentGroup.size() > 0) {
IWidget child = parentGroup.get(0);
// If the widget group is itself a remote label owner,
// its remote label will be deleted in the first call here.
deleteWidget(child, false, fromGroup, editSequence);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup 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.FrameElementGroup in project cogtool by cogtool.
the class FrameEditorController method isMemberOfSelectedGroup.
private boolean isMemberOfSelectedGroup(FrameElement elt, FrameEditorSelectionState seln) {
FrameElement rootElt = elt.getRootElement();
Iterator<FrameElementGroup> grps = rootElt.getEltGroups().iterator();
// that is also selected, skip it
while (grps.hasNext()) {
if (seln.isElementSelected(grps.next())) {
return true;
}
}
return false;
}
use of edu.cmu.cs.hcii.cogtool.model.FrameElementGroup 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);
}
}
}
Aggregations