use of edu.cmu.cs.hcii.cogtool.model.TraversableWidget 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.TraversableWidget 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.TraversableWidget 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.TraversableWidget in project cogtool by cogtool.
the class FrameEditorController method resizeElement.
// deleteWidget
private void resizeElement(FrameElement elt, double oldResizeX, double oldResizeY, double newResizeX, double newResizeY, double ratioX, double ratioY, Set<SimpleWidgetGroup> resizedGroups, boolean childrenToo, CompoundUndoableEdit editSequence) {
if (elt instanceof IWidget) {
IWidget widget = (IWidget) elt;
SimpleWidgetGroup group = widget.getParentGroup();
if ((widget instanceof TraversableWidget) && (group != null)) {
if (!resizedGroups.contains(group)) {
resizeGroup(group, oldResizeX, oldResizeY, newResizeX, newResizeY, ratioX, ratioY, childrenToo, editSequence);
resizedGroups.add(group);
}
} else {
// Resize the actual widget.
resizeWidget(widget, oldResizeX, oldResizeY, newResizeX, newResizeY, ratioX, ratioY, childrenToo, editSequence);
}
} else if (elt instanceof SimpleWidgetGroup) {
Iterator<IWidget> widgets = ((SimpleWidgetGroup) elt).iterator();
while (widgets.hasNext()) {
resizeElement(widgets.next(), oldResizeX, oldResizeY, newResizeX, newResizeY, ratioX, ratioY, resizedGroups, childrenToo, editSequence);
}
} else if (elt instanceof FrameElementGroup) {
Iterator<FrameElement> members = ((FrameElementGroup) elt).iterator();
while (members.hasNext()) {
resizeElement(members.next(), oldResizeX, oldResizeY, newResizeX, newResizeY, ratioX, ratioY, resizedGroups, true, editSequence);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.TraversableWidget in project cogtool by cogtool.
the class FrameEditorMouseState method dynamicResizeWidgets.
/**
* Utility to help with dynamic resize 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 dynamicResizeWidgets(Iterator<FrameEltSelnFig<?>> selectedWFs, double currentScaledX, double currentScaledY) {
// an origin less then 0.0,0.0
if (currentScaledX < 0.0) {
currentScaledX = 0.0;
}
if (currentScaledY < 0.0) {
currentScaledY = 0.0;
}
// Deal with any anchoring issues
if (ui.resizeHandlesUIFig.isTopLeftAnchored()) {
switch(currentResizeHandleType) {
case FrameEditorUI.TOP_RIGHT:
{
// Cannot change Y position
currentScaledY = initialResizeArea.y;
break;
}
case FrameEditorUI.BOTTOM_LEFT:
{
// Cannot change X position
currentScaledX = initialResizeArea.x;
break;
}
default:
{
break;
}
}
// Cannot move left of top-left
if (currentScaledX < initialResizeArea.x) {
currentScaledX = initialResizeArea.x;
}
// Cannot move above of top-left
if (currentScaledY < initialResizeArea.y) {
currentScaledY = initialResizeArea.y;
}
}
double newWidth = Math.abs(currentScaledX - mouseFixedResizeX);
double newHeight = Math.abs(currentScaledY - mouseFixedResizeY);
double newLeft = Math.min(currentScaledX, mouseFixedResizeX);
double newTop = Math.min(currentScaledY, mouseFixedResizeY);
double ratioX = newWidth / initialResizeArea.width;
double ratioY = newHeight / initialResizeArea.height;
// Iterate through selected widgets
while (selectedWFs.hasNext()) {
FrameEltSelnFig<?> f = selectedWFs.next();
if (f instanceof GraphicalWidget<?>) {
GraphicalWidget<?> gw = (GraphicalWidget<?>) f;
IWidget w = gw.getModel();
SimpleWidgetGroup group = w.getParentGroup();
if ((w instanceof TraversableWidget) && (group != null)) {
dynamicResizeGroup(group, ratioX, ratioY, newLeft, newTop, false);
} else {
dynamicResizeWidget(w, gw, ratioX, ratioY, newLeft, newTop);
}
} else if (f instanceof FrameEltGroupHalo) {
dynamicResizeGroup(((FrameEltGroupHalo) f).getModel(), ratioX, ratioY, newLeft, newTop, true);
}
}
}
Aggregations