use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.
the class FrameEditorUI method addFrameWidgetHandler.
/**
* Registers a listener that adjusts selection state in response to
* widget additions or removals
*/
protected void addFrameWidgetHandler() {
AlertHandler frameWidgetHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
Frame.WidgetChange chg = (Frame.WidgetChange) alert;
IWidget chgWidget = chg.getChangeElement();
if (chg != null) {
// Check what action was performed
switch(chg.action) {
// Switch the selection to the newly-added widget
case Frame.WidgetChange.ELEMENT_ADD:
{
GraphicalWidget<?> gw = frameUI.getWidgetFigure(chgWidget);
gw.addChangeHandler(widgetChangeHandler, Widget.WidgetChange.class);
gw.addChangeHandler(widgetChangeHandler, IAttributed.AttributeChange.class);
gw.addChangeHandler(widgetChangeHandler, IAttributed.AuthorityChange.class);
delayedWidgetSelection.addToSelection(chgWidget, gw);
view.requestRename();
break;
}
// Reflect the change in selection state
case Frame.WidgetChange.ELEMENT_DELETE:
{
// Cannot depend on the frameUI to have removed
// this widget's graphical version.
// Call deselect with the model itself.
selection.deselectElement(chgWidget);
delayedWidgetSelection.removeFromSelection(chgWidget);
// call to clean up any resize handles.
delayedRepainting.requestRepaint(REPAINT_SELECT_HANDLES);
break;
}
}
}
}
};
frame.addHandler(this, Frame.WidgetChange.class, frameWidgetHandler);
AlertHandler frameEltHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
delayedRepainting.requestRepaint(REPAINT_SELECT_HANDLES);
}
};
// Do the above for both widget and association changes!
frame.addHandler(this, Frame.ElementChange.class, frameEltHandler);
AlertHandler frameAssocHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
Frame.FrameEltGrpChange chg = (Frame.FrameEltGrpChange) alert;
if (chg.action == Frame.FrameEltGrpChange.ELEMENT_DELETE) {
selection.deselectElement(chg.getChangeElement());
} else if (chg.action == Frame.FrameEltGrpChange.ELEMENT_ADD) {
selection.setSelectedSelnFig(uiModel.getGroupHalo(chg.getChangeElement()));
}
}
};
frame.addHandler(this, Frame.FrameEltGrpChange.class, frameAssocHandler);
}
Aggregations