use of edu.cmu.cs.hcii.cogtool.model.ListItem in project cogtool by cogtool.
the class FrameEditorUI method confirmRenameFigure.
protected void confirmRenameFigure() {
if ((editor != null) && editor.inUse()) {
String newTitle = editor.getText();
editor.cleanup();
// figure whose title is currently being edited
IFigure figure = (IFigure) editor.getData();
if (figure instanceof PotentialFigure) {
if ("".equals(newTitle)) {
// nothing to do if empty string on potential item!
return;
}
GraphicalTraversableWidget<?> parent = potentialUIFig.getFigureOwner();
TraversableWidget parentModel = (TraversableWidget) parent.getModel();
boolean isRightPotentialFigure = (figure == potentialUIFig.getRightFigure());
WidgetType type = null;
AParentWidget header = null;
SimpleWidgetGroup group = null;
boolean isSeparator = false;
if (parentModel instanceof MenuItem) {
type = WidgetType.MenuItem;
MenuItem parentItem = (MenuItem) parentModel;
if (isRightPotentialFigure) {
// position of selected figure is on the right
// parent menuitem becomes a submenu; figure to be
// created becomes a child of the submenu
parentItem.setSubmenu(true);
header = parentItem;
} else {
// if position is on the bottom and the parent is not a
// header, put the new widget in the same menu as the
// parent item
header = parentItem.getParent();
// previous item should hide children if it's a submenu
((GraphicalParentWidget<?, ?>) parent).closeChildren();
}
if (parentModel.getWidgetType() != WidgetType.Submenu) {
isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
}
} else if (parentModel instanceof ContextMenu) {
header = (ContextMenu) parentModel;
type = WidgetType.MenuItem;
isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
} else if (parentModel instanceof MenuHeader) {
// and hide children of the previous header
if (isRightPotentialFigure) {
type = WidgetType.Menu;
((GraphicalParentWidget<?, ?>) parent).closeChildren();
group = parentModel.getParentGroup();
} else {
header = (MenuHeader) parentModel;
type = WidgetType.MenuItem;
isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
}
} else if (parentModel instanceof PullDownItem) {
type = WidgetType.PullDownItem;
if (!isRightPotentialFigure) {
PullDownItem parentItem = (PullDownItem) parentModel;
header = parentItem.getParent();
isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
}
} else if (parentModel instanceof PullDownHeader) {
type = WidgetType.PullDownItem;
if (!isRightPotentialFigure) {
header = (PullDownHeader) parentModel;
isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
}
} else if (parentModel instanceof ListItem) {
type = WidgetType.ListBoxItem;
group = parentModel.getParentGroup();
isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
} else if (parentModel instanceof GridButton) {
type = parentModel.getWidgetType();
group = parentModel.getParentGroup();
}
Rectangle r = ((PotentialFigure) figure).getUnscaledBounds();
DoubleRectangle bounds = new DoubleRectangle(r.x, r.y, r.width, r.height);
performAction(CogToolLID.NewWidget, new FrameEditorUI.NewWidgetParameters(bounds, header, type, view.isAutomaticCreation(), newTitle, group, isSeparator));
} else {
boolean isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
performAction(FrameEditorLID.ChangeTitleProperty, new FrameEditorUI.ActionStringParameters(newTitle, selection, isSeparator), true);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.ListItem in project cogtool by cogtool.
the class FrameEditorController method createWidget.
private Widget createWidget(WidgetType defaultType, DoubleRectangle bounds, String widgetTitle, boolean isStandard) {
Widget widget;
// the user specified actual bounds interactively
if (isStandard) {
if (defaultType == WidgetType.Menu) {
SimpleWidgetGroup newMenuHeaderGroup = new SimpleWidgetGroup(SimpleWidgetGroup.HORIZONTAL);
widget = new MenuHeader(newMenuHeaderGroup, bounds, widgetTitle);
} else if (defaultType == WidgetType.PullDownList) {
widget = new PullDownHeader(bounds, widgetTitle);
} else if (defaultType == WidgetType.ContextMenu) {
widget = new ContextMenu(bounds, widgetTitle);
// The default value for CONTEXT_MENU_ACTION_ATTR
// is RIGHT_CLICK; must change to TAP_HOLD if the devices
// contain a Touchscreen but not a Mouse
Set<DeviceType> deviceTypes = design.getDeviceTypes();
if (deviceTypes.contains(DeviceType.Touchscreen) && !deviceTypes.contains(DeviceType.Mouse)) {
widget.setAttribute(WidgetAttributes.CONTEXT_MENU_ACTION_ATTR, WidgetAttributes.TAP_HOLD);
}
} else if (defaultType == WidgetType.ListBoxItem) {
SimpleWidgetGroup newListItemGroup = new SimpleWidgetGroup(SimpleWidgetGroup.VERTICAL);
widget = new ListItem(newListItemGroup, bounds, widgetTitle);
newListItemGroup.setAttribute(WidgetAttributes.FIRST_VISIBLE_ATTR, widget);
} else if (defaultType == WidgetType.Radio) {
RadioButtonGroup newRadioGroup = new RadioButtonGroup();
widget = new RadioButton(newRadioGroup, bounds, widgetTitle);
} else if (defaultType == WidgetType.Check) {
GridButtonGroup newCheckGroup = new GridButtonGroup();
widget = new CheckBox(newCheckGroup, bounds, widgetTitle);
} else {
// Create new widget in specified location
// Note: could be a child widget;
// if so, the user is managing the hierarchy!
widget = new Widget(bounds, defaultType);
}
widget.setAttribute(WidgetAttributes.IS_STANDARD_ATTR, WidgetAttributes.IS_STANDARD);
} else {
// Create new widget in specified location
// Note: could be a child widget;
// if so, the user is managing the hierarchy!
widget = new Widget(bounds, defaultType);
widget.setAttribute(WidgetAttributes.IS_STANDARD_ATTR, WidgetAttributes.IS_CUSTOM);
}
return widget;
}
use of edu.cmu.cs.hcii.cogtool.model.ListItem 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.ListItem in project cogtool by cogtool.
the class DesignExportToHTML method buildWidgetHTML.
protected String buildWidgetHTML(IWidget widget, Set<SimpleWidgetGroup> visitedGroups, Frame frame) {
//Function is called once for each widget...
StringBuilder html = new StringBuilder();
DoubleRectangle bounds = widget.getEltBounds();
String name = widget.getName();
//How does below boolean work?
boolean isStandard = widget.isStandard();
//MAYBE CREATE AN IF STATEMENT TO HANDLE BUTTONS/MENU BUTTON DIFFERENTLY
// Put the html widget in the same place as the CogTool widget
// (adjusting for the position of the html table)
//WE ARE ADDING TEN HERE TO COMPENSATE FOR LOCATION WITHIN BROWSER
//WE DO NOT WANT TO ADD THAT SINCE WE ARE SWITCHING TO AREA TAG AND DEALING WITHIN IMAGE ONLY
//POSITION AS OF NOW IS RELATIVE TO IMAGE :)
String properties = "onfocus=\"onFocus('" + name + "')\" onblur=\"onBlur()\"" + " id=\"" + name + "\" style=\"position: absolute; left: " + (bounds.x + 10) + "; top: " + (bounds.y + 33) + "; width: " + bounds.width + "; height: " + bounds.height + ";\"";
WidgetType type = widget.getWidgetType();
// don't pop up the "does not help..." message if there is no left click
// transition defined from these widgets
int ignoreButton = 0;
boolean ignoreLeftClick = (WidgetType.Check.equals(type) || WidgetType.TextBox.equals(type) || WidgetType.Graffiti.equals(type) || WidgetType.Menu.equals(type));
if (ignoreLeftClick) {
ignoreButton = LEFT_MOUSE;
} else if (WidgetType.ContextMenu.equals(type)) {
ignoreButton = RIGHT_MOUSE;
}
String eventString = getEventString(widget, ignoreButton);
if (!widget.isRendered() && "".equals(widget.getTitle()) && widget.getImage() == null && frame.getBackgroundImage() == null && !WidgetType.Noninteractive.equals(type)) {
blindHotSpotWarning += "This CogTool model has a hidden widget on screen. " + "You will not be able to visibly identify the location of +" + widget.getName() + ".\n";
}
//Why did they not use a switch statement here ?
if (isStandard) {
if (WidgetType.Noninteractive.equals(type) || WidgetType.Text.equals(type)) {
return getHotspotString(widget, properties, eventString);
}
if (WidgetType.Button.equals(type)) {
if (!widget.isRendered()) {
if (!"".equals(widget.getTitle())) {
html.append("<div align=\"middle\"" + properties + eventString + ">" + widget.getTitle() + "</div>\n");
}
//In the below 6 lines I create an area tag that will be placed within the map tags, within the html code,
//in order to create HotSpots over the image of the frame
mapHTML += "<area shape=\"rect\" name=value ";
mapHTML += "value ='" + widget.getTitle() + "'";
mapHTML += " onfocus=\"onFocus('" + name + "')\" onblur=\"onBlur()\"" + " id=\"" + name + "\"" + " coords=\"" + bounds.x + "," + bounds.y + "," + (bounds.x + bounds.width) + "," + (bounds.y + bounds.height) + "\"";
mapHTML += eventString + "/>\n";
} else {
html.append("<input type=button name=value value='");
html.append(widget.getTitle());
html.append("' " + properties + eventString + ">\n");
}
} else if (WidgetType.Check.equals(type)) {
String checked = "";
Object isSel = widget.getAttribute(WidgetAttributes.IS_SELECTED_ATTR);
if (NullSafe.equals(WidgetAttributes.IS_SELECTED, isSel)) {
checked = " checked";
}
// for checkboxes, width and height don't matter, so only deal with
// the x and y
String styleString = properties.substring(0, properties.indexOf("width")) + "\"";
html.append("<input type=checkbox " + styleString + eventString);
html.append(checked + ">\n");
String textStyle = "style=\"position: absolute; left: " + (bounds.x + 30) + "; top: " + (bounds.y + 33) + ";\"";
String textEvent = eventString;
if (textSelect(widget)) {
textEvent += " onclick=\"toggleCheckbox('";
textEvent += widget.getName();
textEvent += "')\"";
}
html.append("<a " + textStyle + textEvent + ">");
html.append(widget.getTitle() + "</a>\n");
} else if (WidgetType.Radio.equals(type)) {
SimpleWidgetGroup group = widget.getParentGroup();
if ((group != null) && !visitedGroups.contains(group)) {
visitedGroups.add(group);
String groupName = widget.getName();
Iterator<IWidget> widgets = group.iterator();
while (widgets.hasNext()) {
IWidget w = widgets.next();
DoublePoint origin = w.getShape().getOrigin();
String itemString = getEventString(w, LEFT_MOUSE);
String checked = "";
Object isSel = w.getAttribute(WidgetAttributes.IS_SELECTED_ATTR);
if (NullSafe.equals(WidgetAttributes.IS_SELECTED, isSel)) {
checked = " checked";
}
// for radio buttons, width and height don't matter, so only deal with
// the x and y
String styleString = "onfocus=\"onFocus('" + w.getName() + "')\" onblur=\"onBlur()\"" + "style=\"position: absolute; left: " + (origin.x + 10) + "; top: " + (origin.y + 33) + ";\"";
// TODO: if transitioned from, never deselects
html.append("<input type=radio name=\"" + groupName + "\"");
html.append(" id=\"");
html.append(w.getName());
html.append("\" " + styleString + itemString + checked + ">\n");
String textStyle = "style=\"position: absolute; left: " + (origin.x + 30) + "; top: " + (origin.y + 33) + ";\"";
String textEvent = itemString;
if (textSelect(w)) {
textEvent += " onclick=\"selectRadio('";
textEvent += w.getName();
textEvent += "')\"";
}
html.append("<a " + textStyle + textEvent + ">");
html.append(w.getTitle() + "</a>\n");
}
}
} else if (WidgetType.TextBox.equals(type) || WidgetType.Graffiti.equals(type)) {
html.append("<input type=text name=value value='");
html.append(widget.getTitle());
html.append("' " + properties + eventString + ">\n");
} else if (widget instanceof ListItem) {
SimpleWidgetGroup group = widget.getParentGroup();
// this code will change
if (!(visitedGroups.contains(group))) {
visitedGroups.add(group);
ListItem firstItem = (ListItem) group.get(0);
DoubleRectangle itemBounds = firstItem.getEltBounds();
// use properties of the first item in the list
properties = "onfocus=\"onFocus('" + firstItem.getName() + "')\" onblur=\"onBlur()\"" + " id=\"" + firstItem.getName() + "\" style=\"position: absolute; left: " + (itemBounds.x + 10) + "; top: " + (itemBounds.y + 33) + "; width: " + itemBounds.width + ";\"";
html.append("<select size=" + group.size() + " " + properties + ">\n");
Iterator<IWidget> widgets = group.iterator();
while (widgets.hasNext()) {
IWidget w = widgets.next();
String itemEvent = getEventString(w, 0);
html.append("<option" + itemEvent + " id=\"");
html.append(w.getName() + "\">");
html.append(w.getTitle() + "\n");
}
html.append("</select>\n");
}
} else if (widget instanceof MenuHeader) {
// make hotspot associated w/ menu, use widget's
// name for ID
// html.append("<input type=button name=value value='");
// html.append(widget.getTitle());
// html.append("' style=" + style + " id=\"");
// html.append(widget.getName());
// html.append("\">\n");
// TODO: add background color?
properties = properties.substring(0, properties.length() - 1);
properties += " background: lightGray;\"";
html.append("<div " + properties + eventString + ">");
html.append(widget.getTitle());
html.append("</div>\n");
} else if (widget instanceof ContextMenu) {
// TODO: add background color?
// style = style.substring(0, style.length() - 1);
// style += " background: lightGray;\"";
html.append("<div " + properties + eventString + ">");
html.append(widget.getTitle());
html.append("</div>\n");
} else if (widget instanceof PullDownHeader) {
PullDownHeader pdh = (PullDownHeader) widget;
//"select tag is used to create a select list" --> http://www.w3schools.com/TAGS/tag_Select.asp
html.append("<select " + properties + ">\n");
if (pdh.itemCount() > 0) {
//html.append("<optgroup>\n"); //TODO: style
Iterator<IWidget> children = pdh.getChildren().iterator();
while (children.hasNext()) {
IWidget pdi = children.next();
String childEvent = getEventString(pdi, 0);
html.append("<option" + childEvent + " id=\"");
html.append(pdi.getName() + "\">" + pdi.getTitle() + "\n");
}
//html.append("</optgroup>\n");
}
html.append("</select>\n");
} else if (WidgetType.Link.equals(type)) {
properties = properties.substring(0, properties.length() - 1);
html.append("<a " + properties + " color: blue;\"");
html.append(eventString + "><u>");
html.append(widget.getTitle());
html.append("</u></a>\n");
}
} else {
// unknown widget or custom version of an interactive widget
return getHotspotString(widget, properties, eventString);
}
return html.toString();
}
use of edu.cmu.cs.hcii.cogtool.model.ListItem in project cogtool by cogtool.
the class FrameEditorController method reorderWidget.
private boolean reorderWidget(final IWidget widget, final SimpleWidgetGroup newGroup, final int newIndex) {
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;
}
}
DoublePoint prevGroupStartPos = prevGroup.get(0).getShape().getOrigin();
final double prevGroupStartX = prevGroupStartPos.x;
final double prevGroupStartY = prevGroupStartPos.y;
DoubleSize prevSize = widget.getShape().getSize();
final double prevWidth = prevSize.width;
final double prevHeight = prevSize.height;
DoubleRectangle newBds = newGroup.get(0).getEltBounds();
double heightFactor = (widget instanceof ListItem) ? getHeightFactor(widget, newGroup) : 1.0;
final double newWidth = newBds.width;
final double newHeight = newBds.height * heightFactor;
final double newGroupStartX = newBds.x;
final double newGroupStartY = newBds.y;
Object rendered = newGroup.getAttribute(WidgetAttributes.IS_RENDERED_ATTR);
final boolean groupRendered = ((Boolean) rendered).booleanValue();
final boolean widgetRendered = widget.isRendered();
reorderGroupWidget(widget, newWidth, newHeight, index, prevGroup, newGroup, prevGroupStartX, prevGroupStartY, newGroupStartX, newGroupStartY);
if (widgetRendered != groupRendered) {
widget.setRendered(groupRendered);
}
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.Reorder, demoStateMgr) {
@Override
public String getPresentationName() {
return REORDER_WIDGET;
}
@Override
public void redo() {
super.redo();
int index = newIndex;
if (prevGroup == newGroup) {
if (prevIndex < newIndex) {
index--;
}
}
reorderGroupWidget(widget, newWidth, newHeight, index, prevGroup, newGroup, prevGroupStartX, prevGroupStartY, newGroupStartX, newGroupStartY);
if (widgetRendered != groupRendered) {
widget.setRendered(groupRendered);
}
noteEditCheckRegenerate(prevGroup, newGroup, this);
}
@Override
public void undo() {
super.undo();
reorderGroupWidget(widget, prevWidth, prevHeight, prevIndex, newGroup, prevGroup, newGroupStartX, newGroupStartY, prevGroupStartX, prevGroupStartY);
if (widgetRendered != groupRendered) {
widget.setRendered(widgetRendered);
}
noteEditCheckRegenerate(newGroup, prevGroup, this);
}
};
noteEditCheckRegenerate(prevGroup, newGroup, edit);
undoMgr.addEdit(edit);
return true;
}
Aggregations