use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class DesignExportToHTML method buildKeyTransitionMap.
/**
* Outputs a Javascript function that makes a map from the transition
* string to the name of the destination frame
* (treats Graffiti transitions as keyboard transitions)
*/
protected String buildKeyTransitionMap(Collection<InputDevice> devices, Collection<IWidget> widgets) {
StringBuilder html = new StringBuilder();
Iterator<InputDevice> deviceIterator = devices.iterator();
while (deviceIterator.hasNext()) {
InputDevice device = deviceIterator.next();
if (DeviceType.Keyboard.equals(device.getDeviceType()) || DeviceType.Touchscreen.equals(device.getDeviceType())) {
// first save all transitions from the device
Iterator<Transition> transitions = device.getTransitions().values().iterator();
while (transitions.hasNext()) {
Transition transition = transitions.next();
AAction action = transition.getAction();
if (action instanceof TextAction) {
String text = cleanup(((TextAction) action).getText());
html.append("keyTransitionMap[\"" + text + "\"]");
html.append(" = \'");
html.append(getFrameURL(transition.getDestination(), ".html"));
html.append("\';\n");
}
}
}
}
Iterator<IWidget> widgetIterator = widgets.iterator();
// NOTE: does not work with list box items or any menus
while (widgetIterator.hasNext()) {
IWidget w = widgetIterator.next();
String name = "\"" + w.getName() + "\"";
Iterator<Transition> wTransitions = w.getTransitions().values().iterator();
boolean foundKeyTransition = false;
while (wTransitions.hasNext()) {
Transition transition = wTransitions.next();
AAction action = transition.getAction();
if (action instanceof TextAction) {
if (!foundKeyTransition) {
foundKeyTransition = true;
html.append("focusTransitionMaps[" + name + "] = new Object();\n");
}
String key = "\"" + cleanup(((TextAction) action).getText()) + "\"";
String dest = "'" + getFrameURL(transition.getDestination(), ".html") + "'";
html.append("focusTransitionMaps[" + name + "][");
html.append(key + "] = " + dest + ";\n");
}
}
}
return html.toString();
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget 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.IWidget in project cogtool by cogtool.
the class DesignExportToHTML method warningStrings.
public String warningStrings(Design d) {
StringBuilder result = new StringBuilder();
for (Frame frame : d.getFrames()) {
for (IWidget widget : frame.getWidgets()) {
WidgetType type = widget.getWidgetType();
if (widget.isStandard()) {
if (WidgetType.Button.equals(type)) {
if (!widget.isRendered()) {
String title = widget.getTitle();
if (title == null || title.length() == 0) {
result.append("Frame \"");
result.append(frame.getName());
result.append("\" contains a hidden hot-spot button at widget \"");
result.append(widget.getName());
result.append("\".\n");
}
}
}
}
}
}
return (result.length() > 0 ? result.toString() : null);
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorMouseState method withinReorder.
// dynamicReorderWidget
protected boolean withinReorder(int x, int y) {
double zoom = ui.getZoom();
if (lastHoveredWidget != null) {
IWidget lastWidget = lastHoveredWidget.getModel();
SimpleWidgetGroup lastGroup = lastWidget.getParentGroup();
if (lastGroup != null) {
if (lastGroup.indexOf(lastWidget) == lastGroup.size() - 1) {
Rectangle bounds = ui.getGroupFigureBounds(lastGroup);
Rectangle reorderBds = new Rectangle();
Rectangle widgetBds = lastHoveredWidget.getBounds();
reorderBds.width = widgetBds.width + 20;
reorderBds.height = widgetBds.height + 20;
if (lastGroup.getOrientation() == SimpleWidgetGroup.VERTICAL) {
reorderBds.x = bounds.x;
reorderBds.y = bounds.y + bounds.height;
} else if (lastGroup.getOrientation() == SimpleWidgetGroup.HORIZONTAL) {
reorderBds.x = bounds.x + bounds.width;
reorderBds.y = bounds.y;
}
reorderBds.x = PrecisionUtilities.round(reorderBds.x * zoom);
reorderBds.y = PrecisionUtilities.round(reorderBds.y * zoom);
reorderBds.width = PrecisionUtilities.round(reorderBds.width * zoom);
reorderBds.height = PrecisionUtilities.round(reorderBds.height * zoom);
return reorderBds.contains(x, y);
}
}
}
return false;
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorMouseState method handleMousePressed.
/**
* Called on mouse presses
* Determines if the mouse pressed on a resize widget.
* Raises a resizeAlert or a mouseOperations alert.
*
* Alerts contain X,Y coordinates in 1:1 scale.
*/
protected void handleMousePressed(int x, int y, int state) {
ui.view.getEditor().getSWTEditorSubstrate().setFocus();
// Check to see if the pressed event is on the resize handlers.
// Use the ZOOMED scale because the resize widgets are in the
// interaction layer and they're not affected by zoom.
ResizeThumb resize = ui.widgetResizeUnderXY(x, y);
PotentialFigure pWidget = ui.potentialWidgetUnderXY(x, y);
RadioButtonSash sash = ui.radioSashUnderXY(x, y);
// Check to see if the mouse press happened on a resize widget
if (resize != null) {
// Need this because we want the actual AREA,
// not the center of the thumb.
initialResizeArea = ui.getSelectedWidgetArea();
// Set the fixed point of the resize
double fixedX = 0.0;
double fixedY = 0.0;
// Move through the possible types and set the fixed point.
currentResizeHandleType = resize.thumbType;
switch(resize.thumbType) {
case FrameEditorUI.TOP_LEFT:
fixedX = initialResizeArea.x + initialResizeArea.width;
fixedY = initialResizeArea.y + initialResizeArea.height;
break;
case FrameEditorUI.BOTTOM_LEFT:
fixedX = initialResizeArea.x + initialResizeArea.width;
fixedY = initialResizeArea.y;
break;
case FrameEditorUI.TOP_RIGHT:
fixedX = initialResizeArea.x;
fixedY = initialResizeArea.y + initialResizeArea.height;
break;
case FrameEditorUI.BOTTOM_RIGHT:
fixedX = initialResizeArea.x;
fixedY = initialResizeArea.y;
break;
default:
// and this code wasn't modified.
throw new IllegalStateException("Unknown type of Resize Thumb selected");
}
// Specify the fixed resize point.
mouseFixedResizeX = fixedX;
mouseFixedResizeY = fixedY;
// Set the state to "resize" as the next action.
// TODO: Should we implement the other types of resizing?
int nextState = PotentialResizingWidget;
setMouseState(nextState);
// Switch to fast mode rendering for graphical widgets
setWidgetFastRenderMode(true);
} else if (sash != null) {
moveIsVertical = sash.isVertical();
setMouseState(PotentialMovingGridButtons);
} else if (pWidget != null) {
ui.initiateRetitleFigure(pWidget);
} else {
// Get whatever graphical widget under x,y
GraphicalWidget<?> wf = ui.widgetLocatedAtXY(x, y);
MoveHalo halo = ui.moveHaloUnderXY(x, y);
RemoteLinkage linkage = ui.linkageUnderXY(x, y);
GraphicalParentWidget<?, ?> currentParent = null;
// If SHIFT is held, always treat as start of a drag toggle select.
if ((state & InputEvent.SHIFT) != 0) {
setMouseState(PotentialTogglingSelection);
} else if (wf != null) {
IWidget widget = wf.getModel();
SimpleWidgetGroup group = widget.getParentGroup();
lastClickedWidget = widget;
if ((state & platformDuplicateModifierKey()) != 0) {
if (!selection.isElementSelected(widget)) {
selection.setSelectedSelnFig(wf);
}
if ((group != null) && (group.getOrientation() != SimpleWidgetGroup.FREEFORM) && (selection.getWidgetSelectionCount() == 1)) {
setMouseState(PotentialInsertDuplicateWidget);
} else {
setMouseState(PotentialDuplicatingWidget);
}
} else {
if ((group != null) && (group.getOrientation() != SimpleWidgetGroup.FREEFORM)) {
if (!selection.isElementSelected(widget)) {
selection.setSelectedSelnFig(wf);
}
setMouseState(PotentialReorderWidget);
} else // possible move.
if (selection.isSelectionFigureSelected(wf)) {
setMouseState(PotentialMovingSelection);
} else {
selection.setSelectedSelnFig(wf);
setMouseState(PotentialMovingWidget);
}
}
if (wf instanceof GraphicalMenuItem) {
GraphicalMenuItem menuItemFig = (GraphicalMenuItem) wf;
if (menuItemFig.isSubmenu()) {
currentParent = menuItemFig;
} else {
currentParent = menuItemFig.getParentFigure();
}
} else if (wf instanceof GraphicalParentWidget<?, ?>) {
currentParent = (GraphicalParentWidget<?, ?>) wf;
} else if (wf instanceof GraphicalChildWidget<?, ?>) {
currentParent = ((GraphicalChildWidget<?, ?>) wf).getParentFigure();
}
} else if (halo != null) {
if (halo instanceof FrameEltGroupHalo) {
FrameEltGroupHalo groupHalo = (FrameEltGroupHalo) halo;
if ((state & platformDuplicateModifierKey()) != 0) {
if (!selection.isElementSelected(halo.getData())) {
selection.setSelectedSelnFig(groupHalo);
}
setMouseState(PotentialDuplicatingWidget);
} else {
selection.setSelectedSelnFig(groupHalo);
setMouseState(PotentialMovingSelection);
}
} else {
/* if (wf != null) {
IWidget widget = wf.getWidgetModel();
SimpleWidgetGroup group = widget.getParentGroup();
if ((state & platformDuplicateModifierKey()) != 0) {
if (! this.selection.isWidgetSelected(widget)) {
this.selection.setSelectedWidget(wf);
}
if ((group != null) &&
(group.getOrientation() != SimpleWidgetGroup.FREEFORM) &&
(this.selection.getWidgetSelectionCount() == 1))
{
setMouseState(PotentialInsertDuplicateWidget);
}
else {
setMouseState(PotentialDuplicatingWidget);
}
}
else {
setMouseState(PotentialMovingSelection);
}
}
else { */
setMouseState(PotentialMovingSelection);
}
// }
} else if (linkage != null) {
FrameElement owner = linkage.getOwner();
IWidget remoteLabel = linkage.getRemoteLabel();
// Ensure both are selected; if not yet, then set them
// both selected.
FrameEltSelnFig<?> ownerRepresentative = isSomeElementSelected(owner);
if ((!selection.isElementSelected(remoteLabel)) || (ownerRepresentative == null)) {
if (ownerRepresentative == null) {
ownerRepresentative = getRepresentativeElt(owner);
}
selection.setSelectedSelnFig(linkage.getRemoteLabelFigure());
if (ownerRepresentative != null) {
selection.selectSelnFig(ownerRepresentative);
}
}
setMouseState(PotentialMovingSelection);
} else // Otherwise, out in space and SHIFT not held; deselect all and
// prepare to create
{
selection.deselectAll();
setMouseState(PotentialCreatingWidget);
}
ui.hideAllChildren();
if (currentParent != null) {
currentParent.openChildren();
ui.resetVisibleArea();
}
}
}
Aggregations