Search in sources :

Example 11 with GridButtonGroup

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

the class FrameEditorController method duplicateWidgetsAction.

// duplicateFrameEltGroup
private IListenerAction duplicateWidgetsAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorUI.DuplicateParameters parameters = (FrameEditorUI.DuplicateParameters) prms;
            int elementCount = parameters.selection.getElementSelectionCount();
            // If selection is non zero, copy widgets
            if (elementCount > 0) {
                Map<IWidget, IWidget> widgetCopies = new LinkedHashMap<IWidget, IWidget>();
                final Map<FrameElementGroup, FrameElementGroup> groupCopies = new LinkedHashMap<FrameElementGroup, FrameElementGroup>();
                widgetSituator.reset(widgetCopies, groupCopies);
                Set<FrameElement> selectedElements = getSelectedElements(parameters.selection, elementLevelComparator);
                Iterator<FrameElement> elements = selectedElements.iterator();
                // Iterate through the widgets and duplicate.
                while (elements.hasNext()) {
                    FrameElement elt = elements.next();
                    if (elt instanceof IWidget) {
                        duplicateWidget((IWidget) elt, parameters.selection, parameters.moveByX, parameters.moveByY);
                    } else if (elt instanceof FrameElementGroup) {
                        duplicateFrameEltGroup((FrameElementGroup) elt, parameters.moveByX, parameters.moveByY);
                    }
                }
                widgetSituator.completeWork();
                final Iterable<? extends IWidget> widgetDuplicates = new ReadOnlyList<IWidget>(new ArrayList<IWidget>(widgetCopies.values()));
                Iterator<? extends IWidget> copiedWidgets = widgetDuplicates.iterator();
                Set<GridButtonGroup> dupGridGroups = new HashSet<GridButtonGroup>();
                while (copiedWidgets.hasNext()) {
                    IWidget widgetCopy = copiedWidgets.next();
                    // Warning: it is important that each widget be added
                    // to the frame *before* we make the next widget name
                    // unique or we can end up with non-unique names.
                    makeWidgetNameUnique(widgetCopy);
                    model.addWidget(widgetCopy);
                    if (widgetCopy instanceof GridButton) {
                        GridButtonGroup gbg = (GridButtonGroup) widgetCopy.getParentGroup();
                        // for each grid button group
                        if (!dupGridGroups.contains(gbg)) {
                            gbg.recalculateOffsets();
                            dupGridGroups.add(gbg);
                        }
                    }
                }
                Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
                while (copiedGroups.hasNext()) {
                    FrameElementGroup copiedGroup = copiedGroups.next();
                    // Ensure name is unique, then add to frame immediately
                    // Otherwise, it would be possible to generate presumed
                    // unique names that weren't.
                    makeEltGroupNameUnique(copiedGroup);
                    model.addEltGroup(copiedGroup);
                }
                DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(FrameEditorLID.Duplicate, demoStateMgr) {

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

                    @Override
                    public void redo() {
                        super.redo();
                        Iterator<? extends IWidget> addCopies = widgetDuplicates.iterator();
                        while (addCopies.hasNext()) {
                            IWidget widgetCopy = addCopies.next();
                            model.addWidget(widgetCopy);
                        }
                        Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
                        while (copiedGroups.hasNext()) {
                            model.addEltGroup(copiedGroups.next());
                        }
                        demoStateMgr.noteWidgetsEdit(widgetDuplicates, this);
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        Iterator<? extends IWidget> removeCopies = widgetDuplicates.iterator();
                        while (removeCopies.hasNext()) {
                            IWidget widgetCopy = removeCopies.next();
                            model.removeWidget(widgetCopy);
                        }
                        Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
                        while (copiedGroups.hasNext()) {
                            model.removeEltGroup(copiedGroups.next());
                        }
                        demoStateMgr.noteWidgetsEdit(widgetDuplicates, this);
                    }
                };
                demoStateMgr.noteWidgetsEdit(widgetDuplicates, edit);
                undoMgr.addEdit(edit);
                return true;
            }
            // tell user to select something.
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : IDesignUndoableEdit(edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit) LinkedHashMap(java.util.LinkedHashMap) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) HashSet(java.util.HashSet) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) ReadOnlyList(edu.cmu.cs.hcii.cogtool.util.ReadOnlyList) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 12 with GridButtonGroup

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

the class FrameEditorController method moveGridButton.

/**
     * Special case of moveWidget; moves all buttons below or to the right of
     * gb in its group and updates the horizontal and vertical offsets as
     * necessary.
     */
private void moveGridButton(ListenerIdentifier lid, String presentationLabel, GridButton gb, double widgetMoveByX, double widgetMoveByY, double newHoriz, double newVert, IUndoableEditSequence editSequence) {
    // move the list of buttons affected
    DoublePoint oldLocation = gb.getShape().getOrigin();
    double oldX = oldLocation.x;
    double oldY = oldLocation.y;
    GridButtonGroup gbg = (GridButtonGroup) gb.getParentGroup();
    boolean vertical = (widgetMoveByX == 0);
    double oldHoriz = gb.getHorizSpace();
    double oldVert = gb.getVertSpace();
    ReadOnlyList<? extends GridButton> movedButtons = gbg.getMovedButtons(vertical, oldX, oldY);
    for (int i = 0; i < movedButtons.size(); i++) {
        GridButton g = movedButtons.get(i);
        DoublePoint p = g.getShape().getOrigin();
        double tempX = Math.max(p.x + widgetMoveByX, 0.0);
        double tempY = Math.max(p.y + widgetMoveByY, 0.0);
        g.setWidgetOrigin(tempX, tempY);
    }
    if (vertical) {
        gb.setVertSpace(newVert);
    } else {
        List<GridButton> column = gbg.getColumn(gb);
        for (int i = 0; i < column.size(); i++) {
            GridButton g = column.get(i);
            g.setHorizSpace(newHoriz);
        }
    }
    DemoStateManager.IDesignUndoableEdit edit = moveGridButtonsEdit(lid, presentationLabel, movedButtons, widgetMoveByX, widgetMoveByY, oldHoriz, oldVert, newHoriz, newVert, gb);
    editSequence.addEdit(edit);
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IDesignUndoableEdit(edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 13 with GridButtonGroup

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

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

the class DesignEditorCmd method pasteElements.

// pasteFrameElementGroup
public static int pasteElements(Design design, final Frame frame, Collection<Object> objects, DemoStateManager mgr, IUndoableEditSequence editSequence) {
    // If given objects contain widgets, insert into the given frame
    if ((objects != null) && (objects.size() > 0)) {
        Iterator<Object> objIt = objects.iterator();
        Set<SimpleWidgetGroup> addedGroups = new HashSet<SimpleWidgetGroup>();
        final Set<IWidget> addedRemoteLabels = new HashSet<IWidget>();
        final Set<FrameElementGroup> addedEltGroups = new HashSet<FrameElementGroup>();
        int numPasted = 0;
        // May need to add a device
        int currentDeviceTypes = DeviceType.buildDeviceSet(design.getDeviceTypes());
        // create them.
        while (objIt.hasNext()) {
            Object o = objIt.next();
            if (o instanceof IWidget) {
                IWidget widget = (IWidget) o;
                numPasted += pasteWidget(widget, design, currentDeviceTypes, frame, mgr, editSequence, addedEltGroups, addedRemoteLabels);
                SimpleWidgetGroup group = widget.getParentGroup();
                if (group != null) {
                    addedGroups.add(group);
                }
            } else if (o instanceof FrameElementGroup) {
                numPasted += pasteFrameElementGroup((FrameElementGroup) o, design, currentDeviceTypes, frame, mgr, editSequence, addedEltGroups, addedRemoteLabels);
            }
        }
        Iterator<SimpleWidgetGroup> groupsIter = addedGroups.iterator();
        while (groupsIter.hasNext()) {
            SimpleWidgetGroup group = groupsIter.next();
            repositionChildren(group);
            if (group instanceof GridButtonGroup) {
                ((GridButtonGroup) group).recalculateOffsets();
            }
            addedEltGroups.addAll(group.getEltGroups());
        }
        Iterator<FrameElementGroup> eltGroups = addedEltGroups.iterator();
        while (eltGroups.hasNext()) {
            frame.addEltGroup(eltGroups.next());
        }
        Iterator<IWidget> remoteLabels = addedRemoteLabels.iterator();
        while (remoteLabels.hasNext()) {
            IWidget remoteLabel = remoteLabels.next();
            if (!frame.containsWidget(remoteLabel)) {
                String uniqueName = NamedObjectUtil.makeNameUnique(remoteLabel.getName(), frame.getWidgets());
                remoteLabel.setName(uniqueName);
                frame.addWidget(remoteLabel);
            }
        }
        IUndoableEdit edit = new AUndoableEdit(CogToolLID.Paste) {

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

            @Override
            public void redo() {
                super.redo();
                Iterator<FrameElementGroup> eltGroups = addedEltGroups.iterator();
                while (eltGroups.hasNext()) {
                    frame.addEltGroup(eltGroups.next());
                }
                Iterator<IWidget> remoteLabels = addedRemoteLabels.iterator();
                while (remoteLabels.hasNext()) {
                    IWidget remoteLabel = remoteLabels.next();
                    if (!frame.containsWidget(remoteLabel)) {
                        frame.addWidget(remoteLabel);
                    }
                }
            }

            @Override
            public void undo() {
                super.undo();
                Iterator<FrameElementGroup> eltGroups = addedEltGroups.iterator();
                while (eltGroups.hasNext()) {
                    frame.removeEltGroup(eltGroups.next());
                }
                Iterator<IWidget> remoteLabels = addedRemoteLabels.iterator();
                while (remoteLabels.hasNext()) {
                    IWidget remoteLabel = remoteLabels.next();
                    if (frame.containsWidget(remoteLabel)) {
                        frame.removeWidget(remoteLabel);
                    }
                }
            }
        };
        editSequence.addEdit(edit);
        return numPasted;
    }
    return 0;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) HashSet(java.util.HashSet) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 15 with GridButtonGroup

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

the class BalsamiqButtonAPIConverter method parseBMMLWidget.

/** Helper function used by parseFrame
	 * This method is used to parse the tags of each control tag in Balsamiq XML. A control tag
	 * represents a Balsamiq Widget.
     * 
     * @param  node a node of the tree that represents a Balsamiq widget
     * @frame  frame that the widget is being added to
     * @group  parent group
     * @groupX x coordinate of parent group
     * @groupY y coordinate of parent group
     * @return      the newly created widget
     */
protected Widget parseBMMLWidget(Node node, Frame frame, SimpleWidgetGroup group, double groupX, double groupY) throws IOException {
    System.out.println("parseBMMLWidget " + group + " x: " + groupX + "y: " + groupY);
    NodeList children = node.getChildNodes();
    Widget widget = null;
    WidgetType widgetType = null;
    String balsamiqControlType = getAttributeValue(node, CONTROL_TYPE_ATTR);
    String widgetTypeString = (balsamiqControlType == null) ? null : getBMMLWidgetType(balsamiqControlType);
    String widgetName = getAttributeValue(node, CONTROL_ID_ATTR);
    if (widgetName == null) {
    //TODO: make a random widget name and move on. report to the user. need to be unique within the frame. Frame.java has a method for this
    }
    System.out.println("462- wN " + widgetName + "widT " + widgetTypeString);
    if (widgetTypeString == null) {
    //TODO: report to the user
    } else {
        widgetType = getWidgetType(widgetTypeString);
        //Parse the widget name, location and size from the attributes of the XML tag
        //TODO: Error check all of the getAttributeValues()
        double x = Double.parseDouble(getAttributeValue(node, X_ATTR));
        double y = Double.parseDouble(getAttributeValue(node, Y_ATTR));
        //TODO: difference between w and measuredW, same for height
        double width = Integer.parseInt(getAttributeValue(node, BWIDTH_ATTR));
        double height = Integer.parseInt(getAttributeValue(node, BHEIGHT_ATTR));
        double measWidth = Integer.parseInt(getAttributeValue(node, MEASURED_WIDTH_ATTR));
        double measHeight = Integer.parseInt(getAttributeValue(node, MEASURED_HEIGHT_ATTR));
        if (//TODO: make sure the dimensions are positive
        width == -1 && height == -1) {
            System.out.println("493- changing widget dimensions");
            width = measWidth;
            height = measHeight;
        }
        /*bounds is the size and location of the widget*/
        if (group != null) {
            System.out.println("488-Group is not null");
            DoubleRectangle rect = group.getGroupBounds();
            if (rect != null) {
                System.out.println("500-rect is not null");
            //x += groupX;
            //y += groupY;
            }
        }
        x += groupX;
        y += groupY;
        System.out.println("new widget has dimens:" + x + " " + y);
        DoubleRectangle bounds = new DoubleRectangle(x, y, width, height);
        if (widgetType == WidgetType.Check) {
            System.out.println("505-The widget is a check so now make a group for it");
            if (group == null) {
                group = new GridButtonGroup();
                //give it a random widget name										
                group.setName("newName");
                groupRegistry.put("newName", group);
            }
            //if(group instanceof GridButtonGroup)
            //{
            int eltCount = group.elementCount();
            System.out.println("513-group is gridbuttongroup " + group.getName() + " " + eltCount);
            if (eltCount > 0) {
                //TODO: check if the widgets align best horizontally or vertically
                //align the widgets to average coord, first, left or rightmost
                IWidget wid = group.getElement(group.elementCount() - 1);
                DoubleRectangle bounds2 = wid.getEltBounds();
                System.out.println("530 " + bounds2.getX() + " " + bounds2.getWidth() + " " + bounds2.getY() + " " + bounds2.getHeight());
                double diffX = Math.abs(x - bounds2.getX());
                double diffY = Math.abs(y - bounds2.getY());
                System.out.println("diffX " + diffX + " " + diffY);
                DoubleRectangle bounds3 = new DoubleRectangle(bounds2.getX() + bounds2.getWidth(), bounds2.getY(), width, height);
                if (diffX < diffY) {
                    bounds3 = new DoubleRectangle(bounds2.getX(), bounds2.getY() + bounds2.getHeight(), width, height);
                }
                widget = new CheckBox((GridButtonGroup) group, bounds3, widgetName);
            } else {
                widget = new CheckBox((GridButtonGroup) group, bounds, widgetName);
            }
            widget.setWidgetType(widgetType);
        /*}
				else
				{
					System.out.println("517-group2 is gridbuttongroup");
					GridButtonGroup group2 = new GridButtonGroup();
					group2.setName("newNameCheck");										
					groupRegistry.put("newNameCheck", group2);
					widget = new CheckBox(group2, bounds, widgetName);
					//group.addElement((IWidget) group2);

				}*/
        } else {
            widget = new Widget(bounds, widgetType);
        }
        widget.setName(widgetName);
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            String nodeName = child.getNodeName();
            /*Whitespace in the DOM tree is represented as #text. Ignore these nodes. Anywhere between the open and closed tag*/
            if (!nodeName.equals("#text")) {
                if (nodeName.equalsIgnoreCase(CONTROL_PROP_ELT)) {
                    NodeList controlTags = child.getChildNodes();
                    for (int j = 0; j < controlTags.getLength(); j++) {
                        Node controlTag = controlTags.item(j);
                        String propertyTag = controlTag.getNodeName();
                        //CogTool widget Display Label
                        if (propertyTag.equalsIgnoreCase(BALSAMIQ_TEXT_ELT)) {
                            /*Must decode the title. For instance the title in
							    Balsamiq, "First%20Frame" is "First Frame" in CogTool*/
                            String title = getElementText(controlTag);
                            title = URLDecoder.decode(title, "UTF-8");
                            widget.setTitle(title);
                        } else //CogTool transition on the present widget
                        if (propertyTag.equalsIgnoreCase(HREF_ELT)) {
                            String destinationFileName = getElementText(controlTag);
                            File destinationFile = new File(designPathName, destinationFileName);
                            //Make sure the file exists before attempting to parse the file
                            if (destinationFile.exists()) {
                                parseBalsamiqFile(destinationFile);
                                parseTransition(destinationFileName, widget);
                            }
                        } else if (propertyTag.equalsIgnoreCase(STATE_ELT)) {
                            //TODO: work on states
                            //A Balsamiq Button can be normal, selected, or disabled
                            String state = getElementText(controlTag);
                            if (state.equals("selected")) {
                                widget.setAttribute(WidgetAttributes.IS_SELECTED_ATTR, Boolean.TRUE);
                            } else {
                            //TODO: Other Balsamiq states like "disabled", "disabled and selected"
                            }
                        }
                    // END OF STATE OF BUTTON
                    }
                // END OF PROPERTY TAG
                }
            // END OF CONTROL PROPERTIES TAG
            }
        }
    }
    widget.setRendered(true);
    return widget;
}
Also used : CheckBox(edu.cmu.cs.hcii.cogtool.model.CheckBox) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Widget(edu.cmu.cs.hcii.cogtool.model.Widget) WidgetType(edu.cmu.cs.hcii.cogtool.model.WidgetType) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) File(java.io.File) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Aggregations

GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)15 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)12 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)9 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)7 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)6 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)6 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)5 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)4 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)3 CheckBox (edu.cmu.cs.hcii.cogtool.model.CheckBox)3 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)3 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)3 RadioButtonGroup (edu.cmu.cs.hcii.cogtool.model.RadioButtonGroup)3 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)3 AMenuWidget (edu.cmu.cs.hcii.cogtool.model.AMenuWidget)2 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)2 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)2 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)2 RadioButton (edu.cmu.cs.hcii.cogtool.model.RadioButton)2 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)2