use of edu.cmu.cs.hcii.cogtool.model.GridButton in project cogtool by cogtool.
the class FrameEditorController method duplicateWidgetsAction.
// duplicateFrameEltGroup
private IListenerAction duplicateWidgetsAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorUI.DuplicateParameters.class;
}
public boolean performAction(Object prms) {
FrameEditorUI.DuplicateParameters parameters = (FrameEditorUI.DuplicateParameters) prms;
int elementCount = parameters.selection.getElementSelectionCount();
// If selection is non zero, copy widgets
if (elementCount > 0) {
Map<IWidget, IWidget> widgetCopies = new LinkedHashMap<IWidget, IWidget>();
final Map<FrameElementGroup, FrameElementGroup> groupCopies = new LinkedHashMap<FrameElementGroup, FrameElementGroup>();
widgetSituator.reset(widgetCopies, groupCopies);
Set<FrameElement> selectedElements = getSelectedElements(parameters.selection, elementLevelComparator);
Iterator<FrameElement> elements = selectedElements.iterator();
// Iterate through the widgets and duplicate.
while (elements.hasNext()) {
FrameElement elt = elements.next();
if (elt instanceof IWidget) {
duplicateWidget((IWidget) elt, parameters.selection, parameters.moveByX, parameters.moveByY);
} else if (elt instanceof FrameElementGroup) {
duplicateFrameEltGroup((FrameElementGroup) elt, parameters.moveByX, parameters.moveByY);
}
}
widgetSituator.completeWork();
final Iterable<? extends IWidget> widgetDuplicates = new ReadOnlyList<IWidget>(new ArrayList<IWidget>(widgetCopies.values()));
Iterator<? extends IWidget> copiedWidgets = widgetDuplicates.iterator();
Set<GridButtonGroup> dupGridGroups = new HashSet<GridButtonGroup>();
while (copiedWidgets.hasNext()) {
IWidget widgetCopy = copiedWidgets.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);
if (widgetCopy instanceof GridButton) {
GridButtonGroup gbg = (GridButtonGroup) widgetCopy.getParentGroup();
// for each grid button group
if (!dupGridGroups.contains(gbg)) {
gbg.recalculateOffsets();
dupGridGroups.add(gbg);
}
}
}
Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
while (copiedGroups.hasNext()) {
FrameElementGroup copiedGroup = copiedGroups.next();
// Ensure name is unique, then add to frame immediately
// Otherwise, it would be possible to generate presumed
// unique names that weren't.
makeEltGroupNameUnique(copiedGroup);
model.addEltGroup(copiedGroup);
}
DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(FrameEditorLID.Duplicate, demoStateMgr) {
@Override
public String getPresentationName() {
return DUPLICATE_WIDGETS;
}
@Override
public void redo() {
super.redo();
Iterator<? extends IWidget> addCopies = widgetDuplicates.iterator();
while (addCopies.hasNext()) {
IWidget widgetCopy = addCopies.next();
model.addWidget(widgetCopy);
}
Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
while (copiedGroups.hasNext()) {
model.addEltGroup(copiedGroups.next());
}
demoStateMgr.noteWidgetsEdit(widgetDuplicates, this);
}
@Override
public void undo() {
super.undo();
Iterator<? extends IWidget> removeCopies = widgetDuplicates.iterator();
while (removeCopies.hasNext()) {
IWidget widgetCopy = removeCopies.next();
model.removeWidget(widgetCopy);
}
Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
while (copiedGroups.hasNext()) {
model.removeEltGroup(copiedGroups.next());
}
demoStateMgr.noteWidgetsEdit(widgetDuplicates, this);
}
};
demoStateMgr.noteWidgetsEdit(widgetDuplicates, edit);
undoMgr.addEdit(edit);
return true;
}
// tell user to select something.
interaction.protestNoSelection();
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.GridButton in project cogtool by cogtool.
the class FrameEditorController method moveWidget.
private void moveWidget(ListenerIdentifier lid, String presentationLabel, IWidget widget, double widgetMoveByX, double widgetMoveByY, boolean moveAsGroup, Set<SimpleWidgetGroup> movedGroups, Set<IWidget> movedWidgets, IUndoableEditSequence editSequence) {
if (movedWidgets.contains(widget)) {
return;
}
movedWidgets.add(widget);
SimpleWidgetGroup parentGroup = widget.getParentGroup();
if ((parentGroup == null) || (!moveAsGroup)) {
if (widget instanceof GridButton) {
GridButton gb = (GridButton) widget;
moveGridButton(lid, presentationLabel, gb, widgetMoveByX, widgetMoveByY, gb.getHorizSpace() + widgetMoveByX, gb.getVertSpace() + widgetMoveByY, editSequence);
} else {
moveWidget(lid, presentationLabel, widget, widgetMoveByX, widgetMoveByY, editSequence);
}
} else if (!(widget instanceof ChildWidget)) {
// move entire group
if (!movedGroups.contains(parentGroup)) {
moveWidgetGroup(lid, presentationLabel, parentGroup, widgetMoveByX, widgetMoveByY, editSequence);
movedGroups.add(parentGroup);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.GridButton in project cogtool by cogtool.
the class FrameEditorController method moveGridButton.
/**
* Special case of moveWidget; moves all buttons below or to the right of
* gb in its group and updates the horizontal and vertical offsets as
* necessary.
*/
private void moveGridButton(ListenerIdentifier lid, String presentationLabel, GridButton gb, double widgetMoveByX, double widgetMoveByY, double newHoriz, double newVert, IUndoableEditSequence editSequence) {
// move the list of buttons affected
DoublePoint oldLocation = gb.getShape().getOrigin();
double oldX = oldLocation.x;
double oldY = oldLocation.y;
GridButtonGroup gbg = (GridButtonGroup) gb.getParentGroup();
boolean vertical = (widgetMoveByX == 0);
double oldHoriz = gb.getHorizSpace();
double oldVert = gb.getVertSpace();
ReadOnlyList<? extends GridButton> movedButtons = gbg.getMovedButtons(vertical, oldX, oldY);
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 (vertical) {
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);
}
}
DemoStateManager.IDesignUndoableEdit edit = moveGridButtonsEdit(lid, presentationLabel, movedButtons, widgetMoveByX, widgetMoveByY, oldHoriz, oldVert, newHoriz, newVert, gb);
editSequence.addEdit(edit);
}
use of edu.cmu.cs.hcii.cogtool.model.GridButton in project cogtool by cogtool.
the class FrameEditorMouseState method dynamicMoveGridButtons.
// mouseDragged
protected void dynamicMoveGridButtons(double currentScaledX, double currentScaledY) {
GraphicalWidget<?> gw = ui.getPotentialFigureOwner();
GridButton gb = (GridButton) gw.getModel();
DoublePoint start = gb.getShape().getOrigin();
double moveX = 0.0;
double moveY = 0.0;
double offsetX = currentScaledX - scaledMouseDownX;
double offsetY = currentScaledY - scaledMouseDownY;
ui.hideNondynamicSupport(true);
if (moveIsVertical) {
moveY = (currentScaledY < minY) ? (minY - start.y) : offsetY;
} else {
moveX = (currentScaledX < minX) ? (minX - start.x) : offsetX;
}
// Iterate through list of affected radio buttons
for (int i = 0; i < movedGridButtons.size(); i++) {
GridButton w = movedGridButtons.get(i);
GraphicalWidget<?> wf = ui.frameUI.getWidgetFigure(w);
DoublePoint p = w.getShape().getOrigin();
// Temporarily move the widget origin to new location.
wf.setLocation(new Point(PrecisionUtilities.round(p.x + moveX), PrecisionUtilities.round(p.y + moveY)));
// this.ui.setGraphicalWidgetOrigin(p.x + moveX, p.y + moveY, wf);
}
}
Aggregations