use of edu.cmu.cs.hcii.cogtool.model.TransitionSource in project cogtool by cogtool.
the class FramePropertiesPane method update.
public void update(Frame frame) {
Object pathObj = frame.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
if (NullSafe.equals(WidgetAttributes.NO_IMAGE, pathObj)) {
imagePath.setVisible(false);
imagePathText.setVisible(false);
} else {
String imgPath = (String) pathObj;
imagePath.setVisible(true);
imagePathText.setVisible(true);
imagePathText.setText(imgPath);
imagePathText.setSelection(imgPath.length());
}
Set<TransitionSource> children = new LinkedHashSet<TransitionSource>();
children.addAll(frame.getWidgets());
children.addAll(frame.getInputDevices());
widgetUpdater.updateTree(children.iterator());
if (eltGroupTreeLabel != null) {
Set<FrameElementGroup> grps = frame.getEltGroups();
if (!CogToolPref.NESTED_GROUPS_SHOWN_AT_TOP_LEVEL.getBoolean()) {
grps = filterNestedGroups(grps);
}
eltGroupUpdater.updateTree(grps.iterator());
Set<SimpleWidgetGroup> implicitGroups = new HashSet<SimpleWidgetGroup>();
for (IWidget w : frame.getWidgets()) {
SimpleWidgetGroup g = w.getParentGroup();
if (g != null) {
implicitGroups.add(g);
}
}
implicitGroupUpdater.updateTree(implicitGroups.iterator());
}
setFrameName(frame);
}
use of edu.cmu.cs.hcii.cogtool.model.TransitionSource in project cogtool by cogtool.
the class DesignEditorTransition method buildToolTip.
protected void buildToolTip() {
if (showToolTip) {
String transitionAction = transition.getAction().getLocalizedString();
TransitionSource source = transition.getSource();
StringBuilder toolTipText = new StringBuilder();
String sourceName = SWTStringUtil.insertEllipsis(source.getName(), 100, StringUtil.EQUAL, FontUtils.SYMBOL_FONT);
String sourceFrameName = SWTStringUtil.insertEllipsis(source.getFrame().getName(), 150, StringUtil.NO_FRONT, FontUtils.SYMBOL_FONT);
String destName = SWTStringUtil.insertEllipsis(transition.getDestination().getName(), StringUtil.NO_FRONT, FontUtils.SYMBOL_FONT);
toolTipText.append(KeyDisplayUtil.convertActionToDisplay(transitionAction));
toolTipText.append("\n " + L10N.get("DE.Source", "Source") + ": ");
toolTipText.append(sourceName + " (" + sourceFrameName + ")");
toolTipText.append("\n " + L10N.get("DE.Target", "Target") + ": ");
toolTipText.append(destName);
Label toolTipLabel = new Label(" " + toolTipText.toString() + " ");
toolTipLabel.setFont(FontUtils.SYMBOL_FONT);
setToolTip(toolTipLabel);
}
}
use of edu.cmu.cs.hcii.cogtool.model.TransitionSource 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 edu.cmu.cs.hcii.cogtool.model.TransitionSource in project cogtool by cogtool.
the class DesignEditorController method createChangeActionAction.
protected IListenerAction createChangeActionAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignEditorUI.ChangeActionParameters.class;
}
public boolean performAction(Object prms) {
DesignEditorUI.ChangeActionParameters chgPrms = (DesignEditorUI.ChangeActionParameters) prms;
if (chgPrms != null) {
Transition[] transitions = chgPrms.selection.getSelectedTransitions();
if ((transitions != null) && (transitions.length > 0)) {
properties.copyValues(chgPrms.properties);
// TODO: Assume one for the moment; ui enforces it!
TransitionSource source = transitions[0].getSource();
int deviceTypes = DeviceType.buildDeviceSet(design.getDeviceTypes());
int limitMode = ActionProperties.determineChangeActionMode(source);
AAction newAction = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
if (newAction == null) {
return false;
}
newAction = EditActionCmd.ensureActionIsUnique(source, newAction, properties, deviceTypes, limitMode, transitions[0], interaction);
if (newAction == null) {
return false;
}
return changeTransitionsAction(transitions, newAction, NO_DELAY_CHANGE, null);
// TODO: If the given action properties are unusable
// (e.g., not unique from the source or empty string)
// and we should therefore return false so that an
// action that commits property changes can be
// canceled, assign the ensureActionIsUnique result
// to a new variable uniqueAction and return the AND of
// the changeTransitionsAction call (first) with
// (newAction == uniqueAction).
}
}
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.TransitionSource in project cogtool by cogtool.
the class DesignEditorController method changeTransitionSource.
// deleteTransitions
protected boolean changeTransitionSource(final Transition transition, final TransitionSource newSource) {
final TransitionSource oldSource = transition.getSource();
if (newSource != oldSource) {
AAction action = transition.getAction();
// Check that the new source is consistent the transition's action
if (!newSource.canAccept(action)) {
interaction.protestInconsistentSource();
return false;
}
while (newSource.getTransition(action) != null) {
//TODO: allow interaction to change? Must handle in undo then!
if (!interaction.protestNotUniqueAction(action, newSource, false)) {
return false;
}
}
oldSource.removeTransition(transition);
transition.setSource(newSource);
newSource.addTransition(transition);
final boolean invalidating = (newSource.getFrame() != oldSource.getFrame());
DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.DesignUndoableEdit(DesignEditorLID.ChangeSource, demoStateMgr) {
@Override
public String getPresentationName() {
return changeTransitionSource;
}
@Override
public Boolean getEditNature() {
return invalidating ? DemoStateManager.INVALIDATING : DemoStateManager.OBSOLETING;
}
@Override
public void redo() {
super.redo();
oldSource.removeTransition(transition);
transition.setSource(newSource);
newSource.addTransition(transition);
stateMgr.noteTransitionEdit(transition, this);
if (!invalidating && CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
}
}
@Override
public void undo() {
super.undo();
newSource.removeTransition(transition);
transition.setSource(oldSource);
oldSource.addTransition(transition);
stateMgr.noteTransitionEdit(transition, this);
if (!invalidating && CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
}
}
};
demoStateMgr.noteTransitionEdit(transition, edit);
undoMgr.addEdit(edit);
if (!invalidating && CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
}
}
return true;
}
Aggregations