use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorController method createRemoveBackgroundImageAction.
/**
* Create a ListenerAction to handle removing frame background image on
* multiple frames
*/
protected IListenerAction createRemoveBackgroundImageAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameSelectionState.class;
}
public boolean performAction(Object prms) {
// Get selected frames from parameters
FrameSelectionState seln = (FrameSelectionState) prms;
Frame[] frames = seln.getSelectedFrames();
setBackgroundImageOnFrames(frames, null, WidgetAttributes.NO_IMAGE, DesignEditorLID.RemoveBackgroundImage);
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorController method createDuplicateFramesEdit.
protected IUndoableEdit createDuplicateFramesEdit(final Frame[] frames) {
// Based on the code in deleteFrames
return new DemoStateManager.InvalidatingEdit(DesignEditorLID.DuplicateFrame, demoStateMgr) {
protected Transition[][] incidentTransitions = null;
protected boolean recoverMgrs = false;
@Override
public String getPresentationName() {
return (frames.length > 1) ? duplicateFrames : duplicateFrame;
}
@Override
public void redo() {
super.redo();
recoverMgrs = false;
for (int i = frames.length - 1; i >= 0; i--) {
design.addFrame(frames[i]);
}
for (int i = frames.length - 1; i >= 0; i--) {
DesignEditorCmd.addIncidentTransitions(incidentTransitions[i]);
}
stateMgr.noteFramesEdit(frames, this);
}
@Override
public void undo() {
super.undo();
recoverMgrs = true;
if (incidentTransitions == null) {
incidentTransitions = new Transition[frames.length][];
for (int i = 0; i < frames.length; i++) {
// Remove Transition instances for each Frame
incidentTransitions[i] = frames[i].removeIncidentTransitions();
}
for (Frame frame : frames) {
design.removeFrame(frame);
}
} else {
for (Frame frame : frames) {
frame.removeIncidentTransitions();
}
for (Frame frame : frames) {
design.removeFrame(frame);
}
}
stateMgr.noteFramesEdit(frames, this);
}
@Override
public void die() {
super.die();
if (recoverMgrs) {
for (Frame frame : frames) {
recoverManagers(frame);
}
}
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Frame in project cogtool by cogtool.
the class DesignEditorCmd method changeTransitionTarget.
public static void changeTransitionTarget(final DemoStateManager demoStateMgr, final Transition transition, final Frame newDestination, IUndoableEditSequence editSeq) {
final Frame oldDestination = transition.getDestination();
if (newDestination != oldDestination) {
transition.setDestination(newDestination);
DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(DesignEditorLID.ChangeTarget, demoStateMgr) {
@Override
public String getPresentationName() {
return CHANGE_TARGET_FRAME;
}
@Override
public void redo() {
super.redo();
transition.setDestination(newDestination);
demoStateMgr.noteTransitionEdit(transition, this);
}
@Override
public void undo() {
super.undo();
transition.setDestination(oldDestination);
demoStateMgr.noteTransitionEdit(transition, this);
}
};
demoStateMgr.noteTransitionEdit(transition, edit);
editSeq.addEdit(edit);
}
}
use of edu.cmu.cs.hcii.cogtool.model.Frame 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.model.Frame in project cogtool by cogtool.
the class StructureViewUIModel method dispose.
/**
* Override the dispose method so that it only disposes the view if it is
* not null.
*
* Also removes listeners created on the frame.
*
*/
public void dispose() {
design.removeAllHandlers(this);
// Call dispose on the DesignEditorFrameFigures, so that we
// do not get called when a change in a frame occurs. (EVEN if we are
// disposed) Alternative solution, have a dispose flag, and stop
// events from "propagating" when disposed.
// But that will likely cause memory to "Balloon" over time
// Call recoverFrame(Frame frame) on all frames? maybe slow... but
// cleans up EVERYTHING
Iterator<Frame> frames = design.getFrames().iterator();
while (frames.hasNext()) {
Frame frame = frames.next();
recoverFrame(frame);
}
}
Aggregations