use of edu.cmu.cs.hcii.cogtool.model.ChildWidget in project cogtool by cogtool.
the class DesignEditorCmd method copyElements.
public static void copyElements(Design design, FrameElement[] selectedElts, Iterator<FrameElement> eltsToCopy, boolean saveToClipboard) {
try {
// Set up a clipboard saver. Indicate that no transitions
// should be copied.
CogToolClipboard.ClipboardClassSaver s = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyWidgets, selectedElts, saveToClipboard);
// Iterate through the widgets and save the selected items.
while (eltsToCopy.hasNext()) {
FrameElement elt = eltsToCopy.next();
// get pasted.
if (!(elt instanceof ChildWidget)) {
s.saveObject(elt);
}
}
s.finish();
if (!saveToClipboard) {
FrameTemplateSupport.setFrameTemplate(design, s.getSavedString());
}
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (OutOfMemoryError error) {
throw new RcvrOutOfMemoryException("Copying Widgets", error);
}
}
use of edu.cmu.cs.hcii.cogtool.model.ChildWidget in project cogtool by cogtool.
the class DesignEditorCmd method addWidgetUndoableEdit.
public static IDesignUndoableEdit addWidgetUndoableEdit(Frame frame, IWidget widget, DemoStateManager mgr) {
if (widget instanceof ChildWidget) {
ChildWidget childWidget = (ChildWidget) widget;
final AParentWidget itemParent = childWidget.getParent();
final int atIndex = itemParent.indexOf(childWidget);
return new AddWidgetUndoableEdit(frame, widget, mgr) {
@Override
protected void redoHelper() {
itemParent.addItem(atIndex, (ChildWidget) widget);
}
@Override
protected void undoHelper() {
itemParent.removeItem((ChildWidget) widget);
}
};
}
final SimpleWidgetGroup parentGroup = widget.getParentGroup();
final int atIndex = (parentGroup != null) ? parentGroup.indexOf(widget) : -1;
return new AddWidgetUndoableEdit(frame, widget, mgr) {
@Override
protected void redoHelper() {
if (parentGroup != null) {
parentGroup.add(atIndex, widget);
// TODO:mlh reposition items/headers following!
}
}
@Override
protected void undoHelper() {
if (parentGroup != null) {
parentGroup.remove(widget);
// TODO:mlh reposition items/headers following!
}
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.ChildWidget in project cogtool by cogtool.
the class FrameEditorMouseState method dynamicReorderWidget.
protected void dynamicReorderWidget(int x, int y, boolean duplicate) {
int dx = x - lastX;
int dy = y - lastY;
Point frameOrigin = reorderFigure.getLocation();
frameOrigin.x += dx;
frameOrigin.y += dy;
reorderFigure.setLocation(frameOrigin);
GraphicalWidget<?> curWidgetFig = ui.widgetLocatedAtXY(x, y);
PotentialFigure potential = ui.potentialWidgetUnderXY(x, y);
ui.resizeHandlesUIFig.hide();
dividerLine.setVisible(false);
if ((curWidgetFig != null) && ui.areCompatible(lastClickedWidget, curWidgetFig.getModel()) && (duplicate || reorderAllowed(curWidgetFig.getModel()))) {
boolean isChildWidget = lastClickedWidget instanceof ChildWidget;
boolean changedWidget = curWidgetFig.getModel() != lastClickedWidget;
lastHoveredWidget = curWidgetFig;
// If the dragged widget is not a child, it won't make sense to
// drag it onto a potential figure
// MLHQ: How do you know this cast will succeed?
ui.hideNonhaloSupport(!isChildWidget, changedWidget, (GraphicalTraversableWidget<?>) curWidgetFig);
setDividerBounds(curWidgetFig, x, y);
if (lastClickedWidget instanceof ChildWidget) {
if (curWidgetFig instanceof GraphicalChildWidget<?, ?>) {
GraphicalChildWidget<?, ?> child = (GraphicalChildWidget<?, ?>) curWidgetFig;
child.getParentFigure().openChildren();
}
if (curWidgetFig instanceof GraphicalParentWidget<?, ?>) {
if (changedWidget) {
((GraphicalParentWidget<?, ?>) curWidgetFig).openChildren();
}
}
}
} else if (potential != null) {
GraphicalTraversableWidget<?> owner = ui.getPotentialFigureOwner();
if (owner instanceof GraphicalChildWidget<?, ?>) {
((GraphicalChildWidget<?, ?>) owner).getParentFigure().openChildren();
}
ui.potentialUIFig.setSelection(potential);
} else {
if (withinReorder(x, y)) {
setDividerBounds(lastHoveredWidget, x, y);
if (lastHoveredWidget instanceof GraphicalChildWidget<?, ?>) {
GraphicalChildWidget<?, ?> gcw = (GraphicalChildWidget<?, ?>) lastHoveredWidget;
gcw.getParentFigure().openChildren();
}
} else if ((lastClickedWidget instanceof ChildWidget) || !duplicate) {
ui.hideNondynamicSupport(true, false);
InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
drawLayer.setCursor(NOT_ALLOWED_CURSOR);
}
}
}
Aggregations