use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method duplicateWidget.
// duplicateGroupMember
private IWidget duplicateWidget(IWidget widget, FrameEditorSelectionState selection, double moveByX, double moveByY) {
// If already copied, simply return the copy.
IWidget widgetCopy = widgetSituator.getDuplicate(widget);
if (widgetCopy != null) {
return widgetCopy;
}
// call for the remote "label" in duplicateRemoteLabel().
if (widget instanceof ChildWidget) {
return null;
}
// (also gets GridButton and ListItem)
if (widget.getParentGroup() != null) {
widgetCopy = duplicateGroupMember(widget, selection, moveByX, moveByY);
} else {
// This gets PullDownHeader and ContextMenu (but not
// MenuHeader/Item) and all else but MenuItem and PullDownItem
// (i.e., children)
// TODO: Is there any reasonable semantics to
// duplicating menu/pull-down items?
widgetCopy = Frame.duplicateWidget(widget, lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
}
// If this is a remote label, then check if the owner is also being
// duplicated; if so, keep the remote label as a remote label.
// If not, remote the attribute on the copy.
FrameElement remoteLabelOwner = (FrameElement) widget.getAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR);
if (remoteLabelOwner != null) {
if ((selection != null) && !selection.isElementSelected(remoteLabelOwner)) {
// Remove "label"-ness
widgetCopy.unsetAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR);
}
// otherwise, when the owner gets duplicated, it will replace
// the owner of this label with its copy; see duplicateRemoteLabel!
} else {
Frame.duplicateRemoteLabel(widget, widgetCopy, lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
}
return widgetCopy;
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget 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);
}
}
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class DesignEditorCmd method addChildWidgets.
private static void addChildWidgets(Frame frame, SimpleWidgetGroup widgetGroup, DemoStateManager mgr, IUndoableEditSequence editSeq) {
if (widgetGroup != null) {
Iterator<IWidget> children = widgetGroup.iterator();
while (children.hasNext()) {
IWidget child = children.next();
makeWidgetNameUnique(child, frame);
frame.addWidget(child);
if (editSeq != null) {
editSeq.addEdit(addWidgetUndoableEdit(frame, child, mgr));
}
if (child instanceof MenuItem) {
MenuItem item = (MenuItem) child;
if (item.isSubmenu()) {
addChildWidgets(frame, item.getChildren(), mgr, editSeq);
}
}
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class GraphicalWidgetBase method updateType.
public synchronized void updateType() {
// Mark the caches as dirty so that no one will use them
synchronized (this.flagLock) {
this.cachedMidgroundDirty = true;
}
IWidget w = getModel();
try {
// Change the renderer to one that is appropriate for the type
this.renderer = getRendererForType(w.getWidgetType(), w.getFrame().getDesign().getSkin(), w.isRendered());
} catch (Exception e) {
System.err.println("Error creating widget renderer: " + e);
try {
this.renderer = getRendererForType(w.getWidgetType(), SkinType.None, w.isRendered());
} catch (Exception ex) {
System.err.println("Error creating unskinned widget renderer: " + e);
this.renderer = new LabelRenderer(this.attrOverride);
}
}
Dimension widgetExtent = getSize();
this.renderer.setSize(widgetExtent.width, widgetExtent.height);
this.renderer.setText(w.getTitle());
this.renderer.updateData();
setCursor(determineProperCursor(w, this.desiredRolloverCursor));
regenerateCaches();
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class GraphicalWidgetBase method getRendererForType.
/**
* Factory method that generates a painter corresponding to a given widget type
* @param type the widget type, or null to indicate an unrendered widget
* @return a renderer appropriate to the widget type
*/
protected GraphicalWidgetRenderer getRendererForType(WidgetType type, SkinType skin, boolean renderSkin) {
if ((type == WidgetType.Noninteractive) || (type == WidgetType.Text)) {
return new LabelRenderer(this.attrOverride);
}
if ((type == WidgetType.Link) && renderSkin) {
return new LinkWireRenderer(this, this.attrOverride);
}
if (renderSkin && (skin == SkinType.WireFrame)) {
if (type == WidgetType.Button) {
return new ItemWireRenderer(ItemWireRenderer.LABEL_CENTER, this, this.attrOverride);
}
if (type == WidgetType.Check) {
return new ChoiceWireRenderer(ChoiceWireRenderer.CHECK, this, this.attrOverride);
}
if (type == WidgetType.Radio) {
return new ChoiceWireRenderer(ChoiceWireRenderer.RADIO, this, this.attrOverride);
}
if (type == WidgetType.TextBox) {
return new TextBoxRenderer(ItemWireRenderer.LABEL_LEFT, this, this.attrOverride);
}
if (type == WidgetType.Submenu) {
return new SubmenuWireRenderer(this, this.attrOverride);
}
if (type == WidgetType.PullDownList) {
return new PulldownListWireRenderer(this, this.attrOverride);
}
if ((type == WidgetType.PullDownItem) || (type == WidgetType.ListBoxItem) || (type == WidgetType.Menu) || (type == WidgetType.MenuItem) || (type == WidgetType.Graffiti)) {
return new ItemWireRenderer(ItemWireRenderer.LABEL_LEFT, this, this.attrOverride);
}
}
if ((!renderSkin) || (skin == SkinType.None)) {
if (type == WidgetType.TextBox) {
return new LabelRenderer(GraphicalWidgetRenderer.LABEL_LEFT, this.attrOverride);
}
// By default, just paint the widget's title
if (type == WidgetType.Button) {
return new LabelRenderer(this.attrOverride);
}
if (type.equals(WidgetType.Submenu)) {
return new SubmenuLabelRenderer(this.attrOverride);
}
if (type == WidgetType.PullDownList) {
LabelRenderer lRenderer = new LabelRenderer(GraphicalWidgetRenderer.LABEL_LEFT, this.attrOverride) {
@Override
public void updateData() {
GraphicalWidget<?> gw = (GraphicalWidget<?>) getParent();
IWidget widget = gw.getModel();
setText(RendererSupport.getPullDownSelectedTitle(widget, lAttrOverride));
}
};
return lRenderer;
}
if ((type == WidgetType.PullDownItem) || (type == WidgetType.ListBoxItem) || (type == WidgetType.MenuItem)) {
return new LabelRenderer(GraphicalWidgetRenderer.LABEL_LEFT, this.attrOverride) {
@Override
public void updateData() {
GraphicalWidget<?> gw = (GraphicalWidget<?>) getParent();
IWidget w = gw.getModel();
Object sepValue = w.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
boolean isSep = NullSafe.equals(WidgetAttributes.IS_SEPARATOR, sepValue);
setText(isSep ? GraphicalWidgetRenderer.SEPARATOR_STRING : w.getTitle());
}
};
}
return new LabelRenderer(GraphicalWidgetRenderer.LABEL_LEFT, this.attrOverride);
}
// Image renders - either Nine-Part or zoomed image
if (type == WidgetType.Button) {
return new NinePartRenderer(this, type.getKeyName(), skin.getKeyName(), NinePartRenderer.LABEL_CENTER, NinePartRenderer.RENDER_FULL, this.attrOverride) {
@Override
public void updateData() {
IWidget attributed = getModel();
boolean isSelected = RendererSupport.isSelected(attributed, attrOverride);
Object toggleable = attributed.getAttribute(WidgetAttributes.IS_TOGGLEABLE_ATTR);
if (isSelected && NullSafe.equals(toggleable, WidgetAttributes.IS_TOGGLEABLE) && (altSet != null)) {
imageParts = altSet;
} else {
imageParts = defaultSet;
}
}
};
}
if (type == WidgetType.Check) {
NinePartRenderer boxRenderer = new NinePartRenderer(this, type.getKeyName(), skin.getKeyName(), NinePartRenderer.LABEL_LEFT, NinePartRenderer.RENDER_LEFT_SQUARE, this.attrOverride);
ZoomRenderer checkRenderer = new ZoomRenderer(this, type.getKeyName(), skin.getKeyName(), ZoomRenderer.NO_LABEL, ZoomRenderer.RENDER_LEFT_SQUARE, this.attrOverride);
GraphicalWidgetRenderer[] rendererArray = { boxRenderer, checkRenderer };
return new CheckboxImageRenderer(rendererArray, 0);
}
if (type == WidgetType.Radio) {
return new ZoomRenderer(this, type.getKeyName(), skin.getKeyName(), ZoomRenderer.LABEL_LEFT, ZoomRenderer.RENDER_LEFT_SQUARE, this.attrOverride) {
@Override
public void updateData() {
boolean isSelected = RendererSupport.isRadioSelected(getModel(), attrOverride);
if (isSelected && (altImage != null)) {
image = altImage;
} else {
image = defaultImage;
}
}
};
}
if (type == WidgetType.TextBox) {
return new NinePartRenderer(this, type.getKeyName(), skin.getKeyName(), NinePartRenderer.LABEL_LEFT, NinePartRenderer.RENDER_FULL, this.attrOverride);
}
// MacOS pulldownlist only!
if ((skin == SkinType.MacOSX) && (type == WidgetType.PullDownList)) {
ZoomRenderer arrowRenderer = new ZoomRenderer(this, type.getKeyName(), skin.getKeyName(), ZoomRenderer.LABEL_LEFT, ZoomRenderer.RENDER_RIGHT_SQUARE, this.attrOverride);
NinePartRenderer leftRenderer = new NinePartRenderer(this, type.getKeyName() + "_left", skin.getKeyName(), NinePartRenderer.LABEL_LEFT, NinePartRenderer.RENDER_LEFT_FILL, this.attrOverride);
NinePartRenderer rightRenderer = new NinePartRenderer(this, type.getKeyName() + "_right", skin.getKeyName(), NinePartRenderer.LABEL_LEFT, NinePartRenderer.RENDER_RIGHT_SQUARE, this.attrOverride) {
@Override
public void updateData() {
GraphicalWidget<?> gw = (GraphicalWidget<?>) getParent();
IWidget widget = gw.getModel();
setText(RendererSupport.getPullDownSelectedTitle(widget, attrOverride));
}
};
GraphicalWidgetRenderer[] rendererArray = { leftRenderer, rightRenderer, arrowRenderer };
return new GraphicalWidgetRenderer.CompositeRenderer(rendererArray, 1);
}
// WinXP pulldownlist only!
if ((skin == SkinType.WinXP) && (type == WidgetType.PullDownList)) {
ZoomRenderer arrowRenderer = new ZoomRenderer(this, type.getKeyName(), skin.getKeyName(), ZoomRenderer.LABEL_LEFT, ZoomRenderer.RENDER_RIGHT_SQUARE, this.attrOverride);
NinePartRenderer leftRenderer = new NinePartRenderer(this, type.getKeyName() + "_left", skin.getKeyName(), NinePartRenderer.LABEL_LEFT, NinePartRenderer.RENDER_LEFT_FILL, this.attrOverride);
NinePartRenderer rightRenderer = new NinePartRenderer(this, type.getKeyName() + "_right", skin.getKeyName(), NinePartRenderer.LABEL_LEFT, NinePartRenderer.RENDER_RIGHT_SQUARE, this.attrOverride) {
@Override
public void updateData() {
GraphicalWidget<?> gw = (GraphicalWidget<?>) getParent();
IWidget widget = gw.getModel();
setText(RendererSupport.getPullDownSelectedTitle(widget, attrOverride));
}
};
GraphicalWidgetRenderer[] rendererArray = { leftRenderer, rightRenderer, arrowRenderer };
return new GraphicalWidgetRenderer.CompositeRenderer(rendererArray, 1);
}
// Pulldown lists for non-macOSX or WinXP skins only
if (type == WidgetType.Submenu) {
ZoomRenderer arrowRenderer = new ZoomRenderer(this, type.getKeyName(), skin.getKeyName(), ZoomRenderer.LABEL_LEFT, ZoomRenderer.RENDER_RIGHT_SQUARE, this.attrOverride);
NinePartRenderer backgroundRenderer = new NinePartRenderer(this, type.getKeyName(), skin.getKeyName(), NinePartRenderer.LABEL_LEFT, NinePartRenderer.RENDER_FULL, this.attrOverride);
GraphicalWidgetRenderer[] rendererArray = { backgroundRenderer, arrowRenderer };
return new GraphicalWidgetRenderer.CompositeRenderer(rendererArray, 1);
}
if (type == WidgetType.PullDownList) {
ZoomRenderer arrowRenderer = new ZoomRenderer(this, type.getKeyName(), skin.getKeyName(), ZoomRenderer.LABEL_LEFT, ZoomRenderer.RENDER_RIGHT_SQUARE, this.attrOverride) {
@Override
public void updateData() {
GraphicalWidget<?> gw = (GraphicalWidget<?>) getParent();
IWidget widget = gw.getModel();
setText(RendererSupport.getPullDownSelectedTitle(widget, attrOverride));
}
};
NinePartRenderer backgroundRenderer = new NinePartRenderer(this, type.getKeyName(), skin.getKeyName(), NinePartRenderer.LABEL_LEFT, NinePartRenderer.RENDER_FULL, this.attrOverride);
GraphicalWidgetRenderer[] rendererArray = { backgroundRenderer, arrowRenderer };
return new GraphicalWidgetRenderer.CompositeRenderer(rendererArray, 1);
}
if ((type == WidgetType.MenuItem) || (type == WidgetType.PullDownItem) || (type == WidgetType.ListBoxItem)) {
NinePartRenderer itemRenderer = new NinePartRenderer(this, type.getKeyName(), skin.getKeyName(), NinePartRenderer.LABEL_LEFT, NinePartRenderer.RENDER_FULL, this.attrOverride);
ZoomRenderer sepRenderer = new ZoomRenderer(this, "separator", skin.getKeyName(), ZoomRenderer.NO_LABEL, ZoomRenderer.RENDER_FULL, this.attrOverride);
GraphicalWidgetRenderer[] rendererArray = { itemRenderer, sepRenderer };
return new GraphicalWidgetRenderer.ChoiceMultiRenderer(rendererArray, 0) {
@Override
public void updateData() {
Object isSep = getModel().getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if (NullSafe.equals(isSep, WidgetAttributes.IS_SEPARATOR)) {
curRenderer = 1;
} else {
curRenderer = 0;
}
}
};
}
return new NinePartRenderer(this, type.getKeyName(), skin.getKeyName(), NinePartRenderer.LABEL_LEFT, NinePartRenderer.RENDER_FULL, this.attrOverride);
}
Aggregations