use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalSource in project cogtool by cogtool.
the class DesignEditorMouseState method dealWithMouseDragged.
@Override
protected boolean dealWithMouseDragged(IFigure figure, int button, int eventX, int eventY, int state) {
boolean goForward = super.dealWithMouseDragged(figure, button, eventX, eventY, state);
if (goForward && mouseDown) {
StandardDrawingEditor editor = ui.getViewEditor();
// Update VIEW to ensure ME point is visible.
// If outside of the visible canvas, up-click should cancel!
stopMouseDragTimer = true;
stopDynamic = editor.movePointNearEdge(eventX, eventY, updateDelta);
switch(getMouseState()) {
case PotentialMovingFrame:
case PotentialMovingSelection:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
setMouseState(MovingFrames);
// fall through!
}
case MovingFrames:
{
updateDynamicMove(eventX, eventY, false);
break;
}
case PotentialTogglingSelection:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
setMouseState(TogglingSelection);
// fall through!
}
case TogglingSelection:
{
updateDynamicSelectionArea(eventX, eventY);
break;
}
case PotentialSelectingFrames:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
setMouseState(SelectingFrames);
// fall through!
}
case SelectingFrames:
{
updateDynamicSelectionArea(eventX, eventY);
break;
}
case PotentialCreatingTransition:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
// Do not allow transitions from menu headers or submenus
IFigure target = ui.structureView.getFigureAtXY(mouseDownX, mouseDownY, StructureViewUIModel.SOURCE_ONLY);
if ((target instanceof GraphicalParentWidget<?, ?>) && (((GraphicalParentWidget<?, ?>) target).canHaveChildren())) {
break;
}
setMouseState(CreatingTransition);
// Ensures proper default action
selection.deselectAll();
// fall through!
}
case CreatingTransition:
{
dynamicTransition(eventX, eventY);
DesignEditorFrame targetFigure = ui.structureView.getFrameAtXY(eventX, eventY);
if (targetFigure != potentialTarget) {
if (potentialTarget != null) {
potentialTarget.dynamicHighlight(false);
}
potentialTarget = targetFigure;
if (potentialTarget != null) {
potentialTarget.dynamicHighlight(true);
}
}
break;
}
case PotentialSelectTransition:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
handleMousePressed(StructureViewUIModel.NO_TRANSITION);
switch(getMouseState()) {
case PotentialMovingFrame:
{
setMouseState(MovingFrames);
updateDynamicMove(eventX, eventY, false);
break;
}
case PotentialSelectingFrames:
{
setMouseState(SelectingFrames);
updateDynamicSelectionArea(eventX, eventY);
break;
}
case PotentialCreatingTransition:
{
setMouseState(CreatingTransition);
dynamicTransition(eventX, eventY);
break;
}
}
break;
}
case PotentialToggleTransition:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
handleMousePressed(StructureViewUIModel.NO_TRANSITION);
setMouseState(TogglingSelection);
updateDynamicSelectionArea(eventX, eventY);
break;
}
case PotentialChangeTarget:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
setMouseState(ChangingTarget);
Point start = hitTransition.getStart();
hitTransition.setVisible(false);
double zoom = ui.getZoom();
double startX = start.x * zoom;
double startY = start.y * zoom;
ensureDynamicTransition(PrecisionUtilities.round(startX), PrecisionUtilities.round(startY));
// fall through!
}
case ChangingTarget:
{
dynamicTransitionTarget(eventX, eventY);
DesignEditorFrame targetFigure = ui.structureView.getFrameAtXY(eventX, eventY);
if (targetFigure != potentialTarget) {
if (potentialTarget != null) {
potentialTarget.dynamicHighlight(false);
}
potentialTarget = targetFigure;
if (potentialTarget != null) {
potentialTarget.dynamicHighlight(true);
}
}
break;
}
case PotentialChangeSource:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
setMouseState(ChangingSource);
hitTransition.setVisible(false);
ensureDynamicTransition(mouseDownX, mouseDownY);
Point endPt = hitTransition.getEnd();
double zoom = ui.getZoom();
double endX = endPt.x * zoom;
double endY = endPt.y * zoom;
dynamicTransitionTarget(PrecisionUtilities.round(endX), PrecisionUtilities.round(endY));
break;
}
case ChangingSource:
{
dynamicTransitionSource(eventX, eventY);
GraphicalSource<?> sourceFigure = ui.structureView.getSourceAtXY(eventX, eventY);
InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
if (sourceFigure != null) {
drawLayer.setCursor(WindowUtil.getCursor(WindowUtil.DRAW_CURSOR));
} else {
drawLayer.setCursor(WindowUtil.getCursor(WindowUtil.SELECT_CURSOR));
}
break;
}
case PotentialDuplicatingFrame:
{
if (withinHysteresis(eventX, eventY)) {
break;
}
duplicatingDynamic = new ArrayList<RectangleFigure>();
//populate this from selection state
double zoom = ui.getZoom();
Iterator<DesignEditorFrame> selectedFrames = selection.getSelectedFrameFigures();
while (selectedFrames.hasNext()) {
RectangleFigure rect = new RectangleFigure();
DesignEditorFrame currFrame = selectedFrames.next();
//set size of new rectangle object
Rectangle frameSize = currFrame.getBounds();
frameSize.height = PrecisionUtilities.round(frameSize.height / zoom);
frameSize.width = PrecisionUtilities.round(frameSize.width / zoom);
frameSize.x = PrecisionUtilities.round(frameSize.x * zoom);
frameSize.y = PrecisionUtilities.round(frameSize.y * zoom);
rect.setBounds(frameSize);
//add new rectangle object to the array list
duplicatingDynamic.add(rect);
//display the new rectangle object
showSelectionArea(rect);
}
setMouseState(DuplicatingFrames);
// fall through!
}
case DuplicatingFrames:
{
updateDynamicDuplicate(eventX, eventY);
break;
}
}
// Repeating timer for causing events to repeat.
if ((updateDelta.x != 0) || (updateDelta.y != 0)) {
if (rootFigure == null) {
rootFigure = ui.getViewEditor().getInteractionFigure();
}
stopMouseDragTimer = false;
// Determine the new point the mouse "moved" too.
mouseDragTask.setNextMousePosition(eventX + updateDelta.x, eventY + updateDelta.y, button, state);
// Queue the event for 0.1 sec.
WindowUtil.GLOBAL_DISPLAY.timerExec(100, mouseDragTask);
}
}
lastX = eventX;
lastY = eventY;
cleanup();
return goForward;
}
use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalSource in project cogtool by cogtool.
the class DesignEditorMouseState method handleMousePressed.
// dealWithMouseDoubleClicked
protected void handleMousePressed(int filter) {
if (filter == StructureViewUIModel.NO_LABEL) {
ResizeThumb thumb = ui.getResizeAtXY(mouseDownX, mouseDownY);
if (thumb != null) {
hitTransition = (DesignEditorTransition) thumb.getData();
selection.setSelectedTransition(hitTransition);
if (thumb.thumbType == DesignEditorUI.SOURCE) {
setMouseState(PotentialChangeSource);
} else {
setMouseState(PotentialChangeTarget);
}
return;
}
}
IFigure target = ui.structureView.getFigureAtXY(mouseDownX, mouseDownY, filter);
if (target instanceof DesignEditorTransition) {
hitTransition = (DesignEditorTransition) target;
if ((mouseDownState & InputEvent.SHIFT) != 0) {
setMouseState(PotentialToggleTransition);
} else {
setMouseState(PotentialSelectTransition);
}
} else if (target instanceof GraphicalSource<?>) {
potentialTransitionSource = (GraphicalSource<?>) target;
setMouseState(PotentialCreatingTransition);
// drag creates arrow
} else if (target instanceof DesignEditorFrame) {
DesignEditorFrame frameFigure = (DesignEditorFrame) target;
Frame frame = frameFigure.getFrame();
if ((mouseDownState & InputEvent.SHIFT) != 0) {
setMouseState(PotentialTogglingSelection);
} else if ((mouseDownState & platformDuplicateModifierKey()) != 0) {
if (!selection.isFrameSelected(frame)) {
selection.setSelectedFrame(frameFigure);
}
setMouseState(PotentialDuplicatingFrame);
} else {
if (selection.isFrameSelected(frame)) {
setMouseState(PotentialMovingSelection);
} else {
selection.setSelectedFrame(frameFigure);
setMouseState(PotentialMovingFrame);
}
}
} else {
// out in space
if ((mouseDownState & InputEvent.SHIFT) != 0) {
setMouseState(PotentialTogglingSelection);
} else {
selection.deselectAll();
setMouseState(PotentialSelectingFrames);
}
}
}
use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalSource 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