Workflow.js
Summary
No overview generated for 'Workflow.js'
draw2d.Workflow=function(id)
{
if(!id)
return;
this.gridWidthX = 10;
this.gridWidthY = 10;
this.snapToGridHelper = null;
this.verticalSnapToHelperLine = null;
this.horizontalSnapToHelperLine = null;
this.figures = new draw2d.ArrayList();
this.lines = new draw2d.ArrayList();
this.commonPorts = new draw2d.ArrayList();
this.dropTargets = new draw2d.ArrayList();
this.compartments = new draw2d.ArrayList();
this.selectionListeners = new draw2d.ArrayList();
this.dialogs = new draw2d.ArrayList();
this.toolPalette = null;
this.dragging = false;
this.tooltip = null;
this.draggingLine = null;
this.commandStack = new draw2d.CommandStack();
this.oldScrollPosLeft = 0;
this.oldScrollPosTop = 0;
this.currentSelection = null;
this.currentMenu = null;
this.connectionLine = new draw2d.Line();
this.resizeHandleStart = new draw2d.LineStartResizeHandle(this);
this.resizeHandleEnd = new draw2d.LineEndResizeHandle(this);
this.resizeHandle1 = new draw2d.ResizeHandle(this,1);
this.resizeHandle2 = new draw2d.ResizeHandle(this,2);
this.resizeHandle3 = new draw2d.ResizeHandle(this,3);
this.resizeHandle4 = new draw2d.ResizeHandle(this,4);
this.resizeHandle5 = new draw2d.ResizeHandle(this,5);
this.resizeHandle6 = new draw2d.ResizeHandle(this,6);
this.resizeHandle7 = new draw2d.ResizeHandle(this,7);
this.resizeHandle8 = new draw2d.ResizeHandle(this,8);
this.resizeHandleHalfWidth = parseInt(this.resizeHandle2.getWidth()/2);
draw2d.Canvas.call(this,id);
this.setPanning(false);
if(this.html!=null)
{
this.html.style.backgroundImage="url(grid_10.png)";
oThis = this;
this.html.tabIndex="0";
var contextMenu = function ()
{
var oEvent = arguments[0] || window.event;
var diffX = oEvent.clientX;
var diffY = oEvent.clientY;
var scrollLeft = oThis.getScrollLeft();
var scrollTop = oThis.getScrollTop();
var xOffset = oThis.getAbsoluteX();
var yOffset = oThis.getAbsoluteY();
if(oThis.getBestFigure(diffX+scrollLeft-xOffset, diffY+scrollTop-yOffset)!=null)
return;
var line = oThis.getBestLine(diffX+scrollLeft-xOffset, diffY+scrollTop-yOffset,null);
if(line!=null)
line.onContextMenu(diffX+scrollLeft-xOffset, diffY+scrollTop-yOffset);
else
oThis.onContextMenu(diffX+scrollLeft-xOffset, diffY+scrollTop-yOffset);
};
this.html.oncontextmenu=function(){return false;};
var oThis = this;
var keyDown=function(event)
{
var ctrl = event.ctrlKey;
oThis.onKeyDown(event.keyCode, ctrl);
}
var mouseDown = function()
{
var oEvent = arguments[0] || window.event;
var diffX = oEvent.clientX;
var diffY = oEvent.clientY;
var scrollLeft = oThis.getScrollLeft();
var scrollTop = oThis.getScrollTop();
var xOffset = oThis.getAbsoluteX();
var yOffset = oThis.getAbsoluteY();
oThis.onMouseDown(diffX+scrollLeft-xOffset, diffY+scrollTop-yOffset);
}
var mouseUp = function()
{
var oEvent = arguments[0] || window.event;
if(oThis.currentMenu!=null)
{
oThis.removeFigure(oThis.currentMenu);
oThis.currentMenu=null;
}
if(oEvent.button==2)
return;
var diffX = oEvent.clientX;
var diffY = oEvent.clientY;
var scrollLeft = oThis.getScrollLeft();
var scrollTop = oThis.getScrollTop();
var xOffset = oThis.getAbsoluteX();
var yOffset = oThis.getAbsoluteY();
oThis.onMouseUp(diffX+scrollLeft-xOffset, diffY+scrollTop-yOffset);
}
var mouseMove = function()
{
var oEvent = arguments[0] || window.event;
var diffX = oEvent.clientX;
var diffY = oEvent.clientY;
var scrollLeft = oThis.getScrollLeft();
var scrollTop = oThis.getScrollTop();
var xOffset = oThis.getAbsoluteX();
var yOffset = oThis.getAbsoluteY();
oThis.currentMouseX = diffX+scrollLeft-xOffset;
oThis.currentMouseY = diffY+scrollTop-yOffset;
var obj = oThis.getBestFigure(oThis.currentMouseX, oThis.currentMouseY)
if(draw2d.Drag.currentHover!=null && obj==null)
{
var oDropEvent = new draw2d.DragDropEvent();
oDropEvent.initDragDropEvent("mouseleave", false, oThis);
draw2d.Drag.currentHover.dispatchEvent(oDropEvent);
}
else
{
var diffX = oEvent.clientX;
var diffY = oEvent.clientY;
var scrollLeft = oThis.getScrollLeft();
var scrollTop = oThis.getScrollTop();
var xOffset = oThis.getAbsoluteX();
var yOffset = oThis.getAbsoluteY();
oThis.onMouseMove(diffX+scrollLeft-xOffset, diffY+scrollTop-yOffset);
}
if(obj==null)
draw2d.Drag.currentHover = null;
if(oThis.tooltip!=null)
{
if(Math.abs(oThis.currentTooltipX-oThis.currentMouseX)>10 ||Math.abs(oThis.currentTooltipY-oThis.currentMouseY)>10)
{
oThis.showTooltip(null);
}
}
}
var tmpDoubleClick = function (oEvent)
{
var oEvent = arguments[0] || window.event;
var diffX = oEvent.clientX;
var diffY = oEvent.clientY;
var scrollLeft = oThis.getScrollLeft();
var scrollTop = oThis.getScrollTop();
var xOffset = oThis.getAbsoluteX();
var yOffset = oThis.getAbsoluteY();
var line = oThis.getBestLine(diffX+scrollLeft-xOffset, diffY+scrollTop-yOffset,null);
if(line!=null)
line.onDoubleClick();
}
if (this.html.addEventListener)
{
this.html.addEventListener("contextmenu", contextMenu, false);
this.html.addEventListener("mousemove", mouseMove, false);
this.html.addEventListener("mouseup", mouseUp, false);
this.html.addEventListener("mousedown", mouseDown, false);
this.html.addEventListener("keydown", keyDown, false);
this.html.addEventListener("dblclick",tmpDoubleClick,false );
}
else if (this.html.attachEvent)
{
this.html.attachEvent("oncontextmenu", contextMenu);
this.html.attachEvent("onmousemove", mouseMove);
this.html.attachEvent("onmousedown", mouseDown);
this.html.attachEvent("onmouseup", mouseUp);
this.html.attachEvent("onkeydown", keyDown);
this.html.attachEvent("ondblclick", tmpDoubleClick);
}
else
{
throw new Error("Open-jACOB Draw2D not supported in this browser.");
}
}
}
draw2d.Workflow.prototype = new draw2d.Canvas;
draw2d.Workflow.prototype.type="Workflow";
draw2d.Workflow.COLOR_GREEN = new draw2d.Color(0,255,0);
draw2d.Workflow.prototype.onScroll=function()
{
var scrollLeft = this.getScrollLeft();
var scrollTop = this.getScrollTop();
var diffLeft = scrollLeft - this.oldScrollPosLeft;
var diffTop = scrollTop - this.oldScrollPosTop;
for(var i=0;i< this.figures.getSize();i++)
{
var figure = this.figures.get(i);
if(figure.hasFixedPosition && figure.hasFixedPosition()==true)
figure.setPosition(figure.getX()+diffLeft, figure.getY()+diffTop);
}
this.oldScrollPosLeft= scrollLeft;
this.oldScrollPosTop = scrollTop;
}
draw2d.Workflow.prototype.setPanning=function(flag)
{
this.panning= flag;
if(flag)
this.html.style.cursor="move";
else
this.html.style.cursor="default";
}
draw2d.Workflow.prototype.scrollTo=function( x, y, fast)
{
if(fast)
{
this.scrollArea.scrollLeft= x;
this.scrollArea.scrollTop = y;
}
else
{
var steps= 40;
var xStep = (x-this.getScrollLeft())/steps;
var yStep = (y-this.getScrollTop())/steps;
var oldX = this.getScrollLeft();
var oldY = this.getScrollTop();
for(var i=0;i<steps;i++)
{
this.scrollArea.scrollLeft= oldX + (xStep*i);
this.scrollArea.scrollTop = oldY + (yStep*i);
}
}
}
draw2d.Workflow.prototype.showTooltip=function( tooltip, autoHide)
{
if(this.tooltip!=null)
{
this.removeFigure(this.tooltip);
this.tooltip = null;
if(this.tooltipTimer>=0)
{
window.clearTimeout(this.tooltipTimer);
this.tooltipTimer=-1;
}
}
this.tooltip = tooltip;
if(this.tooltip!=null)
{
this.currentTooltipX = this.currentMouseX;
this.currentTooltipY = this.currentMouseY;
this.addFigure(this.tooltip,this.currentTooltipX+10 , this.currentTooltipY+10);
var oThis = this;
var cancelTooltipByTimer = function(){oThis.tooltipTimer=-1;oThis.showTooltip(null);};
if(autoHide==true)
{
this.tooltipTimer = window.setTimeout(cancelTooltipByTimer, 5000);
}
}
}
draw2d.Workflow.prototype.showDialog=function(dialog , xPos , yPos)
{
if(xPos)
this.addFigure(dialog,xPos, yPos);
else
this.addFigure(dialog,200, 100);
this.dialogs.add(dialog);
}
draw2d.Workflow.prototype.showMenu=function(menu , xPos , yPos)
{
if(this.menu!=null)
{
this.html.removeChild(this.menu.getHTMLElement());
this.menu.setWorkflow();
}
this.menu =menu;
if(this.menu!=null)
{
this.menu.setWorkflow(this);
this.menu.setPosition(xPos,yPos);
this.html.appendChild(this.menu.getHTMLElement());
this.menu.paint();
}
}
draw2d.Workflow.prototype.onContextMenu=function( x, y)
{
var menu = this.getContextMenu();
if(menu!=null)
this.showMenu(menu,x,y);
}
draw2d.Workflow.prototype.getContextMenu=function()
{
return null;
}
draw2d.Workflow.prototype.setToolWindow=function( toolWindow, x, y)
{
this.toolPalette = toolWindow;
if(y)
this.addFigure(toolWindow,x,y);
else
this.addFigure(toolWindow,20,20);
this.dialogs.add(toolWindow);
}
draw2d.Workflow.prototype.setSnapToGrid=function( flag)
{
if(flag)
this.snapToGridHelper = new draw2d.SnapToGrid(this);
else
this.snapToGridHelper = null;
}
draw2d.Workflow.prototype.setSnapToGeometry=function( flag)
{
if(flag)
this.snapToGeometryHelper = new draw2d.SnapToGeometry(this);
else
this.snapToGeometryHelper = null;
}
draw2d.Workflow.prototype.setGridWidth=function( dx, dy)
{
this.gridWidthX = dx;
this.gridWidthY = dy;
}
draw2d.Workflow.prototype.addFigure=function( figure , xPos, yPos)
{
draw2d.Canvas.prototype.addFigure.call(this,figure,xPos,yPos,true);
figure.setWorkflow(this);
var oThisWorkflow = this;
if(figure instanceof draw2d.CompartmentFigure)
{
this.compartments.add(figure);
}
if(figure instanceof draw2d.Line)
{
this.lines.add(figure);
}
else
{
this.figures.add(figure);
figure.draggable.addEventListener("dragend", function (oEvent)
{
});
figure.draggable.addEventListener("dragstart", function (oEvent)
{
var figure = oThisWorkflow.getFigure(oEvent.target.element.id);
if(figure==null)
return;
if(figure.isSelectable()==false)
return;
oThisWorkflow.showResizeHandles(figure);
oThisWorkflow.setCurrentSelection(figure);
});
figure.draggable.addEventListener("drag", function (oEvent)
{
var figure = oThisWorkflow.getFigure(oEvent.target.element.id);
if(figure == null)
return;
if(figure.isSelectable()==false)
return;
oThisWorkflow.moveResizeHandles(figure);
});
}
figure.paint();
this.setDocumentDirty();
}
draw2d.Workflow.prototype.removeFigure = function( figure)
{
draw2d.Canvas.prototype.removeFigure.call(this, figure);
this.figures.remove(figure);
this.lines.remove(figure);
this.dialogs.remove(figure);
figure.setWorkflow(null);
if(figure instanceof draw2d.CompartmentFigure)
this.compartments.remove(figure);
if(figure instanceof draw2d.Connection)
figure.disconnect();
if(this.currentSelection == figure)
this.setCurrentSelection(null);
this.setDocumentDirty();
}
draw2d.Workflow.prototype.moveFront = function( figure)
{
this.html.removeChild(figure.getHTMLElement());
this.html.appendChild(figure.getHTMLElement());
}
draw2d.Workflow.prototype.moveBack = function( figure)
{
this.html.removeChild(figure.getHTMLElement());
this.html.insertBefore(figure.getHTMLElement(), this.html.firstChild);
}
draw2d.Workflow.prototype.getBestCompartmentFigure=function( x, y, figureToIgnore)
{
var result = null;
for(var i=0;i<this.figures.getSize();i++)
{
var figure = this.figures.get(i);
if((figure instanceof draw2d.CompartmentFigure) && figure.isOver(x,y)==true && figure!=figureToIgnore)
{
if(result==null)
result = figure;
else if(result.getZOrder() < figure.getZOrder())
result = figure;
}
}
return result;
}
draw2d.Workflow.prototype.getBestFigure=function( x, y, figureToIgnore)
{
var result = null;
for(var i=0;i <this.figures.getSize();i++)
{
var figure = this.figures.get(i);
if(figure.isOver(x,y)==true && figure!=figureToIgnore)
{
if(result==null)
result = figure;
else if(result.getZOrder() < figure.getZOrder())
result = figure;
}
}
return result;
}
draw2d.Workflow.prototype.getBestLine=function( x, y, lineToIgnore)
{
var result = null;
for(var i=0;i< this.lines.getSize();i++)
{
var line = this.lines.get(i);
if(line.containsPoint(x,y)==true && line!=lineToIgnore)
{
if(result==null)
result = line;
else if(result.getZOrder() < line.getZOrder())
result = line;
}
}
return result;
}
draw2d.Workflow.prototype.getFigure=function( id)
{
for(var i=0; i<this.figures.getSize();i++)
{
var figure = this.figures.get(i);
if(figure.id==id)
return figure;
}
return null;;
}
draw2d.Workflow.prototype.getFigures=function()
{
return this.figures;
}
draw2d.Workflow.prototype.getDocument=function()
{
return new draw2d.Document(this);
}
draw2d.Workflow.prototype.addSelectionListener=function( w)
{
this.selectionListeners.add(w);
}
draw2d.Workflow.prototype.removeSelectionListener=function( w )
{
this.selectionListeners.remove(w);
}
draw2d.Workflow.prototype.setCurrentSelection=function( figure )
{
if(figure==null)
{
this.hideResizeHandles();
this.hideLineResizeHandles();
}
this.currentSelection = figure;
for(var i=0;i < this.selectionListeners.getSize();i++)
{
var w = this.selectionListeners.get(i);
if(w!=null && w.onSelectionChanged)
w.onSelectionChanged(this.currentSelection);
}
}
draw2d.Workflow.prototype.getCurrentSelection=function()
{
return this.currentSelection;
}
draw2d.Workflow.prototype.getLines=function()
{
return this.lines;
}
draw2d.Workflow.prototype.registerPort = function( port )
{
port.draggable.targets= this.dropTargets;
this.commonPorts.add(port);
this.dropTargets.add(port.dropable);
}
draw2d.Workflow.prototype.unregisterPort = function( port )
{
port.draggable.targets=null;
this.commonPorts.remove(port);
this.dropTargets.remove(port.dropable);
}
draw2d.Workflow.prototype.getCommandStack = function()
{
return this.commandStack;
}
draw2d.Workflow.prototype.showConnectionLine=function( x1 , y1 , x2, y2 )
{
this.connectionLine.setStartPoint(x1,y1);
this.connectionLine.setEndPoint(x2,y2);
if(this.connectionLine.canvas==null)
draw2d.Canvas.prototype.addFigure.call(this,this.connectionLine);
}
draw2d.Workflow.prototype.hideConnectionLine=function()
{
if(this.connectionLine.canvas!=null)
draw2d.Canvas.prototype.removeFigure.call(this,this.connectionLine);
}
draw2d.Workflow.prototype.showLineResizeHandles=function( figure )
{
var resizeWidthHalf = this.resizeHandleStart.getWidth()/2;
var resizeHeightHalf= this.resizeHandleStart.getHeight()/2;
var startPoint = figure.getStartPoint();
var endPoint = figure.getEndPoint();
draw2d.Canvas.prototype.addFigure.call(this,this.resizeHandleStart,startPoint.x-resizeWidthHalf,startPoint.y-resizeWidthHalf);
draw2d.Canvas.prototype.addFigure.call(this,this.resizeHandleEnd,endPoint.x-resizeWidthHalf,endPoint.y-resizeWidthHalf);
this.resizeHandleStart.setCanDrag(figure.isResizeable());
this.resizeHandleEnd.setCanDrag(figure.isResizeable());
if(figure.isResizeable())
{
this.resizeHandleStart.setBackgroundColor(draw2d.Workflow.COLOR_GREEN);
this.resizeHandleEnd.setBackgroundColor(draw2d.Workflow.COLOR_GREEN);
this.resizeHandleStart.draggable.targets= this.dropTargets;
this.resizeHandleEnd.draggable.targets= this.dropTargets;
}
else
{
this.resizeHandleStart.setBackgroundColor(null);
this.resizeHandleEnd.setBackgroundColor(null);
}
}
draw2d.Workflow.prototype.hideLineResizeHandles=function()
{
if(this.resizeHandleStart.canvas!=null)
draw2d.Canvas.prototype.removeFigure.call(this,this.resizeHandleStart);
if(this.resizeHandleEnd.canvas!=null)
draw2d.Canvas.prototype.removeFigure.call(this,this.resizeHandleEnd);
}
draw2d.Workflow.prototype.showResizeHandles=function( figure)
{
this.hideLineResizeHandles();
this.hideResizeHandles();
if(this.getEnableSmoothFigureHandling()==true && this.getCurrentSelection()!=figure)
{
this.resizeHandle1.setAlpha(0.01);
this.resizeHandle2.setAlpha(0.01);
this.resizeHandle3.setAlpha(0.01);
this.resizeHandle4.setAlpha(0.01);
this.resizeHandle5.setAlpha(0.01);
this.resizeHandle6.setAlpha(0.01);
this.resizeHandle7.setAlpha(0.01);
this.resizeHandle8.setAlpha(0.01);
}
var resizeWidth = this.resizeHandle1.getWidth();
var resizeHeight= this.resizeHandle1.getHeight();
var objHeight = figure.getHeight();
var objWidth = figure.getWidth();
var xPos = figure.getX();
var yPos = figure.getY();
draw2d.Canvas.prototype.addFigure.call(this,this.resizeHandle1,xPos-resizeWidth,yPos-resizeHeight);
draw2d.Canvas.prototype.addFigure.call(this,this.resizeHandle3,xPos+objWidth,yPos-resizeHeight);
draw2d.Canvas.prototype.addFigure.call(this,this.resizeHandle5,xPos+objWidth,yPos+objHeight);
draw2d.Canvas.prototype.addFigure.call(this,this.resizeHandle7,xPos-resizeWidth,yPos+objHeight);
this.moveFront(this.resizeHandle1);
this.moveFront(this.resizeHandle3);
this.moveFront(this.resizeHandle5);
this.moveFront(this.resizeHandle7);
this.resizeHandle1.setCanDrag(figure.isResizeable());
this.resizeHandle3.setCanDrag(figure.isResizeable());
this.resizeHandle5.setCanDrag(figure.isResizeable());
this.resizeHandle7.setCanDrag(figure.isResizeable());
if(figure.isResizeable())
{
var green = new draw2d.Color(0,255,0);
this.resizeHandle1.setBackgroundColor(green);
this.resizeHandle3.setBackgroundColor(green);
this.resizeHandle5.setBackgroundColor(green);
this.resizeHandle7.setBackgroundColor(green);
}
else
{
this.resizeHandle1.setBackgroundColor(null);
this.resizeHandle3.setBackgroundColor(null);
this.resizeHandle5.setBackgroundColor(null);
this.resizeHandle7.setBackgroundColor(null);
}
if(figure.isStrechable() && figure.isResizeable())
{
this.resizeHandle2.setCanDrag(figure.isResizeable());
this.resizeHandle4.setCanDrag(figure.isResizeable());
this.resizeHandle6.setCanDrag(figure.isResizeable());
this.resizeHandle8.setCanDrag(figure.isResizeable());
draw2d.Canvas.prototype.addFigure.call(this,this.resizeHandle2,xPos+(objWidth/2)-this.resizeHandleHalfWidth,yPos-resizeHeight);
draw2d.Canvas.prototype.addFigure.call(this,this.resizeHandle4,xPos+objWidth,yPos+(objHeight/2)-(resizeHeight/2));
draw2d.Canvas.prototype.addFigure.call(this,this.resizeHandle6,xPos+(objWidth/2)-this.resizeHandleHalfWidth,yPos+objHeight);
draw2d.Canvas.prototype.addFigure.call(this,this.resizeHandle8,xPos-resizeWidth,yPos+(objHeight/2)-(resizeHeight/2));
this.moveFront(this.resizeHandle2);
this.moveFront(this.resizeHandle4);
this.moveFront(this.resizeHandle6);
this.moveFront(this.resizeHandle8);
}
}
draw2d.Workflow.prototype.hideResizeHandles=function()
{
if(this.resizeHandle1.canvas!=null)
draw2d.Canvas.prototype.removeFigure.call(this,this.resizeHandle1);
if(this.resizeHandle2.canvas!=null)
draw2d.Canvas.prototype.removeFigure.call(this,this.resizeHandle2);
if(this.resizeHandle3.canvas!=null)
draw2d.Canvas.prototype.removeFigure.call(this,this.resizeHandle3);
if(this.resizeHandle4.canvas!=null)
draw2d.Canvas.prototype.removeFigure.call(this,this.resizeHandle4);
if(this.resizeHandle5.canvas!=null)
draw2d.Canvas.prototype.removeFigure.call(this,this.resizeHandle5);
if(this.resizeHandle6.canvas!=null)
draw2d.Canvas.prototype.removeFigure.call(this,this.resizeHandle6);
if(this.resizeHandle7.canvas!=null)
draw2d.Canvas.prototype.removeFigure.call(this,this.resizeHandle7);
if(this.resizeHandle8.canvas!=null)
draw2d.Canvas.prototype.removeFigure.call(this,this.resizeHandle8);
}
draw2d.Workflow.prototype.moveResizeHandles=function( figure)
{
var resizeWidth = this.resizeHandle1.getWidth();
var resizeHeight= this.resizeHandle1.getHeight();
var objHeight = figure.getHeight();
var objWidth = figure.getWidth();
var xPos = figure.getX();
var yPos = figure.getY();
this.resizeHandle1.setPosition(xPos-resizeWidth,yPos-resizeHeight);
this.resizeHandle3.setPosition(xPos+objWidth,yPos-resizeHeight);
this.resizeHandle5.setPosition(xPos+objWidth,yPos+objHeight);
this.resizeHandle7.setPosition(xPos-resizeWidth,yPos+objHeight);
if(figure.isStrechable())
{
this.resizeHandle2.setPosition(xPos+(objWidth/2)-this.resizeHandleHalfWidth,yPos-resizeHeight);
this.resizeHandle4.setPosition(xPos+objWidth,yPos+(objHeight/2)-(resizeHeight/2));
this.resizeHandle6.setPosition(xPos+(objWidth/2)-this.resizeHandleHalfWidth,yPos+objHeight);
this.resizeHandle8.setPosition(xPos-resizeWidth,yPos+(objHeight/2)-(resizeHeight/2));
}
}
draw2d.Workflow.prototype.onMouseDown=function( x, y)
{
this.dragging = true;
this.mouseDownPosX = x;
this.mouseDownPosY = y;
if(this.toolPalette!=null && this.toolPalette.getActiveTool()!=null)
{
this.toolPalette.getActiveTool().execute(x,y);
}
this.setCurrentSelection(null);
this.showMenu(null);
var size=this.getLines().getSize();
for(var i=0;i< size;i++)
{
var line = this.lines.get(i);
if(line.containsPoint(x,y) && line.isSelectable())
{
this.hideResizeHandles();
this.setCurrentSelection(line);
this.showLineResizeHandles(this.currentSelection);
if(line instanceof draw2d.Line && !(line instanceof draw2d.Connection))
this.draggingLine = line;
break;
}
}
}
draw2d.Workflow.prototype.onMouseUp=function( x , y)
{
this.dragging = false;
this.draggingLine = null;
}
draw2d.Workflow.prototype.onMouseMove=function( x , y)
{
if(this.dragging==true && this.draggingLine!=null)
{
var diffX = x-this.mouseDownPosX;
var diffY = y-this.mouseDownPosY;
this.draggingLine.startX= this.draggingLine.getStartX()+diffX;
this.draggingLine.startY= this.draggingLine.getStartY()+diffY;
this.draggingLine.setEndPoint(this.draggingLine.getEndX()+diffX, this.draggingLine.getEndY()+diffY);
this.mouseDownPosX = x;
this.mouseDownPosY = y;
this.showLineResizeHandles(this.currentSelection);
}
else if(this.dragging==true && this.panning==true)
{
var diffX = x-this.mouseDownPosX;
var diffY = y-this.mouseDownPosY;
this.scrollTo(this.getScrollLeft()-diffX, this.getScrollTop()-diffY,true);
this.onScroll();
}
}
draw2d.Workflow.prototype.onKeyDown=function( keyCode, ctrl)
{
if(keyCode==46 && this.currentSelection!=null && this.currentSelection.isDeleteable())
this.commandStack.execute(new draw2d.CommandDelete(this.currentSelection));
else if(keyCode==90 && ctrl)
this.commandStack.undo();
else if(keyCode==89 && ctrl)
this.commandStack.redo();
}
draw2d.Workflow.prototype.setDocumentDirty=function()
{
for(var i=0;i<this.dialogs.getSize();i++)
{
var d = this.dialogs.get(i);
if(d!=null && d.onSetDocumentDirty)
d.onSetDocumentDirty();
}
if(this.snapToGeometryHelper!=null)
this.snapToGeometryHelper.onSetDocumentDirty();
if(this.snapToGridHelper!=null)
this.snapToGridHelper.onSetDocumentDirty();
}
draw2d.Workflow.prototype.snapToHelper=function(figure, pos)
{
if(this.snapToGeometryHelper!=null)
{
if(figure instanceof draw2d.ResizeHandle)
{
var snapPoint = figure.getSnapToGridAnchor();
pos.x+= snapPoint.x;
pos.y+= snapPoint.y;
var result = new draw2d.Point(pos.x,pos.y);
var snapDirections = figure.getSnapToDirection();
var direction = this.snapToGeometryHelper.snapPoint(snapDirections, pos,result);
if((snapDirections & draw2d.SnapToHelper.EAST_WEST) && !(direction & draw2d.SnapToHelper.EAST_WEST))
this.showSnapToHelperLineVertical(result.x);
else
this.hideSnapToHelperLineVertical();
if((snapDirections & draw2d.SnapToHelper.NORTH_SOUTH) && !(direction & draw2d.SnapToHelper.NORTH_SOUTH))
this.showSnapToHelperLineHorizontal(result.y);
else
this.hideSnapToHelperLineHorizontal();
result.x-= snapPoint.x;
result.y-= snapPoint.y;
return result;
}
else
{
var inputBounds = new draw2d.Dimension(pos.x,pos.y, figure.getWidth(), figure.getHeight());
var result = new draw2d.Dimension(pos.x,pos.y, figure.getWidth(), figure.getHeight());
var snapDirections = draw2d.SnapToHelper.NSEW;
var direction = this.snapToGeometryHelper.snapRectangle( inputBounds, result);
if((snapDirections & draw2d.SnapToHelper.WEST) && !(direction & draw2d.SnapToHelper.WEST))
this.showSnapToHelperLineVertical(result.x);
else if((snapDirections & draw2d.SnapToHelper.EAST) && !(direction & draw2d.SnapToHelper.EAST))
this.showSnapToHelperLineVertical(result.getX()+result.getWidth());
else
this.hideSnapToHelperLineVertical();
if((snapDirections & draw2d.SnapToHelper.NORTH) && !(direction & draw2d.SnapToHelper.NORTH))
this.showSnapToHelperLineHorizontal(result.y);
else if((snapDirections & draw2d.SnapToHelper.SOUTH) && !(direction & draw2d.SnapToHelper.SOUTH))
this.showSnapToHelperLineHorizontal(result.getY()+result.getHeight());
else
this.hideSnapToHelperLineHorizontal();
return result.getTopLeft();
}
}
else if(this.snapToGridHelper!=null)
{
var snapPoint = figure.getSnapToGridAnchor();
pos.x= pos.x+snapPoint.x;
pos.y= pos.y+snapPoint.y;
var result = new draw2d.Point(pos.x,pos.y);
this.snapToGridHelper.snapPoint(0,pos,result);
result.x= result.x-snapPoint.x;
result.y= result.y-snapPoint.y;
return result;
}
return pos;
}
draw2d.Workflow.prototype.showSnapToHelperLineHorizontal=function( horizontalLocation)
{
if(this.horizontalSnapToHelperLine==null)
{
this.horizontalSnapToHelperLine = new draw2d.Line();
this.horizontalSnapToHelperLine.setColor(new draw2d.Color(175,175,255));
this.addFigure(this.horizontalSnapToHelperLine);
}
this.horizontalSnapToHelperLine.setStartPoint(0,horizontalLocation);
this.horizontalSnapToHelperLine.setEndPoint(this.getWidth(),horizontalLocation);
}
draw2d.Workflow.prototype.showSnapToHelperLineVertical=function( verticalLocation)
{
if(this.verticalSnapToHelperLine==null)
{
this.verticalSnapToHelperLine = new draw2d.Line();
this.verticalSnapToHelperLine.setColor(new draw2d.Color(175,175,255));
this.addFigure(this.verticalSnapToHelperLine);
}
this.verticalSnapToHelperLine.setStartPoint(verticalLocation,0);
this.verticalSnapToHelperLine.setEndPoint(verticalLocation,this.getHeight());
}
draw2d.Workflow.prototype.hideSnapToHelperLines=function()
{
this.hideSnapToHelperLineHorizontal();
this.hideSnapToHelperLineVertical();
}
draw2d.Workflow.prototype.hideSnapToHelperLineHorizontal=function()
{
if(this.horizontalSnapToHelperLine!=null)
{
this.removeFigure(this.horizontalSnapToHelperLine);
this.horizontalSnapToHelperLine = null;
}
}
draw2d.Workflow.prototype.hideSnapToHelperLineVertical=function()
{
if(this.verticalSnapToHelperLine!=null)
{
this.removeFigure(this.verticalSnapToHelperLine);
this.verticalSnapToHelperLine = null;
}
}
Documentation generated by
JSDoc on Thu Feb 7 23:45:47 2008