use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup 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.SimpleWidgetGroup in project cogtool by cogtool.
the class FrameEditorUI method removeHalo.
// addSelectionChangeListeners
// TODO: Currently works only for IWidget
protected void removeHalo(IWidget w) {
MoveHalo halo = halosUIFig.getMoveHalo(w);
if (halo != null) {
SimpleWidgetGroup group = w.getParentGroup();
if (group != null) {
IWidget[] widgets = selection.getSelectedIWidgets();
// Avoid removing if another sibling/cousin is selected
for (IWidget widget : widgets) {
if ((widget.getParentGroup() == group) && (widget != w)) {
return;
}
}
}
halosUIFig.hideHalo(halo);
}
}
use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.
the class FrameEditorUI method addWidgetShapeChangeHandler.
/**
* Registers a listener that redraws the frame in response to changes in
* the appearance of widgets
*
* When this event occurs, resize handles are redrawn, the window's size is
* recomputed, and the display updated.
*
*/
protected void addWidgetShapeChangeHandler() {
AlertHandler widgetTitleChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
FrameUIModel.WidgetTitleChange chg = (FrameUIModel.WidgetTitleChange) alert;
// selected widget
if (selection.getElementSelectionCount() == 1) {
FrameElement elt = selection.getSelectedIFrameElements()[0];
if (chg.widget == elt.getAttribute(WidgetAttributes.REMOTE_LABEL_ATTR)) {
view.setRemoteLabelText(chg.widget.getTitle());
}
}
}
};
frameUI.addHandler(this, FrameUIModel.WidgetTitleChange.class, widgetTitleChangeHandler);
AlertHandler widgetShapeChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
delayedRepainting.requestRepaint(SHAPE_CHANGE_REPAINT);
// a FULL repaint is probably not needed
}
};
frameUI.addHandler(this, FrameUIModel.WidgetShapeImageChange.class, widgetShapeChangeHandler);
AlertHandler widgetGroupChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
FrameUIModel.WidgetGroupChange evt = (FrameUIModel.WidgetGroupChange) alert;
if (evt.isAdd) {
GraphicalWidget<?> gw = frameUI.getWidgetFigure(evt.widget);
delayedWidgetSelection.addToSelection(evt.widget, gw);
} else {
delayedWidgetSelection.removeFromSelection(evt.widget);
SimpleWidgetGroup group = evt.widget.getParentGroup();
if (group.size() == 0) {
//evt.widget was the last widget in this group,
//so hide the halo for it
removeHalo(evt.widget);
}
}
}
};
frameUI.addHandler(this, FrameUIModel.WidgetGroupChange.class, widgetGroupChangeHandler);
}
use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup 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.model.SimpleWidgetGroup in project cogtool by cogtool.
the class FrameEditorUI method moveHaloUnderXY.
/**
* Find a move halo at x, y
*/
public MoveHalo moveHaloUnderXY(int x, int y) {
MoveHalo halo = view.moveHaloUnderXY(x, y);
if (halo != null) {
GraphicalWidget<?> clickedFigure = widgetLocatedAtXY(x, y);
if (clickedFigure != null) {
SimpleWidgetGroup group;
IWidget haloWidget;
FrameElement data = halo.getData();
if (data instanceof IWidget) {
haloWidget = (IWidget) data;
group = haloWidget.getParentGroup();
} else if (data instanceof SimpleWidgetGroup) {
group = (SimpleWidgetGroup) data;
haloWidget = group.get(0);
} else {
return halo;
}
IWidget clickedWidget = clickedFigure.getModel();
if ((group != null) && (group.contains(clickedWidget))) {
return null;
}
int haloLevel = haloWidget.getLevel();
int clickedLevel = clickedWidget.getLevel();
if (haloLevel < clickedLevel) {
return null;
}
}
return halo;
}
return null;
}
Aggregations