use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem 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.uimodel.GraphicalMenuItem 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);
}
use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem in project cogtool by cogtool.
the class FrameEditorMouseState method handleMousePressed.
/**
* Called on mouse presses
* Determines if the mouse pressed on a resize widget.
* Raises a resizeAlert or a mouseOperations alert.
*
* Alerts contain X,Y coordinates in 1:1 scale.
*/
protected void handleMousePressed(int x, int y, int state) {
ui.view.getEditor().getSWTEditorSubstrate().setFocus();
// Check to see if the pressed event is on the resize handlers.
// Use the ZOOMED scale because the resize widgets are in the
// interaction layer and they're not affected by zoom.
ResizeThumb resize = ui.widgetResizeUnderXY(x, y);
PotentialFigure pWidget = ui.potentialWidgetUnderXY(x, y);
RadioButtonSash sash = ui.radioSashUnderXY(x, y);
// Check to see if the mouse press happened on a resize widget
if (resize != null) {
// Need this because we want the actual AREA,
// not the center of the thumb.
initialResizeArea = ui.getSelectedWidgetArea();
// Set the fixed point of the resize
double fixedX = 0.0;
double fixedY = 0.0;
// Move through the possible types and set the fixed point.
currentResizeHandleType = resize.thumbType;
switch(resize.thumbType) {
case FrameEditorUI.TOP_LEFT:
fixedX = initialResizeArea.x + initialResizeArea.width;
fixedY = initialResizeArea.y + initialResizeArea.height;
break;
case FrameEditorUI.BOTTOM_LEFT:
fixedX = initialResizeArea.x + initialResizeArea.width;
fixedY = initialResizeArea.y;
break;
case FrameEditorUI.TOP_RIGHT:
fixedX = initialResizeArea.x;
fixedY = initialResizeArea.y + initialResizeArea.height;
break;
case FrameEditorUI.BOTTOM_RIGHT:
fixedX = initialResizeArea.x;
fixedY = initialResizeArea.y;
break;
default:
// and this code wasn't modified.
throw new IllegalStateException("Unknown type of Resize Thumb selected");
}
// Specify the fixed resize point.
mouseFixedResizeX = fixedX;
mouseFixedResizeY = fixedY;
// Set the state to "resize" as the next action.
// TODO: Should we implement the other types of resizing?
int nextState = PotentialResizingWidget;
setMouseState(nextState);
// Switch to fast mode rendering for graphical widgets
setWidgetFastRenderMode(true);
} else if (sash != null) {
moveIsVertical = sash.isVertical();
setMouseState(PotentialMovingGridButtons);
} else if (pWidget != null) {
ui.initiateRetitleFigure(pWidget);
} else {
// Get whatever graphical widget under x,y
GraphicalWidget<?> wf = ui.widgetLocatedAtXY(x, y);
MoveHalo halo = ui.moveHaloUnderXY(x, y);
RemoteLinkage linkage = ui.linkageUnderXY(x, y);
GraphicalParentWidget<?, ?> currentParent = null;
// If SHIFT is held, always treat as start of a drag toggle select.
if ((state & InputEvent.SHIFT) != 0) {
setMouseState(PotentialTogglingSelection);
} else if (wf != null) {
IWidget widget = wf.getModel();
SimpleWidgetGroup group = widget.getParentGroup();
lastClickedWidget = widget;
if ((state & platformDuplicateModifierKey()) != 0) {
if (!selection.isElementSelected(widget)) {
selection.setSelectedSelnFig(wf);
}
if ((group != null) && (group.getOrientation() != SimpleWidgetGroup.FREEFORM) && (selection.getWidgetSelectionCount() == 1)) {
setMouseState(PotentialInsertDuplicateWidget);
} else {
setMouseState(PotentialDuplicatingWidget);
}
} else {
if ((group != null) && (group.getOrientation() != SimpleWidgetGroup.FREEFORM)) {
if (!selection.isElementSelected(widget)) {
selection.setSelectedSelnFig(wf);
}
setMouseState(PotentialReorderWidget);
} else // possible move.
if (selection.isSelectionFigureSelected(wf)) {
setMouseState(PotentialMovingSelection);
} else {
selection.setSelectedSelnFig(wf);
setMouseState(PotentialMovingWidget);
}
}
if (wf instanceof GraphicalMenuItem) {
GraphicalMenuItem menuItemFig = (GraphicalMenuItem) wf;
if (menuItemFig.isSubmenu()) {
currentParent = menuItemFig;
} else {
currentParent = menuItemFig.getParentFigure();
}
} else if (wf instanceof GraphicalParentWidget<?, ?>) {
currentParent = (GraphicalParentWidget<?, ?>) wf;
} else if (wf instanceof GraphicalChildWidget<?, ?>) {
currentParent = ((GraphicalChildWidget<?, ?>) wf).getParentFigure();
}
} else if (halo != null) {
if (halo instanceof FrameEltGroupHalo) {
FrameEltGroupHalo groupHalo = (FrameEltGroupHalo) halo;
if ((state & platformDuplicateModifierKey()) != 0) {
if (!selection.isElementSelected(halo.getData())) {
selection.setSelectedSelnFig(groupHalo);
}
setMouseState(PotentialDuplicatingWidget);
} else {
selection.setSelectedSelnFig(groupHalo);
setMouseState(PotentialMovingSelection);
}
} else {
/* if (wf != null) {
IWidget widget = wf.getWidgetModel();
SimpleWidgetGroup group = widget.getParentGroup();
if ((state & platformDuplicateModifierKey()) != 0) {
if (! this.selection.isWidgetSelected(widget)) {
this.selection.setSelectedWidget(wf);
}
if ((group != null) &&
(group.getOrientation() != SimpleWidgetGroup.FREEFORM) &&
(this.selection.getWidgetSelectionCount() == 1))
{
setMouseState(PotentialInsertDuplicateWidget);
}
else {
setMouseState(PotentialDuplicatingWidget);
}
}
else {
setMouseState(PotentialMovingSelection);
}
}
else { */
setMouseState(PotentialMovingSelection);
}
// }
} else if (linkage != null) {
FrameElement owner = linkage.getOwner();
IWidget remoteLabel = linkage.getRemoteLabel();
// Ensure both are selected; if not yet, then set them
// both selected.
FrameEltSelnFig<?> ownerRepresentative = isSomeElementSelected(owner);
if ((!selection.isElementSelected(remoteLabel)) || (ownerRepresentative == null)) {
if (ownerRepresentative == null) {
ownerRepresentative = getRepresentativeElt(owner);
}
selection.setSelectedSelnFig(linkage.getRemoteLabelFigure());
if (ownerRepresentative != null) {
selection.selectSelnFig(ownerRepresentative);
}
}
setMouseState(PotentialMovingSelection);
} else // Otherwise, out in space and SHIFT not held; deselect all and
// prepare to create
{
selection.deselectAll();
setMouseState(PotentialCreatingWidget);
}
ui.hideAllChildren();
if (currentParent != null) {
currentParent.openChildren();
ui.resetVisibleArea();
}
}
}
Aggregations