use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class DesignEditorCmd method addWidgetUndoableEdit.
public static IDesignUndoableEdit addWidgetUndoableEdit(Frame frame, IWidget widget, DemoStateManager mgr) {
if (widget instanceof ChildWidget) {
ChildWidget childWidget = (ChildWidget) widget;
final AParentWidget itemParent = childWidget.getParent();
final int atIndex = itemParent.indexOf(childWidget);
return new AddWidgetUndoableEdit(frame, widget, mgr) {
@Override
protected void redoHelper() {
itemParent.addItem(atIndex, (ChildWidget) widget);
}
@Override
protected void undoHelper() {
itemParent.removeItem((ChildWidget) widget);
}
};
}
final SimpleWidgetGroup parentGroup = widget.getParentGroup();
final int atIndex = (parentGroup != null) ? parentGroup.indexOf(widget) : -1;
return new AddWidgetUndoableEdit(frame, widget, mgr) {
@Override
protected void redoHelper() {
if (parentGroup != null) {
parentGroup.add(atIndex, widget);
// TODO:mlh reposition items/headers following!
}
}
@Override
protected void undoHelper() {
if (parentGroup != null) {
parentGroup.remove(widget);
// TODO:mlh reposition items/headers following!
}
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class DesignEditorCmd method repositionChildren.
/**
* TODO: If we ever allow children above or left of a parent,
* we need to pass in childrenLocation here in addition to the group.
*/
public static void repositionChildren(SimpleWidgetGroup group, double x, double y) {
int orientation = group.getOrientation();
if (orientation == SimpleWidgetGroup.FREEFORM) {
return;
}
Iterator<IWidget> groupIter = group.iterator();
while (groupIter.hasNext()) {
IWidget widget = groupIter.next();
widget.setWidgetOrigin(x, y);
if (orientation == SimpleWidgetGroup.HORIZONTAL) {
x += widget.getEltBounds().width;
} else if (orientation == SimpleWidgetGroup.VERTICAL) {
y += widget.getEltBounds().height;
}
if (widget instanceof AParentWidget) {
repositionChildren((AParentWidget) widget);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class DesignEditorCmd method pasteWidget.
private static int pasteWidget(IWidget widget, Design design, int currentDeviceTypes, Frame frame, DemoStateManager mgr, IUndoableEditSequence editSequence, Set<FrameElementGroup> groups, Set<IWidget> addedRemoteLabels) {
if (frame.getWidgets().contains(widget)) {
return 0;
}
int requiresOneOf = widget.getWidgetType().requiresOneOf();
if (!DeviceType.intersects(requiresOneOf, currentDeviceTypes)) {
// Missing either Mouse or Touchscreen
if (DeviceType.Touchscreen.isMember(requiresOneOf)) {
DesignCmd.addDevice(design, DeviceType.Touchscreen);
} else if (DeviceType.Mouse.isMember(requiresOneOf)) {
DesignCmd.addDevice(design, DeviceType.Mouse);
}
}
makeWidgetNameUnique(widget, frame);
frame.addWidget(widget);
IDesignUndoableEdit edit = addWidgetUndoableEdit(frame, widget, mgr);
mgr.noteWidgetEdit(widget, edit);
editSequence.addEdit(edit);
if (widget instanceof AParentWidget) {
AParentWidget parent = (AParentWidget) widget;
addChildWidgets(frame, parent.getChildren(), mgr, editSequence);
}
groups.addAll(widget.getEltGroups());
checkForRemoteLabel(widget, addedRemoteLabels);
return 1;
}
Aggregations