use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.
the class FrameEditorController method createSetRenderSkinAction.
private IListenerAction createSetRenderSkinAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorUI.SetRenderSkinParameters.class;
}
public boolean performAction(Object prms) {
FrameEditorUI.SetRenderSkinParameters p = (FrameEditorUI.SetRenderSkinParameters) prms;
// Iterate through selected objects.
Iterator<IWidget> selected = p.selection.getSelectedWidgetsIterator();
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(CHG_WIDGET_RENDERED, FrameEditorLID.SetRenderSkin);
while (selected.hasNext()) {
IWidget w = selected.next();
if (w instanceof TraversableWidget) {
AParentWidget parent = null;
if (w instanceof MenuItem) {
parent = ((MenuItem) w).getTopHeader();
if (parent == null) {
// parent is a context menu
parent = ((MenuItem) w).getParent();
}
} else if (w instanceof ChildWidget) {
parent = ((ChildWidget) w).getParent();
} else if (w instanceof AParentWidget) {
parent = (AParentWidget) w;
}
if (parent != null) {
SimpleWidgetGroup group = parent.getParentGroup();
if (group != null) {
//menu header
renderGroup(group, p.rendered, parent.isRendered(), editSeq);
} else {
//pull down header
renderWidget(parent, p.rendered, parent.isRendered(), editSeq);
renderChildren(parent, p.rendered, parent.isRendered(), editSeq);
}
} else if (w.getParentGroup() != null) {
//list box item or radio button
renderGroup(w.getParentGroup(), p.rendered, w.isRendered(), editSeq);
}
} else {
renderWidget(w, p.rendered, w.isRendered(), editSeq);
}
}
editSeq.end();
// Only add this edit if it is significant
if (editSeq.isSignificant()) {
undoMgr.addEdit(editSeq);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.
the class FrameEditorController method deleteWidget.
/**
* This deletes a widget from the model and adds the action to the undo list.
*
* @param w is the widget to delete.
* @param moveSiblings is a flag - if it is true, the other widgets in the
* group will be moved to close up the space left by the deleted widget.
* @param editSequence is the compound edit to add this delete operation to.
*/
private void deleteWidget(IWidget w, boolean moveSiblings, FrameElementGroup fromGroup, IUndoableEditSequence editSequence) {
// If this is a remote label, delete the attribute indicating so
// from the point of view of its owner.
FrameElement remoteLabelOwner = (FrameElement) w.getAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR);
if (remoteLabelOwner != null) {
DefaultCmd.unsetAttribute(remoteLabelOwner, demoStateMgr, WidgetAttributes.REMOTE_LABEL_ATTR, interaction, editSequence);
} else {
// Check if this widget is a remote label owner; if so, delete
// the remote label as well
deleteRemoteLabel(w, editSequence);
}
SimpleWidgetGroup parentGroup = w.getParentGroup();
int atIndex = (parentGroup != null) ? parentGroup.indexOf(w) : -1;
double deltaX = 0;
double deltaY = 0;
// since we know every item in them will be deleted.
if (w instanceof AParentWidget) {
AParentWidget pw = (AParentWidget) w;
while (pw.itemCount() > 0) {
deleteWidget(pw.getItem(0), false, fromGroup, editSequence);
}
}
// If the widget is the last object of the its root element,
// then the root element must be removed from any containing groups
// and, if the root element is the second to last member of any
// group, then the group should be removed as well.
// This must be done before the removeWidget call.
FrameElement rootElt = w.getRootElement();
// containing associations
if (rootElt == w) {
removeRootElement(DELETE_WIDGET, rootElt, fromGroup, editSequence);
} else if (rootElt instanceof SimpleWidgetGroup) {
// Otherwise, need to do the same only if the root element
// is a widget group that will become empty.
SimpleWidgetGroup rootGroup = (SimpleWidgetGroup) rootElt;
// remove it from containing associations
if (rootGroup.size() == 1) {
removeRootElement(DELETE_WIDGET, rootElt, fromGroup, editSequence);
}
}
model.removeWidget(w);
if (parentGroup != null) {
// Check if this parent group is a remote label owner; if so, delete
// the remote label as well
deleteRemoteLabel(parentGroup, editSequence);
if (moveSiblings) {
int myGroupNum = parentGroup.size();
if (parentGroup.getOrientation() == SimpleWidgetGroup.HORIZONTAL) {
deltaX = -w.getEltBounds().width;
} else if (parentGroup.getOrientation() == SimpleWidgetGroup.VERTICAL) {
deltaY = -w.getEltBounds().height;
}
// This loop will be ineffective for grid buttons
for (int i = atIndex + 1; i < myGroupNum; i++) {
IWidget curWidget = parentGroup.get(i);
curWidget.moveElement(deltaX, deltaY);
}
}
// Otherwise, remove it from its parent group.
if (w instanceof ChildWidget) {
ChildWidget child = (ChildWidget) w;
AParentWidget itemParent = child.getParent();
itemParent.removeItem(child);
} else {
parentGroup.remove(w);
}
if (parentGroup instanceof GridButtonGroup) {
GridButtonGroup gbg = (GridButtonGroup) parentGroup;
GridButton gb = (GridButton) w;
DoubleRectangle b = w.getEltBounds();
double x = b.x + b.width;
double y = b.y + b.height;
double newHoriz = gb.getHorizSpace();
double newVert = gb.getVertSpace();
ReadOnlyList<GridButton> movedButtons = null;
GridButton top = null;
double dx = 0.0;
double dy = 0.0;
if (gbg.getColumn(gb).size() == 0) {
// w was the only widget in the column; need to move next
// column over
movedButtons = gbg.getMovedButtons(false, x, b.y);
if (movedButtons.size() > 0) {
top = movedButtons.get(0);
DoublePoint p = top.getShape().getOrigin();
dx = b.x - p.x;
}
} else {
// need to move lower widgets up to fill the hole
movedButtons = gbg.getMovedButtons(true, b.x, y);
if (movedButtons.size() > 0) {
top = movedButtons.get(0);
DoublePoint p = top.getShape().getOrigin();
dy = b.y - p.y;
}
}
if (top != null) {
moveGridButton(FrameEditorLID.Delete, DELETE_WIDGET, top, dx, dy, newHoriz, newVert, editSequence);
}
}
}
DemoStateManager.IDesignUndoableEdit edit;
// Add the deletion to the undoable history
if (w instanceof ChildWidget) {
ChildWidget child = (ChildWidget) w;
final AParentWidget itemParent = child.getParent();
edit = new DeleteWidgetUndoableEdit(w, parentGroup, atIndex, deltaX, deltaY) {
@Override
public void redoHelper() {
itemParent.removeItem((ChildWidget) widget);
}
@Override
public void undoHelper() {
itemParent.addItem(atIndex, (ChildWidget) widget);
}
};
} else {
edit = new DeleteWidgetUndoableEdit(w, parentGroup, atIndex, deltaX, deltaY) {
@Override
public void redoHelper() {
parentGroup.remove(widget);
}
@Override
public void undoHelper() {
parentGroup.add(atIndex, widget);
}
};
}
demoStateMgr.noteWidgetEdit(w, edit);
editSequence.addEdit(edit);
}
use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.
the class FrameEditorController method createNewWidgetAction.
/**
* Create a ListenerAction to handle creating a new Widget.
*
*/
private IListenerAction createNewWidgetAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
// TODO: Should we provide more input to this default widget?
// Dialog box with option?
// Current/last palette setting
// TODO: Bonnie wanted to have new widgets show up under the
// mouse. To do that we need to do something like
// getCursorLocation() (from display)
// offset based on the (0,0) of the window
// Might want to get that based on GetCursorControl().
// If working with the control, you need to walk the tree to
// get the actual offset from 0,0, in the display.
//
// Alternatively, in specialize, get the mouse pointer position
// from mousestate (but that would require tracking the mouse
// state -- on hover at least).
// Instantiate the appropriate widget. If the class was passed
// a prms, use that to dictate what to do.
Widget widget = null;
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(NEW_WIDGET, FrameEditorLID.NewWidget);
if (prms instanceof FrameEditorUI.NewWidgetParameters) {
FrameEditorUI.NewWidgetParameters nwp = (FrameEditorUI.NewWidgetParameters) prms;
// widget
if (nwp.parent != null) {
if (nwp.type == WidgetType.MenuItem) {
// Create menu item; may become a submenu through
// user interaction later
widget = new MenuItem((AMenuWidget) nwp.parent, nwp.bounds, nwp.widgetTitle);
} else if (nwp.type == WidgetType.PullDownItem) {
widget = new PullDownItem((PullDownHeader) nwp.parent, nwp.bounds, nwp.widgetTitle);
boolean rendered = nwp.parent.isRendered();
SimpleWidgetGroup group = widget.getParentGroup();
group.setAttribute(WidgetAttributes.IS_RENDERED_ATTR, Boolean.valueOf(rendered));
}
} else // widget group
if (nwp.parentGroup != null) {
if (nwp.type == WidgetType.Menu) {
widget = new MenuHeader(nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
} else if (nwp.type == WidgetType.ListBoxItem) {
widget = new ListItem(nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
} else if (nwp.type == WidgetType.Radio) {
widget = new RadioButton((RadioButtonGroup) nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
} else if (nwp.type == WidgetType.Check) {
widget = new CheckBox((GridButtonGroup) nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
}
} else {
widget = createWidget(nwp.type, nwp.bounds, nwp.widgetTitle, nwp.isAutomatic);
}
if (nwp.isSeparator) {
frameSetAttribute(widget, WidgetAttributes.IS_SEPARATOR_ATTR, WidgetAttributes.IS_SEPARATOR, editSequence);
}
}
// if (widget.getWidgetType() == WidgetType.TextBox) {
// widget.setAttribute(WidgetAttributes.IS_STANDARD_ATTR,
// WidgetAttributes.IS_CUSTOM);
// }
// Auto-generate a unique name for the widget
widget.setName(generateUniqueWidgetName());
// Build the widget: check for uniqueness and add to the frame
boolean result = addCreatedWidget(widget, editSequence);
editSequence.end();
undoMgr.addEdit(editSequence);
return result;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.
the class FrameEditorController method deleteGroupMember.
private void deleteGroupMember(FrameElement elt, FrameElementGroup fromGroup, IUndoableEditSequence editSequence) {
if (elt instanceof IWidget) {
deleteWidget((IWidget) elt, false, fromGroup, editSequence);
} else if (elt instanceof FrameElementGroup) {
deleteFrameEltGroup((FrameElementGroup) elt, fromGroup, editSequence);
} else if (elt instanceof SimpleWidgetGroup) {
SimpleWidgetGroup parentGroup = (SimpleWidgetGroup) elt;
while (parentGroup.size() > 0) {
IWidget child = parentGroup.get(0);
// If the widget group is itself a remote label owner,
// its remote label will be deleted in the first call here.
deleteWidget(child, false, fromGroup, editSequence);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.
the class FrameEditorController method duplicateFrameEltGroup.
// duplicateWidget
private FrameElementGroup duplicateFrameEltGroup(FrameElementGroup grp, double moveByX, double moveByY) {
// Temporarily assign the same name; when added to the Frame
// we will ensure the name is then unique
FrameElementGroup newEltGrp = grp.twin();
Iterator<FrameElement> eltsToDup = grp.iterator();
while (eltsToDup.hasNext()) {
FrameElement elt = eltsToDup.next();
FrameElement eltCopy = null;
if (elt instanceof IWidget) {
IWidget widget = (IWidget) elt;
duplicateWidget(widget, null, moveByX, moveByY);
eltCopy = widgetSituator.getDuplicate(widget);
} else if (elt instanceof SimpleWidgetGroup) {
SimpleWidgetGroup group = (SimpleWidgetGroup) elt;
SimpleWidgetGroup groupCopy = widgetSituator.getGroup(group);
Iterator<IWidget> groupWidgets = group.iterator();
while (groupWidgets.hasNext()) {
duplicateGroupMember(groupWidgets.next(), null, moveByX, moveByY);
}
Frame.duplicateRemoteLabel(group, groupCopy, lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
eltCopy = groupCopy;
} else if (elt instanceof FrameElementGroup) {
eltCopy = duplicateFrameEltGroup((FrameElementGroup) elt, moveByX, moveByY);
}
if (eltCopy != null) {
newEltGrp.add(eltCopy);
}
}
widgetSituator.setGroupDuplicate(grp, newEltGrp);
Frame.duplicateRemoteLabel(grp, newEltGrp, lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
return newEltGrp;
}
Aggregations