Search in sources :

Example 31 with SimpleWidgetGroup

use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.

the class FrameEditorController method moveWidget.

private void moveWidget(ListenerIdentifier lid, String presentationLabel, IWidget widget, double widgetMoveByX, double widgetMoveByY, boolean moveAsGroup, Set<SimpleWidgetGroup> movedGroups, Set<IWidget> movedWidgets, IUndoableEditSequence editSequence) {
    if (movedWidgets.contains(widget)) {
        return;
    }
    movedWidgets.add(widget);
    SimpleWidgetGroup parentGroup = widget.getParentGroup();
    if ((parentGroup == null) || (!moveAsGroup)) {
        if (widget instanceof GridButton) {
            GridButton gb = (GridButton) widget;
            moveGridButton(lid, presentationLabel, gb, widgetMoveByX, widgetMoveByY, gb.getHorizSpace() + widgetMoveByX, gb.getVertSpace() + widgetMoveByY, editSequence);
        } else {
            moveWidget(lid, presentationLabel, widget, widgetMoveByX, widgetMoveByY, editSequence);
        }
    } else if (!(widget instanceof ChildWidget)) {
        // move entire group
        if (!movedGroups.contains(parentGroup)) {
            moveWidgetGroup(lid, presentationLabel, parentGroup, widgetMoveByX, widgetMoveByY, editSequence);
            movedGroups.add(parentGroup);
        }
    }
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

Example 32 with SimpleWidgetGroup

use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.

the class FrameEditorController method moveElements.

private boolean moveElements(FrameEditorSelectionState selection, double moveByX, double moveByY, boolean moveAsGroup) {
    String editLabel;
    if (selection.getWidgetSelectionCount() == 1) {
        editLabel = MOVE_WIDGET;
    } else {
        editLabel = MOVE_WIDGETS;
    }
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit(editLabel, FrameEditorLID.MoveWidgets);
    FrameElement[] selected = selection.getSelectedIFrameElements();
    // Avoid moving a group more than once
    Set<SimpleWidgetGroup> movedGroups = new HashSet<SimpleWidgetGroup>();
    Set<IWidget> movedWidgets = new HashSet<IWidget>();
    // Move all selected widgets by the specified amount
    for (FrameElement eltToMove : selected) {
        if (!isMemberOfSelectedGroup(eltToMove, selection)) {
            moveElement(FrameEditorLID.MoveWidgets, editLabel, eltToMove, moveByX, moveByY, moveAsGroup, movedGroups, movedWidgets, editSequence);
        }
    }
    editSequence.end();
    // Only add this edit if it is significant
    if (editSequence.isSignificant()) {
        undoMgr.addEdit(editSequence);
    }
    return true;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) HashSet(java.util.HashSet)

Example 33 with SimpleWidgetGroup

use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup 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);
        }
    }
}
Also used : TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) EmptyIterator(edu.cmu.cs.hcii.cogtool.util.EmptyIterator) Iterator(java.util.Iterator) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 34 with SimpleWidgetGroup

use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.

the class WidgetPropertiesPane method showAttributeWidgets.

public void showAttributeWidgets(IWidget widget) {
    WidgetType type = widget.getWidgetType();
    widgetTitle.setText(DISPLAYED_LABEL);
    Object pathObj = widget.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
    if (!NullSafe.equals(WidgetAttributes.NO_IMAGE, pathObj)) {
        String imgPath = (String) pathObj;
        imagePath.setVisible(true);
        imagePathText.setVisible(true);
        imagePathText.setText(imgPath);
        imagePathText.setSelection(imgPath.length());
    }
    if ((type == WidgetType.MenuItem) || (type == WidgetType.PullDownItem) || (type == WidgetType.ListBoxItem)) {
        isSeparator.setVisible(true);
        Object value = widget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
        boolean isSep = NullSafe.equals(WidgetAttributes.IS_SEPARATOR, value);
        isSeparator.setSelection(isSep);
        widgetTitleText.setEnabled(!isSep);
        widgetAuxText.setEnabled(!isSep);
    }
    // Remote label support
    // First check if this is a remote label
    FrameElement remoteLabelOwner = (FrameElement) widget.getAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR);
    if (remoteLabelOwner != null) {
        String ownerWidgetName = remoteLabelOwner.getName();
        if ((ownerWidgetName == null) || ownerWidgetName.equals("")) {
            if (remoteLabelOwner instanceof RadioButtonGroup) {
                ownerWidgetName = "[ anonymous radio button group ]";
            } else if (remoteLabelOwner instanceof GridButtonGroup) {
                ownerWidgetName = "[ anonymous checkbox group ]";
            } else if (remoteLabelOwner instanceof SimpleWidgetGroup) {
                ownerWidgetName = "[ anonymous widget group ]";
            } else if (remoteLabelOwner instanceof SimpleWidgetGroup) {
                ownerWidgetName = "[ unnamed element group ]";
            } else {
                ownerWidgetName = "[ unnamed widget ]";
            }
        }
        this.remoteLabelOwner.setVisible(true);
        remoteLabelOwnerName.setVisible(true);
        remoteLabelOwnerName.setText("<a>" + ownerWidgetName + "</a>");
        remoteLabelType.setVisible(true);
        remoteLabelTypeCombo.setVisible(true);
        selectCurrentValue(remoteLabelTypeCombo, widgetTypeChoices, widget.getWidgetType());
        imagePath.setLayoutData(isRemoteLabelAlign);
    } else {
        // Otherwise, check if this widget has a remote label
        remoteLabelOwner = widget.getRemoteLabelOwner();
        // reset layout to eliminate space for the remote label
        if (remoteLabelOwner == null) {
            imagePath.setLayoutData(noRemoteLabelAlign);
        } else {
            IWidget remoteLabelWidget = (IWidget) remoteLabelOwner.getAttribute(WidgetAttributes.REMOTE_LABEL_ATTR);
            if (remoteLabelWidget != null) {
                remoteLabelText.setText(remoteLabelWidget.getTitle());
                remoteLabelFind.setVisible(true);
            } else {
                // Display an empty remote label stuff to allow one to be set
                remoteLabelText.setText("");
                remoteLabelFind.setVisible(false);
            }
            remoteLabel.setVisible(true);
            remoteLabelText.setVisible(true);
            imagePath.setLayoutData(hasRemoteLabelAlign);
        }
    }
    if (!widget.isStandard()) {
        layout();
        return;
    }
    if ((type == WidgetType.Menu) || (type == WidgetType.ContextMenu)) {
        submenuActionLabel.setVisible(true);
        submenuAction.setVisible(true);
        submenuDelayLabel.setVisible(true);
        submenuDelay.setVisible(true);
        Integer submenuAction = (Integer) widget.getAttribute(WidgetAttributes.SUBMENU_ACTION_ATTR);
        selectCurrentValue(this.submenuAction, submenuActions, submenuAction);
        Double delay = (Double) widget.getAttribute(WidgetAttributes.SUBMENU_DELAY_ATTR);
        if (NullSafe.equals(WidgetAttributes.NO_SUBMENU_DELAY, delay)) {
            submenuDelay.select(0);
        } else if (NullSafe.equals(WidgetAttributes.PC_SUBMENU_DELAY, delay)) {
            submenuDelay.select(1);
        } else {
            submenuDelay.setText(delay.toString() + " s");
        }
        if (type == WidgetType.ContextMenu) {
            contextMenuActionLabel.setVisible(true);
            contextMenuAction.setVisible(true);
            Integer contextAction = (Integer) widget.getAttribute(WidgetAttributes.CONTEXT_MENU_ACTION_ATTR);
            selectCurrentValue(contextMenuAction, contextMenuActions, contextAction);
        }
    }
    if (type == WidgetType.Check) {
        isInitiallySelected.setVisible(true);
        Boolean selected = (Boolean) widget.getAttribute(WidgetAttributes.IS_SELECTED_ATTR);
        isInitiallySelected.setSelection(selected.booleanValue());
    } else if (type == WidgetType.Button) {
        // TODO: "clicked-on" for Link?
        isToggleable.setVisible(true);
        Boolean selected = (Boolean) widget.getAttribute(WidgetAttributes.IS_TOGGLEABLE_ATTR);
        isToggleable.setSelection(selected.booleanValue());
        isButtonSelected.setEnabled(selected.booleanValue());
        isButtonSelected.setVisible(true);
        selected = (Boolean) widget.getAttribute(WidgetAttributes.IS_SELECTED_ATTR);
        isButtonSelected.setSelection(selected.booleanValue());
    } else if (type == WidgetType.TextBox) {
        //            this.isMultiLine.setVisible(true);
        //
        //            Boolean multi =
        //                (Boolean) widget.getAttribute(WidgetType.IS_MULTILINE_ATTR);
        //
        //            this.isMultiLine.setSelection(multi.booleanValue());
        widgetTitle.setText(TEXT_CONTENTS);
    } else if (type == WidgetType.Radio) {
        selectLabel.setVisible(true);
        initiallySelected.setVisible(true);
        initiallySelected.removeAll();
        initiallySelected.add(SELECT_NONE);
        RadioButtonGroup group = (RadioButtonGroup) widget.getParentGroup();
        if (group != null) {
            Iterator<IWidget> widgets = group.iterator();
            IWidget[] map = new IWidget[group.size()];
            int i = 0;
            while (widgets.hasNext()) {
                IWidget curWidget = widgets.next();
                map[i++] = curWidget;
                String name = curWidget.getNameLabel();
                initiallySelected.add(name);
            }
            // This works because null isn't in the list so indexOf
            // returns -1 if SELECT_NONE is chosen
            int index = group.indexOf(group.getSelection()) + 1;
            initiallySelected.select(index);
            selectionAttrListener.setAttributeHelper(RADIO_HELPER, map);
        }
    } else if (type == WidgetType.PullDownList) {
        selectLabel.setVisible(true);
        initiallySelected.setVisible(true);
        initiallySelected.removeAll();
        initiallySelected.add(SELECT_NONE);
        initiallySelected.select(0);
        SimpleWidgetGroup group = ((AParentWidget) widget).getChildren();
        Iterator<IWidget> widgets = group.iterator();
        IWidget[] map = new IWidget[group.size()];
        int i = 0;
        Widget selected = (Widget) widget.getAttribute(WidgetAttributes.SELECTION_ATTR);
        while (widgets.hasNext()) {
            IWidget curWidget = widgets.next();
            Object isSep = curWidget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
            if (NullSafe.equals(WidgetAttributes.NON_SEPARATOR, isSep)) {
                String name = curWidget.getNameLabel();
                initiallySelected.add(name);
                if (curWidget == selected) {
                    initiallySelected.select(i + 1);
                }
                map[i++] = curWidget;
            }
        }
        selectionAttrListener.setAttributeHelper(PULLDOWN_HELPER, map);
    }
    // TODO implement list box support
    //        else if (type == WidgetType.ListBoxItem) {
    //            this.selectLabel.setVisible(true);
    //            this.initiallySelected.setVisible(true);
    //            this.initiallySelected.removeAll();
    //            this.initiallySelected.add(SELECT_NONE);
    //            this.visibleLabel.setVisible(true);
    //            this.firstVisible.setVisible(true);
    //            this.firstVisible.removeAll();
    //            this.numVisibleLabel.setVisible(true);
    //            this.numVisible.setVisible(true);
    //
    //            SimpleWidgetGroup group = widget.getParentGroup();
    //
    //            Integer num =
    //                (Integer) group.getAttribute(WidgetType.NUM_VISIBLE_ATTR);
    //            this.numVisible.setSelection(num.intValue());
    //
    //            Iterator<IWidget> widgets = group.getAllWidgets();
    //            while (widgets.hasNext()) {
    //                IWidget curWidget = widgets.next();
    //                String name = curWidget.getDisplayLabel();
    //                this.initiallySelected.add(name);
    //                this.firstVisible.add(name);
    //            }
    //
    //            IWidget init =
    //                (IWidget) group.getAttribute(WidgetType.SELECTION_ATTR);
    //            int ind = group.indexOf(init) + 1;
    //            this.initiallySelected.select(ind);
    //            init = (IWidget) group.getAttribute(WidgetType.FIRST_VISIBLE_ATTR);
    //            ind = group.indexOf(init);
    //            this.firstVisible.select(ind);
    //        }
    layout();
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Widget(edu.cmu.cs.hcii.cogtool.model.Widget) RadioButtonGroup(edu.cmu.cs.hcii.cogtool.model.RadioButtonGroup) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) Iterator(java.util.Iterator) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) WidgetType(edu.cmu.cs.hcii.cogtool.model.WidgetType) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 35 with SimpleWidgetGroup

use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.

the class DesignEditorCmd method addWidgetUndoableEdit.

public static IDesignUndoableEdit addWidgetUndoableEdit(Frame frame, IWidget widget, DemoStateManager mgr) {
    if (widget instanceof ChildWidget) {
        ChildWidget childWidget = (ChildWidget) widget;
        final AParentWidget itemParent = childWidget.getParent();
        final int atIndex = itemParent.indexOf(childWidget);
        return new AddWidgetUndoableEdit(frame, widget, mgr) {

            @Override
            protected void redoHelper() {
                itemParent.addItem(atIndex, (ChildWidget) widget);
            }

            @Override
            protected void undoHelper() {
                itemParent.removeItem((ChildWidget) widget);
            }
        };
    }
    final SimpleWidgetGroup parentGroup = widget.getParentGroup();
    final int atIndex = (parentGroup != null) ? parentGroup.indexOf(widget) : -1;
    return new AddWidgetUndoableEdit(frame, widget, mgr) {

        @Override
        protected void redoHelper() {
            if (parentGroup != null) {
                parentGroup.add(atIndex, widget);
            // TODO:mlh reposition items/headers following!
            }
        }

        @Override
        protected void undoHelper() {
            if (parentGroup != null) {
                parentGroup.remove(widget);
            // TODO:mlh reposition items/headers following!
            }
        }
    };
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Aggregations

SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)45 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)32 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)16 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)14 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)13 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)10 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)10 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)9 HashSet (java.util.HashSet)8 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)7 Point (org.eclipse.draw2d.geometry.Point)7 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)6 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)6 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)6 Iterator (java.util.Iterator)6 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)5 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)4 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)4 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)4 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)4