use of edu.cmu.cs.hcii.cogtool.model.MenuItem 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.MenuItem in project cogtool by cogtool.
the class DesignExportToHTML method buildItemsString.
protected String buildItemsString(Iterator<IWidget> children) {
StringBuilder itemString = new StringBuilder();
itemString.append("[\n");
while (children.hasNext()) {
MenuItem child = (MenuItem) children.next();
itemString.append(" { text: \"" + child.getTitle() + "\"");
if (child.isSubmenu()) {
itemString.append(", submenu: { id: \"" + child.getName() + "\", itemdata: " + buildItemsString(child.getChildren().iterator()) + "} ");
} else {
itemString.append(", onclick: { fn: menuTransition, obj: ");
String menuMap = getMenuMap(child);
itemString.append(menuMap + "\n}\n");
}
itemString.append("},\n");
}
itemString.append(" ]");
return itemString.toString();
}
use of edu.cmu.cs.hcii.cogtool.model.MenuItem in project cogtool by cogtool.
the class FrameEditorController method createSetRenderSkinAction.
private IListenerAction createSetRenderSkinAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorUI.SetRenderSkinParameters.class;
}
public boolean performAction(Object prms) {
FrameEditorUI.SetRenderSkinParameters p = (FrameEditorUI.SetRenderSkinParameters) prms;
// Iterate through selected objects.
Iterator<IWidget> selected = p.selection.getSelectedWidgetsIterator();
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(CHG_WIDGET_RENDERED, FrameEditorLID.SetRenderSkin);
while (selected.hasNext()) {
IWidget w = selected.next();
if (w instanceof TraversableWidget) {
AParentWidget parent = null;
if (w instanceof MenuItem) {
parent = ((MenuItem) w).getTopHeader();
if (parent == null) {
// parent is a context menu
parent = ((MenuItem) w).getParent();
}
} else if (w instanceof ChildWidget) {
parent = ((ChildWidget) w).getParent();
} else if (w instanceof AParentWidget) {
parent = (AParentWidget) w;
}
if (parent != null) {
SimpleWidgetGroup group = parent.getParentGroup();
if (group != null) {
//menu header
renderGroup(group, p.rendered, parent.isRendered(), editSeq);
} else {
//pull down header
renderWidget(parent, p.rendered, parent.isRendered(), editSeq);
renderChildren(parent, p.rendered, parent.isRendered(), editSeq);
}
} else if (w.getParentGroup() != null) {
//list box item or radio button
renderGroup(w.getParentGroup(), p.rendered, w.isRendered(), editSeq);
}
} else {
renderWidget(w, p.rendered, w.isRendered(), editSeq);
}
}
editSeq.end();
// Only add this edit if it is significant
if (editSeq.isSignificant()) {
undoMgr.addEdit(editSeq);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.MenuItem 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.MenuItem in project cogtool by cogtool.
the class DesignEditorCmd method addChildWidgets.
private static void addChildWidgets(SimpleWidgetGroup widgetGroup, Frame f) {
if (widgetGroup != null) {
Iterator<IWidget> children = widgetGroup.iterator();
while (children.hasNext()) {
IWidget child = children.next();
makeWidgetNameUnique(child, f);
f.addWidget(child);
if (child instanceof MenuItem) {
MenuItem item = (MenuItem) child;
if (item.isSubmenu()) {
addChildWidgets(item.getChildren(), f);
}
}
}
}
}
Aggregations