use of edu.cmu.cs.hcii.cogtool.model.Transition in project cogtool by cogtool.
the class AbstractGraphicalSource method buildToolTipText.
/**
* Build the ToolTip for this source.
*
* @return
*/
public static String buildToolTipText(TransitionSource source, String typeDescription) {
// Use a string buffer for performance.
StringBuilder strBuffer = new StringBuilder(source.getNameLabel() + " [" + typeDescription + "]");
Iterator<Transition> transIter = source.getTransitions().values().iterator();
IEllipsizer ellipsizer = new SWTStringUtil.SWTEllipsizer(SWTWidthComputer.DEFAULT_WIDTH, StringUtil.NO_FRONT, FontUtils.SYMBOL_FONT);
while (transIter.hasNext()) {
Transition transition = transIter.next();
strBuffer.append("\n ");
String text = transition.toString(false, ellipsizer);
strBuffer.append(text);
}
return strBuffer.toString();
}
use of edu.cmu.cs.hcii.cogtool.model.Transition in project cogtool by cogtool.
the class AbstractGraphicalSource method setSourceModel.
// Must be called by subclass constructor
protected void setSourceModel(T m) {
if (m == null) {
throw new IllegalArgumentException("Cannot set the model of a graphical source to null");
}
TransitionSource oldModel = getModel();
if (oldModel != m) {
if (oldModel != null) {
oldModel.removeAllHandlers(this);
}
setModel(m);
buildToolTip();
getModel().addHandler(this, Widget.WidgetChange.class, this.changeHandler);
getModel().addHandler(this, TransitionSource.TransitionChange.class, this.transitionChangeHandler);
Iterator<Transition> modelTransitions = getModel().getTransitions().values().iterator();
while (modelTransitions.hasNext()) {
Transition t = modelTransitions.next();
t.addHandler(this, Transition.ActionChange.class, this.changeHandler);
t.addHandler(this, Transition.DestinationChange.class, this.changeHandler);
t.getDestination().addHandler(this, NameChangeAlert.class, this.changeHandler);
}
// Inherit attributes from model
updateAttributes();
}
}
use of edu.cmu.cs.hcii.cogtool.model.Transition in project cogtool by cogtool.
the class DesignEditorMouseState method dealWithMouseReleased.
@Override
protected boolean dealWithMouseReleased(IFigure figure, int button, int x, int y, int state) {
boolean goForward = super.dealWithMouseReleased(figure, button, x, y, state);
// Clear any mouse drag timer, that may be running
stopMouseDragTimer = true;
if (goForward) {
// This must be done before the hideAllMenuItems!
IFigure figureAtXY = ui.structureView.getFigureAtXY(mouseDownX, mouseDownY, StructureViewUIModel.SOURCE_ONLY);
// Record the mouse down position.
// Convert mouse coordinates into model coordinates
double zoom = ui.getZoom();
double scaledMouseUpX = x / zoom;
double scaledMouseUpY = y / zoom;
DesignEditorFrame frameAtXY = ui.structureView.getFrameAtXY(mouseDownX, mouseDownY);
if (frameAtXY != null) {
frameAtXY.hideAllChildren();
ui.resetHiddenTransitionSources();
}
int leftX = PrecisionUtilities.round((scaledMouseUpX < scaledMouseDownX) ? scaledMouseUpX : scaledMouseDownX);
int topY = PrecisionUtilities.round((scaledMouseUpY < scaledMouseDownY) ? scaledMouseUpY : scaledMouseDownY);
int width = PrecisionUtilities.round((scaledMouseUpX < scaledMouseDownX) ? (scaledMouseDownX - scaledMouseUpX + 1) : (scaledMouseUpX - scaledMouseDownX + 1));
int height = PrecisionUtilities.round((scaledMouseUpY < scaledMouseDownY) ? (scaledMouseDownY - scaledMouseUpY + 1) : (scaledMouseUpY - scaledMouseDownY + 1));
Rectangle selectionBox = new Rectangle(leftX, topY, width, height);
switch(getMouseState()) {
case PotentialMovingFrame:
{
// set on mouse down.
break;
}
case PotentialMovingSelection:
{
DesignEditorFrame frameFig = ui.structureView.getFrameAtXY(mouseDownX, mouseDownY);
selection.setSelectedFrame(frameFig);
break;
}
case PotentialSelectingFrames:
{
break;
}
case PotentialCreatingTransition:
{
if (figureAtXY instanceof GraphicalParentWidget<?, ?>) {
GraphicalParentWidget<?, ?> parentToOpen = (GraphicalParentWidget<?, ?>) figureAtXY;
if (!parentToOpen.canHaveChildren()) {
parentToOpen = ((GraphicalChildWidget<?, ?>) parentToOpen).getParentFigure();
}
parentToOpen.openChildren();
ui.resetHiddenTransitionSources();
}
break;
}
case MovingFrames:
{
updateDynamicMove(x, y, true);
break;
}
case PotentialTogglingSelection:
{
dynamicSelectionArea.setVisible(false);
DesignEditorFrame frameFig = ui.structureView.getFrameAtXY(mouseDownX, mouseDownY);
if (frameFig != null) {
if (selection.isFrameSelected(frameFig.getFrame())) {
selection.deselectFrame(frameFig);
} else {
if (selection.getSelectedTransitionCount() > 0) {
selection.deselectAll();
}
selection.selectFrame(frameFig);
}
}
break;
}
case TogglingSelection:
{
dynamicSelectionArea.setVisible(false);
Iterator<DesignEditorFrame> frameFigures = ui.structureView.getAllFrameFigures();
while (frameFigures.hasNext()) {
DesignEditorFrame frameFig = frameFigures.next();
Frame frame = frameFig.getFrame();
if (frameFig.intersects(selectionBox)) {
if (selection.isFrameSelected(frame)) {
selection.deselectFrame(frameFig);
} else {
if (selection.getSelectedTransitionCount() > 0) {
selection.deselectAll();
}
selection.selectFrame(frameFig);
}
}
}
break;
}
case SelectingFrames:
{
dynamicSelectionArea.setVisible(false);
Iterator<DesignEditorFrame> frameFigures = ui.structureView.getAllFrameFigures();
while (frameFigures.hasNext()) {
DesignEditorFrame frameFig = frameFigures.next();
if (frameFig.intersects(selectionBox)) {
selection.selectFrame(frameFig);
}
}
break;
}
case CreatingTransition:
{
stopDynamicTransition();
if (potentialTarget != null) {
potentialTarget.dynamicHighlight(false);
potentialTarget = null;
}
if (potentialTransitionSource != null) {
DesignEditorFrame targetFigure = ui.structureView.getFrameAtXY(x, y);
TransitionSource source = potentialTransitionSource.getModel();
Frame target = (targetFigure != null) ? targetFigure.getFrame() : (Frame) null;
// Convert mouse coordinates into model coordinates
DesignEditorUI.NewTransitionParameters prms = new DesignEditorUI.NewTransitionParameters(source, target, scaledMouseUpX, scaledMouseUpY);
ui.performAction(DesignEditorLID.NewTransition, prms);
}
break;
}
case PotentialSelectTransition:
case PotentialChangeTarget:
case PotentialChangeSource:
{
selection.setSelectedTransition(hitTransition);
Transition transition = hitTransition.getTransition();
ui.getInteraction().setTransitionStatusMessage(transition);
hitTransition = null;
break;
}
case PotentialToggleTransition:
{
Transition transition = hitTransition.getTransition();
if (selection.isTransitionSelected(transition)) {
selection.deselectTransition(hitTransition);
} else {
if (selection.getSelectedFrameCount() > 0) {
selection.deselectAll();
}
selection.selectTransition(hitTransition);
}
hitTransition = null;
break;
}
case ChangingTarget:
{
stopDynamicTransition();
if (potentialTarget != null) {
potentialTarget.dynamicHighlight(false);
potentialTarget = null;
}
DesignEditorFrame newTargetFigure = ui.structureView.getFrameAtXY(x, y);
if (newTargetFigure != null) {
Transition transition = hitTransition.getTransition();
DesignEditorUI.ChangeTargetParameters prms = new DesignEditorUI.ChangeTargetParameters(transition, newTargetFigure.getFrame());
ui.performAction(DesignEditorLID.ChangeTarget, prms);
ui.getInteraction().setTransitionStatusMessage(transition);
}
hitTransition.setVisible(true);
break;
}
case ChangingSource:
{
stopDynamicTransition();
InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
drawLayer.setCursor(WindowUtil.getCursor(WindowUtil.SELECT_CURSOR));
GraphicalSource<?> newSourceFigure = ui.structureView.getSourceAtXY(x, y);
hitTransition.setVisible(true);
if (newSourceFigure != null) {
Transition transition = hitTransition.getTransition();
DesignEditorUI.ChangeSourceParameters prms = new DesignEditorUI.ChangeSourceParameters(transition, newSourceFigure.getModel());
ui.performAction(DesignEditorLID.ChangeSource, prms);
ui.getInteraction().setTransitionStatusMessage(transition);
}
hitTransition = null;
break;
}
case PotentialDuplicatingFrame:
{
DesignEditorFrame frameFig = ui.structureView.getFrameAtXY(mouseDownX, mouseDownY);
selection.setSelectedFrame(frameFig);
break;
}
case DuplicatingFrames:
{
double dx = scaledMouseUpX - scaledMouseDownX;
double dy = scaledMouseUpY - scaledMouseDownY;
// Remove all the rectangle figures from the display, clear the list
clearRectFigures();
DesignEditorUI.DuplicateParameters prm = new DesignEditorUI.DuplicateParameters(dx, dy, selection);
ui.performAction(DesignEditorLID.DuplicateFrame, prm);
break;
}
}
}
setMouseState(MouseUp);
mouseDown = false;
cleanup();
return goForward;
}
Aggregations