use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class FrameEditorController method insertDuplicateEdit.
private void insertDuplicateEdit(final IWidget duplicatedWidget, final ReadOnlyList<? extends IWidget> widgetCopies, final SimpleWidgetGroup group, final int index, final AParentWidget parent, final double startPosX, final double startPosY, IUndoableEditSequence editSeq) {
DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(FrameEditorLID.Duplicate, demoStateMgr) {
@Override
public String getPresentationName() {
return DUPLICATE_WIDGET;
}
@Override
public void redo() {
super.redo();
if (duplicatedWidget instanceof ChildWidget) {
ChildWidget child = (ChildWidget) duplicatedWidget;
AParentWidget curParent = child.getParent();
curParent.addItem(index, child);
} else if (index >= 0) {
group.add(index, duplicatedWidget);
} else {
group.add(duplicatedWidget);
}
model.addWidget(duplicatedWidget);
stateMgr.noteWidgetsEdit(widgetCopies, this);
if (parent != null) {
DesignEditorCmd.repositionChildren(parent);
} else if (group != null) {
DesignEditorCmd.repositionChildren(group, startPosX, startPosY);
}
}
@Override
public void undo() {
super.undo();
if (duplicatedWidget instanceof ChildWidget) {
ChildWidget child = (ChildWidget) duplicatedWidget;
AParentWidget curParent = child.getParent();
curParent.removeItem(child);
} else if (duplicatedWidget.getParentGroup() != null) {
SimpleWidgetGroup parentGroup = duplicatedWidget.getParentGroup();
parentGroup.remove(duplicatedWidget);
}
model.removeWidget(duplicatedWidget);
stateMgr.noteWidgetsEdit(widgetCopies, this);
if (parent != null) {
DesignEditorCmd.repositionChildren(parent);
} else if (group != null) {
DesignEditorCmd.repositionChildren(group, startPosX, startPosY);
}
}
};
editSeq.addEdit(edit);
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class FrameEditorController method insertDuplicateWidget.
/**
* If group or parent is non-null, duplicate the widget within the given
* group. If they are both null, the widget was dragged to empty space, so
* give it a new group.
*/
private boolean insertDuplicateWidget(IWidget widget, SimpleWidgetGroup group, int index, AParentWidget parent, double moveByX, double moveByY) {
Map<IWidget, IWidget> widgetCopies = new LinkedHashMap<IWidget, IWidget>();
double startPosX = 0.0;
double startPosY = 0.0;
DoubleSize newSize;
if (parent != null) {
newSize = getNewWidgetSize(parent);
newSize.height *= getHeightFactor(widget, parent.getChildren());
} else if ((group == null) || (group.size() == 0)) {
newSize = widget.getShape().getSize();
} else {
DoublePoint startPos = group.get(0).getShape().getOrigin();
startPosX = startPos.x;
startPosY = startPos.y;
newSize = group.get(0).getShape().getSize();
if (widget instanceof ListItem) {
newSize.height *= getHeightFactor(widget, group);
}
}
widgetSituator.reset(widgetCopies, null);
IWidget newWidget = null;
if (parent != null) {
if (widget instanceof ChildWidget) {
newWidget = ((ChildWidget) widget).duplicate(parent, lookupFrameDuplicator, widgetSituator, index);
newWidget.setWidgetSize(newSize.width, newSize.height);
if (newWidget instanceof AParentWidget) {
resizeChildren(newWidget);
DesignEditorCmd.repositionChildren((AParentWidget) newWidget);
}
DesignEditorCmd.repositionChildren(parent);
}
} else if (group != null) {
if (widget instanceof MenuHeader) {
newWidget = ((MenuHeader) widget).duplicate(group, lookupFrameDuplicator, widgetSituator, index);
} else if (widget instanceof ListItem) {
newWidget = ((ListItem) widget).duplicate(group, lookupFrameDuplicator, index);
}
newWidget.setWidgetSize(newSize.width, newSize.height);
resizeChildren(newWidget);
widgetSituator.placeInContext(widget, newWidget);
DesignEditorCmd.repositionChildren(group, startPosX, startPosY);
} else {
// Duplicating into space
if ((widget instanceof MenuHeader) || (widget instanceof ListItem)) {
SimpleWidgetGroup newGroup = null;
if (widget instanceof MenuHeader) {
newGroup = new SimpleWidgetGroup(SimpleWidgetGroup.HORIZONTAL);
newWidget = ((MenuHeader) widget).duplicate(newGroup, lookupFrameDuplicator, widgetSituator);
} else {
// (widget instanceof ListItem)
newGroup = new SimpleWidgetGroup(SimpleWidgetGroup.VERTICAL);
newWidget = ((ListItem) widget).duplicate(newGroup, lookupFrameDuplicator);
}
group = newGroup;
widgetSituator.placeInContext(widget, newWidget);
newWidget.moveElement(moveByX, moveByY);
group.setAttribute(WidgetAttributes.IS_RENDERED_ATTR, Boolean.valueOf(widget.isRendered()));
}
}
widgetSituator.completeWork();
Collection<IWidget> duplicateWidgets = widgetCopies.values();
Iterator<IWidget> copies = duplicateWidgets.iterator();
while (copies.hasNext()) {
IWidget widgetCopy = copies.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);
}
SimpleWidgetGroup newGroup = (group != null) ? group : newWidget.getParentGroup();
Object rendered = newGroup.getAttribute(WidgetAttributes.IS_RENDERED_ATTR);
boolean groupRendered = ((Boolean) rendered).booleanValue();
boolean widgetRendered = widget.isRendered();
if (groupRendered != widgetRendered) {
newWidget.setRendered(groupRendered);
}
insertDuplicateEdit(newWidget, new ReadOnlyList<IWidget>(new ArrayList<IWidget>(duplicateWidgets)), group, index, parent, startPosX, startPosY, undoMgr);
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class FrameEditorController method reorderChildWidget.
private boolean reorderChildWidget(final ChildWidget widget, final SimpleWidgetGroup newGroup, final int newIndex, final AParentWidget newParent) {
final SimpleWidgetGroup prevGroup = widget.getParentGroup();
final int prevIndex = prevGroup.indexOf(widget);
int index = newIndex;
if (prevGroup == newGroup) {
if (prevIndex < newIndex) {
index--;
}
if (index == prevIndex) {
return true;
}
}
final AParentWidget prevParent = widget.getParent();
DoubleSize prevSize = widget.getShape().getSize();
final double prevWidth = prevSize.width;
final double prevHeight = prevSize.height;
DoubleSize newSize = getNewWidgetSize(newParent);
final double newWidth = newSize.width;
final double newHeight = newSize.height * getHeightFactor(widget, newGroup);
final boolean widgetRendered = widget.isRendered();
reorderChildWidget(widget, newWidth, newHeight, index, prevParent, newParent);
Object rendered = widget.getParentGroup().getAttribute(WidgetAttributes.IS_RENDERED_ATTR);
final boolean groupRendered = ((Boolean) rendered).booleanValue();
if (widgetRendered != groupRendered) {
widget.setRendered(groupRendered);
}
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.Reorder, demoStateMgr) {
private ChildWidget child = widget;
@Override
public String getPresentationName() {
return REORDER_WIDGET;
}
@Override
public void redo() {
super.redo();
int index = newIndex;
if (prevGroup == newGroup) {
if (prevIndex < newIndex) {
index--;
}
}
reorderChildWidget(child, newWidth, newHeight, index, prevParent, newParent);
if (widgetRendered != groupRendered) {
widget.setRendered(groupRendered);
}
noteEditCheckRegenerate(prevParent.getChildren(), newParent.getChildren(), this);
}
@Override
public void undo() {
super.undo();
reorderChildWidget(child, prevWidth, prevHeight, prevIndex, newParent, prevParent);
if (widgetRendered != groupRendered) {
widget.setRendered(widgetRendered);
}
noteEditCheckRegenerate(newParent.getChildren(), prevParent.getChildren(), this);
}
};
noteEditCheckRegenerate(prevParent.getChildren(), newParent.getChildren(), edit);
undoMgr.addEdit(edit);
if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class FrameEditorController method resizeChildren.
private void resizeChildren(IWidget widget) {
if (widget instanceof AParentWidget) {
AParentWidget parent = (AParentWidget) widget;
DoubleSize size = parent.getShape().getSize();
if (parent instanceof MenuHeader) {
size.width *= FrameEditorUI.MENU_ITEM_RATIO;
}
int numItems = parent.itemCount();
for (int i = 0; i < numItems; i++) {
ChildWidget child = parent.getItem(i);
double h = size.height;
Object isSep = child.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, isSep)) {
h /= FrameEditorUI.SEPARATOR_RATIO;
}
child.setWidgetSize(size.width, h);
resizeChildren(child);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class WidgetPropertiesPane method showAttributeWidgets.
public void showAttributeWidgets(IWidget widget) {
WidgetType type = widget.getWidgetType();
widgetTitle.setText(DISPLAYED_LABEL);
Object pathObj = widget.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
if (!NullSafe.equals(WidgetAttributes.NO_IMAGE, pathObj)) {
String imgPath = (String) pathObj;
imagePath.setVisible(true);
imagePathText.setVisible(true);
imagePathText.setText(imgPath);
imagePathText.setSelection(imgPath.length());
}
if ((type == WidgetType.MenuItem) || (type == WidgetType.PullDownItem) || (type == WidgetType.ListBoxItem)) {
isSeparator.setVisible(true);
Object value = widget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
boolean isSep = NullSafe.equals(WidgetAttributes.IS_SEPARATOR, value);
isSeparator.setSelection(isSep);
widgetTitleText.setEnabled(!isSep);
widgetAuxText.setEnabled(!isSep);
}
// Remote label support
// First check if this is a remote label
FrameElement remoteLabelOwner = (FrameElement) widget.getAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR);
if (remoteLabelOwner != null) {
String ownerWidgetName = remoteLabelOwner.getName();
if ((ownerWidgetName == null) || ownerWidgetName.equals("")) {
if (remoteLabelOwner instanceof RadioButtonGroup) {
ownerWidgetName = "[ anonymous radio button group ]";
} else if (remoteLabelOwner instanceof GridButtonGroup) {
ownerWidgetName = "[ anonymous checkbox group ]";
} else if (remoteLabelOwner instanceof SimpleWidgetGroup) {
ownerWidgetName = "[ anonymous widget group ]";
} else if (remoteLabelOwner instanceof SimpleWidgetGroup) {
ownerWidgetName = "[ unnamed element group ]";
} else {
ownerWidgetName = "[ unnamed widget ]";
}
}
this.remoteLabelOwner.setVisible(true);
remoteLabelOwnerName.setVisible(true);
remoteLabelOwnerName.setText("<a>" + ownerWidgetName + "</a>");
remoteLabelType.setVisible(true);
remoteLabelTypeCombo.setVisible(true);
selectCurrentValue(remoteLabelTypeCombo, widgetTypeChoices, widget.getWidgetType());
imagePath.setLayoutData(isRemoteLabelAlign);
} else {
// Otherwise, check if this widget has a remote label
remoteLabelOwner = widget.getRemoteLabelOwner();
// reset layout to eliminate space for the remote label
if (remoteLabelOwner == null) {
imagePath.setLayoutData(noRemoteLabelAlign);
} else {
IWidget remoteLabelWidget = (IWidget) remoteLabelOwner.getAttribute(WidgetAttributes.REMOTE_LABEL_ATTR);
if (remoteLabelWidget != null) {
remoteLabelText.setText(remoteLabelWidget.getTitle());
remoteLabelFind.setVisible(true);
} else {
// Display an empty remote label stuff to allow one to be set
remoteLabelText.setText("");
remoteLabelFind.setVisible(false);
}
remoteLabel.setVisible(true);
remoteLabelText.setVisible(true);
imagePath.setLayoutData(hasRemoteLabelAlign);
}
}
if (!widget.isStandard()) {
layout();
return;
}
if ((type == WidgetType.Menu) || (type == WidgetType.ContextMenu)) {
submenuActionLabel.setVisible(true);
submenuAction.setVisible(true);
submenuDelayLabel.setVisible(true);
submenuDelay.setVisible(true);
Integer submenuAction = (Integer) widget.getAttribute(WidgetAttributes.SUBMENU_ACTION_ATTR);
selectCurrentValue(this.submenuAction, submenuActions, submenuAction);
Double delay = (Double) widget.getAttribute(WidgetAttributes.SUBMENU_DELAY_ATTR);
if (NullSafe.equals(WidgetAttributes.NO_SUBMENU_DELAY, delay)) {
submenuDelay.select(0);
} else if (NullSafe.equals(WidgetAttributes.PC_SUBMENU_DELAY, delay)) {
submenuDelay.select(1);
} else {
submenuDelay.setText(delay.toString() + " s");
}
if (type == WidgetType.ContextMenu) {
contextMenuActionLabel.setVisible(true);
contextMenuAction.setVisible(true);
Integer contextAction = (Integer) widget.getAttribute(WidgetAttributes.CONTEXT_MENU_ACTION_ATTR);
selectCurrentValue(contextMenuAction, contextMenuActions, contextAction);
}
}
if (type == WidgetType.Check) {
isInitiallySelected.setVisible(true);
Boolean selected = (Boolean) widget.getAttribute(WidgetAttributes.IS_SELECTED_ATTR);
isInitiallySelected.setSelection(selected.booleanValue());
} else if (type == WidgetType.Button) {
// TODO: "clicked-on" for Link?
isToggleable.setVisible(true);
Boolean selected = (Boolean) widget.getAttribute(WidgetAttributes.IS_TOGGLEABLE_ATTR);
isToggleable.setSelection(selected.booleanValue());
isButtonSelected.setEnabled(selected.booleanValue());
isButtonSelected.setVisible(true);
selected = (Boolean) widget.getAttribute(WidgetAttributes.IS_SELECTED_ATTR);
isButtonSelected.setSelection(selected.booleanValue());
} else if (type == WidgetType.TextBox) {
// this.isMultiLine.setVisible(true);
//
// Boolean multi =
// (Boolean) widget.getAttribute(WidgetType.IS_MULTILINE_ATTR);
//
// this.isMultiLine.setSelection(multi.booleanValue());
widgetTitle.setText(TEXT_CONTENTS);
} else if (type == WidgetType.Radio) {
selectLabel.setVisible(true);
initiallySelected.setVisible(true);
initiallySelected.removeAll();
initiallySelected.add(SELECT_NONE);
RadioButtonGroup group = (RadioButtonGroup) widget.getParentGroup();
if (group != null) {
Iterator<IWidget> widgets = group.iterator();
IWidget[] map = new IWidget[group.size()];
int i = 0;
while (widgets.hasNext()) {
IWidget curWidget = widgets.next();
map[i++] = curWidget;
String name = curWidget.getNameLabel();
initiallySelected.add(name);
}
// This works because null isn't in the list so indexOf
// returns -1 if SELECT_NONE is chosen
int index = group.indexOf(group.getSelection()) + 1;
initiallySelected.select(index);
selectionAttrListener.setAttributeHelper(RADIO_HELPER, map);
}
} else if (type == WidgetType.PullDownList) {
selectLabel.setVisible(true);
initiallySelected.setVisible(true);
initiallySelected.removeAll();
initiallySelected.add(SELECT_NONE);
initiallySelected.select(0);
SimpleWidgetGroup group = ((AParentWidget) widget).getChildren();
Iterator<IWidget> widgets = group.iterator();
IWidget[] map = new IWidget[group.size()];
int i = 0;
Widget selected = (Widget) widget.getAttribute(WidgetAttributes.SELECTION_ATTR);
while (widgets.hasNext()) {
IWidget curWidget = widgets.next();
Object isSep = curWidget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if (NullSafe.equals(WidgetAttributes.NON_SEPARATOR, isSep)) {
String name = curWidget.getNameLabel();
initiallySelected.add(name);
if (curWidget == selected) {
initiallySelected.select(i + 1);
}
map[i++] = curWidget;
}
}
selectionAttrListener.setAttributeHelper(PULLDOWN_HELPER, map);
}
// TODO implement list box support
// else if (type == WidgetType.ListBoxItem) {
// this.selectLabel.setVisible(true);
// this.initiallySelected.setVisible(true);
// this.initiallySelected.removeAll();
// this.initiallySelected.add(SELECT_NONE);
// this.visibleLabel.setVisible(true);
// this.firstVisible.setVisible(true);
// this.firstVisible.removeAll();
// this.numVisibleLabel.setVisible(true);
// this.numVisible.setVisible(true);
//
// SimpleWidgetGroup group = widget.getParentGroup();
//
// Integer num =
// (Integer) group.getAttribute(WidgetType.NUM_VISIBLE_ATTR);
// this.numVisible.setSelection(num.intValue());
//
// Iterator<IWidget> widgets = group.getAllWidgets();
// while (widgets.hasNext()) {
// IWidget curWidget = widgets.next();
// String name = curWidget.getDisplayLabel();
// this.initiallySelected.add(name);
// this.firstVisible.add(name);
// }
//
// IWidget init =
// (IWidget) group.getAttribute(WidgetType.SELECTION_ATTR);
// int ind = group.indexOf(init) + 1;
// this.initiallySelected.select(ind);
// init = (IWidget) group.getAttribute(WidgetType.FIRST_VISIBLE_ATTR);
// ind = group.indexOf(init);
// this.firstVisible.select(ind);
// }
layout();
}
Aggregations