use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class DesignEditorCmd method repositionChildren.
public static void repositionChildren(AParentWidget parent) {
if (parent.hasChildren()) {
DoublePoint startPos = getFirstChildPosition(parent);
repositionChildren(parent.getChildren(), startPos.x, startPos.y);
}
}
use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class FrameEditorController method moveWidget.
/**
* Move a single widget.
* Add the move to the list of undoable edits using compound edit passed in
*
* Enforce that the move does not move the origin past 0,0
*
* @param w
* @param e
*/
private void moveWidget(ListenerIdentifier lid, String presentationLabel, IWidget w, double widgetMoveByX, double widgetMoveByY, IUndoableEditSequence editSequence) {
// Keep track of old and new locations, ensuring not less than zero
DoublePoint oldLocation = w.getShape().getOrigin();
double oldX = oldLocation.x;
double oldY = oldLocation.y;
double newX = Math.max(oldX + widgetMoveByX, 0.0);
double newY = Math.max(oldY + widgetMoveByY, 0.0);
// Change model and create undo.
w.setWidgetOrigin(newX, newY);
DemoStateManager.ObsoletingEdit edit = new WidgetMoveUndoRedo(lid, presentationLabel, w, newX, newY, oldX, oldY);
noteEditCheckRegenerate(w, edit);
editSequence.addEdit(edit);
}
use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class FrameEditorController method reorderWidget.
private boolean reorderWidget(final IWidget widget, final SimpleWidgetGroup newGroup, final int newIndex) {
final SimpleWidgetGroup prevGroup = widget.getParentGroup();
final int prevIndex = prevGroup.indexOf(widget);
int index = newIndex;
if (prevGroup == newGroup) {
if (prevIndex < newIndex) {
index--;
}
if (index == prevIndex) {
return true;
}
}
DoublePoint prevGroupStartPos = prevGroup.get(0).getShape().getOrigin();
final double prevGroupStartX = prevGroupStartPos.x;
final double prevGroupStartY = prevGroupStartPos.y;
DoubleSize prevSize = widget.getShape().getSize();
final double prevWidth = prevSize.width;
final double prevHeight = prevSize.height;
DoubleRectangle newBds = newGroup.get(0).getEltBounds();
double heightFactor = (widget instanceof ListItem) ? getHeightFactor(widget, newGroup) : 1.0;
final double newWidth = newBds.width;
final double newHeight = newBds.height * heightFactor;
final double newGroupStartX = newBds.x;
final double newGroupStartY = newBds.y;
Object rendered = newGroup.getAttribute(WidgetAttributes.IS_RENDERED_ATTR);
final boolean groupRendered = ((Boolean) rendered).booleanValue();
final boolean widgetRendered = widget.isRendered();
reorderGroupWidget(widget, newWidth, newHeight, index, prevGroup, newGroup, prevGroupStartX, prevGroupStartY, newGroupStartX, newGroupStartY);
if (widgetRendered != groupRendered) {
widget.setRendered(groupRendered);
}
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.Reorder, demoStateMgr) {
@Override
public String getPresentationName() {
return REORDER_WIDGET;
}
@Override
public void redo() {
super.redo();
int index = newIndex;
if (prevGroup == newGroup) {
if (prevIndex < newIndex) {
index--;
}
}
reorderGroupWidget(widget, newWidth, newHeight, index, prevGroup, newGroup, prevGroupStartX, prevGroupStartY, newGroupStartX, newGroupStartY);
if (widgetRendered != groupRendered) {
widget.setRendered(groupRendered);
}
noteEditCheckRegenerate(prevGroup, newGroup, this);
}
@Override
public void undo() {
super.undo();
reorderGroupWidget(widget, prevWidth, prevHeight, prevIndex, newGroup, prevGroup, newGroupStartX, newGroupStartY, prevGroupStartX, prevGroupStartY);
if (widgetRendered != groupRendered) {
widget.setRendered(widgetRendered);
}
noteEditCheckRegenerate(newGroup, prevGroup, this);
}
};
noteEditCheckRegenerate(prevGroup, newGroup, edit);
undoMgr.addEdit(edit);
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class FrameEditorController method moveWidgetGroup.
// moveWidget
private void moveWidgetGroup(ListenerIdentifier lid, final String presentationLabel, final SimpleWidgetGroup group, double widgetMoveByX, double widgetMoveByY, IUndoableEditSequence editSequence) {
// Keep track of old and new locations, ensuring not less than zero
IWidget firstChildWidget = group.get(0);
DoublePoint oldLocation = firstChildWidget.getShape().getOrigin();
final double deltaX = Math.max(widgetMoveByX, -oldLocation.x);
final double deltaY = Math.max(widgetMoveByY, -oldLocation.y);
final int numWidgets = group.size();
List<IWidget> groupWidgets = new ArrayList<IWidget>();
// Change model and create undo.
for (int i = 0; i < numWidgets; i++) {
IWidget widget = group.get(i);
groupWidgets.add(widget);
widget.moveElement(deltaX, deltaY);
}
final ReadOnlyList<? extends IWidget> roGroupWidgets = new ReadOnlyList<IWidget>(groupWidgets);
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(lid, demoStateMgr) {
@Override
public String getPresentationName() {
return presentationLabel;
}
@Override
public void redo() {
super.redo();
for (int i = 0; i < numWidgets; i++) {
IWidget w = roGroupWidgets.get(i);
w.moveElement(deltaX, deltaY);
}
noteEditCheckRegenerate(roGroupWidgets, this);
}
@Override
public void undo() {
super.undo();
for (int i = 0; i < numWidgets; i++) {
IWidget w = roGroupWidgets.get(i);
w.moveElement(-deltaX, -deltaY);
}
noteEditCheckRegenerate(roGroupWidgets, this);
}
};
noteEditCheckRegenerate(roGroupWidgets, edit);
editSequence.addEdit(edit);
}
use of edu.cmu.cs.hcii.cogtool.model.DoublePoint in project cogtool by cogtool.
the class FrameEditorController method insertDuplicateWidget.
/**
* If group or parent is non-null, duplicate the widget within the given
* group. If they are both null, the widget was dragged to empty space, so
* give it a new group.
*/
private boolean insertDuplicateWidget(IWidget widget, SimpleWidgetGroup group, int index, AParentWidget parent, double moveByX, double moveByY) {
Map<IWidget, IWidget> widgetCopies = new LinkedHashMap<IWidget, IWidget>();
double startPosX = 0.0;
double startPosY = 0.0;
DoubleSize newSize;
if (parent != null) {
newSize = getNewWidgetSize(parent);
newSize.height *= getHeightFactor(widget, parent.getChildren());
} else if ((group == null) || (group.size() == 0)) {
newSize = widget.getShape().getSize();
} else {
DoublePoint startPos = group.get(0).getShape().getOrigin();
startPosX = startPos.x;
startPosY = startPos.y;
newSize = group.get(0).getShape().getSize();
if (widget instanceof ListItem) {
newSize.height *= getHeightFactor(widget, group);
}
}
widgetSituator.reset(widgetCopies, null);
IWidget newWidget = null;
if (parent != null) {
if (widget instanceof ChildWidget) {
newWidget = ((ChildWidget) widget).duplicate(parent, lookupFrameDuplicator, widgetSituator, index);
newWidget.setWidgetSize(newSize.width, newSize.height);
if (newWidget instanceof AParentWidget) {
resizeChildren(newWidget);
DesignEditorCmd.repositionChildren((AParentWidget) newWidget);
}
DesignEditorCmd.repositionChildren(parent);
}
} else if (group != null) {
if (widget instanceof MenuHeader) {
newWidget = ((MenuHeader) widget).duplicate(group, lookupFrameDuplicator, widgetSituator, index);
} else if (widget instanceof ListItem) {
newWidget = ((ListItem) widget).duplicate(group, lookupFrameDuplicator, index);
}
newWidget.setWidgetSize(newSize.width, newSize.height);
resizeChildren(newWidget);
widgetSituator.placeInContext(widget, newWidget);
DesignEditorCmd.repositionChildren(group, startPosX, startPosY);
} else {
// Duplicating into space
if ((widget instanceof MenuHeader) || (widget instanceof ListItem)) {
SimpleWidgetGroup newGroup = null;
if (widget instanceof MenuHeader) {
newGroup = new SimpleWidgetGroup(SimpleWidgetGroup.HORIZONTAL);
newWidget = ((MenuHeader) widget).duplicate(newGroup, lookupFrameDuplicator, widgetSituator);
} else {
// (widget instanceof ListItem)
newGroup = new SimpleWidgetGroup(SimpleWidgetGroup.VERTICAL);
newWidget = ((ListItem) widget).duplicate(newGroup, lookupFrameDuplicator);
}
group = newGroup;
widgetSituator.placeInContext(widget, newWidget);
newWidget.moveElement(moveByX, moveByY);
group.setAttribute(WidgetAttributes.IS_RENDERED_ATTR, Boolean.valueOf(widget.isRendered()));
}
}
widgetSituator.completeWork();
Collection<IWidget> duplicateWidgets = widgetCopies.values();
Iterator<IWidget> copies = duplicateWidgets.iterator();
while (copies.hasNext()) {
IWidget widgetCopy = copies.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);
}
SimpleWidgetGroup newGroup = (group != null) ? group : newWidget.getParentGroup();
Object rendered = newGroup.getAttribute(WidgetAttributes.IS_RENDERED_ATTR);
boolean groupRendered = ((Boolean) rendered).booleanValue();
boolean widgetRendered = widget.isRendered();
if (groupRendered != widgetRendered) {
newWidget.setRendered(groupRendered);
}
insertDuplicateEdit(newWidget, new ReadOnlyList<IWidget>(new ArrayList<IWidget>(duplicateWidgets)), group, index, parent, startPosX, startPosY, undoMgr);
return true;
}
Aggregations