use of edu.cmu.cs.hcii.cogtool.model.DoubleSize 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;
}
use of edu.cmu.cs.hcii.cogtool.model.DoubleSize in project cogtool by cogtool.
the class FrameEditorController method reorderChildWidget.
private boolean reorderChildWidget(final ChildWidget widget, final SimpleWidgetGroup newGroup, final int newIndex, final AParentWidget newParent) {
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;
}
}
final AParentWidget prevParent = widget.getParent();
DoubleSize prevSize = widget.getShape().getSize();
final double prevWidth = prevSize.width;
final double prevHeight = prevSize.height;
DoubleSize newSize = getNewWidgetSize(newParent);
final double newWidth = newSize.width;
final double newHeight = newSize.height * getHeightFactor(widget, newGroup);
final boolean widgetRendered = widget.isRendered();
reorderChildWidget(widget, newWidth, newHeight, index, prevParent, newParent);
Object rendered = widget.getParentGroup().getAttribute(WidgetAttributes.IS_RENDERED_ATTR);
final boolean groupRendered = ((Boolean) rendered).booleanValue();
if (widgetRendered != groupRendered) {
widget.setRendered(groupRendered);
}
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.Reorder, demoStateMgr) {
private ChildWidget child = widget;
@Override
public String getPresentationName() {
return REORDER_WIDGET;
}
@Override
public void redo() {
super.redo();
int index = newIndex;
if (prevGroup == newGroup) {
if (prevIndex < newIndex) {
index--;
}
}
reorderChildWidget(child, newWidth, newHeight, index, prevParent, newParent);
if (widgetRendered != groupRendered) {
widget.setRendered(groupRendered);
}
noteEditCheckRegenerate(prevParent.getChildren(), newParent.getChildren(), this);
}
@Override
public void undo() {
super.undo();
reorderChildWidget(child, prevWidth, prevHeight, prevIndex, newParent, prevParent);
if (widgetRendered != groupRendered) {
widget.setRendered(widgetRendered);
}
noteEditCheckRegenerate(newParent.getChildren(), prevParent.getChildren(), this);
}
};
noteEditCheckRegenerate(prevParent.getChildren(), newParent.getChildren(), edit);
undoMgr.addEdit(edit);
if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.DoubleSize in project cogtool by cogtool.
the class FrameEditorController method resizeChildren.
private void resizeChildren(IWidget widget) {
if (widget instanceof AParentWidget) {
AParentWidget parent = (AParentWidget) widget;
DoubleSize size = parent.getShape().getSize();
if (parent instanceof MenuHeader) {
size.width *= FrameEditorUI.MENU_ITEM_RATIO;
}
int numItems = parent.itemCount();
for (int i = 0; i < numItems; i++) {
ChildWidget child = parent.getItem(i);
double h = size.height;
Object isSep = child.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, isSep)) {
h /= FrameEditorUI.SEPARATOR_RATIO;
}
child.setWidgetSize(size.width, h);
resizeChildren(child);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.DoubleSize in project cogtool by cogtool.
the class DesignEditorCmd method getFirstChildPosition.
private static DoublePoint getFirstChildPosition(AParentWidget parent) {
AShape parentShape = parent.getShape();
DoublePoint pos = parentShape.getOrigin();
DoubleSize extent = parentShape.getSize();
switch(parent.getChildrenLocation()) {
case AParentWidget.CHILDREN_BELOW:
{
pos.y += extent.height;
break;
}
case AParentWidget.CHILDREN_RIGHT:
{
pos.x += extent.width;
break;
}
case AParentWidget.CHILDREN_CENTER:
{
pos.x += extent.width / 2.0;
pos.y += extent.height / 2.0;
break;
}
}
return pos;
}
use of edu.cmu.cs.hcii.cogtool.model.DoubleSize in project cogtool by cogtool.
the class SEFrameChooserUI method resetVisibleArea.
// ctor
@Override
public void resetVisibleArea() {
StandardDrawingEditor e = view.getEditor();
e.getLWS().getUpdateManager().performUpdate();
DoubleSize extent = structureView.getPreferredSize();
e.setMinVisibleArea(PrecisionUtilities.round(extent.width), PrecisionUtilities.round(extent.height), false);
}
Aggregations