use of edu.cmu.cs.hcii.cogtool.model.IWidget 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.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method getHeightFactor.
private double getHeightFactor(IWidget widget, SimpleWidgetGroup newGroup) {
double heightFactor = 1.0;
IWidget newWidget = null;
if (newGroup != null) {
if (newGroup.size() > 0) {
newWidget = newGroup.get(0);
}
if (newWidget != null) {
Object isSep = newWidget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, isSep)) {
heightFactor *= FrameEditorUI.SEPARATOR_RATIO;
}
}
}
Object isSep = widget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, isSep)) {
heightFactor *= 1.0 / FrameEditorUI.SEPARATOR_RATIO;
}
return heightFactor;
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method sortSelectedMbrs.
private Iterator<IWidget> sortSelectedMbrs(SimpleWidgetGroup group, FrameEditorSelectionState s) {
Set<IWidget> sortingSet = new TreeSet<IWidget>(groupMemberComparator);
Iterator<IWidget> groupMbrs = group.iterator();
while (groupMbrs.hasNext()) {
IWidget member = groupMbrs.next();
if ((s == null) || s.isElementSelected(member)) {
sortingSet.add(member);
}
}
return sortingSet.iterator();
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method createInitiateRenameAction.
private IListenerAction createInitiateRenameAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorSelectionState.class;
}
public boolean performAction(Object prms) {
FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
int selectedWidgetCount = selection.getWidgetSelectionCount();
if (selectedWidgetCount == 1) {
IWidget w = selection.getSelectedIWidgets()[0];
ui.initiateWidgetRename(w);
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.IWidget in project cogtool by cogtool.
the class FrameEditorController method renderUnRenderAll.
public static void renderUnRenderAll(Design d, boolean render, CogToolLID lid, UndoManager mgr) {
CompoundUndoableEdit edits = new CompoundUndoableEdit((render ? RENDER_ALL : UN_RENDER), lid);
for (Frame f : d.getFrames()) {
for (IWidget w : f.getWidgets()) {
renderWidget(w, render, w.isRendered(), edits);
}
}
edits.end();
if (edits.isSignificant()) {
mgr.addEdit(edits);
}
}
Aggregations