use of edu.cmu.cs.hcii.cogtool.model.MenuHeader 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.MenuHeader 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.MenuHeader in project cogtool by cogtool.
the class FrameEditorMouseState method setDividerBounds.
// dynamicMoveWidgets
protected void setDividerBounds(GraphicalWidget<?> widget, int x, int y) {
double zoom = ui.getZoom();
Rectangle bounds = widget.getBounds();
int originX = bounds.x + (bounds.width / 2);
int originY = bounds.y + (bounds.height / 2);
originX = PrecisionUtilities.round(originX * zoom);
originY = PrecisionUtilities.round(originY * zoom);
double newX = bounds.x;
double newY = bounds.y;
double newH = bounds.height;
double newW = bounds.width;
int heightInc = 0;
int widthInc = 0;
if ((lastClickedWidget instanceof ChildWidget) && (widget instanceof GraphicalParentWidget<?, ?>) && (!(widget instanceof GraphicalMenuItem))) {
AParentWidget parent = (AParentWidget) widget.getModel();
int childrenLoc = parent.getChildrenLocation();
switch(childrenLoc) {
case AParentWidget.CHILDREN_BELOW:
case AParentWidget.CHILDREN_CENTER:
{
if (childrenLoc == AParentWidget.CHILDREN_CENTER) {
newX += newW / 2.0;
newY += newH / 2.0;
} else {
newY += newH;
}
if (parent.hasChildren()) {
IWidget child = parent.getItem(0);
DoubleSize childSize = child.getShape().getSize();
newW = childSize.width;
newH = childSize.height;
Object value = child.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, value)) {
newH *= FrameEditorUI.SEPARATOR_RATIO;
}
} else if (parent instanceof MenuHeader) {
newW *= FrameEditorUI.MENU_ITEM_RATIO;
}
newH /= 10.0;
newY -= newH / 2.0;
heightInc = 1;
break;
}
case AParentWidget.CHILDREN_RIGHT:
{
newX += newW;
if (parent.hasChildren()) {
DoubleSize childSize = parent.getItem(0).getShape().getSize();
newW = childSize.width;
newH = childSize.height;
}
newW /= 20.0;
newX -= newW / 2.0;
widthInc = 1;
break;
}
}
} else {
switch(widget.getModel().getParentGroup().getOrientation()) {
case SimpleWidgetGroup.HORIZONTAL:
{
if (x > originX) {
newX += newW;
}
newW /= 20.0;
newX -= newW / 2.0;
widthInc = 1;
break;
}
case SimpleWidgetGroup.VERTICAL:
{
if (y > originY) {
newY += newH;
}
newH /= 10.0;
Object value = widget.getModel().getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if (WidgetAttributes.IS_SEPARATOR.equals(value)) {
newH *= FrameEditorUI.SEPARATOR_RATIO;
}
newY -= newH / 2.0;
heightInc = 1;
break;
}
}
}
newX *= zoom;
newY *= zoom;
double rightX = newX + (newW + widthInc) * zoom;
double bottomY = newY + (newH + heightInc) * zoom;
newW = PrecisionUtilities.round(rightX - newX);
newH = PrecisionUtilities.round(bottomY - newY);
newX = PrecisionUtilities.round(newX);
newY = PrecisionUtilities.round(newY);
dividerLine.setBounds(new Rectangle((int) newX, (int) newY, (int) newW, (int) newH));
dividerLine.setVisible(true);
}
use of edu.cmu.cs.hcii.cogtool.model.MenuHeader 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.MenuHeader 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;
}
};
}
Aggregations