use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuWidget in project cogtool by cogtool.
the class FrameEditorUI method moveWidgetGroup.
// moveFrameElementGroup
/**
* Assumes gw's model is a traversable widget but not a child widget.
*/
public void moveWidgetGroup(double offsetX, double offsetY, GraphicalTraversableWidget<?> gw) {
// No easier way to do this (hard to make getTopHeader call generic)
TraversableWidget groupWidget = null;
if (gw instanceof GraphicalMenuWidget<?>) {
groupWidget = ((AMenuWidget) gw.getModel()).getTopHeader();
} else if ((gw instanceof GraphicalListItem) || (gw instanceof GraphicalGridButton)) {
groupWidget = (TraversableWidget) gw.getModel();
} else {
return;
}
SimpleWidgetGroup headerGroup = groupWidget.getParentGroup();
// Ensure top-left header doesn't scroll off-screen
groupWidget = (TraversableWidget) headerGroup.get(0);
DoublePoint p = groupWidget.getShape().getOrigin();
// Prevent the ability to move a widget to an origin less than 0,0
if (offsetX + p.x < 0.0) {
offsetX = -p.x;
}
if (offsetY + p.y < 0.0) {
offsetY = -p.y;
}
Point newOrigin = new Point(0, 0);
int index = 1;
int headerCount = headerGroup.size();
do {
newOrigin.setLocation(PrecisionUtilities.round(p.x + offsetX), PrecisionUtilities.round(p.y + offsetY));
frameUI.getWidgetFigure(groupWidget).setLocation(newOrigin);
// Stop when we've moved the last header!
if (index >= headerCount) {
break;
}
groupWidget = (TraversableWidget) headerGroup.get(index++);
p = groupWidget.getShape().getOrigin();
} while (true);
}
Aggregations