use of edu.cmu.cs.hcii.cogtool.model.GridButtonGroup 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.GridButtonGroup 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.GridButtonGroup 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.GridButtonGroup 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.GridButtonGroup 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