Search in sources :

Example 26 with EventObject

use of java.util.EventObject 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 27 with EventObject

use of java.util.EventObject 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)

Example 28 with EventObject

use of java.util.EventObject in project cogtool by cogtool.

the class StructureViewUIModel method installFrame.

/**
     * Creates the visible representation of a frame, installing
     * the "postage stamp" version, the devices, and the transitions
     * connecting sources to their corresponding destination frames.
     *
     * @param frame the model of the Frame to install
     * @return the <code>IFigure</code> representing the frame's visible
     *         representation
     * @author mlh
     */
protected DesignEditorFrame installFrame(Frame frame) {
    frame.addHandler(this, NameChangeAlert.class, frameNameChangeHandler);
    // Create the figure for the frame
    // For the handlers below, we need the frame figure in order to
    // fetch the figure corresponding to each "modified" source.
    final DesignEditorFrame frameFig = new DesignEditorFrame(frame, showToolTips, sourceRolloverCursor);
    frameFig.addWidgetShapeChangeHandler(shapeChangeHandler);
    frameFig.addWidgetRecoveryHandler(widgetRecoveryHandler);
    frameFig.addOriginChangeHandler(new OriginChangeHandler(frameFig));
    // Whenever a transition is added or removed from a source,
    // the transition's visible representation must be added or
    // removed as well.
    final AlertHandler transitionHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            TransitionSource.TransitionChange chg = (TransitionSource.TransitionChange) alert;
            if (chg != null) {
                GraphicalSource<?> sourceFigure = frameFig.getSourceFigure((TransitionSource) alert.getSource());
                if (chg.isAdd) {
                    installSourceTransition((Transition) chg.element, sourceFigure);
                } else {
                    uninstallSourceTransition((Transition) chg.element, sourceFigure);
                }
            }
        }
    };
    frameFig.addTransitionChangeHandler(transitionHandler);
    // When a widget is added to or removed from this frame during the
    // editing of this frame (see frame editing), install or remove the
    // visible representations of the widget's transitions.
    AlertHandler widgetHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            Frame.WidgetChange chg = (Frame.WidgetChange) alert;
            IWidget chgWidget = chg.getChangeElement();
            if (chg != null) {
                if (chg.action == Frame.WidgetChange.ELEMENT_DELETE) {
                    chgWidget.removeHandler(TransitionSource.TransitionChange.class, transitionHandler);
                } else if (chg.action == Frame.WidgetChange.ELEMENT_ADD) {
                    installSourceTransitions(frameFig, chgWidget);
                    chgWidget.addHandler(frameFig, TransitionSource.TransitionChange.class, transitionHandler);
                }
                // At the end of all widget Change Events, refresh.
                contents.repaint();
            }
        }
    };
    frameFig.addWidgetChangeHandler(widgetHandler);
    // Record the correspondence between the given frame and its figure.
    installedFrames.put(frame, frameFig);
    // Install the visible representation of the frame.
    contents.add(frameFig);
    return frameFig;
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) EventObject(java.util.EventObject) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 29 with EventObject

use of java.util.EventObject in project cogtool by cogtool.

the class ProjectUIModel method populateRow.

protected void populateRow(AUndertaking undertaking, final TreeItem row) {
    taskTreeItems.put(undertaking, row);
    row.addListener(SWT.Dispose, onDisposeRow);
    // TODO: This is creating a new handler instance for each row
    // TODO: reuse a single instance by looking up TreeItem in taskTreeItems?
    AlertHandler handler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            AUndertaking task = (AUndertaking) row.getData();
            row.setText(0, SWTStringUtil.insertEllipsis(task.getName(), 300, StringUtil.EQUAL, tree.getFont()));
            setRowBackground(task, row);
        }
    };
    row.setData(undertaking);
    undertaking.addHandler(this, NameChangeAlert.class, handler);
    row.setText(getTaskRowStrings(undertaking));
    Color bkg = setRowBackground(undertaking, row);
    int numCols = tree.getColumnCount();
    for (int i = 0; i < numCols; i++) {
        row.setBackground(i, bkg);
    }
    if (undertaking.isTaskGroup()) {
        TaskGroup group = (TaskGroup) undertaking;
        setGroupAlertHandlers(group, row);
        addTasks(group.getUndertakings().iterator(), row);
    }
    row.setExpanded(true);
    if (rowHook != null) {
        rowHook.onRowCreation(row);
    }
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Color(org.eclipse.swt.graphics.Color) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) EventObject(java.util.EventObject)

Example 30 with EventObject

use of java.util.EventObject in project cogtool by cogtool.

the class ProjectUIModel method setGroupAlertHandlers.

// populateRow
protected void setGroupAlertHandlers(TaskGroup group, final TreeItem row) {
    AlertHandler handler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            TaskGroup.TaskChange chg = (TaskGroup.TaskChange) alert;
            if (chg != null) {
                if (chg.isAdd) {
                    TreeItem newRow;
                    if (chg.atIndex == TaskGroup.TaskChange.AT_END) {
                        newRow = new TreeItem(row, SWT.NONE);
                    } else {
                        newRow = new TreeItem(row, SWT.NONE, chg.atIndex);
                    }
                    row.setExpanded(true);
                    populateRow((AUndertaking) chg.element, newRow);
                    redisplayResults(newRow);
                } else {
                    TreeItem rowToDelete = findChildRow((AUndertaking) chg.element, row.getItems());
                    recoverTreeItem(rowToDelete);
                }
            }
        }
    };
    group.addHandler(this, TaskGroup.TaskChange.class, handler);
    handler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            //                    System.out.println("NatureChange!");
            // walk up the group tree and recalculate
            redisplayResults(row);
        }
    };
    group.addHandler(this, TaskGroup.NatureChange.class, handler);
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) EventObject(java.util.EventObject)

Aggregations

EventObject (java.util.EventObject)91 EventFactory (org.apache.camel.spi.EventFactory)25 EventNotifier (org.apache.camel.spi.EventNotifier)25 ManagementStrategy (org.apache.camel.spi.ManagementStrategy)25 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)21 EventNotifierSupport (org.apache.camel.support.EventNotifierSupport)15 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)10 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)9 ExchangeCompletedEvent (org.apache.camel.management.event.ExchangeCompletedEvent)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 Design (edu.cmu.cs.hcii.cogtool.model.Design)3 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)3 DesignEditorFrame (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame)3 MouseEvent (java.awt.event.MouseEvent)3 PreferencesHandler (jmri.plaf.macosx.PreferencesHandler)3 ExchangeSendingEvent (org.apache.camel.management.event.ExchangeSendingEvent)3 ListenerConfig (com.hazelcast.config.ListenerConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2