use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class FrameEditorController method resizeWidget.
/**
* Implementation on a per widget bases for resize.
* Calculates the new size be the difference between the fixed point and the
* released point.
*
* @param widget The widget to resize
* @param mouseReleased The point where the mouse was let up
* @param fixedPoint The point which will not move after resize
* @param edit The Compound undoable edit
*/
private void resizeWidget(final IWidget widget, double oldResizeX, double oldResizeY, double newResizeX, double newResizeY, final double ratioX, final double ratioY, final boolean childrenToo, IUndoableEditSequence editSequence) {
// Get the old shape bounds for the undo
DoubleRectangle oldBounds = widget.getEltBounds();
final double oldWidgetX = oldBounds.x;
final double oldWidgetY = oldBounds.y;
final double oldWidth = oldBounds.width;
final double oldHeight = oldBounds.height;
final double newWidgetX = ratioX * (oldBounds.x - oldResizeX) + newResizeX;
final double newWidgetY = ratioY * (oldBounds.y - oldResizeY) + newResizeY;
final double newWidth = Math.max(ratioX * oldBounds.width, 1.0);
final double newHeight = Math.max(ratioY * oldBounds.height, 1.0);
final double oldHoriz = (widget instanceof GridButton) ? ((GridButton) widget).getHorizSpace() : 0.0;
final double oldVert = (widget instanceof GridButton) ? ((GridButton) widget).getVertSpace() : 0.0;
// Actually make the changes to the model.
widget.setWidgetOrigin(newWidgetX, newWidgetY);
widget.setWidgetSize(newWidth, newHeight);
if (widget instanceof GridButton) {
GridButton gb = (GridButton) widget;
gb.setHorizSpace(oldHoriz * ratioX);
gb.setVertSpace(oldVert * ratioY);
} else if (widget instanceof AParentWidget) {
if (childrenToo) {
resizeChildren(widget);
}
DesignEditorCmd.repositionChildren((AParentWidget) widget);
}
// Add the undo support
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.ResizeWidgets, demoStateMgr) {
@Override
public String getPresentationName() {
return RESIZE_WIDGET;
}
@Override
public void redo() {
super.redo();
widget.setWidgetOrigin(newWidgetX, newWidgetY);
widget.setWidgetSize(newWidth, newHeight);
if (widget instanceof GridButton) {
GridButton gb = (GridButton) widget;
gb.setHorizSpace(oldHoriz * ratioX);
gb.setVertSpace(oldVert * ratioY);
} else if (widget instanceof AParentWidget) {
if (childrenToo) {
resizeChildren(widget);
}
DesignEditorCmd.repositionChildren((AParentWidget) widget);
}
noteEditCheckRegenerate(widget, this);
}
@Override
public void undo() {
super.undo();
widget.setWidgetOrigin(oldWidgetX, oldWidgetY);
widget.setWidgetSize(oldWidth, oldHeight);
if (widget instanceof GridButton) {
GridButton gb = (GridButton) widget;
gb.setHorizSpace(oldHoriz);
gb.setVertSpace(oldVert);
} else if (widget instanceof AParentWidget) {
if (childrenToo) {
// technically, this won't restore the sizes if they were changed manuallythes
resizeChildren(widget);
}
DesignEditorCmd.repositionChildren((AParentWidget) widget);
}
noteEditCheckRegenerate(widget, this);
}
};
noteEditCheckRegenerate(widget, edit);
editSequence.addEdit(edit);
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class FrameEditorController method renderGroup.
private void renderGroup(SimpleWidgetGroup group, boolean rendered, boolean oldRendered, CompoundUndoableEdit edit) {
Iterator<IWidget> children = group.iterator();
while (children.hasNext()) {
IWidget w = children.next();
if (w instanceof AParentWidget) {
renderChildren((AParentWidget) w, rendered, oldRendered, edit);
}
renderWidget(w, rendered, oldRendered, edit);
}
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class GraphicalMenuItem method getParentFigure.
@SuppressWarnings("unchecked")
public GraphicalParentWidget<AMenuWidget, MenuItem> getParentFigure() {
MenuItem menuWidget = getModel();
AParentWidget parent = menuWidget.getParent();
return (GraphicalMenuWidget<AMenuWidget>) figureSpt.getWidgetFigure(parent);
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class AbstractGraphicalParentWidget method setChildrenVisible.
public void setChildrenVisible(boolean visible) {
AParentWidget parentWidget = model;
int numChildren = parentWidget.itemCount();
for (int i = 0; i < numChildren; i++) {
GraphicalWidget<?> gw = this.figureSpt.getWidgetFigure(parentWidget.getItem(i));
if (gw != null) {
gw.setVisible(visible);
IFigure parent = gw.getParent();
if (visible && (parent != null)) {
parent.add(gw, gw.getBounds(), -1);
}
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class AbstractGraphicalParentWidget method getFigureAt.
@SuppressWarnings("unchecked")
public GraphicalChildWidget<P, C> getFigureAt(int index) {
AParentWidget parentWidget = model;
ChildWidget child = parentWidget.getItem(index);
if (child == null) {
return null;
}
return (GraphicalChildWidget<P, C>) this.figureSpt.getWidgetFigure(child);
}
Aggregations