Search in sources :

Example 1 with GraphicalGridButton

use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalGridButton 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);
}
Also used : TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) GraphicalMenuWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuWidget) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) GraphicalListItem(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalListItem) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GraphicalGridButton(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalGridButton) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Aggregations

DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)1 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)1 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)1 GraphicalGridButton (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalGridButton)1 GraphicalListItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalListItem)1 GraphicalMenuWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuWidget)1 GraphicalTraversableWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget)1 Point (org.eclipse.draw2d.geometry.Point)1