use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.
the class FrameUIModel method addFrameChangeListeners.
/**
* Add listeners for when things change on the frame.
*/
protected void addFrameChangeListeners() {
AlertHandler frameChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
Frame.WidgetChange chg = (Frame.WidgetChange) alert;
IWidget chgWidget = chg.getChangeElement();
if (chg != null) {
// action dictated by the change.
switch(chg.action) {
// Add the graphical representation of the widget
case Frame.WidgetChange.ELEMENT_ADD:
createGraphicalWidget(chgWidget);
raiseAlert(new FrameUIModel.WidgetShapeImageChange(FrameUIModel.this, chgWidget));
break;
// Remove the graphical representation of the widget
case Frame.WidgetChange.ELEMENT_DELETE:
removeWidget(chgWidget);
raiseAlert(new FrameUIModel.WidgetShapeImageChange(FrameUIModel.this, chgWidget));
break;
// Update all existing widgets to the new color
case Frame.WidgetChange.WIDGET_COLORS_CHANGED:
Iterator<GraphicalWidget<?>> gws = figureList.values().iterator();
// Update graphical widgets
while (gws.hasNext()) {
GraphicalWidget<?> gw = gws.next();
gw.setColor(frame.getWidgetColor());
// gw.setFastMode(false);
}
// Update potential temporary widget
contents.setWidgetColor(frame.getWidgetColor());
break;
}
}
// Draw the viewable widgets.
// Adds any new items from the lists.. or moves them
drawWidgets();
}
};
// Add the new handler for frame changes to the list of things to
// alert to changes on the frame
frame.addHandler(this, Frame.WidgetChange.class, frameChangeHandler);
// A separate handler is required to take care of changes of the
// background on the frame.
AlertHandler frameBackgroundChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
Frame.BackgroundImageChange chg = (Frame.BackgroundImageChange) alert;
if (chg != null) {
// Dispose the old background image if there was one
if (backgroundImage.getImage() != null) {
backgroundImage.getImage().dispose();
}
byte[] bgImg = frame.getBackgroundImage();
// If the image is null, don't create it.
if (bgImg != null) {
// the cache is probably out of date
try {
Image img = new Image(null, new ByteArrayInputStream(bgImg));
// AUIModel.imageCache.put(frame, img);
// set the new image to the background
backgroundImage.setImage(img);
// get the size of the image
org.eclipse.swt.graphics.Rectangle bounds = img.getBounds();
// resize background image with the new bounds
backgroundImage.setSize(bounds.width, bounds.height);
} catch (SWTException ex) {
throw new GraphicsUtil.ImageException("Setting frame background image failed", ex);
}
} else {
// Clear the background image.
backgroundImage.setImage(null);
backgroundImage.setSize(0, 0);
}
}
drawWidgets();
// Need to raise Alert after draw widgets since
// the alert call seems to reset the "bounds"
raiseAlert(new FrameUIModel.WidgetShapeImageChange(FrameUIModel.this, null));
}
};
// Add this handler to the list for changes in the background image
frame.addHandler(this, Frame.BackgroundImageChange.class, frameBackgroundChangeHandler);
}
use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.
the class FrameUIModel method addDesignChangeListeners.
/**
* Add listeners for when things change on the design.
*/
protected void addDesignChangeListeners() {
AlertHandler designChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
Design.WidgetAppearanceChange chg = (Design.WidgetAppearanceChange) alert;
if (chg != null) {
Iterator<GraphicalWidget<?>> gws = figureList.values().iterator();
// Update graphical widgets
while (gws.hasNext()) {
GraphicalWidget<?> gw = gws.next();
gw.updateType();
}
}
}
};
// Add the new handler for design changes to the list of things to
// alert to changes on the design
frame.getDesign().addHandler(this, Design.WidgetAppearanceChange.class, designChangeHandler);
}
use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.
the class ProjectUIModel method installTreeColumn.
protected void installTreeColumn(final TreeColumn designColumn, Design design) {
designColumn.addListener(SWT.Dispose, onDisposeColumn);
designColumn.setText(design.getName());
designColumn.setResizable(true);
designColumn.setWidth(CogToolPref.KLM_RESULT_RANGE.getBoolean() ? COL_WIDTH_WITH_RANGE : COL_WIDTH_NO_RANGE);
designColumn.setMoveable(true);
designColumn.addListener(SWT.Move, onColumnReorder);
CogToolPref.ALERTER.addHandler(this, CogToolPref.PreferencesChange.class, new AlertHandler() {
public void handleAlert(EventObject evt) {
if (evt == null) {
return;
}
Set<CogToolPref> changed = ((CogToolPref.PreferencesChange) evt).getPrefs();
if (changed.contains(CogToolPref.KLM_RESULT_RANGE)) {
if (CogToolPref.KLM_RESULT_RANGE.getBoolean()) {
if (designColumn.getWidth() < COL_WIDTH_WITH_RANGE) {
designColumn.setWidth(COL_WIDTH_WITH_RANGE);
}
} else {
if (designColumn.getWidth() > COL_WIDTH_NO_RANGE) {
designColumn.setWidth(COL_WIDTH_NO_RANGE);
}
}
redisplayAllResults();
} else if (changed.contains(CogToolPref.DISPLAY_DIGITS)) {
redisplayAllResults();
}
}
});
AlertHandler handler = new AlertHandler() {
public void handleAlert(EventObject alert) {
Design design = (Design) designColumn.getData();
designColumn.setText(design.getName());
designColumn.setToolTipText(design.getName() + "\n" + selectDesignHelp + "\n" + editDesignHelp);
}
};
designColumn.setData(design);
designColumn.setToolTipText(design.getName() + "\n" + selectDesignHelp + "\n" + editDesignHelp);
design.addHandler(this, NameChangeAlert.class, handler);
design.addHandler(this, Demonstration.StatusChange.class, updateStateHandler);
// Update data cells when a change happens
design.addHandler(this, TaskApplication.TaskApplicationResultChange.class, taskApplicationResultHandler);
if (columnHook != null) {
columnHook.onColumnCreation(designColumn);
}
}
use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.
the class StructureViewUIModel method installSourceTransition.
// installFrame
/**
* Create the visible representation for the given transition
* emanating from a specific source.
* <p>
* Finds the figure for the transition's target frame, creates the
* visible representation of the transition, adds that representation
* to the drawing, and registers the new transition figure with the
* source figure.
* <p>
* The figures for the source object and destination frames
* must be created/installed before attempting to create/install
* the visible representations for transitions.
*
* @param transition the transition to install
* @param sourceFigure the figure for the transition's source
* @author mlh
*/
protected void installSourceTransition(final Transition transition, final GraphicalSource<?> sourceFigure) {
DesignEditorFrame targetFigure = getFrameFigure(transition.getDestination());
final DesignEditorTransition transitionFigure = new DesignEditorTransition(transition, sourceFigure, targetFigure, showToolTips);
if (sourceFigure instanceof GraphicalChildWidget<?, ?>) {
checkSrcTransitions.add(transitionFigure);
}
installedTransitions.put(transition, transitionFigure);
AlertHandler localDestChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
DesignEditorFrame newTargetFigure = installedFrames.get(transition.getDestination());
if (newTargetFigure != null) {
sourceFigure.buildToolTip();
transitionFigure.changeTarget(newTargetFigure);
}
if (destinationChangeHandler != null) {
destinationChangeHandler.handleAlert(alert);
}
}
};
transitionFigure.addDestinationChangeHandler(localDestChangeHandler);
if (actionChangeHandler != null) {
transitionFigure.addActionChangeHandler(actionChangeHandler);
}
contents.add(transitionFigure);
sourceFigure.addTransition(transition, transitionFigure);
transitionAddRemoveEvent.setTransitionFigure(transitionFigure, true);
raiseAlert(transitionAddRemoveEvent);
}
use of edu.cmu.cs.hcii.cogtool.util.AlertHandler in project cogtool by cogtool.
the class PERTPanel method observeSelectionState.
/**
* Associates this panel with a PERTChartSelectionState so that when a new
* operator is selected, this panel will redraw itself accordingly.
*
* @param selectionState
*/
public void observeSelectionState(PERTChartSelectionState selectionState) {
chartSelectionState = selectionState;
AlertHandler handler = new AlertHandler() {
public void handleAlert(EventObject alert) {
// TODO: Change this to map or set
List<ResultStep> selectedSteps = ((PERTChartSelectionState.SelectionChange) alert).selectedSteps;
// clear selection boxes
Iterator<SelectionHalo> haloIterator = selectionBoxes.iterator();
SelectionHalo deadHalo = null;
while (haloIterator.hasNext()) {
deadHalo = haloIterator.next();
contents.remove(deadHalo);
deadHalo.dispose();
}
selectionBoxes.clear();
Iterator<PERTChartOperatorBar> barIterator = bars.iterator();
PERTChartOperatorBar bar;
while (barIterator.hasNext()) {
bar = barIterator.next();
if (selectedSteps.contains(bar.getStep())) {
bar.setSelected(true);
SelectionHalo halo = new SelectionHalo();
halo.setTarget(bar);
contents.add(halo);
selectionBoxes.add(halo);
} else {
bar.setSelected(false);
}
}
//redraw();
contents.repaint();
}
};
chartSelectionState.addHandler(this, PERTChartSelectionState.SelectionChange.class, handler);
}
Aggregations