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);
}
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);
}
}
};
}
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;
}
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);
}
}
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);
}
Aggregations