use of edu.cmu.cs.hcii.cogtool.model.PullDownHeader in project cogtool by cogtool.
the class SEDemoUI method populateContextMenu.
protected void populateContextMenu(TransitionSource source, List<MenuItemDefinition> menuItems) {
Collection<Transition> values = source.getTransitions().values();
Iterator<Transition> iter = values.iterator();
SEDemoTransitionLID itemLID;
while (iter.hasNext()) {
Transition trans = iter.next();
SEDemoUI.DemoTransition ftrans = new SEDemoUI.FollowTransition(selection, trans);
// Add the ftrans to the list in the context menus
itemLID = new SEDemoTransitionLID("PerformDemoTransition", ftrans);
String transitionStr = KeyDisplayUtil.convertActionToMenuText(ftrans.getLocalizedString());
MenuItemDefinition mItem = new SimpleMenuItemDefinition(transitionStr, itemLID, MenuUtil.ENABLED);
menuItems.add(mItem);
}
// Check to see if any transitions are actually available.
if (values.size() == 0) {
MenuItemDefinition mItem = new SimpleMenuItemDefinition(L10N.get("SE.DemoNoPredefinedTransitions", "No defined transitions for ") + source.getName(), null);
// Add a default disabled message
menuItems.add(mItem);
}
boolean selfTransitionOK = true;
// Add a default look-at transition for all regions except Devices
if (source.getTransitionSourceType() == TransitionSourceType.Widget) {
IWidget widget = (IWidget) source;
Object isSep = widget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if ((NullSafe.equals(WidgetAttributes.IS_SEPARATOR, isSep)) || (widget.getWidgetType() == WidgetType.Noninteractive) || ((widget instanceof MenuHeader) || (widget instanceof PullDownHeader) || (widget instanceof ContextMenu))) {
selfTransitionOK = false;
}
// Add standard menus to the list of items
menuItems.add(MenuUtil.SEPARATOR);
SEDemoUI.DemoTransition lookAtTrans = new SEDemoUI.LookAtTransition(selection, widget);
// Add default transition options.
String itemLabel = L10N.get("SE.DemoLookAt", "Look at") + " " + widget.getName();
itemLID = new SEDemoTransitionLID("PerformDemoLookAtTransition", lookAtTrans);
menuItems.add(new SimpleMenuItemDefinition(itemLabel, itemLID, MenuUtil.ENABLED));
}
if (selfTransitionOK) {
menuItems.add(MenuUtil.SEPARATOR);
itemLID = new SEDemoTransitionLID("PerformSelfTransition", new SEDemoUI.SelfTransition(selection, source, null));
MenuItemDefinition mItem = new SimpleMenuItemDefinition(L10N.get("SE.SelfTransition", "Perform Self-transition"), itemLID, MenuUtil.ENABLED);
menuItems.add(mItem);
}
}
use of edu.cmu.cs.hcii.cogtool.model.PullDownHeader 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.PullDownHeader 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.PullDownHeader 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();
}
Aggregations