Search in sources :

Example 21 with FrameElement

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

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

the class FrameEditorController method getSelectedElements.

/**
     * Helper method which returns a list of models instead of the
     * SelectionState returned Figures
     * @param selection
     * @return
     */
private Set<FrameElement> getSelectedElements(FrameEditorSelectionState seln, Comparator<? super FrameElement> c) {
    Set<FrameElement> elements = new TreeSet<FrameElement>(c);
    Iterator<FrameElement> selectedElts = seln.getSelectedElementsIterator();
    // Determine which elements can participate
    while (selectedElts.hasNext()) {
        FrameElement elt = selectedElts.next();
        if (!isMemberOfSelectedGroup(elt, seln)) {
            elements.add(elt);
        }
    }
    return elements;
}
Also used : TreeSet(java.util.TreeSet) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement)

Example 23 with FrameElement

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

the class FrameEditorController method createUngroupElementsAction.

private IListenerAction createUngroupElementsAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            Iterator<FrameElement> selectedElts = selection.getSelectedElementsIterator();
            final Set<FrameElementGroup> selectedGroups = new HashSet<FrameElementGroup>();
            while (selectedElts.hasNext()) {
                FrameElement elt = selectedElts.next();
                if (elt instanceof FrameElementGroup) {
                    selectedGroups.add((FrameElementGroup) elt);
                } else {
                    selectedGroups.addAll(elt.getRootElement().getEltGroups());
                }
            }
            if (selectedGroups.size() > 0) {
                CompoundUndoableEdit editSequence = new CompoundUndoableEdit(UNGROUP_ELEMENTS, FrameEditorLID.Ungroup);
                Iterator<FrameElementGroup> groups = selectedGroups.iterator();
                while (groups.hasNext()) {
                    FrameElementGroup group = groups.next();
                    ungroup(group, editSequence);
                    removeRootElement(UNGROUP_ELEMENTS, group, null, editSequence);
                }
                IUndoableEdit edit = new AUndoableEdit(FrameEditorLID.Ungroup) {

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

                    @Override
                    public void redo() {
                        super.redo();
                        Iterator<FrameElementGroup> groups = selectedGroups.iterator();
                        while (groups.hasNext()) {
                            FrameElementGroup group = groups.next();
                            ungroup(group, null);
                        }
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        Iterator<FrameElementGroup> groups = selectedGroups.iterator();
                        while (groups.hasNext()) {
                            FrameElementGroup group = groups.next();
                            regroup(group);
                        }
                    }
                };
                editSequence.addEdit(edit);
                // Commit the edit
                editSequence.end();
                // Only add this edit if it is significant
                if (editSequence.isSignificant()) {
                    undoMgr.addEdit(editSequence);
                }
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) HashSet(java.util.HashSet)

Example 24 with FrameElement

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

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

the class DesignEditorCmd method copyElements.

public static void copyElements(Design design, FrameElement[] selectedElts, Iterator<FrameElement> eltsToCopy, boolean saveToClipboard) {
    try {
        // Set up a clipboard saver.  Indicate that no transitions
        // should be copied.
        CogToolClipboard.ClipboardClassSaver s = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyWidgets, selectedElts, saveToClipboard);
        // Iterate through the widgets and save the selected items.
        while (eltsToCopy.hasNext()) {
            FrameElement elt = eltsToCopy.next();
            //       get pasted.
            if (!(elt instanceof ChildWidget)) {
                s.saveObject(elt);
            }
        }
        s.finish();
        if (!saveToClipboard) {
            FrameTemplateSupport.setFrameTemplate(design, s.getSavedString());
        }
    } catch (IOException e) {
        throw new RcvrClipboardException(e);
    } catch (OutOfMemoryError error) {
        throw new RcvrOutOfMemoryException("Copying Widgets", error);
    }
}
Also used : RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) CogToolClipboard(edu.cmu.cs.hcii.cogtool.CogToolClipboard) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IOException(java.io.IOException) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

Aggregations

FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)31 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)20 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)16 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)14 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)9 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)7 HashSet (java.util.HashSet)6 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)5 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)5 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)5 Iterator (java.util.Iterator)5 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)4 Point (org.eclipse.draw2d.geometry.Point)4 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)3 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)3 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)3 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)3 EmptyIterator (edu.cmu.cs.hcii.cogtool.util.EmptyIterator)3 MoveHalo (edu.cmu.cs.hcii.cogtool.view.MoveHalo)3 CogToolLID (edu.cmu.cs.hcii.cogtool.CogToolLID)2