use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget 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.uimodel.GraphicalTraversableWidget in project cogtool by cogtool.
the class FrameEditorUI method moveWidgetGroup.
// moveFrameElementGroup
/**
* Assumes gw's model is a traversable widget but not a child widget.
*/
public void moveWidgetGroup(double offsetX, double offsetY, GraphicalTraversableWidget<?> gw) {
// No easier way to do this (hard to make getTopHeader call generic)
TraversableWidget groupWidget = null;
if (gw instanceof GraphicalMenuWidget<?>) {
groupWidget = ((AMenuWidget) gw.getModel()).getTopHeader();
} else if ((gw instanceof GraphicalListItem) || (gw instanceof GraphicalGridButton)) {
groupWidget = (TraversableWidget) gw.getModel();
} else {
return;
}
SimpleWidgetGroup headerGroup = groupWidget.getParentGroup();
// Ensure top-left header doesn't scroll off-screen
groupWidget = (TraversableWidget) headerGroup.get(0);
DoublePoint p = groupWidget.getShape().getOrigin();
// Prevent the ability to move a widget to an origin less than 0,0
if (offsetX + p.x < 0.0) {
offsetX = -p.x;
}
if (offsetY + p.y < 0.0) {
offsetY = -p.y;
}
Point newOrigin = new Point(0, 0);
int index = 1;
int headerCount = headerGroup.size();
do {
newOrigin.setLocation(PrecisionUtilities.round(p.x + offsetX), PrecisionUtilities.round(p.y + offsetY));
frameUI.getWidgetFigure(groupWidget).setLocation(newOrigin);
// Stop when we've moved the last header!
if (index >= headerCount) {
break;
}
groupWidget = (TraversableWidget) headerGroup.get(index++);
p = groupWidget.getShape().getOrigin();
} while (true);
}
use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget in project cogtool by cogtool.
the class FrameEditorMouseState method dynamicMoveWidgets.
/**
* Utility to help with dynamic move of selected widgets.
*
* @param selectedWFs the set of selected graphical widget figures
* @param currentScaledX scaled X location of the current mouse position
* @param currentScaledY scaled Y location of the current mouse position
* @author mlh/alex
*/
protected void dynamicMoveWidgets(Iterator<FrameEltSelnFig<?>> selectedFigs, double currentScaledX, double currentScaledY) {
ui.hideNondynamicSupport(true);
// Iterate through list of selected objects
while (selectedFigs.hasNext()) {
FrameEltSelnFig<?> fig = selectedFigs.next();
// Determine movement amount from initial points.
double offsetX = currentScaledX - scaledMouseDownX;
double offsetY = currentScaledY - scaledMouseDownY;
if (fig instanceof GraphicalChildWidget<?, ?>) {
continue;
} else if (fig instanceof FrameEltGroupHalo) {
ui.moveFrameElementGroup(offsetX, offsetY, ((FrameEltGroupHalo) fig).getModel());
} else if (fig instanceof GraphicalWidget<?>) {
GraphicalWidget<?> gw = (GraphicalWidget<?>) fig;
if ((gw instanceof GraphicalTraversableWidget<?>) && (gw.getModel().getParentGroup() != null)) {
ui.moveWidgetGroup(offsetX, offsetY, (GraphicalTraversableWidget<?>) gw);
} else {
DoublePoint p = gw.getModel().getShape().getOrigin();
double tempX = offsetX + p.x;
double tempY = offsetY + p.y;
// Prevent moving a widget to an origin less than 0.0,0.0
if (tempX < 0.0) {
tempX = 0.0;
}
if (tempY < 0.0) {
tempY = 0.0;
}
// Temporarily move the widget origin to new location.
ui.setGraphicalWidgetOrigin(tempX, tempY, gw);
}
}
}
}
use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget in project cogtool by cogtool.
the class FrameEditorMouseState method dynamicReorderWidget.
protected void dynamicReorderWidget(int x, int y, boolean duplicate) {
int dx = x - lastX;
int dy = y - lastY;
Point frameOrigin = reorderFigure.getLocation();
frameOrigin.x += dx;
frameOrigin.y += dy;
reorderFigure.setLocation(frameOrigin);
GraphicalWidget<?> curWidgetFig = ui.widgetLocatedAtXY(x, y);
PotentialFigure potential = ui.potentialWidgetUnderXY(x, y);
ui.resizeHandlesUIFig.hide();
dividerLine.setVisible(false);
if ((curWidgetFig != null) && ui.areCompatible(lastClickedWidget, curWidgetFig.getModel()) && (duplicate || reorderAllowed(curWidgetFig.getModel()))) {
boolean isChildWidget = lastClickedWidget instanceof ChildWidget;
boolean changedWidget = curWidgetFig.getModel() != lastClickedWidget;
lastHoveredWidget = curWidgetFig;
// If the dragged widget is not a child, it won't make sense to
// drag it onto a potential figure
// MLHQ: How do you know this cast will succeed?
ui.hideNonhaloSupport(!isChildWidget, changedWidget, (GraphicalTraversableWidget<?>) curWidgetFig);
setDividerBounds(curWidgetFig, x, y);
if (lastClickedWidget instanceof ChildWidget) {
if (curWidgetFig instanceof GraphicalChildWidget<?, ?>) {
GraphicalChildWidget<?, ?> child = (GraphicalChildWidget<?, ?>) curWidgetFig;
child.getParentFigure().openChildren();
}
if (curWidgetFig instanceof GraphicalParentWidget<?, ?>) {
if (changedWidget) {
((GraphicalParentWidget<?, ?>) curWidgetFig).openChildren();
}
}
}
} else if (potential != null) {
GraphicalTraversableWidget<?> owner = ui.getPotentialFigureOwner();
if (owner instanceof GraphicalChildWidget<?, ?>) {
((GraphicalChildWidget<?, ?>) owner).getParentFigure().openChildren();
}
ui.potentialUIFig.setSelection(potential);
} else {
if (withinReorder(x, y)) {
setDividerBounds(lastHoveredWidget, x, y);
if (lastHoveredWidget instanceof GraphicalChildWidget<?, ?>) {
GraphicalChildWidget<?, ?> gcw = (GraphicalChildWidget<?, ?>) lastHoveredWidget;
gcw.getParentFigure().openChildren();
}
} else if ((lastClickedWidget instanceof ChildWidget) || !duplicate) {
ui.hideNondynamicSupport(true, false);
InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
drawLayer.setCursor(NOT_ALLOWED_CURSOR);
}
}
}
Aggregations