use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class AbstractGraphicalParentWidget method selectChild.
protected GraphicalWidget<?> selectChild() {
AParentWidget hdr = getModel();
SimpleWidgetGroup childItems = hdr.getChildren();
if ((childItems != null) && (childItems.size() > 0)) {
return this.figureSpt.getWidgetFigure(childItems.get(0));
}
return null;
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget 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.AParentWidget in project cogtool by cogtool.
the class FrameEditorMouseState method dynamicResizeGroup.
protected void dynamicResizeGroup(Association<?> group, double ratioX, double ratioY, double newLeft, double newTop, boolean childrenToo) {
Iterator<? extends FrameElement> groupElts = group.iterator();
while (groupElts.hasNext()) {
FrameElement elt = groupElts.next();
if (elt instanceof IWidget) {
IWidget w = (IWidget) elt;
GraphicalWidget<?> gw = ui.frameUI.getWidgetFigure(w);
dynamicResizeWidget(w, gw, ratioX, ratioY, newLeft, newTop);
if (childrenToo && (w instanceof AParentWidget)) {
AParentWidget pw = (AParentWidget) w;
SimpleWidgetGroup children = pw.getChildren();
if (children != null) {
dynamicResizeGroup(children, ratioX, ratioY, newLeft, newTop, childrenToo);
}
}
} else if (elt instanceof Association<?>) {
dynamicResizeGroup((Association<?>) elt, ratioX, ratioY, newLeft, newTop, childrenToo);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget in project cogtool by cogtool.
the class FrameEditorMouseState method reorderWidget.
protected boolean reorderWidget(int x, int y, FrameEditorUI.ReorderWidgetParameters prms) {
GraphicalWidget<?> wf = ui.widgetLocatedAtXY(x, y);
if ((wf == null) && withinReorder(x, y)) {
wf = lastHoveredWidget;
}
prms.widgetGroup = null;
prms.insertIndex = -1;
prms.parent = null;
prms.reorderWidget = lastClickedWidget;
if (wf != null) {
IWidget targetWidget = wf.getModel();
if (!ui.areCompatible(lastClickedWidget, targetWidget)) {
return false;
}
if (!reorderAllowed(targetWidget)) {
return false;
}
prms.insertIndex = getInsertIndex(targetWidget, x, y);
if (prms.insertIndex < 0) {
return false;
}
if (lastClickedWidget instanceof ChildWidget) {
if (targetWidget instanceof ChildWidget) {
prms.widgetGroup = targetWidget.getParentGroup();
prms.parent = ((ChildWidget) targetWidget).getParent();
} else if (targetWidget instanceof AParentWidget) {
// "else if" because only MenuItems are both, and for them
// we want the ChildWidget behavior (to add the item to
// a submenu, drag it over the potential figure)
prms.parent = (AParentWidget) targetWidget;
prms.widgetGroup = prms.parent.getChildren();
prms.insertIndex = 0;
}
} else {
// moving around menu headers or list items
prms.widgetGroup = targetWidget.getParentGroup();
}
return true;
}
PotentialFigure pf = ui.potentialWidgetUnderXY(x, y);
if (pf != null) {
GraphicalTraversableWidget<?> owner = ui.getPotentialFigureOwner();
if (owner instanceof GraphicalMenuItem) {
if (pf == ui.potentialUIFig.getRightFigure()) {
prms.parent = (MenuItem) owner.getModel();
prms.widgetGroup = prms.parent.getChildren();
prms.insertIndex = 0;
return true;
}
} else {
if ((owner instanceof GraphicalParentWidget<?, ?>) && (pf == ui.potentialUIFig.getBottomFigure())) {
prms.parent = (AParentWidget) owner.getModel();
prms.widgetGroup = prms.parent.getChildren();
prms.insertIndex = 0;
} else {
IWidget widget = owner.getModel();
prms.widgetGroup = widget.getParentGroup();
prms.insertIndex = prms.widgetGroup.indexOf(widget) + 1;
}
return true;
}
}
// out in space
return ((!prms.requiresTarget()) && !(lastClickedWidget instanceof ChildWidget));
}
use of edu.cmu.cs.hcii.cogtool.model.AParentWidget 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);
}
Aggregations