Search in sources :

Example 6 with AlertHandler

use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.

the class FrameEditorUI method addSelectionChangeListeners.

/**
     * Add the selection Change event listeners.
     */
protected void addSelectionChangeListeners() {
    AlertHandler widgetSelectionHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            FrameEditorSelectionState.SelectionChange evt = (FrameEditorSelectionState.SelectionChange) alert;
            if (evt != null) {
                // Set the state of corresponding graphical widgets
                GraphicalWidget<?> gw;
                // Alter state of all widgets in selection
                if (evt.changedElement == null) {
                    Iterator<GraphicalWidget<?>> widgetFigs = ((FrameEditorSelectionState) evt.getSource()).getSelectedWidgetFigures();
                    while (widgetFigs.hasNext()) {
                        gw = widgetFigs.next();
                        gw.setSelected(evt.selected);
                    }
                } else if (evt.changedElement instanceof GraphicalWidget<?>) {
                    // If an object was passed on the event, set its
                    // selected state to the event's selected state
                    gw = (GraphicalWidget<?>) evt.changedElement;
                    if (frame.getWidgets().contains(gw.getModel())) {
                        gw.setSelected(evt.selected);
                    }
                }
            }
            // Repaint the frame contents
            // This causes the resize handles to be redrawn.
            // Also causes the entire frame to be "refreshed"
            delayedRepainting.requestRepaint(REPAINT_ALL);
        // Add the following back when another window's actions
        // can cause changes to a Frame Editor's selection state
        // (such as something that deletes a widget)
        //                    updateView();
        }
    };
    selection.addHandler(this, FrameEditorSelectionState.SelectionChange.class, widgetSelectionHandler);
}
Also used : AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) EventObject(java.util.EventObject)

Example 7 with AlertHandler

use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.

the class FrameEditorUI method addBackgroundImageHandler.

/**
     * Registers a listener that enables/disables the
     * "remove background image" menu item as necessary.
     *
     * Also enable or disabled the capture Background button.
     * TODO: when capture background becomes a menu item, add to setEnabled
     */
protected void addBackgroundImageHandler() {
    AlertHandler backgroundEnabler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            // Checks to see if the frame has a background.
            // if so enable remove background and capture background
            // buttons.
            boolean enable = (frame.getBackgroundImage() == null) ? MenuUtil.DISABLED : MenuUtil.ENABLED;
            // Enable or disabled the remove background menu item
            setEnabled(CogToolLID.RemoveBackgroundImage, ListenerIdentifierMap.ALL, enable);
            // Enable or disabled the capture background button
            view.setIsBackgroundAvailable(enable);
        }
    };
    frame.addHandler(this, Frame.BackgroundImageChange.class, backgroundEnabler);
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) EventObject(java.util.EventObject)

Example 8 with AlertHandler

use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.

the class FrameEditorUI method addWidgetShapeChangeHandler.

/**
     * Registers a listener that redraws the frame in response to changes in
     * the appearance of widgets
     *
     * When this event occurs, resize handles are redrawn, the window's size is
     * recomputed, and the display updated.
     *
     */
protected void addWidgetShapeChangeHandler() {
    AlertHandler widgetTitleChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            FrameUIModel.WidgetTitleChange chg = (FrameUIModel.WidgetTitleChange) alert;
            // selected widget
            if (selection.getElementSelectionCount() == 1) {
                FrameElement elt = selection.getSelectedIFrameElements()[0];
                if (chg.widget == elt.getAttribute(WidgetAttributes.REMOTE_LABEL_ATTR)) {
                    view.setRemoteLabelText(chg.widget.getTitle());
                }
            }
        }
    };
    frameUI.addHandler(this, FrameUIModel.WidgetTitleChange.class, widgetTitleChangeHandler);
    AlertHandler widgetShapeChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            delayedRepainting.requestRepaint(SHAPE_CHANGE_REPAINT);
        // a FULL repaint is probably not needed
        }
    };
    frameUI.addHandler(this, FrameUIModel.WidgetShapeImageChange.class, widgetShapeChangeHandler);
    AlertHandler widgetGroupChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            FrameUIModel.WidgetGroupChange evt = (FrameUIModel.WidgetGroupChange) alert;
            if (evt.isAdd) {
                GraphicalWidget<?> gw = frameUI.getWidgetFigure(evt.widget);
                delayedWidgetSelection.addToSelection(evt.widget, gw);
            } else {
                delayedWidgetSelection.removeFromSelection(evt.widget);
                SimpleWidgetGroup group = evt.widget.getParentGroup();
                if (group.size() == 0) {
                    //evt.widget was the last widget in this group,
                    //so hide the halo for it
                    removeHalo(evt.widget);
                }
            }
        }
    };
    frameUI.addHandler(this, FrameUIModel.WidgetGroupChange.class, widgetGroupChangeHandler);
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameUIModel(edu.cmu.cs.hcii.cogtool.uimodel.FrameUIModel) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) EventObject(java.util.EventObject)

Example 9 with AlertHandler

use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.

the class FrameEditorUI method init.

/**
     * Set up this object for editing widgets.
     * This method should be called from within the constructor.
     */
private void init() {
    // Add listeners to the view
    addEventListeners();
    addSelectionChangeListeners();
    // Add listeners to the model
    addBackgroundImageHandler();
    addFrameWidgetHandler();
    addWidgetShapeChangeHandler();
    project.addHandler(this, Project.DesignChange.class, new AlertHandler() {

        public void handleAlert(EventObject alert) {
            Project.DesignChange chg = (Project.DesignChange) alert;
            if ((!chg.isAdd) && (chg.element == design)) {
                closeOpenController();
            }
        }
    });
    design.addHandler(this, Design.FrameChange.class, new AlertHandler() {

        public void handleAlert(EventObject alert) {
            Design.FrameChange chg = (Design.FrameChange) alert;
            if ((!chg.isAdd) && (chg.element == frame)) {
                closeOpenController();
            }
        }
    });
    design.addHandler(this, Design.DeviceTypeChange.class, new AlertHandler() {

        public void handleAlert(EventObject alert) {
            Set<DeviceType> dts = design.getDeviceTypes();
            int deviceTypes = DeviceType.buildDeviceSet(dts);
            view.resetDeviceTypes(deviceTypes);
        }
    });
    // Add listeners to rename events on project and design
    frame.addHandler(this, NameChangeAlert.class, renameHandler);
    design.addHandler(this, NameChangeAlert.class, renameHandler);
    // Some items should always be enabled.
    // Should be the last call in the constructor
    setInitiallyEnabled(true);
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) Project(edu.cmu.cs.hcii.cogtool.model.Project) Set(java.util.Set) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) EventObject(java.util.EventObject)

Example 10 with AlertHandler

use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.

the class DesignEditorUI method createFrameSelectionHandler.

protected AlertHandler createFrameSelectionHandler() {
    return new AlertHandler() {

        public void handleAlert(EventObject alert) {
            FrameSelectionChange evt = (FrameSelectionChange) alert;
            ActionPropertySet actionProps = view.getActionPropertySet();
            if (evt != null) {
                if (evt.changedFrameFigure != null) {
                    evt.changedFrameFigure.setSelected(evt.selected);
                    // Handle property sheet selection
                    Frame[] selectedFrames = selection.getSelectedFrames();
                    int selectedFrameCount = selectedFrames.length;
                    if (selectedFrameCount > 0) {
                        actionProps.setComposite(ActionPropertySet.FRAME);
                        if (selectedFrameCount == 1) {
                            actionProps.setFrameName(selectedFrames[0]);
                        }
                    } else {
                        actionProps.setComposite(ActionSet.USE_NONE);
                    }
                    actionProps.enableFrameName(selectedFrameCount == 1);
                } else {
                    actionProps.setComposite(ActionSet.USE_NONE);
                    Iterator<DesignEditorFrame> frameFigures = selection.getSelectedFrameFigures();
                    while (frameFigures.hasNext()) {
                        DesignEditorFrame frameFigure = frameFigures.next();
                        frameFigure.setSelected(evt.selected);
                    }
                }
                // Repaint the frame contents
                delayedRepainting.requestRepaint(REPAINT_ALL);
            }
        }
    };
}
Also used : ActionPropertySet(edu.cmu.cs.hcii.cogtool.view.ActionPropertySet) FrameSelectionChange(edu.cmu.cs.hcii.cogtool.ui.DesignEditorSelectionState.FrameSelectionChange) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) DesignEditorFrame(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame) DesignEditorFrame(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) EventObject(java.util.EventObject) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)21 EventObject (java.util.EventObject)21 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)9 Design (edu.cmu.cs.hcii.cogtool.model.Design)4 DesignEditorFrame (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame)4 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)3 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)3 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)3 Set (java.util.Set)3 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)2 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)2 ResultStep (edu.cmu.cs.hcii.cogtool.model.ResultStep)2 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)2 PERTChartSelectionState (edu.cmu.cs.hcii.cogtool.ui.PERTChartSelectionState)2 GraphicalWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget)2 StructureViewUIModel (edu.cmu.cs.hcii.cogtool.uimodel.StructureViewUIModel)2 RcvrImageException (edu.cmu.cs.hcii.cogtool.util.RcvrImageException)2 ActionPropertySet (edu.cmu.cs.hcii.cogtool.view.ActionPropertySet)2 SWTList (edu.cmu.cs.hcii.cogtool.view.SWTList)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2