Search in sources :

Example 11 with IWidget

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

the class ItemWireRenderer method paintForeground.

public void paintForeground(Graphics g) {
    g.pushState();
    try {
        IWidget model = ((GraphicalWidget<?>) getParent()).getModel();
        Object value = model.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
        if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, value)) {
            int startY = (boxHeight + 1) / 2;
            g.drawLine(boxX, startY, boxWidth, startY);
            g.drawLine(boxX, boxY, boxX, boxHeight - 1);
            g.drawLine(boxWidth, boxY, boxWidth, boxHeight - 1);
        } else {
            g.drawRectangle(boxX, boxY, boxWidth - 1, boxHeight - 1);
            if (titleLabel != null) {
                titleLabel.paint(g);
            }
            if (rightIconExists) {
                paintRightIcon(g);
            }
        }
    } finally {
        g.popState();
    }
}
Also used : IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Point(org.eclipse.draw2d.geometry.Point)

Example 12 with IWidget

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

the class FrameEditorUI method removeHalo.

// addSelectionChangeListeners
// TODO: Currently works only for IWidget
protected void removeHalo(IWidget w) {
    MoveHalo halo = halosUIFig.getMoveHalo(w);
    if (halo != null) {
        SimpleWidgetGroup group = w.getParentGroup();
        if (group != null) {
            IWidget[] widgets = selection.getSelectedIWidgets();
            // Avoid removing if another sibling/cousin is selected
            for (IWidget widget : widgets) {
                if ((widget.getParentGroup() == group) && (widget != w)) {
                    return;
                }
            }
        }
        halosUIFig.hideHalo(halo);
    }
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MoveHalo(edu.cmu.cs.hcii.cogtool.view.MoveHalo) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 13 with IWidget

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

the class FrameEditorUI method initiateRetitleFigure.

public void initiateRetitleFigure(IFigure widgetFigure) {
    if (widgetFigure instanceof GraphicalWidget<?>) {
        IWidget w = ((GraphicalWidget<?>) widgetFigure).getModel();
        Object value = w.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
        if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, value)) {
            // don't allow renaming of separators
            return;
        }
    }
    // The editor control must be a child of an SWT object (the canvas)
    if (editor == null) {
        editor = new WidgetTitleEditor();
    }
    cleanupFigureLabelEditor();
    if (widgetFigure != null) {
        editor.editTitle(widgetFigure);
    }
}
Also used : EventObject(java.util.EventObject) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 14 with IWidget

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

the class FrameEditorUI method moveHaloUnderXY.

/**
     * Find a move halo at x, y
     */
public MoveHalo moveHaloUnderXY(int x, int y) {
    MoveHalo halo = view.moveHaloUnderXY(x, y);
    if (halo != null) {
        GraphicalWidget<?> clickedFigure = widgetLocatedAtXY(x, y);
        if (clickedFigure != null) {
            SimpleWidgetGroup group;
            IWidget haloWidget;
            FrameElement data = halo.getData();
            if (data instanceof IWidget) {
                haloWidget = (IWidget) data;
                group = haloWidget.getParentGroup();
            } else if (data instanceof SimpleWidgetGroup) {
                group = (SimpleWidgetGroup) data;
                haloWidget = group.get(0);
            } else {
                return halo;
            }
            IWidget clickedWidget = clickedFigure.getModel();
            if ((group != null) && (group.contains(clickedWidget))) {
                return null;
            }
            int haloLevel = haloWidget.getLevel();
            int clickedLevel = clickedWidget.getLevel();
            if (haloLevel < clickedLevel) {
                return null;
            }
        }
        return halo;
    }
    return null;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MoveHalo(edu.cmu.cs.hcii.cogtool.view.MoveHalo) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 15 with IWidget

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

the class FrameEditorUI method setViewEnabledState.

/**
     * Enables or disables LIDs as appropriate
     * @param sel the selection state on which to base enabling/disabling
     * @param availability NORMAL or CONTEXT
     * @see ListenerIdentifierMap
     */
protected void setViewEnabledState(FrameEditorSelectionState sel, Boolean availability) {
    String label = "";
    int widgetCount = sel.getWidgetSelectionCount();
    int elementCount = sel.getElementSelectionCount();
    IWidget selectedWidget = null;
    FrameElement selectedElement = null;
    if ((widgetCount > 0) || (elementCount > 0)) {
        if (widgetCount == 1) {
            label = " " + WIDGET_LABEL;
            selectedWidget = sel.getSelectedIWidgets()[0];
            selectedElement = selectedWidget;
        } else {
            label = " " + WIDGETS_LABEL;
            if (elementCount == 1) {
                selectedElement = sel.getSelectedIFrameElements()[0];
            }
        }
    }
    Text t = WindowUtil.getFocusedText();
    boolean editing = ((editor != null) && editor.getVisible());
    String cutCopyLabel = (editing || (t != null)) ? "" : label;
    // Turn on rename support if selection is exactly 1
    boolean enabled = (widgetCount == 1);
    String renameString = MenuFactory.RENAME_STRING;
    String relabelString = MenuFactory.RELABEL_STRING;
    if (enabled) {
        renameString += label;
        relabelString += label;
    }
    setEnabled(CogToolLID.Rename, availability, enabled, renameString);
    setEnabled(FrameEditorLID.Relabel, availability, enabled, relabelString);
    setEnabled(CogToolLID.CopyPath, availability, enabled);
    setEnabled(FrameEditorLID.RemoveImageProperty, availability, (selectedWidget != null) && (selectedWidget.getImage() != null));
    setEnabled(FrameEditorLID.ToggleRenderSkin, availability, enabled, MenuFactory.RENDER_WIDGET_SKIN_LABEL, (selectedWidget != null) && selectedWidget.isRendered());
    if (enabled && (selectedWidget != null)) {
        enabled = selectedWidget.getAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR) != null;
    }
    setEnabled(FrameEditorLID.SetRemoteLabelType, availability, enabled);
    if (elementCount == 1) {
        enabled = selectedElement.getRemoteLabelOwner() != null;
    }
    setEnabled(FrameEditorLID.SetRemoteLabelText, availability, enabled);
    // Turn on these LIDs if the selection is > 0
    enabled = (widgetCount > 0);
    setEnabled(FrameEditorLID.SetImageProperty, availability, enabled);
    setEnabled(FrameEditorLID.CaptureImageProperty, availability, enabled && view.isBackgroundAvailable());
    enabled = (elementCount > 0);
    String deleteString = MenuFactory.DELETE_STRING + label;
    setEnabled(CogToolLID.Delete, availability, enabled, deleteString);
    String dupString = MenuFactory.DUPLICATE_STRING + label;
    setEnabled(CogToolLID.Duplicate, availability, enabled, dupString);
    // For these, there must exist a non-IChildWidget selected widget
    int nonchildWidgetCount = sel.getNonchildSelectionCount();
    enabled = (nonchildWidgetCount > 0);
    String cutString = MenuFactory.CUT_STRING + cutCopyLabel;
    setEnabled(CogToolLID.Cut, availability, enabled, cutString);
    String copyString = MenuFactory.COPY_STRING + cutCopyLabel;
    setEnabled(CogToolLID.Copy, availability, enabled, copyString);
    setEnabled(CogToolLID.SetFrameTemplate, availability, enabled);
    setEnabled(CogToolLID.NudgeLeft, availability, enabled);
    setEnabled(CogToolLID.NudgeRight, availability, enabled);
    setEnabled(CogToolLID.NudgeDown, availability, enabled);
    setEnabled(CogToolLID.NudgeUp, availability, enabled);
    setEnabled(CogToolLID.BringToFront, availability, enabled);
    setEnabled(CogToolLID.BringForward, availability, enabled);
    setEnabled(CogToolLID.SendBackward, availability, enabled);
    setEnabled(CogToolLID.SendToBack, availability, enabled);
    // Grouping enabled only if multiple unrelated IFrameElements are selected
    enabled = false;
    FrameElement firstSelectedElt = null;
    Iterator<FrameElement> selectedElts = sel.getSelectedElementsIterator();
    while (selectedElts.hasNext()) {
        FrameElement elt = selectedElts.next();
        if (firstSelectedElt == null) {
            firstSelectedElt = elt.getRootElement();
        } else if (firstSelectedElt != elt.getRootElement()) {
            enabled = true;
            break;
        }
    }
    setEnabled(CogToolLID.Group, availability, enabled);
    enabled = false;
    selectedElts = sel.getSelectedElementsIterator();
    while (selectedElts.hasNext()) {
        FrameElement elt = selectedElts.next();
        enabled = enabled || (elt instanceof FrameElementGroup) || (elt.getRootElement().getEltGroups().size() > 0);
    }
    setEnabled(CogToolLID.Ungroup, availability, enabled);
    // don't allow alignment if any of the selected widgets are part of a
    // widget group (e.g. menu headers, list box items, grid buttons)
    // TODO might want to allow it for grid buttons, with extra work in the
    // controller to calculate horizontal and vertical space
    boolean groupWidgetSelected = false;
    IWidget[] widgets = sel.getSelectedIWidgets();
    for (IWidget widget : widgets) {
        if (widget.getParentGroup() != null) {
            groupWidgetSelected = true;
        }
    }
    // Enable alignment items if multiple non-child widgets are selected
    enabled = (nonchildWidgetCount > 1);
    setEnabled(CogToolLID.AlignTop, availability, enabled);
    setEnabled(CogToolLID.AlignBottom, availability, enabled);
    setEnabled(CogToolLID.AlignLeft, availability, enabled);
    setEnabled(CogToolLID.AlignRight, availability, enabled);
    setEnabled(CogToolLID.AlignCenter, availability, enabled);
    setEnabled(CogToolLID.AlignHorizCenter, availability, enabled);
    setEnabled(CogToolLID.AlignVertCenter, availability, enabled);
    // Enable spacing items if at least 3 non-child widgets are selected
    enabled = (nonchildWidgetCount >= 3) && !groupWidgetSelected;
    setEnabled(CogToolLID.SpaceVertically, availability, enabled);
    setEnabled(CogToolLID.SpaceHorizontally, availability, enabled);
    // If there is at least one widget in the model, enable these.
    enabled = (frame.getWidgets().size() > 0);
    setEnabled(CogToolLID.SelectAll, availability, enabled, SELECT_ALL_WIDGETS);
    // Draws the dot to indicate that the correct skin type is selected
    setSelected(CogToolLID.SkinNone, availability, false);
    setSelected(CogToolLID.SkinWireFrame, availability, false);
    setSelected(CogToolLID.SkinMacOSX, availability, false);
    setSelected(CogToolLID.SkinWinXP, availability, false);
    setSelected(CogToolLID.SkinPalm, availability, false);
    SkinType skin = design.getSkin();
    CogToolLID id = null;
    if (skin == SkinType.None) {
        id = CogToolLID.SkinNone;
    } else if (skin == SkinType.WireFrame) {
        id = CogToolLID.SkinWireFrame;
    } else if (skin == SkinType.MacOSX) {
        id = CogToolLID.SkinMacOSX;
    } else if (skin == SkinType.WinXP) {
        id = CogToolLID.SkinWinXP;
    } else if (skin == SkinType.Palm) {
        id = CogToolLID.SkinPalm;
    }
    if (id != null) {
        setSelected(id, availability, true);
    }
    setEnabled(CogToolLID.ClearFrameTemplate, ListenerIdentifierMap.ALL, FrameTemplateSupport.hasFrameTemplate(design));
}
Also used : CogToolLID(edu.cmu.cs.hcii.cogtool.CogToolLID) SkinType(edu.cmu.cs.hcii.cogtool.model.SkinType) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) Text(org.eclipse.swt.widgets.Text) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) Point(org.eclipse.draw2d.geometry.Point) 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