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