Search in sources :

Example 71 with IWidget

use of edu.cmu.cs.hcii.cogtool.model.IWidget 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 72 with IWidget

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

the class FrameEditorController method createChangeShapeAction.

/**
     * Create a listener for changing the shape of a widget.
     *
     * @return
     */
private IListenerAction createChangeShapeAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorUI.ShapeChangeParameters.class;
        }

        public boolean performAction(Object prms) {
            // Get the parameters to change the shape into
            final FrameEditorUI.ShapeChangeParameters p = (FrameEditorUI.ShapeChangeParameters) prms;
            Iterator<IWidget> selected = p.selection.getSelectedWidgetsIterator();
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(CHG_WIDGET_SHAPE, FrameEditorLID.ChangeShapeProperty);
            // Loop through all selected widgets.
            while (selected.hasNext()) {
                final IWidget w = selected.next();
                final ShapeType oldShapeType = w.getShape().getShapeType();
                final ShapeType newShapeType = p.newShapeType;
                // Don't make a non-changing edit!
                if (!oldShapeType.equals(newShapeType)) {
                    w.setShapeType(newShapeType);
                    DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.ChangeShapeProperty, demoStateMgr) {

                        @Override
                        public String getPresentationName() {
                            return CHG_WIDGET_SHAPE;
                        }

                        @Override
                        public void redo() {
                            super.redo();
                            w.setShapeType(p.newShapeType);
                            noteEditCheckRegenerate(w, this);
                        }

                        @Override
                        public void undo() {
                            super.undo();
                            w.setShapeType(oldShapeType);
                            noteEditCheckRegenerate(w, this);
                        }
                    };
                    noteEditCheckRegenerate(w, edit);
                    editSequence.addEdit(edit);
                }
            }
            editSequence.end();
            // Don't add empty edits!
            if (editSequence.isSignificant()) {
                undoMgr.addEdit(editSequence);
            }
            return true;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ShapeType(edu.cmu.cs.hcii.cogtool.model.ShapeType) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 73 with IWidget

use of edu.cmu.cs.hcii.cogtool.model.IWidget 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 74 with IWidget

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

the class DesignEditorCmd method pasteFrameElementGroup.

private static int pasteFrameElementGroup(FrameElementGroup eltGroup, Design design, int currentDeviceTypes, Frame frame, DemoStateManager mgr, IUndoableEditSequence editSeq, Set<FrameElementGroup> groups, Set<IWidget> addedRemoteLabels) {
    int numPasted = 0;
    makeEltGroupNameUnique(eltGroup, frame);
    groups.add(eltGroup);
    groups.addAll(eltGroup.getEltGroups());
    checkForRemoteLabel(eltGroup, addedRemoteLabels);
    Iterator<FrameElement> elementsToAdd = eltGroup.iterator();
    while (elementsToAdd.hasNext()) {
        FrameElement eltToAdd = elementsToAdd.next();
        if (eltToAdd instanceof IWidget) {
            numPasted += pasteWidget((IWidget) eltToAdd, design, currentDeviceTypes, frame, mgr, editSeq, groups, addedRemoteLabels);
        } else if (eltToAdd instanceof SimpleWidgetGroup) {
            numPasted += pasteWidgetGroup((SimpleWidgetGroup) eltToAdd, design, currentDeviceTypes, frame, mgr, editSeq, groups, addedRemoteLabels);
        } else if (eltToAdd instanceof FrameElementGroup) {
            numPasted += pasteFrameElementGroup((FrameElementGroup) eltToAdd, design, currentDeviceTypes, frame, mgr, editSeq, groups, addedRemoteLabels);
        }
    }
    return numPasted;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 75 with IWidget

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

the class DesignEditorCmd method pasteWidgetGroup.

private static int pasteWidgetGroup(SimpleWidgetGroup group, Design design, int currentDeviceTypes, Frame frame, DemoStateManager mgr, IUndoableEditSequence editSequence, Set<FrameElementGroup> groups, Set<IWidget> addedRemoteLabels) {
    int numPasted = 0;
    Iterator<IWidget> groupWidgets = group.iterator();
    while (groupWidgets.hasNext()) {
        numPasted += pasteWidget(groupWidgets.next(), design, currentDeviceTypes, frame, mgr, editSequence, groups, addedRemoteLabels);
    }
    groups.addAll(group.getEltGroups());
    checkForRemoteLabel(group, addedRemoteLabels);
    return numPasted;
}
Also used : DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)93 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)29 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)20 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)19 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)15 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)15 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)12 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)11 Point (org.eclipse.draw2d.geometry.Point)11 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)10 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)9 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)9 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)9 HashSet (java.util.HashSet)8 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)7 InputDevice (edu.cmu.cs.hcii.cogtool.model.InputDevice)7 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)7 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)7 Iterator (java.util.Iterator)7 EventObject (java.util.EventObject)6