use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup 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;
}
use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.
the class FrameUIModel method getNextInGroup.
public GraphicalWidget<?> getNextInGroup(GraphicalWidget<?> fromWidgetFig) {
IWidget modelWidget = fromWidgetFig.getModel();
SimpleWidgetGroup group = modelWidget.getParentGroup();
if (group != null) {
int widgetIndex = group.indexOf(modelWidget);
if (widgetIndex < group.size() - 1) {
return getWidgetFigure(group.get(widgetIndex + 1));
}
}
return null;
}
use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.
the class FrameUIModel method getLastInGroup.
public GraphicalWidget<?> getLastInGroup(GraphicalWidget<?> fromWidgetFig) {
IWidget modelWidget = fromWidgetFig.getModel();
SimpleWidgetGroup group = modelWidget.getParentGroup();
if (group != null) {
int widgetIndex = group.size() - 1;
return getWidgetFigure(group.get(widgetIndex));
}
return null;
}
use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.
the class FrameEditorController method insertDuplicateEdit.
private void insertDuplicateEdit(final IWidget duplicatedWidget, final ReadOnlyList<? extends IWidget> widgetCopies, final SimpleWidgetGroup group, final int index, final AParentWidget parent, final double startPosX, final double startPosY, IUndoableEditSequence editSeq) {
DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(FrameEditorLID.Duplicate, demoStateMgr) {
@Override
public String getPresentationName() {
return DUPLICATE_WIDGET;
}
@Override
public void redo() {
super.redo();
if (duplicatedWidget instanceof ChildWidget) {
ChildWidget child = (ChildWidget) duplicatedWidget;
AParentWidget curParent = child.getParent();
curParent.addItem(index, child);
} else if (index >= 0) {
group.add(index, duplicatedWidget);
} else {
group.add(duplicatedWidget);
}
model.addWidget(duplicatedWidget);
stateMgr.noteWidgetsEdit(widgetCopies, this);
if (parent != null) {
DesignEditorCmd.repositionChildren(parent);
} else if (group != null) {
DesignEditorCmd.repositionChildren(group, startPosX, startPosY);
}
}
@Override
public void undo() {
super.undo();
if (duplicatedWidget instanceof ChildWidget) {
ChildWidget child = (ChildWidget) duplicatedWidget;
AParentWidget curParent = child.getParent();
curParent.removeItem(child);
} else if (duplicatedWidget.getParentGroup() != null) {
SimpleWidgetGroup parentGroup = duplicatedWidget.getParentGroup();
parentGroup.remove(duplicatedWidget);
}
model.removeWidget(duplicatedWidget);
stateMgr.noteWidgetsEdit(widgetCopies, this);
if (parent != null) {
DesignEditorCmd.repositionChildren(parent);
} else if (group != null) {
DesignEditorCmd.repositionChildren(group, startPosX, startPosY);
}
}
};
editSeq.addEdit(edit);
}
use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.
the class FrameEditorController method duplicateGroupMember.
// Assumes that widget is an instance of MenuHeader, ListItem, or
// GridButton
private IWidget duplicateGroupMember(IWidget widget, FrameEditorSelectionState selection, double moveByX, double moveByY) {
SimpleWidgetGroup existingGroup = widget.getParentGroup();
SimpleWidgetGroup newGroup = widgetSituator.getGroup(existingGroup);
// If the first time this group has been seen, populate.
if (newGroup.size() == 0) {
Iterator<IWidget> widgets = sortSelectedMbrs(existingGroup, selection);
while (widgets.hasNext()) {
Frame.duplicateWidget(widgets.next(), lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
}
DesignEditorCmd.repositionChildren(newGroup);
}
return widgetSituator.getDuplicate(widget);
}
Aggregations