use of edu.cmu.cs.hcii.cogtool.model.GridButton 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.GridButton in project cogtool by cogtool.
the class FrameEditorController method moveGridButtonsEdit.
// moveWidgetGroup
private IDesignUndoableEdit moveGridButtonsEdit(ListenerIdentifier lid, final String presentationLabel, final ReadOnlyList<? extends GridButton> movedButtons, final double widgetMoveByX, final double widgetMoveByY, final double oldHoriz, final double oldVert, final double newHoriz, final double newVert, final GridButton gb) {
final GridButtonGroup gbg = (GridButtonGroup) gb.getParentGroup();
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 < movedButtons.size(); i++) {
GridButton g = movedButtons.get(i);
DoublePoint p = g.getShape().getOrigin();
double tempX = Math.max(p.x + widgetMoveByX, 0.0);
double tempY = Math.max(p.y + widgetMoveByY, 0.0);
g.setWidgetOrigin(tempX, tempY);
}
if (widgetMoveByX == 0) {
gb.setVertSpace(newVert);
} else {
List<GridButton> column = gbg.getColumn(gb);
for (int i = 0; i < column.size(); i++) {
GridButton g = column.get(i);
g.setHorizSpace(newHoriz);
}
}
noteEditCheckRegenerate(movedButtons, this);
}
@Override
public void undo() {
super.undo();
for (int i = 0; i < movedButtons.size(); i++) {
GridButton g = movedButtons.get(i);
DoublePoint p = g.getShape().getOrigin();
double tempX = Math.max(p.x - widgetMoveByX, 0.0);
double tempY = Math.max(p.y - widgetMoveByY, 0.0);
g.setWidgetOrigin(tempX, tempY);
}
if (widgetMoveByX == 0) {
gb.setVertSpace(oldVert);
} else {
List<GridButton> column = gbg.getColumn(gb);
for (int i = 0; i < column.size(); i++) {
GridButton g = column.get(i);
g.setHorizSpace(oldHoriz);
}
}
noteEditCheckRegenerate(movedButtons, this);
}
};
noteEditCheckRegenerate(movedButtons, edit);
return edit;
}
use of edu.cmu.cs.hcii.cogtool.model.GridButton in project cogtool by cogtool.
the class FrameUIModel method getRightGridFigure.
@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getRightGridFigure(GraphicalGridButton gridFig) {
GridButton gb = gridFig.getModel();
GridButtonGroup group = (GridButtonGroup) gb.getParentGroup();
Iterator<IWidget> gbs = group.iterator();
DoubleRectangle bds = gb.getEltBounds();
double startX = bds.x;
double startY = bds.y;
IWidget result = null;
double resultX = 0.0;
while (gbs.hasNext()) {
IWidget cur = gbs.next();
if (cur == gb) {
continue;
}
bds = cur.getEltBounds();
double curX = bds.x;
double curY = bds.y;
if (PrecisionUtilities.withinEpsilon(startY, curY, GridButtonGroup.PIXEL_EPSILON) && (curX > startX)) {
if ((result == null) || (curX < resultX)) {
result = cur;
resultX = curX;
}
}
}
return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
use of edu.cmu.cs.hcii.cogtool.model.GridButton in project cogtool by cogtool.
the class FrameUIModel method getTopGridFigure.
@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getTopGridFigure(GraphicalGridButton gridFig) {
GridButton gb = gridFig.getModel();
GridButtonGroup group = (GridButtonGroup) gb.getParentGroup();
Iterator<IWidget> gbs = group.iterator();
DoubleRectangle bds = gb.getEltBounds();
double startX = bds.x;
double startY = bds.y;
IWidget result = null;
double resultY = 0.0;
while (gbs.hasNext()) {
IWidget cur = gbs.next();
if (cur == gb) {
continue;
}
bds = cur.getEltBounds();
double curX = bds.x;
double curY = bds.y;
if (PrecisionUtilities.withinEpsilon(startX, curX, GridButtonGroup.PIXEL_EPSILON) && (curY < startY)) {
if ((result == null) || (curY > resultY)) {
result = cur;
resultY = curY;
}
}
}
return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
use of edu.cmu.cs.hcii.cogtool.model.GridButton in project cogtool by cogtool.
the class FrameUIModel method getLeftGridFigure.
@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getLeftGridFigure(GraphicalGridButton gridFig) {
GridButton gb = gridFig.getModel();
GridButtonGroup group = (GridButtonGroup) gb.getParentGroup();
Iterator<IWidget> gbs = group.iterator();
DoubleRectangle bds = gb.getEltBounds();
double startX = bds.x;
double startY = bds.y;
IWidget result = null;
double resultX = 0.0;
while (gbs.hasNext()) {
IWidget cur = gbs.next();
if (cur == gb) {
continue;
}
bds = cur.getEltBounds();
double curX = bds.x;
double curY = bds.y;
if (PrecisionUtilities.withinEpsilon(startY, curY, GridButtonGroup.PIXEL_EPSILON) && (curX < startX)) {
if ((result == null) || (curX > resultX)) {
result = cur;
resultX = curX;
}
}
}
return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
Aggregations