/
var
/
www
/
html
/
sugar14
/
cache
/
include
/
javascript
/
Upload File
HOME
var jCore=(function($,window){var isCtrl=false,isShift=false,activeCanvas=null,ArrayList,Point,Geometry,Graphics,Utils,Command,CommandStack,CommandResize,CommandConnect,CommandReconnect,CommandSegmentMove,CommandMove,CommandCreate,CommandSwitchContainer,CommandDelete,CommandPaste,CommandEditLabel,ContainerBehavior,RegularContainerBehavior,NoContainerBehavior,DragBehavior,RegularDragBehavior,NoDragBehavior,ConnectionDragBehavior,CustomShapeDragBehavior,ResizeBehavior,RegularResizeBehavior,NoResizeBehavior,DropBehavior,ConnectionDropBehavior,NoDropBehavior,ContainerDropBehavior,ConnectionContainerDropBehavior,Color,Style,JCoreObject,Handler,ReadOnlyLayer,ResizeHandler,SegmentMoveHandler,Port,Router,ManhattanConnectionRouter,ConnectionDecorator,Connection,BehavioralElement,Layer,Shape,Label,CustomShape,Segment,RegularShape,Polygon,Rectangle,Oval,Arc,MultipleSelectionContainer,Intersection,Snapper,Canvas,version='1.2';ArrayList=function(){var elements=[],size=0,index,i;return{id:Math.random(),get:function(index){return elements[index];},insert:function(item){elements[size]=item;size+=1;return this;},insertAt:function(item,index){elements.splice(index,0,item);size=elements.length;return this;},remove:function(item){index=this.indexOf(item);if(index===-1){return false;} size-=1;elements.splice(index,1);return true;},getSize:function(){return size;},isEmpty:function(){return size===0;},indexOf:function(item){for(i=0;i<size;i+=1){if(item.id===elements[i].id){return i;}} return-1;},find:function(attribute,value){var i,current;for(i=0;i<elements.length;i+=1){current=elements[i];if(current[attribute]===value){return current;}} return undefined;},contains:function(item){if(this.indexOf(item)!==-1){return true;} return false;},sort:function(compFunction){var returnValue=false;if(compFunction){elements.sort(compFunction);returnValue=true;} return returnValue;},asArray:function(){return elements;},getFirst:function(){return elements[0];},getLast:function(){return elements[size-1];},popLast:function(){var lastElement;size-=1;lastElement=elements[size];elements.splice(size,1);return lastElement;},getDimensionLimit:function(){var result=[100000,-1,-1,100000],objects=[undefined,undefined,undefined,undefined];for(i=0;i<size;i+=1){if(result[0]>elements[i].y){result[0]=elements[i].y;objects[0]=elements[i];} if(result[1]<elements[i].x+elements[i].width){result[1]=elements[i].x+elements[i].width;objects[1]=elements[i];} if(result[2]<elements[i].y+elements[i].height){result[2]=elements[i].y+elements[i].height;objects[2]=elements[i];} if(result[3]>elements[i].x){result[3]=elements[i].x;objects[3]=elements[i];}} return result;},clear:function(){if(size!==0){elements=[];size=0;} return this;},getCanvas:function(){return(this.getSize()>0)?this.get(0).getCanvas():undefined;}};};if(typeof exports!=='undefined'){module.exports=ArrayList;} Point=function(xCoordinate,yCoordinate){this.x=xCoordinate;this.y=yCoordinate;};Point.prototype.type="Point";Point.prototype.getX=function(){return this.x;};Point.prototype.getY=function(){return this.y;};Point.prototype.add=function(other){return new Point(this.x+other.x,this.y+other.y);};Point.prototype.subtract=function(other){return new Point(this.x-other.x,this.y-other.y);};Point.prototype.multiply=function(k){return new Point(this.x*k,this.y*k);};Point.prototype.equals=function(other){return(Math.abs(this.x-other.x)<Geometry.eps)&&(Math.abs(this.y-other.y)<Geometry.eps);};Point.prototype.getDistance=function(other){return Math.sqrt((this.x-other.x)*(this.x-other.x)+ (this.y-other.y)*(this.y-other.y));};Point.prototype.getSquaredDistance=function(other){return(this.x-other.x)*(this.x-other.x)+ (this.y-other.y)*(this.y-other.y);};Point.prototype.getManhattanDistance=function(other){return Math.abs(this.x-other.x)+Math.abs(this.y-other.y);};Point.prototype.clone=function(){return new Point(this.x,this.y);};if(typeof exports!=='undefined'){module.exports=Point;} Geometry={pi:Math.acos(-1),eps:1e-8,cross:function(p1,p2){return p1.x*p2.y-p1.y*p2.x;},area:function(p1,p2,p3){var auxP2=p2.clone(),auxP3=p3.clone();return this.cross(auxP2.subtract(p1),auxP3.subtract(p1));},onSegment:function(P,A,B){return(Math.abs(this.area(A,B,P))<this.eps&&P.x>=Math.min(A.x,B.x)&&P.x<=Math.max(A.x,B.x)&&P.y>=Math.min(A.y,B.y)&&P.y<=Math.max(A.y,B.y));},perpendicularSegmentIntersection:function(A,B,C,D){var clone,returnValue=null;if(A.x>B.x||A.y>B.y){clone=A.clone();A=B.clone();B=clone;} if(C.x>D.x||C.y>D.y){clone=C.clone();C=D.clone();D=clone;} if(A.x===B.x){if(C.y===D.y&&C.x<A.x&&A.x<D.x&&A.y<C.y&&C.y<B.y){returnValue=new Point(A.x,C.y);}}else if(A.y===B.y){if(C.x===D.x&&A.x<C.x&&C.x<B.x&&C.y<A.y&&A.y<D.y){returnValue=new Point(C.x,A.y);}} return returnValue;},segmentIntersection:function(A,B,C,D,strict){var area1=this.area(C,D,A),area2=this.area(C,D,B),area3=this.area(A,B,C),area4=this.area(A,B,D),returnValue;if(((area1>0&&area2<0)||(area1<0&&area2>0))&&((area3>0&&area4<0)||(area3<0&&area4>0))){return true;} returnValue=false;if(strict){if(area1===0&&this.onSegment(A,C,D)){returnValue=true;}else if(area2===0&&this.onSegment(B,C,D)){returnValue=true;}else if(area3===0&&this.onSegment(C,A,B)){returnValue=true;}else if(area4===0&&this.onSegment(D,A,B)){returnValue=true;}} return returnValue;},segmentIntersectionPoint:function(A,B,C,D){return A.add((B.subtract(A)).multiply(this.cross(C.subtract(A),D.subtract(A))/ this.cross(B.subtract(A),D.subtract(C))));},pointInRectangle:function(point,upperLeft,bottomRight){return(point.x>=upperLeft.x&&point.x<=bottomRight.x&&point.y>=upperLeft.y&&point.y<=bottomRight.y);},pointInCircle:function(point,center,radius){return center.getDistance(point)<=radius;},pointInRhombus:function(point,rhombus,center){var i,j=rhombus.length-1;for(i=0;i<rhombus.length;j=i,i+=1){if(this.segmentIntersection(center,point,rhombus[j],rhombus[i],true)&&this.onSegment(point,rhombus[j],rhombus[i])===false){return false;}} return true;}};if(typeof exports!=='undefined'){module.exports=Geometry;} Utils={pageCoordinatesToShapeCoordinates:function(shape,e,xCoord,yCoord){var coordinates,x=(!xCoord)?e.pageX:xCoord,y=(!yCoord)?e.pageY:yCoord,canvas=shape.getCanvas();x+=canvas.getLeftScroll()-shape.getAbsoluteX()-canvas.getX();y+=canvas.getTopScroll()-shape.getAbsoluteY()-canvas.getY();coordinates=new Point(x,y);return coordinates;},getPointRelativeToPage:function(shape){var canvas=shape.getCanvas(),x=shape.absoluteX+canvas.getX()-canvas.getLeftScroll()+ shape.zoomWidth / 2,y=shape.absoluteY+canvas.getY()-canvas.getTopScroll()+ shape.zoomHeight / 2;return new Point(x,y);},generateUniqueId:function(){var rand=function(min,max){if(typeof min==="undefined"){min=0;} if(typeof max==="undefined"){max=999999999;} return Math.floor(Math.random()*(max-min+1))+min;},uniqid=function(prefix,more_entropy){if(typeof prefix==='undefined'){prefix="";} var retId,formatSeed=function(seed,reqWidth){var tempString="",i;seed=parseInt(seed,10).toString(16);if(reqWidth<seed.length){return seed.slice(seed.length-reqWidth);} if(reqWidth>seed.length){tempString="";for(i=0;i<1+(reqWidth-seed.length);i+=1){tempString+="0";} return tempString+seed;} return seed;};if(!this.php_js){this.php_js={};} if(!this.php_js.uniqidSeed){this.php_js.uniqidSeed=Math.floor(Math.random()*0x75bcd15);} this.php_js.uniqidSeed+=1;retId=prefix;retId+=formatSeed(parseInt(new Date().getTime()/ 1000,10),8);retId+=formatSeed(this.php_js.uniqidSeed,5);if(more_entropy){retId+=(Math.random()*10).toFixed(8).toString();} return retId;},sUID;do{sUID=uniqid(rand(0,999999999),true);sUID=sUID.replace('.','0');}while(sUID.length!==32);return sUID;}};Command=function(receiver){this.receiver=receiver;this.canvas=(!receiver)?null:receiver.getCanvas();};Command.prototype.family="Command";Command.prototype.execute=function(stopTrigger){};Command.prototype.undo=function(stopTrigger){};Command.prototype.redo=function(stopTrigger){};CommandStack=function(stackSize,successCallback){var undoStack,redoStack,maxSize;undoStack=[];redoStack=[];maxSize=stackSize||20;function emptyRedoStack(){redoStack=[];} function onSuccess(){} if(successCallback&&{}.toString.call(successCallback)==='[object Function]'){onSuccess=successCallback;} return{add:function(action){emptyRedoStack();undoStack.push(action);if(undoStack.length>maxSize){undoStack.shift();} onSuccess();},addToRedo:function(action){redoStack.push(action);},undo:function(){var action;if(undoStack.length===0){return false;} action=undoStack.pop();action.undo();redoStack.unshift(action);onSuccess();return true;},redo:function(){var action;if(redoStack.length===0){return false;} action=redoStack.shift();action.redo();undoStack.push(action);onSuccess();return true;},clearStack:function(){redoStack=[];undoStack=[];},debug:function(showDetailed){var i;console.log("Debugging command stack:");console.log("Undo stack size: "+undoStack.length);if(showDetailed){for(i=0;i<undoStack.length;i+=1){console.log((i+1)+") "+undoStack[i].type);}} console.log("Redo stack size: "+redoStack.length);if(showDetailed){for(i=0;i<redoStack.length;i+=1){console.log((i+1)+") "+redoStack[i].type);}}},getRedoSize:function(){return redoStack.length;},getUndoSize:function(){return undoStack.length;},setHandler:function(successCallback){if(successCallback&&{}.toString.call(successCallback)==='[object Function]'){onSuccess=successCallback;} return this;}};};CommandResize=function(receiver){Command.call(this,receiver);this.before={x:this.receiver.getOldX(),y:this.receiver.getOldY(),width:this.receiver.getOldWidth(),height:this.receiver.getOldHeight()};this.after={x:this.receiver.getX(),y:this.receiver.getY(),width:this.receiver.getWidth(),height:this.receiver.getHeight()};};CommandResize.prototype=new Command();CommandResize.prototype.type="CommandResize";CommandResize.prototype.execute=function(){var shape=this.receiver,canvas=shape.getCanvas();shape.setPosition(this.after.x,this.after.y).setDimension(this.after.width,this.after.height);shape.fixConnectionsOnResize(shape.resizing,true);canvas.triggerDimensionChangeEvent(shape,this.before.width,this.before.height,this.after.width,this.after.height);if((this.after.x!==this.before.x)||(this.after.y!==this.before.y)){canvas.triggerPositionChangeEvent([shape],[{x:this.before.x,y:this.before.y}],[{x:this.after.x,y:this.after.y}]);} return this;};CommandResize.prototype.undo=function(){var shape=this.receiver,canvas=shape.getCanvas();shape.setPosition(this.before.x,this.before.y).setDimension(this.before.width,this.before.height);shape.fixConnectionsOnResize(shape.resizing,true);canvas.triggerDimensionChangeEvent(shape,this.after.width,this.after.height,this.before.width,this.before.height);if((this.after.x!==this.before.x)||(this.after.y!==this.before.y)){canvas.triggerPositionChangeEvent([shape],[{x:this.after.x,y:this.after.y}],[{x:this.before.x,y:this.before.y}]);} return this;};CommandResize.prototype.redo=function(){this.execute();return this;};CommandConnect=function(receiver){Command.call(this,receiver);};CommandConnect.prototype=new Command();CommandConnect.prototype.type="CommandConnect";CommandConnect.prototype.buildConnection=function(fromUndo){var connection=this.receiver,canvas=connection.canvas,srcPort=connection.getSrcPort(),destPort=connection.getDestPort();srcPort.parent.ports.insert(srcPort);destPort.parent.ports.insert(destPort);srcPort.parent.html.appendChild(srcPort.getHTML());destPort.parent.html.appendChild(destPort.getHTML());connection.inUndo=fromUndo===true;canvas.addConnection(connection);connection.inUndo=!connection.inUndo;canvas.updatedElement=connection;return connection;};CommandConnect.prototype.execute=function(){var connection=this.buildConnection();connection.canvas.triggerCreateEvent(connection,[]);return this;};CommandConnect.prototype.undo=function(){this.receiver.saveAndDestroy();this.receiver.canvas.triggerRemoveEvent(this.receiver,[this.receiver]);return this;};CommandConnect.prototype.redo=function(){this.execute();return this;};CommandReconnect=function(receiver){Command.call(this,receiver);this.before={x:this.receiver.getOldX(),y:this.receiver.getOldY(),parent:this.receiver.getOldParent()};this.after={x:this.receiver.getX(),y:this.receiver.getY(),parent:this.receiver.getParent()};};CommandReconnect.prototype=new Command();CommandReconnect.prototype.type="CommandReconnect";CommandReconnect.prototype.execute=function(){var port=this.receiver,parent=this.after.parent,oldParent=this.before.parent;if(parent.canvas.currentConnection){parent.canvas.currentConnection.hidePortsAndHandlers();parent.canvas.currentConnection=null;} if(parent.getID()!==oldParent.getID()){oldParent.removePort(port);port.canvas.regularShapes.insert(port);}else{parent.definePortPosition(port,new Point(this.after.x+Math.round(port.getWidth()/ 2),this.after.y+Math.round(port.getHeight()/2)));} port.connection.disconnect().connect().setSegmentMoveHandlers().checkAndCreateIntersectionsWithAll();this.receiver.canvas.triggerPortChangeEvent(port);return this;};CommandReconnect.prototype.undo=function(){var port=this.receiver,parent=this.after.parent,oldParent=this.before.parent;if(parent.canvas.currentConnection){parent.canvas.currentConnection.hidePortsAndHandlers();parent.canvas.currentConnection=null;} if(parent.getID()!==oldParent.getID()){parent.removePort(port);oldParent.addPort(port,this.before.x,this.before.y,true);port.canvas.regularShapes.insert(port);}else{parent.definePortPosition(port,new Point(this.before.x+Math.round(port.getWidth()/ 2),this.before.y+Math.round(port.getHeight()/2)));} port.connection.disconnect().connect().setSegmentMoveHandlers().checkAndCreateIntersectionsWithAll();this.receiver.canvas.triggerPortChangeEvent(port);return this;};CommandReconnect.prototype.redo=function(){this.execute();return this;};CommandSegmentMove=function(receiver,options){Command.call(this,receiver);this.oldPoints=[];this.newPoints=[];CommandSegmentMove.prototype.initObject.call(this,options);};CommandSegmentMove.prototype=new Command();CommandSegmentMove.prototype.type="CommandResize";CommandSegmentMove.prototype.initObject=function(options){var defaults={oldPoints:[],newPoints:[]},i,point;$.extend(true,defaults,options);this.oldPoints=[];for(i=0;i<defaults.oldPoints.length;i+=1){point=defaults.oldPoints[i];this.oldPoints.push(new Point(point.x,point.y));} this.newPoints=[];for(i=0;i<defaults.newPoints.length;i+=1){point=defaults.newPoints[i];this.newPoints.push(new Point(point.x,point.y));}};CommandSegmentMove.prototype.common=function(action){var connection=this.receiver;$(connection.destDecorator.getHTML()).trigger('click');connection.hidePortsAndHandlers();connection.disconnect(true).connect({algorithm:'user',points:this[action]});connection.setSegmentMoveHandlers();connection.checkAndCreateIntersectionsWithAll();connection.showPortsAndHandlers();connection.canvas.triggerConnectionStateChangeEvent(connection);return this;};CommandSegmentMove.prototype.execute=function(){this.common("newPoints");return this;};CommandSegmentMove.prototype.undo=function(){this.common("oldPoints");return this;};CommandSegmentMove.prototype.redo=function(){this.execute();return this;};CommandMove=function(receiver){Command.call(this,receiver);this.before=null;this.after=null;this.relatedShapes=[];CommandMove.prototype.initObject.call(this,receiver);};CommandMove.prototype=new Command();CommandMove.prototype.type="CommandMove";CommandMove.prototype.initObject=function(receiver){var i,beforeShapes=[],afterShapes=[];for(i=0;i<receiver.getSize();i+=1){this.relatedShapes.push(receiver.get(i));beforeShapes.push({x:receiver.get(i).getOldX(),y:receiver.get(i).getOldY()});afterShapes.push({x:receiver.get(i).getX(),y:receiver.get(i).getY()});} this.before={shapes:beforeShapes};this.after={shapes:afterShapes};this.isDragged=true;};CommandMove.prototype.execute=function(){var i,shape;for(i=0;i<this.relatedShapes.length;i+=1){shape=this.relatedShapes[i];if(!this.isDragged){shape.setPosition(this.after.shapes[i].x,this.after.shapes[i].y);} shape.refreshChildrenPositions(true);shape.refreshConnections(false,this.isDragged);} this.isDragged=false;this.canvas.triggerPositionChangeEvent(this.relatedShapes,this.before.shapes,this.after.shapes);};CommandMove.prototype.undo=function(){var i,shape;for(i=0;i<this.relatedShapes.length;i+=1){shape=this.relatedShapes[i];shape.setPosition(this.before.shapes[i].x,this.before.shapes[i].y).refreshChildrenPositions(true);shape.refreshConnections(false,this.isDragged);} this.canvas.triggerPositionChangeEvent(this.relatedShapes,this.after.shapes,this.before.shapes);};CommandMove.prototype.redo=function(){this.execute();};CommandCreate=function(receiver){Command.call(this,receiver);this.before=null;this.after=null;CommandCreate.prototype.initObject.call(this,receiver);};CommandCreate.prototype=new Command();CommandCreate.prototype.type="CommandCreate";CommandCreate.prototype.initObject=function(receiver){this.before={};this.after={x:receiver.getX(),y:receiver.getY(),parent:receiver.getParent()};};CommandCreate.prototype.execute=function(){var shape=this.receiver,parent=shape.parent;if(!parent.getChildren().contains(shape)){parent.getChildren().insert(shape);} this.after.parent.html.appendChild(shape.getHTML());shape.canvas.addToList(shape);shape.showOrHideResizeHandlers(false);shape.canvas.triggerCreateEvent(shape,[]);return this;};CommandCreate.prototype.undo=function(){this.receiver.parent.getChildren().remove(this.receiver);this.receiver.saveAndDestroy();this.receiver.canvas.triggerRemoveEvent(this.receiver,[this.receiver]);return this;};CommandCreate.prototype.redo=function(){this.execute();return this;};CommandSwitchContainer=function(shapesAdded){Command.call(this,shapesAdded[0].shape);this.before=null;this.after=null;this.relatedShapes=[];CommandSwitchContainer.prototype.initObject.call(this,shapesAdded);};CommandSwitchContainer.prototype=new Command();CommandSwitchContainer.prototype.type="CommandSwitchContainer";CommandSwitchContainer.prototype.initObject=function(shapesAdded){var i,shape,beforeShapes=[],afterShapes=[];for(i=0;i<shapesAdded.length;i+=1){shape=shapesAdded[i];this.relatedShapes.push(shape.shape);beforeShapes.push({parent:shape.shape.parent,x:shape.shape.getOldX(),y:shape.shape.getOldY(),topLeft:true});afterShapes.push({parent:shape.container,x:shape.x,y:shape.y,topLeft:shape.topLeft});} this.before={shapes:beforeShapes};this.after={shapes:afterShapes};};CommandSwitchContainer.prototype.execute=function(){var i,shape;for(i=0;i<this.relatedShapes.length;i+=1){shape=this.relatedShapes[i];this.before.shapes[i].parent.swapElementContainer(shape,this.after.shapes[i].parent,this.after.shapes[i].x,this.after.shapes[i].y,this.after.shapes[i].topLeft);shape.refreshChildrenPositions().refreshConnections();} this.canvas.triggerParentChangeEvent(this.relatedShapes,this.before.shapes,this.after.shapes);};CommandSwitchContainer.prototype.undo=function(){var i,shape;for(i=0;i<this.relatedShapes.length;i+=1){shape=this.relatedShapes[i];this.before.shapes[i].parent.swapElementContainer(shape,this.before.shapes[i].parent,this.before.shapes[i].x,this.before.shapes[i].y,this.before.shapes[i].topLeft);shape.refreshChildrenPositions().refreshConnections();} this.canvas.triggerParentChangeEvent(this.relatedShapes,this.after.shapes,this.before.shapes);};CommandSwitchContainer.prototype.redo=function(){this.execute();};CommandDelete=function(receiver){Command.call(this,receiver);this.stackCommandConnect=[];this.currentSelection=new ArrayList();this.currentConnection=null;this.relatedElements=[];CommandDelete.prototype.initObject.call(this,receiver);};CommandDelete.prototype=new Command();CommandDelete.prototype.type="CommandDelete";CommandDelete.prototype.initObject=function(receiver){var i,shape;for(i=0;i<receiver.getCurrentSelection().getSize()>0;i+=1){shape=receiver.getCurrentSelection().get(i);this.currentSelection.insert(shape);} if(receiver.currentConnection){this.currentConnection=receiver.currentConnection;}};CommandDelete.prototype.saveAndDestroy=function(shape,root,fillArray){var i,child,parent,children=null,connection,canvas=shape.canvas;if(shape.hasOwnProperty("children")){children=shape.children;} if(shape.destroy){shape.destroy();} for(i=0;i<children.getSize();i+=1){child=children.get(i);this.saveAndDestroy(child,false,fillArray);} while(shape.ports&&shape.ports.getSize()>0){connection=shape.ports.getFirst().connection;if(fillArray){this.relatedElements.push(connection);} this.stackCommandConnect.push(new CommandConnect(connection));connection.saveAndDestroy();} if(root){parent=shape.parent;parent.getChildren().remove(shape);if(parent.isResizable()){parent.resizeBehavior.updateResizeMinimums(shape.parent);} shape.html=$(shape.html).detach()[0];} if(fillArray){this.relatedElements.push(shape);} canvas.removeFromList(shape);return true;};CommandDelete.prototype.execute=function(){var shape,i,canvas=this.receiver,currentConnection,stringified,fillArray=false,mainShape=null;if(this.relatedElements.length===0){fillArray=true;} canvas.emptyCurrentSelection();for(i=0;i<this.currentSelection.getSize();i+=1){shape=this.currentSelection.get(i);canvas.addToSelection(shape);} if(canvas.currentSelection.getSize()===1){mainShape=shape;} stringified=[];while(canvas.getCurrentSelection().getSize()>0){shape=canvas.getCurrentSelection().getFirst();this.saveAndDestroy(shape,true,fillArray);stringified.push(shape.stringify());} canvas.currentConnection=this.currentConnection;currentConnection=canvas.currentConnection;if(currentConnection){this.relatedElements.push(currentConnection);this.stackCommandConnect.push(new CommandConnect(currentConnection));currentConnection.saveAndDestroy();currentConnection=null;} canvas.triggerRemoveEvent(mainShape,this.relatedElements);return this;};CommandDelete.prototype.undo=function(){var i,shape,mainShape=this.currentSelection.getFirst();for(i=0;i<this.currentSelection.getSize();i+=1){shape=this.currentSelection.get(i);shape.canvas.addToList(shape);shape.parent.getChildren().insert(shape);shape.parent.html.appendChild(shape.getHTML());ResizeBehavior.prototype.updateResizeMinimums(shape.parent);shape.showOrHideResizeHandlers(false);} for(i=this.stackCommandConnect.length-1;i>=0;i-=1){this.stackCommandConnect[i].buildConnection(true);} this.receiver.triggerCreateEvent(mainShape,this.relatedElements);return this;};CommandDelete.prototype.redo=function(){this.execute();return this;};CommandPaste=function(receiver,options){Command.call(this,receiver);this.stackCommandConnect=[];this.stackCommandCreate=[];CommandPaste.prototype.initObject.call(this,receiver,options);};CommandPaste.prototype=new Command();CommandPaste.prototype.type="CommandPaste";CommandPaste.prototype.initObject=function(receiver,options){var i,shape,defaults={stackCommandConnect:[],stackCommandCreate:[]};$.extend(true,defaults,options);this.stackCommandConnect=defaults.stackCommandConnect;this.stackCommandCreate=defaults.stackCommandCreate;};CommandPaste.prototype.execute=function(){var i,command;for(i=0;i<this.stackCommandCreate.length;i+=1){command=this.stackCommandCreate[i];command.redo();} for(i=0;i<this.stackCommandConnect.length;i+=1){command=this.stackCommandConnect[i];command.redo();} return this;};CommandPaste.prototype.undo=function(){var i,command;for(i=0;i<this.stackCommandCreate.length;i+=1){command=this.stackCommandCreate[i];command.undo();} for(i=0;i<this.stackCommandConnect.length;i+=1){command=this.stackCommandConnect[i];command.undo();} return this;};CommandPaste.prototype.redo=function(){this.execute();return this;};CommandEditLabel=function(receiver,newMessage){Command.call(this,receiver);this.before=null;this.after=null;CommandEditLabel.prototype.initObject.call(this,receiver,newMessage);};CommandEditLabel.prototype=new Command();CommandEditLabel.prototype.type="CommandEditLabel";CommandEditLabel.prototype.initObject=function(receiver,newMessage){var parentHeight=0,parentWidth=0;if(receiver.parent){parentHeight=receiver.parent.height;parentWidth=receiver.parent.width;} this.before={message:receiver.message,width:receiver.width,height:receiver.height,parentHeight:parentHeight,parentWidth:parentWidth};this.after={message:newMessage,width:0,height:0,parentHeight:parentWidth,parentWidth:parentHeight};};CommandEditLabel.prototype.execute=function(stopTrigger){this.receiver.setMessage(this.after.message);this.receiver.updateDimension();if(this.after.width===0){this.after.width=this.receiver.width;this.after.height=this.receiver.height;if(this.after.parentWidth!==0){this.after.parentWidth=this.receiver.parent.width;this.after.parentHeight=this.receiver.parent.height;}} this.receiver.paint();if(!stopTrigger){this.receiver.canvas.triggerTextChangeEvent(this.receiver,this.before.message,this.after.message);if((this.after.parentWidth!==this.before.parentWidth)||(this.before.parentHeight!==this.after.parentHeight)){this.receiver.canvas.triggerDimensionChangeEvent (this.receiver.parent,this.before.parentWidth,this.before.parentHeight,this.after.parentWidth,this.after.parentHeight);}}};CommandEditLabel.prototype.undo=function(stopTrigger){this.receiver.setMessage(this.before.message);if(this.receiver.parent){this.receiver.parent.setDimension(this.before.parentWidth,this.before.parentHeight);} this.receiver.setDimension(this.before.width,this.before.height);this.receiver.updateDimension();this.receiver.paint();this.receiver.canvas.triggerTextChangeEvent(this.receiver,this.after.message,this.before.message);if((this.after.parentWidth!==this.before.parentWidth)&&(this.before.parentHeight!==this.after.parentHeight)){this.receiver.canvas.triggerDimensionChangeEvent(this.receiver.parent,this.after.parentWidth,this.after.parentHeight,this.before.parentWidth,this.before.parentHeight);}};CommandEditLabel.prototype.redo=function(){this.execute();};ContainerBehavior=function(){};ContainerBehavior.prototype.type="ContainerBehavior";ContainerBehavior.prototype.family="ContainerBehavior";ContainerBehavior.prototype.addToContainer=function(container,shape,x,y,topLeftCorner){};ContainerBehavior.prototype.removeFromContainer=function(shape){};ContainerBehavior.prototype.addShape=function(container,shape,x,y){};ContainerBehavior.prototype.isContainer=function(){return false;};RegularContainerBehavior=function(){};RegularContainerBehavior.prototype=new ContainerBehavior();RegularContainerBehavior.prototype.type="RegularContainerBehavior";RegularContainerBehavior.prototype.addToContainer=function(container,shape,x,y,topLeftCorner){var shapeLeft=0,shapeTop=0,shapeWidth,shapeHeight,canvas,topLeftFactor=(topLeftCorner===true)?0:1;if(container.family==="Canvas"){canvas=container;}else{canvas=container.canvas;} shapeWidth=shape.getZoomWidth();shapeHeight=shape.getZoomHeight();shapeLeft+=x-(shapeWidth / 2)*topLeftFactor;shapeTop+=y-(shapeHeight / 2)*topLeftFactor;shapeLeft /=canvas.zoomFactor;shapeTop /=canvas.zoomFactor;shape.setParent(container);container.getChildren().insert(shape);this.addShape(container,shape,shapeLeft,shapeTop);shape.fixZIndex(shape,0);container.updateDimensions(10);canvas.addToList(shape);};RegularContainerBehavior.prototype.removeFromContainer=function(shape){var parent=shape.parent;parent.getChildren().remove(shape);if(parent.isResizable()){parent.resizeBehavior.updateResizeMinimums(shape.parent);} shape.parent=null;};RegularContainerBehavior.prototype.addShape=function(container,shape,x,y){shape.setPosition(x,y);container.getHTML().appendChild(shape.getHTML());shape.paint();shape.updateHTML();return this;};NoContainerBehavior=function(){};NoContainerBehavior.prototype=new ContainerBehavior();NoContainerBehavior.prototype.type="NoContainerBehavior";DragBehavior=function(){};DragBehavior.prototype.type="DragBehavior";DragBehavior.prototype.family="DragBehavior";DragBehavior.prototype.attachDragBehavior=function(shape){var dragOptions,$shape=$(shape.getHTML());dragOptions={revert:false,helper:"none",cursorAt:false,revertDuration:0,grid:[1,1],start:this.onDragStart(shape),drag:this.onDrag(shape),stop:this.onDragEnd(shape)};$shape.draggable(dragOptions);};DragBehavior.prototype.onDragStart=function(shape){return function(e,ui){};};DragBehavior.prototype.onDrag=function(shape){return function(e,ui){};};DragBehavior.prototype.onDragEnd=function(shape){return function(e,ui){};};DragBehavior.prototype.dragStartHook=function(hookFunction){};DragBehavior.prototype.dragHook=function(hookFunction){};DragBehavior.prototype.dragEndHook=function(){};RegularDragBehavior=function(){};RegularDragBehavior.prototype=new DragBehavior();RegularDragBehavior.prototype.type="RegularDragBehavior";RegularDragBehavior.prototype.attachDragBehavior=function(shape){var $shape=$(shape.getHTML());DragBehavior.prototype.attachDragBehavior.call(this,shape);$shape.draggable({'cursor':"move"});};RegularDragBehavior.prototype.onDragStart=function(shape){return function(e,ui){var canvas=shape.canvas,currentLabel=canvas.currentLabel,selectedShape,i;canvas.hideCurrentConnection();if(currentLabel){currentLabel.loseFocus();$(currentLabel.textField).focusout();} if(!canvas.currentSelection.contains(shape)){canvas.emptyCurrentSelection();canvas.addToSelection(shape);} for(i=0;i<canvas.currentSelection.getSize();i+=1){selectedShape=canvas.currentSelection.get(i);selectedShape.setOldX(selectedShape.getX());selectedShape.setOldY(selectedShape.getY());selectedShape.setOldParent(selectedShape.getParent());} shape.increaseParentZIndex(shape.getParent());return true;};};RegularDragBehavior.prototype.onDrag=function(shape){return function(e,ui){shape.setPosition(ui.helper.position().left,ui.helper.position().top);shape.canvas.showOrHideSnappers(shape);};};RegularDragBehavior.prototype.onDragEnd=function(shape){return function(e,ui){var command;shape.setPosition(ui.helper.position().left,ui.helper.position().top);shape.decreaseParentZIndex(shape.oldParent);shape.dragging=false;shape.canvas.verticalSnapper.hide();shape.canvas.horizontalSnapper.hide();if(!shape.changedContainer){command=new CommandMove(shape);command.execute();shape.canvas.commandStack.add(command);} shape.changedContainer=false;};};NoDragBehavior=function(){};NoDragBehavior.prototype=new DragBehavior();NoDragBehavior.prototype.type="NoDragBehavior";NoDragBehavior.prototype.onDragStart=function(shape){return function(e,ui){shape.canvas.hideCurrentConnection();return false;};};ConnectionDragBehavior=function(){};ConnectionDragBehavior.prototype=new DragBehavior();ConnectionDragBehavior.prototype.type="ConnectionDragBehavior";ConnectionDragBehavior.prototype.attachDragBehavior=function(shape){var $shape=$(shape.getHTML()),dragOptions;dragOptions={helper:shape.createDragHelper,cursorAt:{top:0,left:0},revert:true};DragBehavior.prototype.attachDragBehavior.call(this,shape);$shape.draggable(dragOptions);$shape.draggable('enable');};ConnectionDragBehavior.prototype.onDragStart=function(customShape){return function(e,ui){var canvas=customShape.canvas,currentLabel=canvas.currentLabel;customShape.canvas.emptyCurrentSelection();if(currentLabel){currentLabel.loseFocus();$(currentLabel.textField).focusout();} if(customShape.family!=="CustomShape"){return false;} customShape.setOldX(customShape.getX());customShape.setOldY(customShape.getY());customShape.startConnectionPoint.x+=customShape.getAbsoluteX();customShape.startConnectionPoint.y+=customShape.getAbsoluteY();return true;};};ConnectionDragBehavior.prototype.onDrag=function(customShape){return function(e,ui){var canvas=customShape.getCanvas(),endPoint=new Point();if(canvas.connectionSegment){$(canvas.connectionSegment.getHTML()).remove();} endPoint.x=e.pageX-canvas.getX()+canvas.getLeftScroll();endPoint.y=e.pageY-canvas.getY()+canvas.getTopScroll();canvas.connectionSegment=new Segment({startPoint:customShape.startConnectionPoint,endPoint:endPoint,parent:canvas,zOrder:Style.MAX_ZINDEX*2});canvas.connectionSegment.pointsTo=customShape;canvas.connectionSegment.paint();};};ConnectionDragBehavior.prototype.onDragEnd=function(customShape){return function(e,ui){if(customShape.canvas.connectionSegment){$(customShape.canvas.connectionSegment.getHTML()).remove();} customShape.setPosition(customShape.getOldX(),customShape.getOldY());customShape.dragging=false;};};CustomShapeDragBehavior=function(){};CustomShapeDragBehavior.prototype=new DragBehavior();CustomShapeDragBehavior.prototype.type="CustomShapeDragBehavior";CustomShapeDragBehavior.prototype.attachDragBehavior=function(customShape){var dragOptions,$customShape=$(customShape.getHTML());dragOptions={revert:false,helper:"none",cursorAt:false,revertDuration:0,disable:false,grid:[1,1],start:this.onDragStart(customShape),drag:this.onDrag(customShape,true),stop:this.onDragEnd(customShape,true)};$customShape.draggable(dragOptions);};CustomShapeDragBehavior.prototype.onDragStart=function(customShape){return function(e,ui){RegularDragBehavior.prototype.onDragStart.call(this,customShape)(e,ui);customShape.previousXDragPosition=customShape.getX();customShape.previousYDragPosition=customShape.getY();if(customShape.canvas.snapToGuide){customShape.canvas.startSnappers(e);}};};CustomShapeDragBehavior.prototype.onDragProcedure=function(customShape,root,childDiffX,childDiffY,e,ui){var i,j,sibling,diffX,diffY,port,child,connection,shape1,shape2,canvas=customShape.canvas;if(root){if(customShape.canvas.snapToGuide){customShape.canvas.processGuides(e,ui,customShape);} customShape.setPosition(ui.helper.position().left / canvas.zoomFactor,ui.helper.position().top / canvas.zoomFactor);diffX=customShape.x-customShape.previousXDragPosition;diffY=customShape.y-customShape.previousYDragPosition;customShape.previousXDragPosition=customShape.x;customShape.previousYDragPosition=customShape.y;for(i=0;i<customShape.canvas.currentSelection.getSize();i+=1){sibling=customShape.canvas.currentSelection.get(i);if(sibling.id!==customShape.id){sibling.setPosition(sibling.x+diffX,sibling.y+diffY);}}}else{customShape.setPosition(customShape.x,customShape.y);} if(root){for(i=0;i<customShape.canvas.currentSelection.getSize();i+=1){sibling=customShape.canvas.currentSelection.get(i);for(j=0;j<sibling.children.getSize();j+=1){child=sibling.children.get(j);CustomShapeDragBehavior.prototype.onDragProcedure.call(this,child,false,diffX,diffY,e,ui);}}}else{for(i=0;i<customShape.children.getSize();i+=1){child=customShape.children.get(i);CustomShapeDragBehavior.prototype.onDragProcedure.call(this,child,false,childDiffX,childDiffY,e,ui);}} if(root){for(i=0;i<customShape.canvas.currentSelection.getSize();i+=1){sibling=customShape.canvas.currentSelection.get(i);for(j=0;j<sibling.ports.getSize();j+=1){port=sibling.ports.get(j);connection=port.connection;port.setPosition(port.x,port.y);if(customShape.canvas.sharedConnections.find('id',connection.getID())){if(connection.srcPort.parent.getID()===sibling.getID()){connection.move(diffX*canvas.zoomFactor,diffY*canvas.zoomFactor);}}else{connection.disconnect().connect();}}}}else{for(i=0;i<customShape.ports.getSize();i+=1){port=customShape.ports.get(i);connection=port.connection;shape1=connection.srcPort.parent;shape2=connection.destPort.parent;port.setPosition(port.x,port.y);if(customShape.canvas.sharedConnections.find('id',connection.getID())){if(connection.srcPort.parent.getID()===customShape.getID()){connection.move(childDiffX*canvas.zoomFactor,childDiffY*canvas.zoomFactor);}}else{connection.setSegmentColor(Color.GREY,false).setSegmentStyle("regular",false).disconnect().connect();}}}};CustomShapeDragBehavior.prototype.onDrag=function(customShape,root,childDiffX,childDiffY){var self=this;return function(e,ui){self.onDragProcedure(customShape,root,childDiffX,childDiffY,e,ui);};};CustomShapeDragBehavior.prototype.dragEndProcedure=function(customShape,root,e,ui){var i,j,sibling,port,child,connection,shape1,shape2,canvas=customShape.canvas;if(root){customShape.setPosition(ui.helper.position().left / canvas.zoomFactor,ui.helper.position().top / canvas.zoomFactor);customShape.wasDragged=true;}else{customShape.setPosition(customShape.x,customShape.y);} if(root){for(i=0;i<customShape.canvas.currentSelection.getSize();i+=1){sibling=customShape.canvas.currentSelection.get(i);for(j=0;j<sibling.children.getSize();j+=1){child=sibling.children.get(j);child.changedContainer=true;CustomShapeDragBehavior.prototype.dragEndProcedure.call(this,child,false,e,ui);}}}else{for(i=0;i<customShape.children.getSize();i+=1){child=customShape.children.get(i);CustomShapeDragBehavior.prototype.dragEndProcedure.call(this,child,false,e,ui);}} if(root){for(i=0;i<customShape.canvas.currentSelection.getSize();i+=1){sibling=customShape.canvas.currentSelection.get(i);for(j=0;j<sibling.ports.getSize();j+=1){port=sibling.ports.get(j);connection=port.connection;port.setPosition(port.x,port.y);if(customShape.canvas.sharedConnections.find('id',connection.getID())){if(connection.srcPort.parent.getID()===sibling.getID()){connection.disconnect(true).connect({algorithm:'user',points:connection.points,dx:parseFloat($(connection.html).css('left')),dy:parseFloat($(connection.html).css('top'))});connection.checkAndCreateIntersectionsWithAll();}}else{connection.setSegmentColor(connection.originalSegmentColor,false).setSegmentStyle(connection.originalSegmentStyle,false);connection.setSegmentMoveHandlers();connection.checkAndCreateIntersectionsWithAll();}}}}else{for(i=0;i<customShape.ports.getSize();i+=1){port=customShape.ports.get(i);connection=port.connection;shape1=connection.srcPort.parent;shape2=connection.destPort.parent;port.setPosition(port.x,port.y);if(customShape.canvas.sharedConnections.find('id',connection.getID())){if(connection.srcPort.parent.getID()===customShape.getID()){connection.checkAndCreateIntersectionsWithAll();}}else{connection.setSegmentColor(connection.originalSegmentColor,false).setSegmentStyle(connection.originalSegmentStyle,false).disconnect().connect();connection.setSegmentMoveHandlers();connection.checkAndCreateIntersectionsWithAll();}}}};CustomShapeDragBehavior.prototype.onDragEnd=function(customShape){var command,self=this;return function(e,ui){self.dragEndProcedure(customShape,true,e,ui);customShape.dragging=false;customShape.canvas.verticalSnapper.hide();customShape.canvas.horizontalSnapper.hide();if(!customShape.changedContainer){command=new CommandMove(customShape.canvas.currentSelection);command.execute();customShape.canvas.commandStack.add(command);} customShape.changedContainer=false;customShape.decreaseParentZIndex(customShape.oldParent);};};ResizeBehavior=function(){};ResizeBehavior.prototype.type="ResizeBehavior";ResizeBehavior.prototype.family="ResizeBehavior";ResizeBehavior.prototype.init=function(shape){var $shape=$(shape.getHTML()),shapeResizeOptions={handles:shape.getHandlesIDs(),disable:false,start:this.onResizeStart(shape),resize:this.onResize(shape),stop:this.onResizeEnd(shape)};$shape.resizable(shapeResizeOptions);$(shape.parent.getHTML()).resizable({disabled:true});this.updateResizeMinimums(shape.parent);};ResizeBehavior.prototype.onResizeStart=function(shape){};ResizeBehavior.prototype.onResize=function(shape){};ResizeBehavior.prototype.onResizeEnd=function(shape){};ResizeBehavior.prototype.updateResizeMinimums=function(shape){var minW,minH,children=shape.getChildren(),limits=children.getDimensionLimit(),margin=15,$shape=$(shape.getHTML());minW=limits[1]+margin;minH=limits[2]+margin;if(typeof $shape.resizable("instance")!='undefined'){$shape.resizable('option','minWidth',minW);$shape.resizable('option','minHeight',minH);}else{$shape.resizable({minWidth:minW,minHeight:minH});} return this;};RegularResizeBehavior=function(){};RegularResizeBehavior.prototype=new ResizeBehavior();RegularResizeBehavior.prototype.type="RegularResizeBehavior";RegularResizeBehavior.prototype.init=function(shape){var $shape=$(shape.getHTML());ResizeBehavior.prototype.init.call(this,shape);$shape.resizable('enable');shape.applyStyleToHandlers('resizableStyle');shape.showOrHideResizeHandlers(false);};RegularResizeBehavior.prototype.onResizeStart=function(shape){return function(e,ui){shape.resizing=true;shape.dragging=false;shape.oldWidth=shape.width;shape.oldHeight=shape.height;shape.oldX=shape.x;shape.oldY=shape.y;shape.oldAbsoluteX=shape.absoluteX;shape.oldAbsoluteY=shape.absoluteY;if(shape.ports){shape.initPortsChange();} if(shape.canvas.currentSelection.getSize()>1){shape.canvas.emptyCurrentSelection();shape.canvas.addToSelection(shape);} shape.showOrHideResizeHandlers(false);shape.calculateLabelsPercentage();return true;};};RegularResizeBehavior.prototype.onResize=function(shape){return function(e,ui){var i,port,canvas=shape.canvas;shape.setPosition(ui.position.left / canvas.zoomFactor,ui.position.top / canvas.zoomFactor);shape.setDimension(ui.size.width / canvas.zoomFactor,ui.size.height / canvas.zoomFactor);shape.fixConnectionsOnResize(shape.resizing,true);shape.updateLabelsPosition();};};RegularResizeBehavior.prototype.onResizeEnd=function(shape){return function(e,ui){var i,label,command;shape.resizing=false;RegularResizeBehavior.prototype.onResize.call(this,shape)(e,ui);shape.showOrHideResizeHandlers(true);shape.parent.updateDimensions(10);if(shape.ports){shape.firePortsChange();} command=new CommandResize(shape);shape.canvas.commandStack.add(command);command.execute();for(i=0;i<shape.labels.getSize();i+=1){label=shape.labels.get(i);label.setLabelPosition(label.location,label.diffX,label.diffY);} return true;};};NoResizeBehavior=function(){};NoResizeBehavior.prototype=new ResizeBehavior();NoResizeBehavior.prototype.type="NoResizeBehavior";NoResizeBehavior.prototype.init=function(shape){var $shape=$(shape.getHTML());try{$shape.resizable('destroy');}catch(e){} $shape.removeClass('ui-state-disabled');shape.applyStyleToHandlers('nonResizableStyle');shape.showOrHideResizeHandlers(false);};NoResizeBehavior.prototype.updateResizeMinimums=function(shape){};DropBehavior=function(selectors){this.selectors=selectors||[];};DropBehavior.prototype.type="DropBehavior";DropBehavior.prototype.family="DropBehavior";DropBehavior.prototype.defaultSelector="";DropBehavior.prototype.attachDropBehavior=function(shape){var $shape=$(shape.getHTML()),dropOptions={accept:this.defaultSelector,drop:this.onDrop(shape),over:this.onDragEnter(shape),out:this.onDragLeave(shape),greedy:true};$shape.droppable(dropOptions);};DropBehavior.prototype.onDragEnter=function(shape){return function(e,ui){};};DropBehavior.prototype.onDragLeave=function(shape){return function(e,ui){};};DropBehavior.prototype.onDrop=function(shape){return function(e,ui){};};DropBehavior.prototype.setSelectors=function(selectors,overwrite){var currentSelectors="",index,i;if(selectors){this.selectors=selectors;} if(!overwrite){currentSelectors=this.defaultSelector;index=0;}else if(selectors.length>0){currentSelectors=selectors[0];index=1;} for(i=index;i<selectors.length;i+=1){currentSelectors+=","+this.selectors[i];} return this;};DropBehavior.prototype.updateSelectors=function(shape,selectors){var $shape=$(shape.getHTML()),currentSelectors,i;if(selectors){this.selectors=selectors;} if(this.selectors.length>0){currentSelectors=this.selectors[0];} for(i=1;i<this.selectors.length;i+=1){currentSelectors+=','+this.selectors[i];} $shape.droppable({"accept":currentSelectors});return this;};DropBehavior.prototype.dragEnterHook=function(){return true;};DropBehavior.prototype.dragLeaveHook=function(){return true;};DropBehavior.prototype.dropStartHook=function(shape,e,ui){return true;};DropBehavior.prototype.dropHook=function(shape,e,ui){return true;};DropBehavior.prototype.dropEndHook=function(shape,e,ui){return true;};ConnectionDropBehavior=function(selectors){DropBehavior.call(this,selectors);};ConnectionDropBehavior.prototype=new DropBehavior();ConnectionDropBehavior.prototype.type="ConnectionDropBehavior";ConnectionDropBehavior.prototype.defaultSelector=".custom_shape,.port";ConnectionDropBehavior.prototype.setSelectors=function(selectors,overwrite){DropBehavior.prototype.setSelectors.call(this,selectors,overwrite);this.selectors.push(".port");this.selectors.push(".custom_shape");return this;};ConnectionDropBehavior.prototype.onDragEnter=function(shape){return function(e,ui){shape.entered=true;};};ConnectionDropBehavior.prototype.onDragLeave=function(shape){return function(e,ui){shape.entered=false;};};ConnectionDropBehavior.prototype.onDrop=function(shape){var that=this;return function(e,ui){var canvas=shape.getCanvas(),id=ui.draggable.attr('id'),x,y,currLeft,currTop,startPoint,sourceShape,sourcePort,endPort,endPortXCoord,endPortYCoord,connection,currentConnection=canvas.currentConnection,srcPort,dstPort,port,success=false,command;shape.entered=false;if(!shape.dropBehavior.dropStartHook(shape,e,ui)){return false;} if(shape.getConnectionType()==="none"){return true;} if(currentConnection){srcPort=currentConnection.srcPort;dstPort=currentConnection.destPort;if(srcPort.id===id){port=srcPort;}else if(dstPort.id===id){port=dstPort;}else{port=null;}} if(ui.helper&&ui.helper.attr('id')==="drag-helper"){startPoint=shape.canvas.connectionSegment.startPoint;sourceShape=shape.canvas.connectionSegment.pointsTo;if(sourceShape.parent&&sourceShape.parent.id===shape.id){return true;} sourceShape.setPosition(sourceShape.oldX,sourceShape.oldY);startPoint.x-=sourceShape.absoluteX;startPoint.y-=sourceShape.absoluteY;sourcePort=new Port({width:8,height:8});endPort=new Port({width:8,height:8});endPortXCoord=ui.offset.left-shape.canvas.getX()- shape.getAbsoluteX()+shape.canvas.getLeftScroll();endPortYCoord=ui.offset.top-shape.canvas.getY()- shape.getAbsoluteY()+shape.canvas.getTopScroll();sourceShape.addPort(sourcePort,startPoint.x,startPoint.y);shape.addPort(endPort,endPortXCoord,endPortYCoord,false,sourcePort);connection=new Connection({srcPort:sourcePort,destPort:endPort,canvas:shape.canvas,segmentStyle:shape.connectionType});connection.setSrcDecorator(new ConnectionDecorator({width:11,height:11,canvas:canvas,decoratorPrefix:"con_normal",decoratorType:"source",parent:connection}));connection.setDestDecorator(new ConnectionDecorator({width:11,height:11,canvas:canvas,decoratorPrefix:"con_normal",decoratorType:"target",parent:connection}));connection.canvas.commandStack.add(new CommandConnect(connection));connection.connect();connection.setSegmentMoveHandlers();canvas.addConnection(connection);connection.checkAndCreateIntersectionsWithAll();sourcePort.attachListeners(sourcePort);endPort.attachListeners(endPort);canvas.triggerCreateEvent(connection,[]);}else if(port){port.setOldParent(port.getParent());port.setOldX(port.getX());port.setOldY(port.getY());x=ui.position.left;y=ui.position.top;port.setPosition(x,y);shape.dragging=false;if(shape.getID()!==port.parent.getID()){port.parent.removePort(port);currLeft=ui.offset.left-canvas.getX()- shape.absoluteX+shape.canvas.getLeftScroll();currTop=ui.offset.top-canvas.getY()- shape.absoluteY+shape.canvas.getTopScroll();shape.addPort(port,currLeft,currTop,true);canvas.regularShapes.insert(port);}else{shape.definePortPosition(port,port.getPoint(true));} port.connection.connect();canvas.triggerPortChangeEvent(port);port.connection.disconnect();command=new CommandReconnect(port);port.canvas.commandStack.add(command);} return false;};};NoDropBehavior=function(selectors){DropBehavior.call(this,selectors);};NoDropBehavior.prototype=new DropBehavior();NoDropBehavior.prototype.type="NoDropBehavior";NoDropBehavior.prototype.attachDropBehavior=function(shape){var $shape=$(shape.getHTML());DropBehavior.prototype.attachDropBehavior.call(this,shape);$shape.droppable('option','accept',"");};ContainerDropBehavior=function(selectors){DropBehavior.call(this,selectors);};ContainerDropBehavior.prototype=new DropBehavior();ContainerDropBehavior.prototype.type="ContainerDropBehavior";ContainerDropBehavior.prototype.defaultSelector=".custom_shape";ContainerDropBehavior.prototype.onDrop=function(shape){return function(e,ui){var customShape=null,canvas=shape.getCanvas(),selection,sibling,i,command,coordinates,id,shapesAdded=[],containerBehavior=shape.containerBehavior;if(canvas.readOnly){return false;} shape.entered=false;if(ui.helper&&ui.helper.attr('id')==="drag-helper"){return false;} id=ui.draggable.attr('id');customShape=canvas.toolBarShapeFactory(id);if(customShape===null){customShape=canvas.customShapes.find('id',id);if(!customShape||!shape.dropBehavior.dropHook(shape,e,ui)){return false;} if(!(customShape.parent&&customShape.parent.id===shape.id)){selection=canvas.currentSelection;for(i=0;i<selection.getSize();i+=1){sibling=selection.get(i);coordinates=Utils.getPointRelativeToPage(sibling);coordinates=Utils.pageCoordinatesToShapeCoordinates(shape,null,coordinates.x,coordinates.y);shapesAdded.push({shape:sibling,container:shape,x:coordinates.x,y:coordinates.y,topLeft:false});} command=new CommandSwitchContainer(shapesAdded);command.execute();canvas.commandStack.add(command);canvas.multipleDrop=true;} shape.updateDimensions(10);canvas.updatedElement=null;}else{coordinates=Utils.pageCoordinatesToShapeCoordinates(shape,e);shape.addElement(customShape,coordinates.x,coordinates.y,customShape.topLeftOnCreation);customShape.attachListeners();canvas.updatedElement=customShape;command=new CommandCreate(customShape);canvas.commandStack.add(command);command.execute();}};};ConnectionContainerDropBehavior=function(selectors){DropBehavior.call(this,selectors);};ConnectionContainerDropBehavior.prototype=new DropBehavior();ConnectionContainerDropBehavior.prototype.type="ConnectionContainerDropBehavior";ConnectionContainerDropBehavior.prototype.defaultSelector=".custom_shape,.port";ConnectionContainerDropBehavior.prototype.setSelectors=function(selectors,overwrite){DropBehavior.prototype.setSelectors.call(this,selectors,overwrite);this.selectors.push(".port");this.selectors.push(".custom_shape");return this;};ConnectionContainerDropBehavior.prototype.onDrop=function(shape){return function(e,ui){if(!ConnectionDropBehavior.prototype.onDrop.call(this,shape)(e,ui)){ContainerDropBehavior.prototype.onDrop.call(this,shape)(e,ui);}};};Color=function(red,green,blue,opacity){this.red=(!red)?0:red;this.green=(!green)?0:green;this.blue=(!blue)?0:blue;this.opacity=(!opacity)?1:opacity;};Color.prototype.type="Color";Color.GREY=new Color(192,192,192,1);Color.prototype.getRed=function(){return this.red;};Color.prototype.getGreen=function(){return this.green;};Color.prototype.getBlue=function(){return this.blue;};Color.prototype.getOpacity=function(){return this.opacity;};Color.prototype.setRed=function(newRed){if(typeof newRed==="number"&&newRed>=0&&newRed<=255){this.red=newRed;} return this;};Color.prototype.setGreen=function(newGreen){if(typeof newGreen==="number"&&newGreen>=0&&newGreen<=255){this.green=newGreen;} return this;};Color.prototype.setBlue=function(newBlue){if(typeof newBlue==="number"&&newBlue>=0&&newBlue<=255){this.blue=newBlue;} return this;};Color.prototype.setOpacity=function(newOpacity){if(typeof newOpacity==="number"&&newOpacity>=0&&newOpacity<=255){this.opacity=newOpacity;} return this;};Color.prototype.getCSS=function(){var css="rgba("+this.red+","+this.green+","+this.blue+","+this.opacity+")";return css;};Style=function(options){this.cssProperties=null;this.cssClasses=null;this.belongsTo=null;Style.prototype.initObject.call(this,options);};Style.prototype.type="Style";Style.MAX_ZINDEX=100;Style.prototype.initObject=function(options){var defaults={cssClasses:[],cssProperties:{},belongsTo:null};$.extend(true,defaults,options);this.cssClasses=defaults.cssClasses;this.cssProperties=defaults.cssProperties;this.belongsTo=defaults.belongsTo;};Style.prototype.applyStyle=function(){if(!this.belongsTo.html){throw new Error("applyStyle(): can't apply style to an"+" object with no html");} var i,class_i;$(this.belongsTo.html).css(this.cssProperties);for(i=0;i<this.cssClasses.length;i+=1){class_i=this.cssClasses[i];if(!$(this.belongsTo.html).hasClass(class_i)){$(this.belongsTo.html).addClass(class_i);}} return this;};Style.prototype.addProperties=function(properties){$.extend(true,this.cssProperties,properties);$(this.belongsTo.html).css(properties);return this;};Style.prototype.getProperty=function(property){return this.cssProperties[property]||$(this.belongsTo.html).css(property)||window.getComputedStyle(this.belongsTo.html,null).getPropertyValue(property);};Style.prototype.removeProperties=function(properties){var property,i;for(i=0;i<properties.length;i+=1){property=properties[i];if(this.cssProperties.hasOwnProperty(property)){$(this.belongsTo.html).css(property,"");delete this.cssProperties[property];}} return this;};Style.prototype.addClasses=function(cssClasses){var i,cssClass;if(cssClasses&&cssClasses instanceof Array){for(i=0;i<cssClasses.length;i+=1){cssClass=cssClasses[i];if(typeof cssClass==="string"){if(this.cssClasses.indexOf(cssClass)===-1){this.cssClasses.push(cssClass);$(this.belongsTo.html).addClass(cssClass);}}else{throw new Error("addClasses(): array element is not of type string");}}}else{throw new Error("addClasses(): parameter must be of type Array");} return this;};Style.prototype.removeClasses=function(cssClasses){var i,index,cssClass;if(cssClasses&&cssClasses instanceof Array){for(i=0;i<cssClasses.length;i+=1){cssClass=cssClasses[i];if(typeof cssClass==="string"){index=this.cssClasses.indexOf(cssClass);if(index!==-1){$(this.belongsTo.html).removeClass(this.cssClasses[index]);this.cssClasses.splice(index,1);}}else{throw new Error("removeClasses(): array element is not of "+"type string");}}}else{throw new Error("removeClasses(): parameter must be of type Array");} return this;};Style.prototype.removeAllClasses=function(){this.cssClasses=[];$(this.belongsTo.html).removeClass();return this;};Style.prototype.containsClass=function(cssClass){return this.cssClasses.indexOf(cssClass)!==-1;};Style.prototype.getClasses=function(){return this.cssClasses;};Style.prototype.stringify=function(){return{cssClasses:this.cssClasses};};JCoreObject=function(options){this.id=null;this.canvas=null;this.html=null;this.style=null;this.width=0;this.height=0;this.oldWidth=0;this.oldHeight=0;this.x=0;this.y=0;this.oldX=0;this.oldY=0;this.absoluteX=0;this.absoluteY=0;this.oldAbsoluteX=0;this.oldAbsoluteY=0;this.zoomX=0;this.zoomY=0;this.zoomWidth=0;this.zoomHeight=0;this.zOrder=1;this.visible=true;this.dragBehavior=null;this.savedOptions={};JCoreObject.prototype.initObject.call(this,options);};JCoreObject.prototype.type="JCoreObject";JCoreObject.prototype.family="CoreObject";JCoreObject.prototype.paint=function(){};JCoreObject.prototype.attachListeners=function(){};JCoreObject.prototype.initObject=function(options){var defaultOptions={id:(options&&options.id)||Utils.generateUniqueId(),style:{cssProperties:{},cssClasses:[]},width:0,height:0,x:0,y:0,zOrder:1,visible:true,canvas:null};$.extend(true,defaultOptions,options);this.setID(defaultOptions.id).setStyle(new Style({belongsTo:this,cssProperties:defaultOptions.style.cssProperties,cssClasses:defaultOptions.style.cssClasses})).setCanvas(defaultOptions.canvas).setDimension(defaultOptions.width,defaultOptions.height).setPosition(defaultOptions.x,defaultOptions.y).setZOrder(defaultOptions.zOrder).setVisible(defaultOptions.visible).setSavedOptions(defaultOptions);};JCoreObject.prototype.createHTMLDiv=function(){return document.createElement("div");};JCoreObject.prototype.createHTML=function(){if(!this.html){this.html=this.createHTMLDiv();this.html.id=this.id;this.style.applyStyle();this.style.addProperties({position:"absolute",left:this.zoomX,top:this.zoomY,width:this.zoomWidth,height:this.zoomHeight,zIndex:this.zOrder});} return this.html;};JCoreObject.prototype.setPosition=function(newX,newY){this.setX(newX);this.setY(newY);return this;};JCoreObject.prototype.setDimension=function(newWidth,newHeight){this.setWidth(newWidth);this.setHeight(newHeight);return this;};JCoreObject.prototype.setX=function(newX){if(typeof newX==="number"){newX=Math.round(newX);this.x=newX;if(this.canvas){this.zoomX=this.x*this.canvas.zoomFactor;}else{this.zoomX=this.x;} this.setAbsoluteX();if(this.html){this.style.addProperties({left:this.zoomX});}}else{throw new Error("setX : parameter newX is not a number");} return this;};JCoreObject.prototype.setY=function(newY){if(typeof newY==="number"){newY=Math.round(newY);this.y=newY;if(this.canvas){this.zoomY=this.y*this.canvas.zoomFactor;}else{this.zoomY=this.y;} this.setAbsoluteY();if(this.html){this.style.addProperties({top:this.zoomY});}} return this;};JCoreObject.prototype.setAbsoluteX=function(){if(!this.parent){this.absoluteX=this.zoomX;}else{this.absoluteX=this.zoomX+this.parent.absoluteX;} return this;};JCoreObject.prototype.setOldX=function(newX){if(typeof newX==="number"){this.oldX=newX;} return this;};JCoreObject.prototype.setOldY=function(newY){if(typeof newY==="number"){this.oldY=newY;} return this;};JCoreObject.prototype.setAbsoluteY=function(){if(!this.parent){this.absoluteY=this.zoomY;}else{this.absoluteY=this.zoomY+this.parent.absoluteY;} return this;};JCoreObject.prototype.setWidth=function(newWidth){var intPart;if(typeof newWidth==="number"&&newWidth>=0){this.width=newWidth;if(this.canvas){this.zoomWidth=this.width*this.canvas.zoomFactor;intPart=Math.floor(this.zoomWidth);this.zoomWidth=(intPart%2===0)?intPart+1:intPart;}else{this.zoomWidth=this.width;} if(this.html){this.style.addProperties({width:this.zoomWidth});}} return this;};JCoreObject.prototype.setHeight=function(newHeight){var intPart;if(typeof newHeight==="number"&&newHeight>=0){this.height=newHeight;if(this.canvas){this.zoomHeight=this.height*this.canvas.zoomFactor;intPart=Math.floor(this.zoomHeight);this.zoomHeight=(intPart%2===0)?intPart+1:intPart;}else{this.zoomHeight=this.height;} if(this.html){this.style.addProperties({height:this.zoomHeight});}} return this;};JCoreObject.prototype.setZOrder=function(newZOrder){if(typeof newZOrder==="number"&&newZOrder>0){this.zOrder=newZOrder;if(this.html){this.style.addProperties({zIndex:this.zOrder});}} return this;};JCoreObject.prototype.setCanvas=function(newCanvas){if(newCanvas&&newCanvas.family==="Canvas"){this.canvas=newCanvas;} return this;};JCoreObject.prototype.setStyle=function(newStyle){if(newStyle.type&&newStyle.type==="Style"){this.style=newStyle;} return this;};JCoreObject.prototype.setVisible=function(newVisible){if(typeof newVisible==="boolean"){this.visible=newVisible;if(this.html){if(newVisible){this.style.addProperties({display:"inline"});}else{this.style.addProperties({display:"none"});}}} return this;};JCoreObject.prototype.setID=function(newID){this.id=newID;if(this.html){this.html.id=this.id;} return this;};JCoreObject.prototype.getID=function(){return this.id;};JCoreObject.prototype.getHTML=function(){if(this.html===null){return this.createHTML();} return this.html;};JCoreObject.prototype.getZOrder=function(){return this.zOrder;};JCoreObject.prototype.getCanvas=function(){return this.canvas;};JCoreObject.prototype.getWidth=function(){return this.width;};JCoreObject.prototype.getHeight=function(){return this.height;};JCoreObject.prototype.getX=function(){return this.x;};JCoreObject.prototype.getY=function(){return this.y;};JCoreObject.prototype.getAbsoluteX=function(){return this.absoluteX;};JCoreObject.prototype.getAbsoluteY=function(){return this.absoluteY;};JCoreObject.prototype.getStyle=function(){return this.style;};JCoreObject.prototype.getVisible=function(){return this.visible;};JCoreObject.prototype.getZoomX=function(){return this.zoomX;};JCoreObject.prototype.getZoomY=function(){return this.zoomY;};JCoreObject.prototype.getZoomWidth=function(){return this.zoomWidth;};JCoreObject.prototype.getZoomHeight=function(){return this.zoomHeight;};JCoreObject.prototype.getOldX=function(){return this.oldX;};JCoreObject.prototype.getOldY=function(){return this.oldY;};JCoreObject.prototype.getOldWidth=function(){return this.oldWidth;};JCoreObject.prototype.getOldHeight=function(){return this.oldHeight;};JCoreObject.prototype.setSavedOptions=function(options){this.savedOptions=options;return this;};JCoreObject.prototype.stringify=function(){return{id:this.getID(),x:this.getX(),y:this.getY(),width:this.getWidth(),height:this.getHeight(),type:this.type,style:this.getStyle().stringify(),drag:this.savedOptions.drag};};JCoreObject.prototype.parseJSON=function(json){this.initObject(json);};JCoreObject.prototype.TOP=0;JCoreObject.prototype.RIGHT=1;JCoreObject.prototype.BOTTOM=2;JCoreObject.prototype.LEFT=3;JCoreObject.prototype.HORIZONTAL=0;JCoreObject.prototype.VERTICAL=1;JCoreObject.prototype.ZOOMSCALES=5;Handler=function(options){JCoreObject.call(this,options);this.representation=null;this.parent=null;this.color=null;this.orientation=null;};Handler.prototype=new JCoreObject();Handler.prototype.setParent=function(newParent){this.parent=newParent;return this;};Handler.prototype.getParent=function(){return this.parent;};Handler.prototype.setRepresentation=function(representation){this.representation=representation;return this;};Handler.prototype.getRepresentation=function(){return this.representation;};Handler.prototype.setOrientation=function(newOrientation){this.orientation=newOrientation;return this;};Handler.prototype.getOrientation=function(){return this.orientation;};Handler.prototype.paint=function(){this.representation.paint.call(this);this.style.applyStyle();return this;};Handler.prototype.setColor=function(newColor){this.color=newColor;return this;};Handler.prototype.getColor=function(){return this.color;};ResizeHandler=function(options){Handler.call(this,options);this.category=null;this.visible=false;this.resizableStyle=null;this.nonResizableStyle=null;ResizeHandler.prototype.initObject.call(this,options);};ResizeHandler.prototype=new Handler();ResizeHandler.prototype.type="ResizeHandler";ResizeHandler.prototype.initObject=function(options){var defaults={width:4,height:4,parent:null,orientation:null,representation:null,resizableStyle:{},nonResizableStyle:{},zOrder:2};$.extend(true,defaults,options);if(defaults.resizableStyle.cssProperties){defaults.resizableStyle.cssProperties.zIndex=defaults.zOrder;} if(defaults.nonResizableStyle.cssProperties){defaults.nonResizableStyle.cssProperties.zIndex=defaults.zOrder;} this.setParent(defaults.parent).setWidth(defaults.width).setHeight(defaults.height).setOrientation(defaults.orientation).setRepresentation(defaults.representation).setResizableStyle(defaults.resizableStyle).setNonResizableStyle(defaults.nonResizableStyle);this.id=defaults.orientation+defaults.parent.id+"resizehandler";};ResizeHandler.prototype.setParent=function(newParent){this.parent=newParent;return this;};ResizeHandler.prototype.getParent=function(){return this.parent;};ResizeHandler.prototype.paint=function(){if(!this.html){throw new Error("paint(): This handler has no html");} Handler.prototype.paint.call(this);this.setVisible(this.visible);return this;};ResizeHandler.prototype.setCategory=function(newCategory){if(typeof newCategory==="string"){this.category=newCategory;} if(this.category==="resizable"){this.color=new Color(0,255,0);this.style.addClasses(["ui-resizable-handle","ui-resizable-"+this.orientation]);}else{this.color=new Color(255,255,255);this.style.removeClasses(["ui-resizable-handle","ui-resizable-"+this.orientation]);} return this;};ResizeHandler.prototype.setResizableStyle=function(style){this.resizableStyle=new Style({belongsTo:this,cssProperties:style.cssProperties,cssClasses:style.cssClasses});return this;};ResizeHandler.prototype.setNonResizableStyle=function(style){this.nonResizableStyle=new Style({belongsTo:this,cssProperties:style.cssProperties,cssClasses:style.cssClasses});return this;};SegmentMoveHandler=function(options){Handler.call(this,options);this.orientation=null;this.visible=false;this.zOrder=2;SegmentMoveHandler.prototype.initObject.call(this,options);};SegmentMoveHandler.prototype=new Handler();SegmentMoveHandler.prototype.type="SegmentMoveHandler";SegmentMoveHandler.prototype.initObject=function(options){var defaults={width:4,height:4,parent:null,orientation:null,representation:new Rectangle(),color:new Color(0,255,0)};$.extend(true,defaults,options);this.setWidth(defaults.width).setHeight(defaults.height).setParent(defaults.parent).setColor(defaults.color).setOrientation(defaults.orientation).setRepresentation(defaults.representation);};SegmentMoveHandler.prototype.paint=function(){Handler.prototype.paint.call(this);this.setVisible(this.visible);return this;};SegmentMoveHandler.prototype.attachListeners=function(handler){var $handler=$(handler.html);$handler.on('click',handler.onClick(handler));$handler.on('mousedown',handler.onMouseDown(handler));$handler.draggable({start:handler.onDragStart(handler),drag:handler.onDrag(handler),stop:handler.onDragEnd(handler),axis:(handler.orientation===handler.HORIZONTAL)?"y":"x"});return this;};SegmentMoveHandler.prototype.onMouseDown=function(handler){return function(e,ui){handler.parent.parent.canvas.draggingASegmentHandler=true;};};SegmentMoveHandler.prototype.onClick=function(handler){return function(e,ui){e.stopPropagation();};};SegmentMoveHandler.prototype.onDragStart=function(handler){return function(e,ui){var parentSegment=handler.parent,segment,connection=parentSegment.getParent(),i;connection.savePoints({saveToOldPoints:true});for(i=0;i<parentSegment.parent.lineSegments.getSize();i+=1){segment=parentSegment.parent.lineSegments.get(i);segment.clearIntersections();} parentSegment.parent.clearAllIntersections();e.stopPropagation();};};SegmentMoveHandler.prototype.onDrag=function(handler){return function(e,ui){var parentSegment=handler.parent;parentSegment.moveSegment(ui.position.left,ui.position.top);};};SegmentMoveHandler.prototype.onDragEnd=function(handler){return function(e,ui){var parentSegment=handler.parent,connection=parentSegment.getParent(),canvas=connection.canvas,command;canvas.draggingASegmentHandler=false;handler.onDrag(handler)(e,ui);connection.savePoints();command=new CommandSegmentMove(connection,{oldPoints:connection.getOldPoints(),newPoints:connection.getPoints()});command.execute();canvas.commandStack.add(command);};};Port=function(options){JCoreObject.call(this);this.connection=null;this.representation=null;this.parent=null;this.oldParent=null;this.direction=null;this.percentage=null;this.zOrder=1;this.defaultZOrder=1;this.realX=0;this.realY=0;this.dragging=false;Port.prototype.initObject.call(this,options);};Port.prototype=new JCoreObject();Port.prototype.TOWARDS_CENTER=5;Port.prototype.type="Port";Port.prototype.initObject=function(options){var defaults={width:8,height:8,visible:false,parent:null};$.extend(true,defaults,options);$.extend(true,defaults,{representation:new Oval({width:defaults.width,height:defaults.height,center:new Point(0,0),visible:true})});this.setVisible(defaults.visible).setParent(defaults.parent).setDimension(defaults.width,defaults.height).setRepresentation(defaults.representation);};Port.prototype.createHTML=function(){JCoreObject.prototype.createHTML.call(this);this.html.style.background='red';this.html.style.borderRadius='1em';this.html.style.MozBorderRadius='1em';this.style.addClasses(["port"]);return this.html;};Port.prototype.applyBorderMargin=function(positive){var factor=(positive)?1:-1;this.x+=factor*this.parent.border[this.direction].x;this.y+=factor*this.parent.border[this.direction].y;this.zoomX=this.x;this.zoomY=this.y;this.setAbsoluteX();this.setAbsoluteY();if(this.html){this.style.addProperties({left:this.zoomX,top:this.zoomY});} return this;};Port.prototype.setX=function(newX){this.x=newX;this.zoomX=this.x;if(this.canvas){this.realX=this.x / this.canvas.zoomFactor;}else{this.realX=this.x;} this.setAbsoluteX();if(this.html){this.style.addProperties({left:this.zoomX});} return this;};Port.prototype.setY=function(newY){this.y=newY;this.zoomY=this.y;this.setAbsoluteY();if(this.canvas){this.realY=this.y / this.canvas.zoomFactor;}else{this.realY=this.y;} if(this.html){this.style.addProperties({top:this.zoomY});} return this;};Port.prototype.setWidth=function(newWidth){this.width=newWidth;this.zoomWidth=this.width;if(this.html){this.style.addProperties({width:this.zoomWidth});} return this;};Port.prototype.setHeight=function(newHeight){this.height=newHeight;this.zoomHeight=this.height;if(this.html){this.style.addProperties({height:this.zoomHeight});} return this;};Port.prototype.paint=function(){this.setVisible(this.visible);this.style.applyStyle();return this;};Port.prototype.repaint=function(port){port.style.addProperties({left:port.x,top:port.y});port.connection.disconnect();port.connection.connect();port.connection.setSegmentMoveHandlers();port.connection.checkAndCreateIntersectionsWithAll();return this;};Port.prototype.onDragStart=function(port,otherPort){return function(e,ui){port.dragging=true;port.setColor('#40CA09');port.connection.disconnect();return true;};};Port.prototype.onDrag=function(port,endPoint,otherPort,canvas){return function(e,ui){if(canvas.connectionSegment){$(canvas.connectionSegment.getHTML()).remove();} endPoint.x=e.pageX-canvas.getX()+canvas.getLeftScroll();endPoint.y=e.pageY-canvas.getY()+canvas.getTopScroll();canvas.connectionSegment=new Segment({startPoint:otherPort.getPoint(false),endPoint:endPoint,parent:canvas});canvas.connectionSegment.pointsTo=port;canvas.connectionSegment.createHTML();canvas.connectionSegment.paint();};};Port.prototype.onDragEnd=function(port,otherPort,canvas){return function(e,ui){if(canvas.connectionSegment){$(canvas.connectionSegment.getHTML()).remove();} port.repaint(port);port.connection.showPortsAndHandlers();canvas.currentConnection=port.connection;port.dragging=false;port.setColor('red');};};Port.prototype.determinePercentage=function(){var shapeDimension,portDimension;if(!this.parent){return false;} if(this.direction===this.TOP||this.direction===this.BOTTOM){shapeDimension=this.parent.getZoomWidth();portDimension=this.x;}else{shapeDimension=this.parent.getZoomHeight();portDimension=this.y;} this.percentage=Math.round((portDimension / shapeDimension)*100.0);return true;};Port.prototype.show=function(){this.visible=true;this.paint();this.html.style.zIndex=3;return this;};Port.prototype.hide=function(){this.visible=false;this.paint();this.html.style.zIndex=1;return this;};Port.prototype.saveAndDestroy=function(){this.parent.removePort(this);this.html=$(this.html).detach()[0];return this;};Port.prototype.attachListeners=function(currPort){var otherPort,portDragOptions;otherPort=currPort.connection.srcPort.getPoint(false).equals(currPort.getPoint(false))?currPort.connection.destPort:currPort.connection.srcPort;portDragOptions={start:currPort.onDragStart(currPort,otherPort),drag:currPort.onDrag(currPort,currPort.getPoint(false),otherPort,currPort.parent.canvas),stop:currPort.onDragEnd(currPort,otherPort,currPort.parent.canvas)};$(currPort.html).draggable(portDragOptions);$(currPort.html).mouseover(function(){currPort.setColor('#40CA09');$(currPort.html).css('cursor','Move');});$(currPort.html).mouseleave(function(){if(!currPort.dragging){currPort.setColor('red');}});return currPort;};Port.prototype.setColor=function(newColor){this.html.style.background=newColor;return this;};Port.prototype.moveTowardsTheCenter=function(reverse){var towardsCenterDistance=Port.prototype.TOWARDS_CENTER,dx=[0,-towardsCenterDistance,0,towardsCenterDistance],dy=[towardsCenterDistance,0,-towardsCenterDistance,0],multiplier=1;if(reverse){multiplier=-1;} this.setPosition(this.x+dx[this.direction]*multiplier,this.y+dy[this.direction]*multiplier);return this;};Port.prototype.setDirection=function(newDirection){if(newDirection>=0&&newDirection<4){this.direction=newDirection;}else{throw new Error("setDirection(): parameter '"+newDirection+"'is not valid");} return this;};Port.prototype.getDirection=function(){return this.direction;};Port.prototype.setParent=function(newParent,triggerChange){if(this.canvas&&triggerChange){this.canvas.updatedElement={"id":this.id,"type":this.type,"fields":[{"field":"parent","oldVal":this.parent,"newVal":newParent}]};$(this.canvas.html).trigger("changeelement");} this.parent=newParent;return this;};Port.prototype.getParent=function(){return this.parent;};Port.prototype.setOldParent=function(parent){this.oldParent=parent;return this;};Port.prototype.getOldParent=function(){return this.oldParent;};Port.prototype.setConnection=function(newConn){if(newConn&&newConn.family==="Connection"){this.connection=newConn;}else{throw new Error("setConnection(): parameter is not valid");} return this;};Port.prototype.getConnection=function(){return this.connection;};Port.prototype.getRepresentation=function(){return this.representation;};Port.prototype.setRepresentation=function(newRep){if(newRep instanceof RegularShape){this.representation=newRep;}else{throw new Error("setRepresentation(): parameter must be an instance"+" of any regularShape");} return this;};Port.prototype.getPoint=function(relativeToShape){var border=parseInt(this.parent.style.getProperty('border'),10)||0;if(relativeToShape){return new Point(this.getX()+Math.round(this.getWidth()/ 2),this.getY()+Math.round(this.getHeight()/ 2));} return new Point(this.getAbsoluteX()+Math.round(this.getWidth()/ 2),this.getAbsoluteY()+Math.round(this.getHeight()/ 2));};Port.prototype.getPercentage=function(){return this.percentage;};Port.prototype.stringify=function(){var inheritedJSON={},thisJSON={x:this.getX(),y:this.getY(),realX:this.realX,realY:this.realY,parent:this.getParent().getID()};$.extend(true,inheritedJSON,thisJSON);return inheritedJSON;};Router=function(){JCoreObject.call(this);};Router.prototype=new JCoreObject();Router.prototype.type="Router";Router.prototype.createRoute=function(){return true;};ManhattanConnectionRouter=function(){Router.call(this);this.mindist=20;};ManhattanConnectionRouter.prototype=new Router();ManhattanConnectionRouter.prototype.type="ManhattanConnectionRouter";ManhattanConnectionRouter.prototype.createRoute=function(connection){var fromPt,fromDir,toPt,toDir,points=[];fromPt=connection.srcPort.getPoint(false);fromDir=connection.srcPort.direction;toPt=connection.destPort.getPoint(false);toDir=connection.destPort.direction;this.route(connection,toPt,toDir,fromPt,fromDir,points);return points;};ManhattanConnectionRouter.prototype.route=function(conn,fromPt,fromDir,toPt,toDir,points){var PORT=(['UP','RIGHT','DOWN','LEFT']);var SEGMENT,newPointA,newPointB,findPoint;var findAuxPoint,thor=false,thor2=false;newPointB=fromPt;newPointA=toPt;SEGMENT=this.getSegment2(fromDir,toDir,fromPt,toPt,PORT);points.push(toPt);if(SEGMENT==1){points.push(fromPt);return;} do{if(SEGMENT===5){var dirAux;if(toDir===0){findPoint=new Point(newPointA.x,newPointA.y-this.mindist);if(findPoint.x-newPointB.x<0){dirAux=1;} else{dirAux=3;}} if(toDir===1){findPoint=new Point(newPointA.x+this.mindist,newPointA.y);if(findPoint.y-newPointB.y<0){dirAux=2;} else{dirAux=0;}} if(toDir===2){findPoint=new Point(newPointA.x,newPointA.y+this.mindist);if(findPoint.x-newPointB.x<0){dirAux=1;} else{dirAux=3;}} if(toDir===3){findPoint=new Point(newPointA.x-this.mindist,newPointA.y);if(findPoint.y-newPointB.y>0){dirAux=0;} else{dirAux=2;}} newPointA=findPoint;thor2=true;toDir=dirAux;} if(SEGMENT===4){var dirAux;if(fromDir===0){findPoint=new Point(newPointB.x,newPointB.y-this.mindist);if(findPoint.x-newPointA.x<0){dirAux=1;} else{dirAux=3;}} if(fromDir===1){findPoint=new Point(newPointB.x+this.mindist,newPointB.y);if(findPoint.y-newPointA.y>0){dirAux=0;} else{dirAux=2;}} if(fromDir===2){findPoint=new Point(newPointB.x,newPointB.y+this.mindist);if(findPoint.x-newPointA.x<0){dirAux=1;} else{dirAux=3;}} if(fromDir===3){findPoint=new Point(newPointB.x-this.mindist,newPointB.y);if(findPoint.y-newPointA.y<0){dirAux=2;} else{dirAux=0;}} newPointB=findPoint;findAuxPoint=true;fromDir=dirAux;} if(SEGMENT===3){var etx=0;var ety=0;if(newPointA.y<newPointB.y){etx=this.positive(newPointA.y-newPointB.y);} if(newPointA.x<newPointB.x){ety=this.positive(newPointA.x-newPointB.x);} if(toDir===0){if(toDir===0&&fromDir===0){if(newPointA.y<newPointB.y){findPoint=new Point(newPointA.x,newPointA.y-this.mindist);} else{etx=this.positive(newPointA.y-newPointB.y);findPoint=new Point(newPointA.x,newPointA.y-(this.mindist+etx));}}else{var newAux=0;newAux=(newPointA.y+newPointB.y)/2;findPoint=new Point(newPointA.x,newAux);}} if(toDir===1){if(toDir===1&&fromDir===1){findPoint=new Point(newPointA.x+(this.mindist+ety),newPointA.y);}else{var newAux=0;newAux=(newPointA.x+newPointB.x)/2;findPoint=new Point(newAux,newPointA.y);}} if(toDir===2){if(toDir===2&&fromDir===2){findPoint=new Point(newPointA.x,newPointA.y+(this.mindist+etx));}else{var newAux=0;newAux=(newPointA.y+newPointB.y)/2;findPoint=new Point(newPointA.x,newAux);}} if(toDir===3){if(toDir===3&&fromDir===3){if(newPointA.x<newPointB.x){findPoint=new Point(newPointA.x-this.mindist,newPointA.y);} else{ety=this.positive(newPointA.x-newPointB.x);findPoint=new Point(newPointA.x-(this.mindist+ety),newPointA.y);}}else{var newAux=0;newAux=(newPointA.x+newPointB.x)/2;findPoint=new Point(newAux,newPointA.y);}} newPointA=findPoint;}else if(SEGMENT==2){if(thor==false){if(fromDir===0||fromDir===2){findPoint=new Point(newPointB.x,newPointA.y);}else if(fromDir===1||fromDir===3){findPoint=new Point(newPointA.x,newPointB.y);}}else{if(fromDir===0||fromDir===2){if(newPointA.x<newPointB.x&&newPointA.y>newPointB.y){if(fromDir===2){findPoint=new Point(newPointB.x,newPointA.y);}else{findPoint=new Point(newPointA.x,newPointB.y);}}else{findPoint=new Point(newPointB.x,newPointA.y);}}else if(fromDir===1||fromDir===3){if(newPointA.x-newPointB.x>newPointA.y-newPointB.y){findPoint=new Point(newPointA.x,newPointB.y);}else{findPoint=new Point(newPointA.x,newPointB.y);}}}} SEGMENT--;if(!findAuxPoint){points.push(findPoint);}else{findAuxPoint=false;thor=true;}}while(SEGMENT>1);if(thor){points.push(newPointB);} points.push(fromPt);return;};ManhattanConnectionRouter.prototype.getSegment2=function(fromDir,toDir,fromPt,toPt,PORT){if(fromDir===toDir){return 3;}else{if((0===fromDir&&2===toDir)&&(fromPt.x===toPt.x&&fromPt.y>toPt.y)){return 1;}else if((1===fromDir&&3===toDir)&&(fromPt.x<toPt.x&&fromPt.y===toPt.y)){return 1;}else if((2===fromDir&&0===toDir)&&(fromPt.x===toPt.x&&fromPt.y<toPt.y)){return 1;}else if((3===fromDir&&1===toDir)&&(fromPt.x>toPt.x&&fromPt.y===toPt.y)){return 1;}else if(1===fromDir&&0===toDir){if(fromPt.x<toPt.x&&fromPt.y<toPt.y){return 2;}else{return 4;}}else if(0===fromDir&&1===toDir){if(fromPt.x<toPt.x||fromPt.y<toPt.y){return 4;}else{return 2;}}else if(2===fromDir&&0===toDir){if(fromPt.y<toPt.y){return 3;}else{return 5;}}else if(0===fromDir&&2===toDir){if(fromPt.y>toPt.y){return 3;}else{return 5;}}else if(3===fromDir&&0===toDir){if(fromPt.x>toPt.x&&fromPt.y<toPt.y){return 2;}else{return 4;}}else if(0===fromDir&&3===toDir){if(fromPt.x<toPt.x&&fromPt.y>toPt.y){return 2;}else{return 4;}}else if(2===fromDir&&1===toDir){if((fromPt.x<toPt.x&&fromPt.y<toPt.y)||fromPt.y>toPt.y){return 4;}else{return 2;}}else if(1===fromDir&&2===toDir){if(fromPt.x<toPt.x&&fromPt.y>toPt.y){return 2;}else{return 4;}}else if(3===fromDir&&1===toDir){if(fromPt.x<toPt.x){return 5;}else{return 3;}}else if(1===fromDir&&3===toDir){if(fromPt.x>toPt.x){return 5;}else{return 3;}}else if(3===fromDir&&2===toDir){if((fromPt.x<toPt.x&&fromPt.y>toPt.y)||fromPt.y<toPt.y){return 4;}else{return 2;}}else if(2===fromDir&&3===toDir){if(fromPt.x<toPt.x&&fromPt.y<toPt.y){return 2;}else{return 4;}}else{this.getSegment2(toDir,fromDir,fromPt,toPt,PORT);}}};ManhattanConnectionRouter.prototype.positive=function(num){if(num<0){num*=-1;} return num;};ConnectionDecorator=function(options){JCoreObject.call(this,options);this.parent=null;this.decoratorType=null;this.decoratorPrefix=null;this.spriteDirection={'0':'top','1':'right','2':'bottom','3':'left'};this.height=11;this.width=11;this.separator=null;this.sprite=null;this.cssClass=null;ConnectionDecorator.prototype.initObject.call(this,options);};ConnectionDecorator.prototype=new JCoreObject();ConnectionDecorator.prototype.type="ConnectionDecorator";ConnectionDecorator.prototype.initObject=function(options){var defaults={sprite:'bpmn_zoom',decoratorPrefix:'',separator:'_',decoratorType:'target',parent:null};$.extend(true,defaults,options);this.setDecoratorType(defaults.decoratorType).setDecoratorPrefix(defaults.decoratorPrefix).setSeparator(defaults.separator).setSprite(defaults.sprite).setParent(defaults.parent).setCssClass('');};ConnectionDecorator.prototype.paint=function(){var point,canvas,direction,port,topStyle,leftStyle;if(this.decoratorType==="source"){port=this.parent.getSrcPort();}else{port=this.parent.getDestPort();} point=port.getPoint(false);direction=port.getDirection();canvas=port.canvas;topStyle=[point.y-this.zoomHeight,point.y-Math.round(this.zoomHeight / 2),point.y,point.y-Math.round(this.zoomHeight / 2)];leftStyle=[point.x-Math.round(this.zoomWidth / 2)+1,point.x,point.x-Math.round(this.zoomWidth / 2)+1,point.x-this.zoomWidth];if(this.getHTML()===null){this.createHTML();} if(this.decoratorType===null){this.html=null;return this;} this.style.removeClasses([this.cssClass]);this.setCssClass([this.prefix,parseInt(canvas.zoomFactor*100,10),this.decoratorType,this.spriteDirection[direction]].join(this.separator));this.style.addClasses([this.sprite,this.getCssClass()]);this.style.addProperties({top:topStyle[direction],left:leftStyle[direction]});this.parent.html.appendChild(this.html);return this;};ConnectionDecorator.prototype.createHTML=function(){this.html=document.createElement('div');this.html.id=this.id;this.style.applyStyle();this.style.addProperties({position:"absolute",left:0,top:0,height:this.zoomHeight,width:this.zoomWidth,zIndex:Style.MAX_ZINDEX});return this.html;};ConnectionDecorator.prototype.attachListeners=function(){var $connectionDecorator;$connectionDecorator=$(this.getHTML()).click(this.onClick(this));$connectionDecorator.on("mousedown",this.onMouseDown(this));return this;};ConnectionDecorator.prototype.applyZoom=function(){this.setDimension(this.width,this.height);return this;};ConnectionDecorator.prototype.onMouseDown=function(decorator){return function(e,ui){e.preventDefault();if(e.which===3){decorator.parent.canvas.updatedElement=decorator.parent;$(decorator.parent.canvas.html).trigger("rightclick");} e.stopPropagation();};};ConnectionDecorator.prototype.onClick=function(decorator){return function(e,ui){var connection=decorator.parent,oldConnection=decorator.parent.canvas.currentConnection,canvas=connection.canvas;canvas.emptyCurrentSelection();if(oldConnection){oldConnection.hidePortsAndHandlers();} connection.showPortsAndHandlers();canvas.currentConnection=connection;e.stopPropagation();};};ConnectionDecorator.prototype.stringify=function(){var inheritedJSON={},thisJSON={decoratorType:this.getDecoratorType(),decoratorPrefix:this.getDecoratorPrefix()};$.extend(true,inheritedJSON,thisJSON);return inheritedJSON;};ConnectionDecorator.prototype.getDecoratorType=function(){return this.decoratorType;};ConnectionDecorator.prototype.setDecoratorType=function(newType){this.decoratorType=newType;return this;};ConnectionDecorator.prototype.getDecoratorPrefix=function(){return this.prefix;};ConnectionDecorator.prototype.setDecoratorPrefix=function(newType){this.prefix=newType;return this;};ConnectionDecorator.prototype.setParent=function(newParent){this.parent=newParent;return this;};ConnectionDecorator.prototype.getParent=function(){return this.parent;};ConnectionDecorator.prototype.setSeparator=function(newSeparator){this.separator=newSeparator;return this;};ConnectionDecorator.prototype.setSprite=function(newSprite){this.sprite=newSprite;return this;};ConnectionDecorator.prototype.getSeparator=function(){return this.separator;};ConnectionDecorator.prototype.setCssClass=function(newCssClass){this.cssClass=newCssClass;return this;};ConnectionDecorator.prototype.getCssClass=function(){return this.cssClass;};Connection=function(options){JCoreObject.call(this,options);this.srcPort=null;this.destPort=null;this.srcDecorator=null;this.destDecorator=null;this.lineSegments=new ArrayList();this.points=[];this.oldPoints=[];this.segmentStyle=null;this.originalSegmentStyle=null;this.segmentColor=null;this.originalSegmentColor=null;this.defaultZOrder=2;this.zOrder=2;this.intersectionWith=new ArrayList();Connection.prototype.initObject.call(this,options);};Connection.prototype=new JCoreObject();Connection.prototype.type="Connection";Connection.prototype.family="Connection";Connection.prototype.router=new ManhattanConnectionRouter();Connection.prototype.initObject=function(options){var defaultOptions={srcPort:new Port(),destPort:new Port(),segmentColor:new Color(0,0,0),segmentStyle:"regular"};$.extend(true,defaultOptions,options);this.setSrcPort(defaultOptions.srcPort).setDestPort(defaultOptions.destPort).setSegmentStyle(defaultOptions.segmentStyle,false).setSegmentColor(defaultOptions.segmentColor,false);this.originalSegmentStyle=defaultOptions.segmentStyle;this.originalSegmentColor=defaultOptions.segmentColor;this.getSrcPort().setConnection(this);this.getDestPort().setConnection(this);};Connection.prototype.createHTML=function(){this.html=document.createElement('div');this.html.id=this.id;this.style.addProperties({position:"absolute",left:0,top:0,height:0,width:0,zIndex:this.zOrder});return this.html;};Connection.prototype.setSegmentMoveHandlers=function(){var i,currentSegment,orientationOptions=[this.HORIZONTAL,this.VERTICAL],segmentOrientation=(this.destPort.direction===this.TOP||this.destPort.direction===this.BOTTOM)?1:0;for(i=this.lineSegments.getSize()-1;i>=0;i-=1){currentSegment=this.lineSegments.get(i);currentSegment.orientation=orientationOptions[segmentOrientation];currentSegment.hasMoveHandler=false;if(i<this.lineSegments.getSize()-1&&i>0){currentSegment.nextNeighbor=this.lineSegments.get(i+1);currentSegment.previousNeighbor=this.lineSegments.get(i-1);currentSegment.hasMoveHandler=true;currentSegment.addSegmentMoveHandler();} segmentOrientation=1-segmentOrientation;} return this;};Connection.prototype.removeAllSegmentHandlers=function(){var segment,i;for(i=0;i<this.lineSegments.getSize();i+=1){segment=this.lineSegments.get(i);if(segment.hasMoveHandler){$(segment.moveHandler.html).remove();}} return this;};Connection.prototype.showMoveHandlers=function(){var i,currentHandler;for(i=0;i<this.lineSegments.getSize();i+=1){currentHandler=this.lineSegments.get(i).moveHandler;if(currentHandler){currentHandler.setVisible(true);}} return this;};Connection.prototype.hideMoveHandlers=function(){var i,currentHandler;for(i=0;i<this.lineSegments.getSize();i+=1){currentHandler=this.lineSegments.get(i).moveHandler;if(currentHandler){currentHandler.setVisible(false);}} return this;};Connection.prototype.hidePortsAndHandlers=function(){this.hidePorts();this.hideMoveHandlers();return this;};Connection.prototype.showPortsAndHandlers=function(){this.showPorts();this.showMoveHandlers();return this;};Connection.prototype.paint=function(options){var defaults={algorithm:'manhattan',points:[],dx:0,dy:0};$.extend(true,defaults,options);try{if(this.html===null){this.createHTML();} $(this.html).empty();this.oldPoint=null;switch(defaults.algorithm){case'manhattan':this.createManhattanRoute();break;case'user':this.createUserDefinedRoute(defaults.points,defaults.dx,defaults.dy);break;default:throw new Error('Connection.paint(): the algorithm provided '+'is not correct');} this.style.applyStyle();this.style.addProperties({top:0,left:0});if(this.destDecorator!==null){this.destDecorator.paint();this.destDecorator.attachListeners();} if(this.srcDecorator!==null){this.srcDecorator.paint();} this.oldPoint=null;}catch(e){console.log(e.message);} return this;};Connection.prototype.disconnect=function(savePoints){this.clearAllIntersections();this.hideMoveHandlers();if(savePoints){this.savePoints();} this.lineSegments.clear();$(this.html).empty();return this;};Connection.prototype.connect=function(options){this.paint(options);return this;};Connection.prototype.hidePorts=function(){this.srcPort.hide();this.destPort.hide();return this;};Connection.prototype.showPorts=function(){this.srcPort.show();this.destPort.show();return this;};Connection.prototype.savePoints=function(options){var i,segment,point,arrayChosen='points',defaults={saveToOldPoints:false};$.extend(true,defaults,options);if(defaults.saveToOldPoints){arrayChosen="oldPoints";} this[arrayChosen]=[];for(i=0;i<this.lineSegments.getSize();i+=1){segment=this.lineSegments.get(i);if(i===0){this[arrayChosen].push(new Point(segment.startPoint.x,segment.startPoint.y));} this[arrayChosen].push(new Point(segment.endPoint.x,segment.endPoint.y));} return this;};Connection.prototype.createUserDefinedRoute=function(points,dx,dy){var i,segment,diffPoint=new Point(dx,dy);for(i=1;i<points.length;i+=1){segment=new Segment({startPoint:new Point(parseInt(points[i-1].x,10),parseInt(points[i-1].y,10)).add(diffPoint),endPoint:new Point(parseInt(points[i].x,10),parseInt(points[i].y,10)).add(diffPoint),parent:this,canvas:this.canvas,color:this.segmentColor});this.addSegment(segment);} return this;};Connection.prototype.createManhattanRoute=function(){var points=this.router.createRoute(this),i,segment;for(i=1;i<points.length;i+=1){segment=new Segment({startPoint:new Point(parseInt(points[i-1].x,10),parseInt(points[i-1].y,10)),endPoint:new Point(parseInt(points[i].x,10),parseInt(points[i].y,10)),parent:this,canvas:this.canvas,color:this.segmentColor});this.addSegment(segment);} return this;};Connection.prototype.addSegment=function(segment){segment.setStyle(this.segmentStyle);segment.paint();this.lineSegments.insert(segment);return this;};Connection.prototype.saveAndDestroy=function(){if(this.canvas.currentConnection){this.hidePortsAndHandlers();this.canvas.currentConnection=null;} this.canvas.removeConnection(this);this.srcPort.saveAndDestroy();this.destPort.saveAndDestroy();this.html=$(this.html).detach()[0];return this;};Connection.prototype.fixZIndex=function(){var sourceShape=this.srcPort.parent,destShape=this.destPort.parent,sourceShapeParent,destShapeParent,sourceShapeParentZIndex,destShapeParentZIndex;if(sourceShape.parent){sourceShapeParent=sourceShape.parent;}else{sourceShapeParent=sourceShape.canvas;} sourceShapeParentZIndex=Math.min(sourceShapeParent.getZOrder(),sourceShape.getZOrder()-1);if(destShape.parent){destShapeParent=destShape.parent;}else{destShapeParent=destShape.canvas;} destShapeParentZIndex=Math.min(destShapeParent.getZOrder(),destShape.getZOrder()-1);this.setZOrder(Math.max(sourceShapeParentZIndex,destShapeParentZIndex)+ 2);return this;};Connection.prototype.checkAndCreateIntersections=function(otherConnection){var i,j,segment,testingSegment,hasAtLeastOneIntersection=false,ip;for(i=0;i<this.lineSegments.getSize();i+=1){segment=this.lineSegments.get(i);for(j=0;j<otherConnection.lineSegments.getSize();j+=1){testingSegment=otherConnection.lineSegments.get(j);ip=Geometry.perpendicularSegmentIntersection(segment.startPoint,segment.endPoint,testingSegment.startPoint,testingSegment.endPoint);if(ip){hasAtLeastOneIntersection=true;segment.createIntersectionWith(testingSegment,ip);}}} if(hasAtLeastOneIntersection){if(!this.intersectionWith.find('id',otherConnection.getID())){this.intersectionWith.insert(otherConnection);} if(!otherConnection.intersectionWith.find('id',this.getID())){otherConnection.intersectionWith.insert(this);}} return hasAtLeastOneIntersection;};Connection.prototype.checkAndCreateIntersectionsWithAll=function(){var i,otherConnection,segment;for(i=0;i<this.canvas.connections.getSize();i+=1){otherConnection=this.canvas.connections.get(i);if(otherConnection.getID()!==this.getID()){this.checkAndCreateIntersections(otherConnection);}} for(i=0;i<this.lineSegments.getSize();i+=1){segment=this.lineSegments.get(i);if(segment.intersections.getSize()){segment.paintWithIntersections();}} return this;};Connection.prototype.clearIntersectionsWith=function(otherConnection){var i,segment,intersectionObject,intersectionWasErased;for(i=0;i<this.lineSegments.getSize();i+=1){intersectionWasErased=false;segment=this.lineSegments.get(i);while(true){intersectionObject=segment.intersections.find('idOtherConnection',otherConnection.getID());if(intersectionObject){segment.intersections.remove(intersectionObject);intersectionObject.destroy();}else{break;} intersectionWasErased=true;} if(intersectionWasErased){segment.paintWithIntersections();}} this.intersectionWith.remove(otherConnection);otherConnection.intersectionWith.remove(this);return this;};Connection.prototype.clearAllIntersections=function(){var otherIntersection;while(this.intersectionWith.getSize()>0){otherIntersection=this.intersectionWith.get(0);otherIntersection.clearIntersectionsWith(this);} return this;};Connection.prototype.move=function(dx,dy){var top,left;top=parseFloat(this.html.style.top);left=parseFloat(this.html.style.left);$(this.html).css({'top':top+dy,'left':left+dx});return this;};Connection.prototype.stringify=function(){return{segmentStyle:this.getSegmentStyle(),srcPort:this.getSrcPort().stringify(),destPort:this.getDestPort().stringify(),state:this.savePoints()&&this.points,srcDecoratorPrefix:this.getSrcDecorator().getDecoratorPrefix(),destDecoratorPrefix:this.getDestDecorator().getDecoratorPrefix()};};Connection.prototype.setSegmentColor=function(newColor,repaint){var i,segment;this.segmentColor=newColor;if(this.html&&repaint){for(i=0;i<this.lineSegments.getSize();i+=1){segment=this.lineSegments.get(i);segment.setColor(this.segmentColor);segment.paint();}} return this;};Connection.prototype.getSegmentColor=function(){return this.segmentColor;};Connection.prototype.setSegmentStyle=function(newStyle,repaint){var i,segment;this.segmentStyle=newStyle;if(this.html&&repaint){for(i=0;i<this.lineSegments.getSize();i+=1){segment=this.lineSegments.get(i);segment.setStyle(this.segmentStyle);segment.paint();}} return this;};Connection.prototype.getSegmentStyle=function(){return this.segmentStyle;};Connection.prototype.setSrcPort=function(newSrcPort){this.srcPort=newSrcPort;return this;};Connection.prototype.getSrcPort=function(){return this.srcPort;};Connection.prototype.setDestPort=function(newDestPort){this.destPort=newDestPort;return this;};Connection.prototype.getDestPort=function(){return this.destPort;};Connection.prototype.getSrcDecorator=function(){return this.srcDecorator;};Connection.prototype.getDestDecorator=function(){return this.destDecorator;};Connection.prototype.getLineSegments=function(){return this.lineSegments;};Connection.prototype.setSrcDecorator=function(newDecorator){if(newDecorator.type==='ConnectionDecorator'){this.srcDecorator=newDecorator;} return this;};Connection.prototype.setDestDecorator=function(newDecorator){if(newDecorator.type==='ConnectionDecorator'){this.destDecorator=newDecorator;} return this;};Connection.prototype.getZOrder=function(){return Shape.prototype.getZOrder.call(this);};Connection.prototype.getOldPoints=function(){return this.oldPoints;};Connection.prototype.getPoints=function(){return this.points;};BehavioralElement=function(options){JCoreObject.call(this,options);this.containerBehavior=null;this.dropBehavior=null;this.children=null;BehavioralElement.prototype.initObject.call(this,options);};BehavioralElement.prototype=new JCoreObject();BehavioralElement.prototype.type="BehavioralElement";BehavioralElement.prototype.noDropBehavior=null;BehavioralElement.prototype.containerDropBehavior=null;BehavioralElement.prototype.connectionDropBehavior=null;BehavioralElement.prototype.connectionContainerDropBehavior=null;BehavioralElement.prototype.noContainerBehavior=null;BehavioralElement.prototype.regularContainerBehavior=null;BehavioralElement.prototype.initObject=function(options){var defaults={drop:{type:"nodrop",selectors:[],overwrite:false},container:"nocontainer"};$.extend(true,defaults,options);this.setDropBehavior(defaults.drop.type,defaults.drop.selectors,defaults.drop.overwrite);this.setContainerBehavior(defaults.container);this.children=new ArrayList();};BehavioralElement.prototype.dropBehaviorFactory=function(type,selectors){if(type==="nodrop"){if(!this.noDropBehavior){this.noDropBehavior=new NoDropBehavior(selectors);} return this.noDropBehavior;} if(type==="container"){if(!this.containerDropBehavior){this.containerDropBehavior=new ContainerDropBehavior(selectors);} return this.containerDropBehavior;} if(type==="connection"){if(!this.connectionDropBehavior){this.connectionDropBehavior=new ConnectionDropBehavior(selectors);} return this.connectionDropBehavior;} if(type==="connectioncontainer"){if(!this.connectionContainerDropBehavior){this.connectionContainerDropBehavior=new ConnectionContainerDropBehavior(selectors);} return this.connectionContainerDropBehavior;}};BehavioralElement.prototype.containerBehaviorFactory=function(type){if(type==="regular"){if(!this.regularContainerBehavior){this.regularContainerBehavior=new RegularContainerBehavior();} return this.regularContainerBehavior;} if(!this.noContainerBehavior){this.noContainerBehavior=new NoContainerBehavior();} return this.noContainerBehavior;};BehavioralElement.prototype.updateChildrenPosition=function(diffX,diffY){var children=this.getChildren(),child,i,updatedChildren=[],previousValues=[],newValues=[];for(i=0;i<children.getSize();i+=1){child=children.get(i);if((diffX!==0||diffY!==0)&&!this.canvas.currentSelection.contains(child)){updatedChildren.push(child);previousValues.push({x:child.x,y:child.y});newValues.push({x:child.x+diffX,y:child.y+diffY});} child.setPosition(child.x+diffX,child.y+diffY);} if(updatedChildren.length>0){this.canvas.triggerPositionChangeEvent(updatedChildren,previousValues,newValues);} return this;};BehavioralElement.prototype.isContainer=function(){return this.containerBehavior&&this.containerBehavior.type!=="NoContainerBehavior";};BehavioralElement.prototype.setContainerBehavior=function(behavior){$.extend(true,this.savedOptions,{container:behavior});this.containerBehavior=this.containerBehaviorFactory(behavior);return this;};BehavioralElement.prototype.addElement=function(shape,x,y,topLeftCorner){this.containerBehavior.addToContainer(this,shape,x,y,topLeftCorner);return this;};BehavioralElement.prototype.removeElement=function(shape){this.containerBehavior.removeFromContainer(shape);return this;};BehavioralElement.prototype.swapElementContainer=function(shape,otherContainer,x,y,topLeftCorner){var newX=!x?shape.getX():x,newY=!y?shape.getY():y;shape.changedContainer=true;this.removeElement(shape);otherContainer.addElement(shape,newX,newY,topLeftCorner);return this;};BehavioralElement.prototype.getChildren=function(){return this.children;};BehavioralElement.prototype.updateDimensions=function(margin){if(this.family!=='Canvas'){this.updateSize(margin);this.refreshConnections();ResizeBehavior.prototype.updateResizeMinimums(this);BehavioralElement.prototype.updateDimensions.call(this.parent,margin);} return this;};BehavioralElement.prototype.setDropBehavior=function(behavior,selectors,overwrite){this.dropBehavior=this.dropBehaviorFactory(behavior,selectors);this.dropBehavior.setSelectors(selectors,overwrite);if(this.html&&this.dropBehavior){this.dropBehavior.attachDropBehavior(this);$.extend(true,this.savedOptions.drop,{type:behavior,overwrite:overwrite});if(selectors&&selectors.hasOwnProperty('length')){this.dropBehavior.updateSelectors(this,selectors,overwrite);$.extend(true,this.savedOptions.drop,{selectors:selectors});}} return this;};BehavioralElement.prototype.setDropAcceptedSelectors=function(selectors,overwrite){if(selectors&&selectors.hasOwnProperty('length')){this.dropBehavior.updateSelectors(this,selectors,overwrite);} return this;};BehavioralElement.prototype.updateBehaviors=function(){if(this.dropBehavior){this.dropBehavior.attachDropBehavior(this);this.dropBehavior.updateSelectors(this);} return this;};BehavioralElement.prototype.stringify=function(){var inheritedJSON=JCoreObject.prototype.stringify.call(this),thisJSON={container:this.savedOptions.container,drop:this.savedOptions.drop};$.extend(true,inheritedJSON,thisJSON);return inheritedJSON;};Layer=function(options){JCoreObject.call(this,options);this.layerName=null;this.priority=null;this.parent=null;this.visible=null;this.currentZoomClass="";this.zoomSprites=[];Layer.prototype.initObject.call(this,options);};Layer.prototype=new JCoreObject();Layer.prototype.type="Layer";Layer.prototype.initObject=function(options){var defaults={x:0,y:0,parent:null,layerName:"defaultLayerName",priority:0,visible:true,zoomSprites:["","","","",""]};$.extend(true,defaults,options);this.setParent(defaults.parent).setPosition(defaults.x,defaults.y).setLayerName(defaults.layerName).setPriority(defaults.priority).setVisible(defaults.visible).setZoomSprites(defaults.zoomSprites).setProperties();};Layer.prototype.applyZoom=function(){this.setProperties();};Layer.prototype.comparisonFunction=function(layer1,layer2){return layer1.priority>layer2.priority;};Layer.prototype.createHTML=function(modifying){this.setProperties();JCoreObject.prototype.createHTML.call(this,modifying);return this.html;};Layer.prototype.paint=function(){var $layer=$(this.html),newSprite;this.style.removeClasses([this.currentZoomClass]);newSprite=this.zoomSprites[this.canvas.zoomPropertiesIndex];this.style.addClasses([newSprite]);this.currentZoomClass=newSprite;this.style.applyStyle();return this;};Layer.prototype.setProperties=function(){if(!this.parent){return this;} this.id=this.parent.getID()+"Layer-"+this.layerName;this.setDimension(this.parent.getWidth(),this.parent.getHeight());this.canvas=this.parent.canvas;return this;};Layer.prototype.getLayerName=function(){return this.layerName;};Layer.prototype.getPriority=function(){return this.priority;};Layer.prototype.setLayerName=function(newLayerName){if(typeof newLayerName==="string"&&newLayerName!==""){this.layerName=newLayerName;} return this;};Layer.prototype.setPriority=function(newPriority){if(typeof newPriority==="number"){this.priority=newPriority;} return this;};Layer.prototype.setParent=function(newParent){if(newParent){this.parent=newParent;} return this;};Layer.prototype.getParent=function(){return this.parent;};Layer.prototype.setZoomSprites=function(zoomSprites){var i;this.zoomSprites=["","","","",""];for(i=0;i<zoomSprites.length;i+=1){this.zoomSprites[i]=zoomSprites[i];} return this;};Layer.prototype.stringify=function(){var inheritedJSON={},thisJSON={id:this.getID(),x:this.getX(),y:this.getY(),layerName:this.getLayerName(),priority:this.getPriority(),style:{cssClasses:this.style.getClasses()},zoomSprites:this.zoomSprites};$.extend(true,inheritedJSON,thisJSON);return inheritedJSON;};Shape=function(options){this.xCorners=[0,0,0,0];this.yCorners=[0,0,0,0];this.xMidPoints=[0,0,0,0];this.yMidPoints=[0,0,0,0];this.cornerResizeHandlers=new ArrayList();this.midResizeHandlers=new ArrayList();BehavioralElement.call(this,options);this.center=null;this.parent=null;this.oldParent=null;this.defaultZOrder=1;this.dragging=false;this.wasDragged=false;this.entered=false;this.resizeBehavior=null;this.resizing=false;this.repainted=false;this.fixed=true;this.changedContainer=false;this.topLeftOnCreation=false;Shape.prototype.initObject.call(this,options);};Shape.prototype=new BehavioralElement();Shape.prototype.type="Shape";Shape.prototype.family="Shape";Shape.prototype.noDragBehavior=null;Shape.prototype.regularDragBehavior=null;Shape.prototype.connectionDragBehavior=null;Shape.prototype.customShapeDragBehavior=null;Shape.prototype.cornersIdentifiers=['nw','ne','se','sw'];Shape.prototype.midPointIdentifiers=['n','e','s','w'];Shape.prototype.MAX_ZINDEX=100;Shape.prototype.DEFAULT_RADIUS=6;Shape.prototype.initObject=function(options){var defaults={topLeft:false,resizeBehavior:"no",resizeHandlers:{type:"None",total:4,resizableStyle:{cssProperties:{'background-color':"rgb(0, 255, 0)",'border':'1px solid black'}},nonResizableStyle:{cssProperties:{'background-color':"white",'border':'1px solid black'}}},drag:"disabled"};$.extend(true,defaults,options);this.resizeBehavior=this.resizeBehaviorFactory(defaults.resizeBehavior);if(defaults.drag!=="disabled"){this.setDragBehavior(defaults.drag);} this.createHandlers(defaults.resizeHandlers.type,defaults.resizeHandlers.total,defaults.resizeHandlers.resizableStyle,defaults.resizeHandlers.nonResizableStyle);this.topLeftOnCreation=defaults.topLeft;};Shape.prototype.createHandlers=function(type,number,resizableStyle,nonResizableStyle){if(type==="Rectangle"){var i;if(!number||(number!==8&&number!==4&&number!==0)){number=4;} for(i=0;i<number&&i<4;i+=1){this.cornerResizeHandlers.insert(new ResizeHandler({parent:this,zOrder:Style.MAX_ZINDEX+3,representation:new Rectangle(),orientation:this.cornersIdentifiers[i],resizableStyle:resizableStyle,nonResizableStyle:nonResizableStyle}));} number-=4;for(i=0;i<number;i+=1){this.midResizeHandlers.insert(new ResizeHandler({parent:this,zOrder:Style.MAX_ZINDEX+3,representation:new Rectangle(),orientation:this.midPointIdentifiers[i],resizableStyle:resizableStyle,nonResizableStyle:nonResizableStyle}));}} return this;};Shape.prototype.updateHandlers=function(){var handler,i;for(i=0;i<this.cornerResizeHandlers.getSize();i+=1){handler=this.cornerResizeHandlers.get(i);handler.setPosition(this.xCorners[i]- Math.round(handler.width / 2)-1,this.yCorners[i]-Math.round(handler.height / 2)-1);} for(i=0;i<this.midResizeHandlers.getSize();i+=1){handler=this.midResizeHandlers.get(i);handler.setPosition(this.xMidPoints[i]- Math.round(handler.width / 2)-1,this.yMidPoints[i]-Math.round(handler.height / 2)-1);} return this;};Shape.prototype.showOrHideResizeHandlers=function(visible){var i;if(!visible){visible=false;} for(i=0;i<this.cornerResizeHandlers.getSize();i+=1){this.cornerResizeHandlers.get(i).setVisible(visible);} for(i=0;i<this.midResizeHandlers.getSize();i+=1){this.midResizeHandlers.get(i).setVisible(visible);} return this;};Shape.prototype.applyStyleToHandlers=function(styleType){var i;for(i=0;i<this.cornerResizeHandlers.getSize();i+=1){this.cornerResizeHandlers.get(i)[styleType].applyStyle();} for(i=0;i<this.midResizeHandlers.getSize();i+=1){this.midResizeHandlers.get(i)[styleType].applyStyle();} return this;};Shape.prototype.attachListeners=function(){var $shape=$(this.html);$shape.on("mousedown",this.onMouseDown(this));$shape.on("mouseup",this.onMouseUp(this));$shape.on("click",this.onClick(this));this.updateBehaviors();return this;};Shape.prototype.onMouseDown=function(shape){return function(e,ui){};};Shape.prototype.onMouseUp=function(shape){return function(e,ui){};};Shape.prototype.onClick=function(shape){return function(e,ui){};};Shape.prototype.createHTML=function(){var i;BehavioralElement.prototype.createHTML.call(this);for(i=0;i<this.cornerResizeHandlers.getSize();i+=1){this.addResizeHandler(this.cornerResizeHandlers.get(i),this.xCorners[i],this.yCorners[i]);} for(i=0;i<this.midResizeHandlers.getSize();i+=1){this.addResizeHandler(this.midResizeHandlers.get(i),this.xMidPoints[i],this.yMidPoints[i]);} return this.html;};Shape.prototype.dragBehaviorFactory=function(type){if(type==="regular"){if(!this.regularDragBehavior){this.regularDragBehavior=new RegularDragBehavior();} return this.regularDragBehavior;} if(type==="connection"){if(!this.connectionDragBehavior){this.connectionDragBehavior=new ConnectionDragBehavior();} return this.connectionDragBehavior;} if(type==="customshapedrag"){if(!this.customShapeDragBehavior){this.customShapeDragBehavior=new CustomShapeDragBehavior();} return this.customShapeDragBehavior;} if(!this.noDragBehavior){this.noDragBehavior=new NoDragBehavior();} return this.noDragBehavior;};Shape.prototype.isDraggable=function(){return this.dragBehavior&&this.dragBehavior.type!=="NoDragBehavior";};Shape.prototype.setDragBehavior=function(behavior){this.dragBehavior=this.dragBehaviorFactory(behavior);if(this.html&&this.dragBehavior){this.dragBehavior.attachDragBehavior(this);} return this;};Shape.prototype.updateBehaviors=function(){BehavioralElement.prototype.updateBehaviors.call(this);if(this.dragBehavior){this.dragBehavior.attachDragBehavior(this);} if(this.resizeBehavior){this.resizeBehavior.init(this);} return this;};Shape.prototype.addResizeHandler=function(resizeHandler,x,y){if(!this.html){return;} this.html.appendChild(resizeHandler.getHTML());resizeHandler.setPosition(x-Math.round(resizeHandler.width / 2)-1,y-Math.round(resizeHandler.height / 2)-1);resizeHandler.setCategory("resizable");return this;};Shape.prototype.paint=function(){var i,styleToApply;for(i=0;i<this.cornerResizeHandlers.getSize();i+=1){this.cornerResizeHandlers.get(i).paint();} for(i=0;i<this.midResizeHandlers.getSize();i+=1){this.midResizeHandlers.get(i).paint();} if(this.resizeBehavior){styleToApply=this.resizeBehavior.type==="NoResizeBehavior"?"nonResizableStyle":"resizableStyle";this.applyStyleToHandlers(styleToApply);} return this;};Shape.prototype.updateHTML=function(){return this;};Shape.prototype.saveAndDestroy=function(){this.html=$(this.html).detach()[0];this.canvas.removeFromList(this);return this;};Shape.prototype.updateSize=function(newMargin){var children=this.children,limits=children.getDimensionLimit(),left=limits[3],top=limits[0],right=limits[1],bottom=limits[2],newLeft=this.getX(),newTop=this.getY(),newWidth=this.getWidth(),newHeight=this.getHeight(),margin,diffX=0,diffY=0,positionShift=false,dimensionIncrement=false;if(newMargin!=="undefined"){margin=newMargin;}else{margin=15;} if(left<0){diffX=margin-left;positionShift=true;this.oldX=this.x;this.oldAbsoluteX=this.x;this.oldY=this.y;this.oldAbsoluteY=this.absoluteY;} if(top<0){diffY=margin-top;positionShift=true;this.oldX=this.x;this.oldAbsoluteX=this.x;this.oldY=this.y;this.oldAbsoluteY=this.absoluteY;} newLeft-=diffX;newTop-=diffY;newWidth+=diffX;newHeight+=diffY;if(right>this.width){newWidth+=right-this.width+margin;dimensionIncrement=true;this.oldWidth=this.width;} if(bottom>this.height){newHeight+=bottom-this.height+margin;dimensionIncrement=true;this.oldHeight=this.height;} this.setPosition(newLeft,newTop);this.setDimension(newWidth,newHeight);if(positionShift){this.changePosition(this.oldX,this.oldY,this.absoluteX,this.absoluteY);} if(dimensionIncrement){this.changeSize(this.oldWidth,this.oldHeight);} this.updateChildrenPosition(diffX,diffY);return this;};Shape.prototype.applyZoom=function(){this.refreshShape();return this;};Shape.prototype.setDimension=function(width,height){BehavioralElement.prototype.setDimension.call(this,width,height);if(this.xCorners){this.xCorners=[0,Math.round(this.zoomWidth),Math.round(this.zoomWidth),0];this.yCorners=[0,0,Math.round(this.zoomHeight),Math.round(this.zoomHeight)];this.xMidPoints=[Math.round(this.zoomWidth / 2),Math.round(this.zoomWidth),Math.round(this.zoomWidth / 2),0];this.yMidPoints=[0,Math.round(this.zoomHeight / 2),Math.round(this.zoomHeight),Math.round(this.zoomHeight / 2)];this.updateHandlers();} return this;};Shape.prototype.changeParent=function(oldX,oldY,oldAbsoluteX,oldAbsoluteY,oldParent,canvas){var fields=[{"field":"x","oldVal":oldX,"newVal":this.x},{"field":"y","oldVal":oldY,"newVal":this.y},{"field":"absoluteX","oldVal":oldAbsoluteX,"newVal":this.absoluteX},{"field":"absoluteY","oldVal":oldAbsoluteY,"newVal":this.absoluteY},{"field":"parent","oldVal":oldParent,"newVal":this.parent}];canvas.updatedElement={"id":this.id,"type":this.type,"fields":fields,"relatedObject":this};$(canvas.html).trigger("changeelement");return this;};Shape.prototype.changeSize=function(oldWidth,oldHeight){var canvas=this.canvas,fields=[{"field":"width","oldVal":oldWidth,"newVal":this.width},{"field":"height","oldVal":oldHeight,"newVal":this.height}];canvas.updatedElement={"id":this.id,"type":this.type,"fields":fields,"relatedObject":this};$(canvas.html).trigger("changeelement");return this;};Shape.prototype.changePosition=function(oldX,oldY,oldAbsoluteX,oldAbsoluteY){var canvas=this.canvas,fields=[{"field":"x","oldVal":oldX,"newVal":this.x},{"field":"y","oldVal":oldY,"newVal":this.y}];canvas.updatedElement=[{"id":this.id,"type":this.type,"fields":fields,"relatedObject":this}];$(canvas.html).trigger("changeelement");return this;};Shape.prototype.setFixed=function(fixed){if(typeof fixed==="boolean"){this.fixed=fixed;} return this;};Shape.prototype.fixZIndex=function(shape,value){var i,anotherShape,port,srcShape,destShape,srcShapeZIndex,destShapeZIndex,parentZIndex;parentZIndex=shape.parent.html.style.zIndex;shape.setZOrder(parseInt(parentZIndex,10)+value+parseInt(shape.defaultZOrder,10));for(i=0;i<shape.children.getSize();i+=1){anotherShape=shape.children.get(i);anotherShape.fixZIndex(anotherShape,0);} if(shape.ports){for(i=0;i<shape.ports.getSize();i+=1){port=shape.ports.get(i);srcShape=port.connection.srcPort.parent;destShape=port.connection.destPort.parent;srcShapeZIndex=parseInt(srcShape.html.style.zIndex,10);destShapeZIndex=parseInt(destShape.html.style.zIndex,10);port.connection.style.addProperties({zIndex:Math.max(srcShapeZIndex+1,destShapeZIndex+1)});}} return this;};Shape.prototype.increaseZIndex=function(){this.fixZIndex(this,Style.MAX_ZINDEX);return this;};Shape.prototype.decreaseZIndex=function(){this.fixZIndex(this,0);return this;};Shape.prototype.increaseParentZIndex=function(shape){if(shape.family!=="Canvas"){shape.style.addProperties({zIndex:parseInt(shape.html.style.zIndex,10)+1});shape.increaseParentZIndex(shape.parent);} return this;};Shape.prototype.decreaseParentZIndex=function(shape){if(shape&&shape.family!=="Canvas"){shape.style.addProperties({zIndex:parseInt(shape.html.style.zIndex,10)-1});shape.decreaseParentZIndex(shape.parent);} return this;};Shape.prototype.resizeBehaviorFactory=function(type){if(type==="NoResize"||type==="no"){return new NoResizeBehavior();} if(type==="Resize"||type==="yes"){return new RegularResizeBehavior();} throw new Error("resizeBehaviorFactory(): parameter is not valid");};Shape.prototype.setResizeBehavior=function(behavior){if(this.html&&behavior){this.resizeBehavior=this.resizeBehaviorFactory(behavior);this.resizeBehavior.init(this);} return this;};Shape.prototype.isResizable=function(){return this.resizeBehavior&&this.resizeBehavior.type!=="NoResizeBehavior";};Shape.prototype.refreshShape=function(){this.setPosition(this.x,this.y).setDimension(this.width,this.height);return this;};Shape.prototype.refreshConnections=function(){return this;};Shape.prototype.refreshChildrenPositions=function(onCommand){var i,children=this.children,child,relatedShapes=[],coordinates=[];for(i=0;i<children.getSize();i+=1){child=children.get(i);child.setPosition(child.getX(),child.getY());if(onCommand){child.refreshConnections(false);} relatedShapes.push(child);coordinates.push({x:child.getX(),y:child.getY()});child.refreshChildrenPositions(onCommand);} this.canvas.triggerPositionChangeEvent(relatedShapes,coordinates,coordinates);return this;};Shape.prototype.fixConnectionsOnResize=function(resizing,root){var i,port,child,connection,zoomFactor=this.canvas.zoomFactor;if(root){if(this.ports){for(i=0;i<this.ports.getSize();i+=1){port=this.ports.get(i);connection=port.connection;this.recalculatePortPosition(port);connection.disconnect().connect();if(!this.resizing){connection.setSegmentMoveHandlers();connection.checkAndCreateIntersectionsWithAll();}}}}else{if(this.ports){for(i=0;i<this.ports.getSize();i+=1){port=this.ports.get(i);connection=port.connection;port.setPosition(port.x,port.y);connection.disconnect().connect();if(!this.resizing){connection.setSegmentMoveHandlers();connection.checkAndCreateIntersectionsWithAll();}}}} for(i=0;i<this.children.getSize();i+=1){child=this.children.get(i);child.setPosition(child.x,child.y);child.fixConnectionsOnResize(child.resizing,false);} return this;};Shape.prototype.stringify=function(){var inheritedJSON=BehavioralElement.prototype.stringify.call(this),type=(this.savedOptions.resizeHandlers&&this.savedOptions.resizeHandlers.type)||'Rectangle',total=(this.savedOptions.resizeHandlers&&this.savedOptions.resizeHandlers.total)||4,thisJSON={resizeBehavior:this.savedOptions.resizeBehavior,resizeHandlers:{type:type,total:total}};$.extend(true,inheritedJSON,thisJSON);return inheritedJSON;};Shape.prototype.setCenter=function(newCenter){if(newCenter instanceof Point){this.center=newCenter;}else{throw new Error("setCenter(): argument is not an instance of Point");} return this;};Shape.prototype.setParent=function(newParent,triggerChange){if(newParent){if(this.canvas&&triggerChange){this.canvas.updatedElement={"id":this.id,"type":this.type,"fields":[{"field":"parent","oldVal":this.parent,"newVal":newParent}]};$(this.canvas.html).trigger("changeelement");} this.parent=newParent;} return this;};Shape.prototype.setOldParent=function(oldParent){this.oldParent=oldParent;return this;};Shape.prototype.getCenter=function(){return this.center;};Shape.prototype.getParent=function(){return this.parent;};Shape.prototype.getOldParent=function(){return this.oldParent;};Shape.prototype.getHandlesIDs=function(){var handlesObject={},i;for(i=0;i<this.midPointIdentifiers.length;i+=1){handlesObject[this.midPointIdentifiers[i]]='#'+ this.midPointIdentifiers[i]+this.id+'resizehandler';} for(i=0;i<this.cornersIdentifiers.length;i+=1){handlesObject[this.cornersIdentifiers[i]]='#'+ this.cornersIdentifiers[i]+this.id+'resizehandler';} return handlesObject;};Label=function(options){Shape.call(this,options);this.xPercentage=0;this.yPercentage=0;this.message="";this.orientation="";this.text=null;this.updateParent=false;this.overflow=false;this.onFocus=false;this.location="";this.diffX=0;this.diffY=0;this.fontSizeOnZoom=[];this.fontSize=0;this.textField=null;Label.prototype.initObject.call(this,options);};Label.prototype=new Shape();Label.prototype.type="Label";Label.prototype.lineHeight=20;Label.prototype.initObject=function(options){var defaults={message:"New Label",orientation:"horizontal",fontFamily:"arial",size:0,position:{location:"none",diffX:0,diffY:0},overflow:false,updateParent:false,parent:null,updateParentOnLoad:true};this.fontSizeOnZoom=[6,8,10,13,15];$.extend(true,defaults,options);this.setMessage(defaults.message).setOverflow(defaults.overflow).setUpdateParent(defaults.updateParent).setOrientation(defaults.orientation).setFontFamily(defaults.fontFamily).setFontSize(defaults.size).setParent(defaults.parent).updateDimension().setLabelPosition(defaults.position.location,defaults.position.diffX,defaults.position.diffY).setUpdateParentOnLoad(defaults.updateParentOnLoad);};Label.prototype.attachListeners=function(){var $label=$(this.html);if(!this.html){return this;} Shape.prototype.attachListeners.call(this);$(this.textField).on("keydown",function(e){e.stopPropagation();});$label.on("dblclick",this.onDblClick(this));return this;};Label.prototype.createHTML=function(){Shape.prototype.createHTML.call(this);this.html.style.textAlign="center";this.html.style.align="center";this.html.style.fontFamily=this.fontFamily;this.html.style.fontSize=this.fontSize+"pt";this.textField=document.createElement("input");this.textField.style.width="200px";this.textField.style.position="absolute";this.textField.style.display="none";this.text=document.createElement("span");this.text.style.width="auto";this.text.style.height="auto";this.text.style.lineHeight=this.lineHeight*this.canvas.zoomFactor+"px";this.text.textContent=this.message;this.html.appendChild(this.text);this.html.appendChild(this.textField);this.html.style.zIndex=2;return this.html;};Label.prototype.paint=function(){var $label=$(this.text);this.text.style.lineHeight=this.lineHeight*this.canvas.zoomFactor+"px";this.textField.value=this.message;this.text.textContent=this.message;this.html.style.verticalAlign="middle";if(this.overflow){this.html.style.overflow="hidden";}else{this.html.style.overflow="none";} this.displayText(true);if(this.orientation==="vertical"){$label.addClass('rotateText');}else{$label.removeClass('rotateText');} return this;};Label.prototype.displayText=function(display){if(display){this.text.style.display="block";this.textField.style.display="none";if(this.orientation==="vertical"){this.textField.style.left="0px";}}else{this.textField.style.display="block";if(this.orientation==="vertical"){this.textField.style.left=this.width / 2-100+"px";} this.text.style.display="none";} return this;};Label.prototype.setMessage=function(newMessage){this.message=newMessage;if(this.text){this.text.textContent=this.message;} return this;};Label.prototype.getMessage=function(){return this.message;};Label.prototype.setOrientation=function(newOrientation){var $label;this.orientation=newOrientation;if(!this.html){return this;} $label=$(this.text);if(newOrientation==="vertical"){$label.addClass("rotateText");}else{$label.removeClass("rotateText");} return this;};Label.prototype.getOrientation=function(){return this.orientation;};Label.prototype.setFontFamily=function(newFontFamily){this.fontFamily=newFontFamily;if(this.html){this.html.style.fontFamily=this.fontFamily;} return this;};Label.prototype.setFontSize=function(newFontSize){if(newFontSize===0){this.fontSize=this.getZoomFontSize();}else{this.fontSize=newFontSize;} if(this.html){this.html.style.fontSize=this.fontSize+"pt";} return this;};Label.prototype.setUpdateParent=function(newUpdateParent){this.updateParent=newUpdateParent;return this;};Label.prototype.setOverflow=function(newOverflow){this.overflow=newOverflow;return this;};Label.prototype.setLabelPosition=function(position,diffX,diffY){var x,y,i,width=this.zoomWidth,height=this.zoomHeight,parent=this.parent,parentWidth,parentHeight,zoomFactor=this.canvas.zoomFactor,bottomHeightFactor=4*zoomFactor,positionString=['top-left','top','top-right','center-left','center','center-right','bottom-left','bottom','bottom-right'],orientation,orientationIndex=(this.orientation==="vertical")?1:0,positionCoordinates;if(!position||position===""){position="top-left";} if(diffX===undefined||diffX===null){diffX=0;} if(diffY===undefined||diffY===null){diffY=0;} if(parent&&parent.family!=="Canvas"){parentWidth=parent.getZoomWidth();parentHeight=parent.getZoomHeight();orientation=[{x:width / 2,y:0},{x:0,y:height / 2}];positionCoordinates=[{x:-width / 2,y:0},{x:parentWidth / 2-width / 2,y:0},{x:parentWidth-width / 2,y:0},{x:-width / 2,y:parentHeight / 2-height / 2},{x:parentWidth / 2-width / 2,y:parentHeight / 2-height / 2},{x:parentWidth-width,y:parentHeight / 2-height / 2},{x:-width / 2,y:parentHeight-bottomHeightFactor},{x:parentWidth / 2-width / 2,y:parentHeight-bottomHeightFactor},{x:parentWidth-width / 2,y:parentHeight-bottomHeightFactor}];for(i=0;i<9;i+=1){if(position===positionString[i]){this.setPosition(positionCoordinates[i].x / zoomFactor+diffX,positionCoordinates[i].y / zoomFactor+diffY);break;}}} this.location=position;this.diffX=diffX;this.diffY=diffY;return this;};Label.prototype.setUpdateParentOnLoad=function(value){this.updateParentOnLoad=value;return this;};Label.prototype.getFocus=function(){var $textField=$(this.textField.html);this.displayText(false);this.canvas.currentLabel=this;$($textField).select();this.onFocus=true;return this;};Label.prototype.loseFocus=function(){var command;this.canvas.currentLabel=null;if(this.textField.value!==this.message){command=new CommandEditLabel(this,this.textField.value);command.execute();this.canvas.commandStack.add(command);this.setLabelPosition(this.location,this.diffX,this.diffY);} this.paint();this.onFocus=false;return this;};Label.prototype.onMouseDown=function(label){return function(e,ui){if(label.parent.family==="Canvas"){e.stopPropagation();}};};Label.prototype.onClick=function(label){return function(e,ui){if(label.parent.family==="Canvas"){e.stopPropagation();} if(label.onFocus){e.stopPropagation();}};};Label.prototype.onDblClick=function(label){return function(e,ui){var canvas=label.getCanvas(),$label=$(label.html);if(canvas.currentLabel){canvas.currentLabel.loseFocus();} label.getFocus();};};Label.prototype.getZoomFontSize=function(){var canvas=this.canvas;this.fontSize=this.fontSizeOnZoom[canvas.zoomPropertiesIndex];return this.fontSize;};Label.prototype.parseMessage=function(){var i,start=0,result=[],word;while(this.message.charAt(start)===' '){start+=1;} word=0;for(i=start;i<this.message.length;i+=1){if(this.message.charAt(i)===' '){result.push(word);word=0;}else{word+=1;}} result.push(word);return result;};Label.prototype.updateDimension=function(firstTime){var divWidth=$(this.text).width(),newWidth,newHeight;newWidth=Math.max(divWidth,this.zoomWidth);newHeight=$(this.text).height();this.setDimension(newWidth / this.canvas.zoomFactor,newHeight / this.canvas.zoomFactor);if(this.updateParent){this.updateParentDimension();} return this;};Label.prototype.applyZoom=function(){var canvas=this.canvas;this.setFontSize(0);this.paint();return this;};Label.prototype.updateParentDimension=function(){if(this.orientation==="vertical"){this.updateVertically();}else{this.updateHorizontally();} if(this.parent.html){this.parent.paint();} return this;};Label.prototype.updateVertically=function(){var margin=5,parent=this.parent,labelWidth=this.zoomWidth,newHeight,zoomFactor=this.canvas.zoomFactor;if(labelWidth>parent.zoomHeight-margin*2){newHeight=labelWidth+margin*2;}else{newHeight=parent.zoomHeight;} parent.setDimension(parent.width,newHeight / zoomFactor);parent.updateChildrenPosition(0,0);parent.refreshConnections();this.setLabelPosition(this.location,this.diffX,this.diffY);return this;};Label.prototype.updateHorizontally=function(){var margin=5,parent=this.parent,labelWidth=this.zoomWidth,labelHeight=this.zoomHeight,newWidth,newHeight,zoomFactor=this.canvas.zoomFactor;if(labelWidth>parent.zoomWidth-margin*2){newWidth=labelWidth+margin*2;}else{newWidth=parent.zoomWidth;} if(labelHeight>parent.zoomHeight-margin*2){newHeight=labelHeight+margin*2;}else{newHeight=parent.zoomHeight;} if(!this.updateParentOnLoad){this.updateParentOnLoad=true;}else{parent.setDimension(newWidth / zoomFactor,newHeight / zoomFactor);} parent.fixConnectionsOnResize(parent.resizing,true);parent.refreshConnections();this.setLabelPosition(this.location,this.diffX,this.diffY);return this;};Label.prototype.stringify=function(){var inheritedJSON={},thisJSON={id:this.getID(),message:this.getMessage(),orientation:this.getOrientation(),position:{location:this.location,diffX:this.diffX,diffY:this.diffY}};$.extend(true,inheritedJSON,thisJSON);return inheritedJSON;};CustomShape=function(options){this.layers=new ArrayList();Shape.call(this,options);this.ports=new ArrayList();this.labels=new ArrayList();this.zoomProperties=new ArrayList();this.limits=[0,0,0,0];this.border=[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}];this.dragType=this.CANCEL;this.startConnectionPoint=null;this.connectAtMiddlePoints=null;this.previousXDragPosition=0;this.previousYDragPosition=0;this.connectionType=null;CustomShape.prototype.initObject.call(this,options);};CustomShape.prototype=new Shape();CustomShape.prototype.type="CustomShape";CustomShape.prototype.family="CustomShape";CustomShape.prototype.containerDropBehavior=null;CustomShape.prototype.connectionDropBehavior=null;CustomShape.prototype.noDropBehavior=null;CustomShape.prototype.CONNECT=1;CustomShape.prototype.DRAG=2;CustomShape.prototype.CANCEL=0;CustomShape.prototype.initObject=function(options){var defaults={connectAtMiddlePoints:true,layers:[],labels:[],connectionType:"regular"},i;this.limits=[5,5,5,5,5];this.setStartConnectionPoint(new Point(0,0));$.extend(true,defaults,options);for(i=0;i<defaults.layers.length;i+=1){this.createLayer(defaults.layers[i]);} for(i=0;i<defaults.labels.length;i+=1){this.createLabel(defaults.labels[i]);} this.setConnectAtMiddlePoints(defaults.connectAtMiddlePoints).setConnectionType(defaults.connectionType);};CustomShape.prototype.createLayer=function(options){var layer;options.parent=this;layer=new Layer(options);this.addLayer(layer);return layer;};CustomShape.prototype.createLabel=function(options){var label;options.canvas=this.canvas;options.parent=this;if(options.width===0){options.width=this.width*0.9;} label=new Label(options);this.addLabel(label);return label;};CustomShape.prototype.addLabel=function(label){if(this.html){label.parent=this;this.html.appendChild(label.getHTML());} if(!this.labels.contains(label)){this.labels.insert(label);}};CustomShape.prototype.createHTML=function(){var i,label;Shape.prototype.createHTML.call(this);this.style.addClasses(["custom_shape"]);this.layers.sort(Layer.prototype.comparisonFunction);for(i=0;i<this.layers.getSize();i+=1){this.html.appendChild(this.layers.get(i).getHTML());} for(i=0;i<this.labels.getSize();i+=1){label=this.labels.get(i);this.addLabel(label);label.attachListeners();} return this.html;};CustomShape.prototype.attachListeners=function(){if(this.html===null){return this;} var $customShape=$(this.html).click(this.onClick(this));$customShape.on("mousedown",this.onMouseDown(this));$customShape.mousemove(this.onMouseMove(this));$customShape.mouseup(this.onMouseUp(this));$customShape.on("contextmenu",function(e){e.preventDefault();});this.updateBehaviors();return this;};CustomShape.prototype.paint=function(){var i,label;Shape.prototype.paint.call(this);for(i=0;i<this.layers.getSize();i+=1){this.layers.get(i).paint();} for(i=0;i<this.ports.getSize();i+=1){this.ports.get(i).paint();} for(i=0;i<this.labels.getSize();i+=1){label=this.labels.get(i);label.paint();} return this;};CustomShape.prototype.updateHTML=function(){var i,label;this.setDimension(this.width,this.height);for(i=0;i<this.labels.getSize();i+=1){label=this.labels.get(i);label.paint();label.updateDimension();} return this;};CustomShape.prototype.refreshConnections=function(inContainer,isDragged,isZoomed){var i,connection,ports=this.ports,port;for(i=0;i<ports.getSize();i+=1){port=ports.get(i);port.setPosition(port.getX(),port.getY());connection=port.connection;if(!isDragged){connection.disconnect(inContainer).connect(inContainer);} connection.setSegmentMoveHandlers().checkAndCreateIntersectionsWithAll();if(!isZoomed){this.canvas.triggerConnectionStateChangeEvent(connection);}} return this;};CustomShape.prototype.updateLayers=function(){var i,j,layer;for(i=0;i<this.getLayers().getSize();i+=1){layer=this.getLayers().get(i);layer.setProperties();} return this;};CustomShape.prototype.findLayerPosition=function(layer){var nextLayer=null,minVal=10000000,i,currLayer,currPriority;for(i=0;i<this.layers.getSize();i+=1){currLayer=this.layers.get(i);currPriority=currLayer.getPriority();if(currPriority>layer.getPriority()){if(minVal>currPriority){minVal=currPriority;nextLayer=currLayer;}}} return nextLayer;};CustomShape.prototype.addLayer=function(newLayer){var nextLayer=this.findLayerPosition(newLayer);if(this.html){if(!nextLayer){this.html.appendChild(newLayer.getHTML());}else{this.html.insertBefore(newLayer.getHTML(),nextLayer.getHTML());} newLayer.paint();} this.layers.insert(newLayer);return this;};CustomShape.prototype.findLayer=function(layerID){var currLayer,i;currLayer=this.layers.find('id',layerID);return currLayer;};CustomShape.prototype.setDimension=function(newWidth,newHeight){Shape.prototype.setDimension.call(this,newWidth,newHeight);this.updateLabels();this.updateLayers();return this;};CustomShape.prototype.updateLabels=function(){};CustomShape.prototype.hideLayer=function(layerID){var currLayer;if(!layerID||typeof layerID!=="string"){return this;} currLayer=this.findLayer(layerID);if(!currLayer){return this;} currLayer.setVisible(false);return this;};CustomShape.prototype.showLayer=function(layerID){var currLayer;if(!layerID||typeof layerID!=="string"){return this;} currLayer=this.findLayer(layerID);if(!currLayer){return this;} currLayer.setVisible(true);return this;};CustomShape.prototype.addPort=function(port,xPortCoord,yPortCoord,triggerChange,sourcePort){var position=new Point(xPortCoord,yPortCoord);port.setParent(this);port.setCanvas(this.canvas);this.definePortPosition(port,position,sourcePort);this.html.appendChild(port.getHTML());port.paint();this.ports.insert(port);return this;};CustomShape.prototype.removePort=function(port){this.ports.remove(port);return this;};CustomShape.prototype.definePortPosition=function(port,point,sourcePort){var canvas=this.canvas,directionArray=[this.TOP,this.RIGHT,this.BOTTOM,this.LEFT],midPointArray=[new Point(Math.round(this.zoomWidth / 2),0),new Point(this.zoomWidth,Math.round(this.zoomHeight / 2)),new Point(Math.round(this.zoomWidth / 2),this.zoomHeight),new Point(0,Math.round(this.zoomHeight / 2))],sideArray=[new Point(point.x,0),new Point(this.getZoomWidth(),point.y),new Point(point.x,this.getZoomHeight()),new Point(0,point.y)],usedArray,direction,i,candidateDistance,minDistance,option,border,directionBorderMultiplier=[-1,1,1,-1],rightBorderMultiplier=[0,0,-2,0],bottomBorderMultiplier=[0,-2,0,0];usedArray=this.connectAtMiddlePoints?midPointArray:sideArray;option="getSquaredDistance";if(sourcePort&&this.connectAtMiddlePoints){option="getManhattanDistance";} direction=undefined;minDistance=Infinity;for(i=0;i<usedArray.length;i+=1){candidateDistance=point[option](usedArray[i]);if(minDistance>candidateDistance){minDistance=candidateDistance;direction=directionArray[i];}} border=this.getBorderConsideringLayers();for(i=0;i<4;i+=1){this.border[i].x=(border*directionBorderMultiplier[i]+ border*rightBorderMultiplier[i]);this.border[i].y=(border*directionBorderMultiplier[i]+ border*bottomBorderMultiplier[i]);} port.setDirection(direction);port.setPosition((usedArray[direction].x -port.getWidth()/ 2),(usedArray[direction].y -port.getHeight()/ 2));port.applyBorderMargin(true);port.determinePercentage();return this;};CustomShape.prototype.getBorderConsideringLayers=function(){var border=parseInt(this.style.getProperty('borderTopWidth')||0,10),layer,i;for(i=0;i<this.getLayers().getSize();i+=1){layer=this.getLayers().get(i);border=Math.max(border,parseInt(layer.style.getProperty('borderTopWidth')||0,10));} return border;};CustomShape.prototype.showPorts=function(){var i;for(i=0;i<this.ports.getSize();i+=1){this.ports.get(i).show();} return this;};CustomShape.prototype.hidePorts=function(){var i;for(i=0;i<this.ports.getSize();i+=1){this.ports.get(i).hide();} return this;};CustomShape.prototype.updatePortsPosition=function(xDiff,yDiff){var i,port,ports=this.ports;for(i=0;i<ports.getSize();i+=1){port=ports.get(i);if(port.direction===this.RIGHT||port.direction===this.BOTTOM){port.oldX=port.x;port.oldY=port.y;port.oldAbsoluteX=port.absoluteX;port.oldAbsoluteY=port.absoluteY;port.setPosition(port.x+xDiff,port.y+yDiff,true);port.changePosition(port.oldX,port.oldY,port.oldAbsoluteX,port.oldAbsoluteY);}else{port.setPosition(port.x,port.y,true);} port.connection.disconnect().connect();port.connection.setSegmentMoveHandlers();} return this;};CustomShape.prototype.recalculatePortPosition=function(port){var xPercentage=Math.round((port.percentage*port.parent.getZoomWidth())/ 100),yPercentage=Math.round((port.percentage*port.parent.getZoomHeight())/ 100),xCoordinate=[xPercentage,port.parent.getZoomWidth(),xPercentage,0],yCoordinate=[0,yPercentage,port.parent.getZoomHeight(),yPercentage];if(this.connectAtMiddlePoints){xCoordinate=[port.parent.getZoomWidth()/ 2,port.parent.getZoomWidth(),port.parent.getZoomWidth()/ 2,0];yCoordinate=[0,port.parent.getZoomHeight()/ 2,port.parent.getZoomHeight(),port.parent.getZoomHeight()/ 2];} port.setPosition(this.border[port.direction].x+xCoordinate[port.direction]- Math.round(port.width / 2),this.border[port.direction].y+yCoordinate[port.direction]- Math.round(port.height / 2));return this;};CustomShape.prototype.initPortsChange=function(){var i,ports=this.ports,port;for(i=0;i<ports.getSize();i+=1){port=ports.get(i);port.oldX=port.x;port.oldY=port.y;port.oldAbsoluteX=port.absoluteX;port.oldAbsoluteY=port.absoluteY;} return this;};CustomShape.prototype.firePortsChange=function(){var i,ports=this.ports,port;for(i=0;i<ports.getSize();i+=1){port=ports.get(i);Shape.prototype.changePosition.call(this,port.oldX,port.oldY,port.oldAbsoluteX,port.oldAbsoluteY);} return this;};CustomShape.prototype.refreshShape=function(){Shape.prototype.refreshShape.call(this);this.updatePortsOnZoom().refreshConnections(false,false,true);this.paint();return this;};CustomShape.prototype.updatePortsOnZoom=function(){var i,ports=this.ports,port,zoomFactor=this.canvas.zoomFactor,prevZoomFactor=(this.canvas.prevZoom*25+50)/ 100,portFactor=(ports.getSize()>0)?ports.get(0).width / 2:0,srcDecorator,destDecorator,xCoords=[this.zoomWidth / 2-portFactor,this.zoomWidth-portFactor,this.zoomWidth / 2-portFactor,-portFactor],yCoords=[-portFactor,this.zoomHeight / 2-portFactor,this.zoomHeight-portFactor,this.zoomHeight / 2-portFactor];for(i=0;i<ports.getSize();i+=1){port=ports.get(i);port.applyBorderMargin(false);if(this.connectAtMiddlePoints){port.setPosition(Math.round(xCoords[port.direction]),Math.round(yCoords[port.direction]));}else{xCoords=[port.x / prevZoomFactor*zoomFactor,this.getZoomWidth()-port.getZoomWidth()/ 2,port.x / prevZoomFactor*zoomFactor,port.x];yCoords=[port.y,port.y / prevZoomFactor*zoomFactor,this.getZoomHeight()-port.getZoomHeight()/ 2,port.y / prevZoomFactor*zoomFactor];port.setPosition(Math.round(xCoords[port.direction]),Math.round(yCoords[port.direction]));} port.applyBorderMargin(true);srcDecorator=port.connection.srcDecorator;destDecorator=port.connection.destDecorator;if(srcDecorator){srcDecorator.applyZoom();} if(destDecorator){destDecorator.applyZoom();}} return this;};CustomShape.prototype.calculateLabelsPercentage=function(){var i,label;for(i=0;i<this.labels.getSize();i+=1){label=this.labels.get(i);label.xPercentage=label.getX()/ this.getWidth();label.yPercentage=label.getY()/ this.getHeight();}};CustomShape.prototype.updateLabelsPosition=function(){var i,label;for(i=0;i<this.labels.getSize();i+=1){label=this.labels.get(i);label.setLabelPosition(label.location,label.diffX,label.diffY);} return this;};CustomShape.prototype.determineDragBehavior=function(point){var limit=this.limits[this.canvas.zoomPropertiesIndex],border=parseInt(this.style.getProperty('border')||0,10);if(Geometry.pointInRectangle(point,new Point(0,0),new Point(this.zoomWidth+2*border,this.zoomHeight+2*border))){if(Geometry.pointInRectangle(point,new Point(border+limit,border+limit),new Point(this.zoomWidth+border-limit,this.zoomHeight+border-limit))){return this.DRAG;} return this.CONNECT;} return this.CANCEL;};CustomShape.prototype.createDragHelper=function(){var html=document.createElement("div");html.style.width=8+"px";html.style.height=8+"px";html.style.backgroundColor="black";html.style.zIndex=2*Shape.prototype.MAX_ZINDEX;html.id="drag-helper";html.className="drag-helper";return html;};CustomShape.prototype.onMouseDown=function(customShape){return function(e,ui){var canvas=customShape.canvas;if(e.which===3){$(canvas.html).trigger("rightclick",[e,customShape]);}else{if(customShape.dragType===customShape.DRAG){customShape.setDragBehavior("customshapedrag");}else if(customShape.dragType===customShape.CONNECT){customShape.setDragBehavior("connection");}else{customShape.setDragBehavior("nodrag");} customShape.dragging=true;} e.stopPropagation();};};CustomShape.prototype.onMouseUp=function(customShape){return function(e,ui){customShape.dragging=false;};};CustomShape.prototype.onMouseMove=function(customShape){return function(e,ui){var $customShape,canvas;if(customShape.dragging||customShape.entered){return;} $customShape=$(customShape.html);canvas=customShape.getCanvas();customShape.startConnectionPoint.x=e.pageX-canvas.getX()- customShape.absoluteX+canvas.getLeftScroll();customShape.startConnectionPoint.y=e.pageY-canvas.getY()- customShape.absoluteY+canvas.getTopScroll();customShape.dragType=customShape.determineDragBehavior(customShape.startConnectionPoint);if(customShape.dragType===customShape.DRAG){$customShape.css('cursor','move');}else if(customShape.dragType===customShape.CONNECT){$customShape.css('cursor','crosshair');}else{$customShape.css('cursor','default');}};};CustomShape.prototype.onClick=function(customShape){var i,erros,id,item;return function(e,ui){var isCtrl=false,canvas=customShape.canvas,currentSelection=canvas.currentSelection,currentLabel=canvas.currentLabel;if(e.ctrlKey){isCtrl=true;} customShape.canvas.hideCurrentConnection();if(e.which===3){e.preventDefault();customShape.canvas.triggerRightClickEvent(customShape);}else{if(!customShape.wasDragged){if(isCtrl){if(currentSelection.contains(customShape)){canvas.removeFromSelection(customShape);}else{canvas.addToSelection(customShape);}}else{canvas.emptyCurrentSelection();canvas.addToSelection(customShape);}} if(!currentSelection.isEmpty()){canvas.triggerSelectEvent(currentSelection.asArray());}} if(this.helper){$(this.helper.html).remove();} if(currentLabel){currentLabel.loseFocus();$(currentLabel.textField).focusout();} customShape.wasDragged=false;e.stopPropagation();};};CustomShape.prototype.parseHook=function(){};CustomShape.prototype.getPorts=function(){return this.ports;};CustomShape.prototype.getLayers=function(){return this.layers;};CustomShape.prototype.getLabels=function(){return this.labels;};CustomShape.prototype.applyZoom=function(){var i,label;Shape.prototype.applyZoom.call(this);for(i=0;i<this.layers.getSize();i+=1){this.layers.get(i).applyZoom();} for(i=0;i<this.labels.getSize();i+=1){label=this.labels.get(i);label.applyZoom();label.setLabelPosition(label.location,label.diffX,label.diffY);} return this;};CustomShape.prototype.setStartConnectionPoint=function(point){this.startConnectionPoint=point;return this;};CustomShape.prototype.setConnectAtMiddlePoints=function(connect){this.connectAtMiddlePoints=connect;return this;};CustomShape.prototype.getConnectAtMiddlePoints=function(){return this.connectAtMiddlePoints;};CustomShape.prototype.setConnectionType=function(newConnType){this.connectionType=newConnType;return this;};CustomShape.prototype.getConnectionType=function(){return this.connectionType;};CustomShape.prototype.stringify=function(){var sLayers=[],labels=[],i,inheritedJSON,thisJSON;for(i=0;i<this.layers.getSize();i+=1){sLayers.push(this.layers.get(i).stringify());} for(i=0;i<this.labels.getSize();i+=1){labels.push(this.labels.get(i).stringify());} inheritedJSON=Shape.prototype.stringify.call(this);thisJSON={canvas:this.canvas.getID(),layers:sLayers,labels:labels,connectAtMiddlePoints:this.getConnectAtMiddlePoints(),connectionType:this.getConnectionType(),parent:this.parent.getID()};$.extend(true,inheritedJSON,thisJSON);return inheritedJSON;};CustomShape.prototype.parseJSON=function(json){this.initObject(json);return this;};Segment=function(options){JCoreObject.call(this,options);this.parent=null;this.startPoint=null;this.endPoint=null;this.zOrder=Shape.prototype.MAX_ZINDEX;this.previousNeighbor=null;this.nextNeighbor=null;this.orientation="";this.width=1;this.customLine=null;this.segmentStyle=null;this.segmentColor=null;this.moveHandler=null;this.intersections=new ArrayList();this.hasMoveHandler=false;Segment.prototype.initObject.call(this,options);};Segment.prototype=new JCoreObject();Segment.prototype.type="Segment";Segment.prototype.initObject=function(options){var defaults={startPoint:new Point(0,0),endPoint:new Point(0,0),parent:null,color:new Color(0,0,0)};$.extend(true,defaults,options);this.setStartPoint(defaults.startPoint).setEndPoint(defaults.endPoint).setColor(defaults.color).setParent(defaults.parent);};Segment.prototype.createHTML=function(){this.html=document.createElement('div');this.html.id=this.id;this.html.style.position="absolute";this.html.style.left="0px";this.html.style.top="0px";this.html.style.height="0px";this.html.style.width="0px";this.html.style.zIndex=this.zOrder;return this.html;};Segment.prototype.paint=function(){if(this.getHTML()===null){return this;} if(this.customLine===null){this.customLine=new CustomLine({canvas:this.html});} this.customLine.drawLine(this.startPoint.x,this.startPoint.y,this.endPoint.x,this.endPoint.y);this.parent.html.appendChild(this.html);return this;};Segment.prototype.destroy=function(){$(this.html).remove();return this;};Segment.prototype.paintWithIntersections=function(){this.destroy();var startPoint,endPoint,diff,i,reverse=false;if(this.getHTML()===null){return this;} if(this.customLine===null){this.customLine=new CustomLine({canvas:this.html});} if(this.hasMoveHandler){$(this.moveHandler.html).remove();this.addSegmentMoveHandler();} if(this.orientation===this.HORIZONTAL){diff=new Point(Shape.prototype.DEFAULT_RADIUS,0);if(this.startPoint.x>this.endPoint.x){reverse=true;} this.intersections.sort(function(i,j){return i.center.x>=j.center.x;});}else{diff=new Point(0,Shape.prototype.DEFAULT_RADIUS);if(this.startPoint.y>this.endPoint.y){reverse=true;} this.intersections.sort(function(i,j){return i.center.y>=j.center.y;});} this.customLine.clear();startPoint=this.startPoint.clone();for(i=0;i<this.intersections.getSize();i+=1){if(reverse){endPoint=this.intersections.get(this.intersections.getSize()-i-1).center;}else{endPoint=this.intersections.get(i).center;} if(reverse){endPoint=endPoint.add(diff);}else{endPoint=endPoint.subtract(diff);} this.customLine.drawLine(startPoint.x,startPoint.y,endPoint.x,endPoint.y);if(reverse){startPoint=endPoint.subtract(diff.multiply(2));}else{startPoint=endPoint.add(diff.multiply(2));}} endPoint=this.endPoint.clone();this.customLine.drawLine(startPoint.x,startPoint.y,endPoint.x,endPoint.y);this.parent.html.appendChild(this.html);return this;};Segment.prototype.addSegmentMoveHandler=function(){var midX=(this.startPoint.x+this.endPoint.x)/ 2,midY=(this.startPoint.y+this.endPoint.y)/ 2;this.moveHandler=new SegmentMoveHandler({parent:this,orientation:this.orientation,style:{cssProperties:{border:"1px solid black"}}});midX-=this.moveHandler.width / 2;midY-=this.moveHandler.height / 2;this.moveHandler.setPosition(midX,midY);this.html.appendChild(this.moveHandler.getHTML());this.moveHandler.paint();this.moveHandler.attachListeners(this.moveHandler);return this;};Segment.prototype.getParent=function(){return this.parent;};Segment.prototype.getStartPoint=function(){return this.startPoint;};Segment.prototype.getEndPoint=function(){return this.endPoint;};Segment.prototype.setParent=function(newParent){this.parent=newParent;return this;};Segment.prototype.setStartPoint=function(newPoint){this.startPoint=newPoint;return this;};Segment.prototype.setEndPoint=function(newPoint){this.endPoint=newPoint;return this;};Segment.prototype.setStyle=function(newStyle){this.segmentStyle=newStyle;return this;};Segment.prototype.setColor=function(newColor){this.segmentColor=newColor;return this;};Segment.prototype.createIntersectionWith=function(otherSegment,ip){var intersectionObject,intersectionPoint,i,goodToInsert=true;if(ip){intersectionPoint=ip;}else{intersectionPoint=Geometry.segmentIntersectionPoint(this.startPoint,this.endPoint,otherSegment.startPoint,otherSegment.endPoint);} for(i=0;i<this.intersections.getSize();i+=1){if(ip.equals(this.intersections.get(i).center)){goodToInsert=false;}} if(goodToInsert){intersectionObject=new Intersection(intersectionPoint,otherSegment.parent.getID(),this);this.html.appendChild(intersectionObject.getHTML());intersectionObject.paint();this.intersections.insert(intersectionObject);} return this;};Segment.prototype.clearIntersections=function(){var i,intersection,size=this.intersections.getSize();while(size>0){intersection=this.intersections.get(size-1);$(intersection.html).remove();this.intersections.popLast();size-=1;} return this;};Segment.prototype.moveSegment=function(x,y){var handler=this.moveHandler,prevNeighbor=this.previousNeighbor,nextNeighbor=this.nextNeighbor,midX,midY;if(handler.orientation===handler.VERTICAL){this.startPoint.x=x +handler.width / 2;this.endPoint.x=x +handler.width / 2;prevNeighbor.endPoint.x=this.startPoint.x;nextNeighbor.startPoint.x=this.endPoint.x;}else{this.startPoint.y=y +handler.height / 2;this.endPoint.y=y +handler.height / 2;prevNeighbor.endPoint.y=this.startPoint.y;nextNeighbor.startPoint.y=this.endPoint.y;} if(this.moveHandler){midX=(this.startPoint.x+this.endPoint.x)/ 2 -this.moveHandler.width / 2;midY=(this.startPoint.y+this.endPoint.y)/ 2 -this.moveHandler.height / 2;this.moveHandler.setPosition(midX,midY);} prevNeighbor.paint();if(prevNeighbor.moveHandler){midX=(prevNeighbor.startPoint.x+prevNeighbor.endPoint.x)/ 2 -prevNeighbor.moveHandler.width / 2;midY=(prevNeighbor.startPoint.y+prevNeighbor.endPoint.y)/ 2 -prevNeighbor.moveHandler.height / 2;prevNeighbor.moveHandler.setPosition(midX,midY);} nextNeighbor.paint();if(nextNeighbor.moveHandler){midX=(nextNeighbor.startPoint.x+nextNeighbor.endPoint.x)/ 2 -nextNeighbor.moveHandler.width / 2;midY=(nextNeighbor.startPoint.y+nextNeighbor.endPoint.y)/ 2 -nextNeighbor.moveHandler.height / 2;nextNeighbor.moveHandler.setPosition(midX,midY);} this.paint();return this;};RegularShape=function(options){Shape.call(this,options);this.color=new Color();this.graphics=null;};RegularShape.prototype=new Shape();RegularShape.prototype.type="RegularShape";RegularShape.prototype.getColor=function(){return this.color;};RegularShape.prototype.setColor=function(newColor){if(newColor.type&&newColor.type==="Color"){this.color=newColor;} return this;};Polygon=function(options){RegularShape.call(this,options);this.points=null;Polygon.prototype.initObject.call(this,options);};Polygon.prototype=new RegularShape();Polygon.prototype.type="Polygon";Polygon.prototype.initObject=function(options){var defaults={points:[]};$.extend(true,defaults,options);this.setPoints(defaults.points);};Polygon.prototype.setPoints=function(newPoints){var i,point;this.points=[];for(i=0;i<newPoints.length;i+=1){point=newPoints[i];this.points.push(new Point(point.getX(),point.getY()));}};Polygon.prototype.getPoints=function(){return this.points;};Rectangle=function(options){Polygon.call(this,options);Rectangle.prototype.initObject.call(this,options);};Rectangle.prototype=new Polygon();Rectangle.prototype.type="Rectangle";Rectangle.prototype.initObject=function(options){};Rectangle.prototype.paint=function(){if(this.html){this.style.applyStyle();if(this.color){this.style.addProperties({backgroundColor:this.color.getCSS()});}} return this;};Rectangle.prototype.createHTML=function(){Shape.prototype.createHTML.call(this);return this.html;};Oval=function(options){RegularShape.call(this,options);Oval.prototype.initObject.call(this,options);};Oval.prototype=new RegularShape();Oval.prototype.type="Oval";Oval.prototype.initObject=function(options){var defaults={center:new Point(0,0),width:4,height:4};$.extend(true,defaults,options);this.setCenter(defaults.center).setWidth(defaults.width).setHeight(defaults.height);};Oval.prototype.paint=function(){this.setVisible(this.visible);if(this.html){this.style.applyStyle();} return this;};Oval.prototype.createHTML=function(){Shape.prototype.createHTML.call(this);return this.html;};Oval.prototype.setColor=function(newColor){this.graphic.setColor(newColor);this.graphic.fillOval(0,0,this.getWidth(),this.getHeight());this.graphic.paint();return this;} Arc=function(options){RegularShape.call(this);this.startAngle=null;this.endAngle=null;this.radius=null;this.step=null;Arc.prototype.initObject.call(this,options);};Arc.prototype=new RegularShape();Arc.prototype.type="Arc";Arc.prototype.initObject=function(options){var defaults={center:new Point(0,0),radius:Shape.prototype.DEFAULT_RADIUS,startAngle:270,endAngle:90,step:10};$.extend(true,defaults,options);this.setCenter(defaults.center).setStartAngle(defaults.startAngle).setEndAngle(defaults.endAngle).setRadius(defaults.radius).setStep(defaults.step);this.id+="-ARC";};Arc.prototype.paint=function(){this.setVisible(this.visible);if(this.html){this.style.applyStyle();} return this;};Arc.prototype.createHTML=function(){Shape.prototype.createHTML.call(this);return this.html;};Arc.prototype.getStartAngle=function(){return this.startAngle;};Arc.prototype.setStartAngle=function(newAngle){this.startAngle=newAngle;return this;};Arc.prototype.getEndAngle=function(){return this.endAngle;};Arc.prototype.setEndAngle=function(newAngle){this.endAngle=newAngle;return this;};Arc.prototype.getRadius=function(){return this.radius;};Arc.prototype.setRadius=function(newRadius){this.radius=newRadius;return this;};Arc.prototype.getStep=function(){return this.step;};Arc.prototype.setStep=function(newStep){this.step=newStep;return this;};MultipleSelectionContainer=function(canvas){RegularShape.call(this);this.backgroundColor=null;this.canvas=null;MultipleSelectionContainer.prototype.initObject.call(this,canvas);};MultipleSelectionContainer.prototype=new Rectangle();MultipleSelectionContainer.prototype.type="MultipleSelectionContainer";MultipleSelectionContainer.prototype.initObject=function(canvas){this.backgroundColor=new Color(0,128,255,0.1);this.canvas=canvas;this.canvas.addElement(this,0,0,true);};MultipleSelectionContainer.prototype.paint=function(){this.style.addProperties({backgroundColor:this.backgroundColor.getCSS()});return this;};MultipleSelectionContainer.prototype.changeOpacity=function(value){this.backgroundColor.setOpacity(value);this.paint();return this;};MultipleSelectionContainer.prototype.wrapElements=function(){var currentSelection=this.canvas.currentSelection,selection=[];this.intersectElements();if(!currentSelection.isEmpty()){selection=currentSelection.asArray();this.canvas.triggerSelectEvent(selection);} this.reset();this.setVisible(false);return this;};MultipleSelectionContainer.prototype.intersectElements=function(){var i,shape,children;this.canvas.emptyCurrentSelection();children=this.canvas.customShapes;for(i=0;i<children.getSize();i+=1){shape=children.get(i);if(shape.parent.family==="Canvas"&&this.checkIntersection(shape)){this.canvas.addToSelection(shape);}} return this;};MultipleSelectionContainer.prototype.reset=function(){this.setPosition(0,0);this.setDimension(0,0);return this;};MultipleSelectionContainer.prototype.getLeft=Shape.prototype.getAbsoluteX;MultipleSelectionContainer.prototype.getTop=Shape.prototype.getAbsoluteY;MultipleSelectionContainer.prototype.checkIntersection=function(shape){var topLeft=new Point(this.zoomX,this.zoomY),bottomRight=new Point(this.zoomX+this.zoomWidth,this.zoomY+this.zoomHeight);return Geometry.pointInRectangle(new Point(shape.getZoomX(),shape.getZoomY()),topLeft,bottomRight)||Geometry.pointInRectangle(new Point(shape.zoomX+ shape.zoomWidth,shape.zoomY),topLeft,bottomRight)||Geometry.pointInRectangle(new Point(shape.zoomX,shape.zoomY+ shape.zoomHeight),topLeft,bottomRight)||Geometry.pointInRectangle(new Point(shape.zoomX+ shape.zoomWidth,shape.zoomY+shape.zoomHeight),topLeft,bottomRight);};Intersection=function(center,idOtherConnection,parent){Arc.call(this);this.center=(!center)?null:center;this.visible=true;this.parent=parent;this.idOtherConnection=idOtherConnection;};Intersection.prototype=new Arc();Intersection.prototype.type="Intersection";Intersection.prototype.paint=function(){if(this.parent.orientation===this.VERTICAL){this.startAngle=270;this.endAngle=90;}else{this.startAngle=180;this.endAngle=0;} Arc.prototype.paint.call(this);this.style.applyStyle();return this;};Intersection.prototype.destroy=function(){$(this.html).remove();return this;};Intersection.prototype.createHTML=function(){Shape.prototype.createHTML.call(this);return this.html;};Snapper=function(options){JCoreObject.call(this,options);this.orientation=null;this.data=[];this.visible=false;Snapper.prototype.initObject.call(this,options);};Snapper.prototype=new JCoreObject();Snapper.prototype.type="Snapper";Snapper.prototype.initObject=function(options){var defaults={orientation:"horizontal"};$.extend(true,defaults,options);this.setOrientation(defaults.orientation);this.setDimension(defaults.width,defaults.height);this.createHTML();this.hide();};Snapper.prototype.createHTML=function(){JCoreObject.prototype.createHTML.call(this);$(this.canvas.getHTML()).append(this.html);this.setZOrder(99);this.html.className='custom-snapper';if(this.getOrientation()=='horizontal'){this.html.id='guide-h';this.html.style.borderTop='1px dashed #55f';this.html.style.width='100%';}else{this.html.id='guide-v';this.html.style.borderLeft='1px dashed #55f';this.html.style.height='100%';} return this.html;};Snapper.prototype.hide=function(){this.visible=false;this.setVisible(this.visible);return this;};Snapper.prototype.show=function(){this.visible=true;this.setVisible(this.visible);return this;};Snapper.prototype.createSnapData=function(){var i,index=0,shape,border=0;this.data=[];for(i=0;i<this.canvas.customShapes.getSize();i+=1){shape=this.canvas.customShapes.get(i);if(!this.canvas.currentSelection.find('id',shape.getID())){border=parseInt($(shape.getHTML()).css('borderTopWidth'),10);if(this.orientation==='horizontal'){this.data[index*2]=shape.getAbsoluteY()-border;this.data[index*2+1]=shape.getAbsoluteY()+shape.getZoomHeight();}else{this.data[index*2]=shape.getAbsoluteX()-border;this.data[index*2+1]=shape.getAbsoluteX()+shape.getZoomWidth();} index+=1;}} for(i=0;i<this.canvas.regularShapes.getSize();i+=1){shape=this.canvas.regularShapes.get(i);border=parseInt($(shape.getHTML()).css('borderTopWidth'),10);if(this.orientation==='horizontal'){this.data[index*2]=shape.getAbsoluteY()-border;this.data[index*2+1]=shape.getAbsoluteY()+ shape.getZoomHeight();}else{this.data[index*2]=shape.getAbsoluteX()-border;this.data[index*2+1]=shape.getAbsoluteX()+ shape.getZoomWidth();} index+=1;} return this;};Snapper.prototype.sortData=function(){this.data.sort(function(a,b){return a>b;});return this;};Snapper.prototype.binarySearch=function(value){var low=0,up=this.data.length-1,mid;while(low<=up){mid=parseInt((low+up)/ 2,10);if(this.data[mid]===value){return value;} if(this.data[mid]>value){up=mid-1;}else{low=mid+1;}} return false;};Snapper.prototype.attachListeners=function(snapper){var $snapper=$(snapper.html).mousemove(function(){snapper.hide();});return this;};Snapper.prototype.setOrientation=function(orientation){if(orientation==="horizontal"||orientation==="vertical"){this.orientation=orientation;}else{throw new Error("setOrientation(): parameter is not valid");} return this;};Snapper.prototype.getOrientation=function(){return this.orientation;};ReadOnlyLayer=function(options){JCoreObject.call(this,options);ReadOnlyLayer.prototype.initObject.call(this,options);};ReadOnlyLayer.prototype=new JCoreObject();ReadOnlyLayer.prototype.initObject=function(options){this.createHTML();this.attachListeners();};ReadOnlyLayer.prototype.attachListeners=function(){var $layer=$(this.html);$layer.on('mousedown',this.onMouseDown(this)).on('mouseup',this.onMouseUp(this)).on('mousemove',this.onMouseMove(this)).on('click',this.onClick(this)).droppable({accept:"*",greedy:true,onDrop:function(){return false;}});};ReadOnlyLayer.prototype.onMouseDown=function(layer){return function(e,ui){e.stopPropagation();};};ReadOnlyLayer.prototype.onMouseUp=function(layer){return function(e,ui){e.stopPropagation();};};ReadOnlyLayer.prototype.onClick=function(layer){return function(e,ui){e.stopPropagation();};};ReadOnlyLayer.prototype.onMouseMove=function(layer){return function(e,ui){e.stopPropagation();};};Canvas=function(options){BehavioralElement.call(this,options);this.html=null;this.customShapes=null;this.regularShapes=null;this.connections=null;this.currentSelection=null;this.sharedConnections=null;this.leftScroll=0;this.topScroll=0;this.currentConnection=null;this.oldCurrentConnection=null;this.connectionSegment=null;this.multipleSelectionHelper=null;this.horizontalSnapper=null;this.verticalSnapper=null;this.zoomFactor=1;this.zoomPropertiesIndex=2;this.zOrder=0;this.isMouseDown=false;this.currentShape=null;this.isMouseDownAndMove=false;this.multipleDrop=false;this.draggingASegmentHandler=false;this.updatedElement=null;this.rightClick=false;this.intersectionTimeout=null;this.currentLabel=null;this.commandStack=null;this.shapesToCopy=[];this.connectionsToCopy=[];this.readOnly=false;this.readOnlyLayer=null;this.copyAndPasteReferences={};this.prevZoom=1;this.dummyLabelInitializer=null;this.MIN_DISTANCE=4;this.guides=[];Canvas.prototype.initObject.call(this,options);};Canvas.prototype=new BehavioralElement();Canvas.prototype.type="Canvas";Canvas.prototype.family="Canvas";Canvas.prototype.initObject=function(options){var canvasPosition,defaults;defaults={width:4000,commandStackOnSuccess:function(){},height:4000,toolbarFactory:(options&&options.toolbarFactory)||Canvas.prototype.toolBarShapeFactory||function(id){return null;},copyAndPasteReferences:(options&&options.copyAndPasteReferences)||{},readOnly:false,snapToGuide:true};$.extend(true,defaults,options);if(options){this.createHTML();canvasPosition=$("#"+this.id).offset();this.children=new ArrayList();this.customShapes=new ArrayList();this.regularShapes=new ArrayList();this.connections=new ArrayList();this.currentSelection=new ArrayList();this.sharedConnections=new ArrayList();this.commandStack=new CommandStack(20,defaults.commandStackOnSuccess);this.multipleSelectionHelper=new MultipleSelectionContainer(this);this.copyAndPaste=false;this.copyAndPasteReferences=defaults.copyAndPasteReferences;this.setToolBarShapeFactory(defaults.toolbarFactory);this.setPosition(canvasPosition.left,canvasPosition.top).setDimension(defaults.width,defaults.height).setCanvas(this).setSnapToGuide(defaults.snapToGuide).setCopyAndPaste(defaults.copyAndPaste);if(defaults.readOnly){this.setToReadOnly();}}};Canvas.prototype.setReadOnly=function(readOnly){if(readOnly){this.setToReadOnly();}else{this.unsetReadOnly();} return this;};Canvas.prototype.setToReadOnly=function(){var readOnlyLayer=this.readOnlyLayer;if(readOnlyLayer&&readOnlyLayer.html){this.html.appendChild(this.readOnlyLayer.html);}else{this.readOnlyLayer=new ReadOnlyLayer({width:this.width,height:this.height});this.html.appendChild(this.readOnlyLayer.html);} this.readOnly=true;return this;};Canvas.prototype.unsetReadOnly=function(){var readOnlyLayer=this.readOnlyLayer;this.html.removeChild(readOnlyLayer.getHTML());this.readOnly=false;return this;};Canvas.prototype.setPosition=function(x,y){this.setX(x);this.setY(y);return this;};Canvas.prototype.setX=function(newX){this.x=this.zoomX=newX;this.absoluteX=0;return this;};Canvas.prototype.setY=function(newY){this.y=this.zoomY=newY;this.absoluteY=0;return this;};Canvas.prototype.setSnapToGuide=function(snap){this.snapToGuide=snap;if(!this.horizontalSnapper){this.horizontalSnapper=new Snapper({orientation:'horizontal',canvas:this,width:4000,height:1});} if(!this.verticalSnapper){this.verticalSnapper=new Snapper({orientation:'vertical',canvas:this,width:1,height:4000});} return this;};Canvas.prototype.setCopyAndPaste=function(value){this.copyAndPaste=value;return this;};Canvas.prototype.createHTMLDiv=function(){return document.getElementById(this.id);};Canvas.prototype.toolBarShapeFactory=function(id){var customShape=null;switch(id){case"tiny_shape":customShape=new CustomShape({width:50,height:50,"canvas":this,"connectAtMiddlePoints":false,"drop":{type:"connection"},"style":{cssClasses:["grey"],cssProperties:{border:"1px solid blue","-webkit-box-shadow":"0px 0px 4px 0px black","box-shadow":"0px 0px 4px 0px black"}},resizeBehavior:"NoResize",resizeHandlers:{type:"Rectangle",total:8,resizableStyle:{cssProperties:{'background-color':"rgb(0, 255, 0)",'border':'1px solid black'}},nonResizableStyle:{cssProperties:{'background-color':"white",'border':'1px solid black'}}}});customShape.attachListeners();break;case"big_shape":customShape=new CustomShape({width:200,height:200,canvas:this,container:'regular',"connectAtMiddlePoints":false,drop:{type:"connectioncontainer",selectors:['.custom_shape']},"style":{cssClasses:["grey"],cssProperties:{border:"1px solid green","-webkit-box-shadow":"0px 0px 4px 0px black","box-shadow":"0px 0px 4px 0px black"}},resizeBehavior:"yes",resizeHandlers:{type:"Rectangle",total:8,resizableStyle:{cssProperties:{'background-color':"rgb(0, 255, 0)",'border':'1px solid black'}},nonResizableStyle:{cssProperties:{'background-color':"white",'border':'1px solid black'}}}});customShape.attachListeners();break;default:} return customShape;};Canvas.prototype.addToList=function(shape){switch(shape.family){case"CustomShape":if(!this.customShapes.contains(shape)){this.customShapes.insert(shape);} break;case"RegularShape":if(!this.regularShapes.contains(shape)){this.regularShapes.insert(shape);} break;default:} return this;};Canvas.prototype.hideCurrentConnection=function(){if(this.currentConnection){this.currentConnection.hidePortsAndHandlers();this.currentConnection=null;} return this;};Canvas.prototype.applyZoom=function(scale){var i,shape;if(scale>0){scale-=1;this.prevZoom=this.zoomPropertiesIndex;this.zoomPropertiesIndex=scale;this.zoomFactor=(scale*25+50)/ 100;} for(i=0;i<this.customShapes.getSize();i+=1){shape=this.customShapes.get(i);shape.applyZoom();shape.paint();} for(i=0;i<this.regularShapes.getSize();i+=1){shape=this.regularShapes.get(i);shape.applyZoom();shape.paint();} return this;};Canvas.prototype.addConnection=function(conn){this.html.appendChild(conn.getHTML());this.connections.insert(conn);this.updatedElement=conn;return this;};Canvas.prototype.removeElements=function(){var shape,command;command=new CommandDelete(this);this.commandStack.add(command);command.execute();return this;};Canvas.prototype.moveAllChildConnections=function(shape){var i,child,j,port;if(shape.child!==null){for(i=0;i<shape.children.getSize();i+=1){child=shape.children.get(i);child.setPosition(child.x,child.y);for(j=0;j<child.getPorts().getSize();j+=1){port=child.getPorts().get(j);port.setPosition(port.x,port.y);port.connection.disconnect();port.connection.connect();} this.moveAllChildConnections(child);}} return this;};Canvas.prototype.moveElements=function(canvas,direction,hook){var i,j,shape,hfactor=0,vfactor=0,port,currentSelection=[],canMove;switch(direction){case'LEFT':hfactor=-1;break;case'RIGHT':hfactor=1;break;case'TOP':vfactor=-1;break;case'BOTTOM':vfactor=1;break;} for(i=0;i<canvas.getCurrentSelection().getSize();i+=1){canMove=true;shape=canvas.getCurrentSelection().get(i);currentSelection.push(shape);if(hook&&typeof hook==="function"&&!hook(shape)){canMove=false;} if(canMove){shape.oldX=shape.x;shape.oldY=shape.y;shape.oldAbsoluteX=shape.absoluteX;shape.oldAbsoluteY=shape.absoluteY;shape.setPosition(shape.getX()+hfactor,shape.getY()+vfactor);shape.changePosition(shape.oldX,shape.oldY,shape.oldAbsoluteX,shape.oldAbsoluteY);for(j=0;j<shape.ports.getSize();j+=1){port=shape.ports.get(j);port.setPosition(port.x,port.y);port.connection.disconnect().connect();} this.moveAllChildConnections(shape);shape.refreshConnections(false);}} clearTimeout(this.intersectionTimeout);this.intersectionTimeout=window.setTimeout(function(currentSelection){var stack=[],selection=currentSelection||[];for(i=0;i<selection.length;i+=1){shape=selection[i];stack.push(shape);} while(stack.length>0){shape=stack.pop();for(i=0;i<shape.getChildren().getSize();i+=1){stack.push(shape.getChildren().get(i));} for(j=0;j<shape.ports.getSize();j+=1){port=shape.ports.get(j);port.connection.disconnect().connect();port.connection.setSegmentMoveHandlers();port.connection.checkAndCreateIntersectionsWithAll();}}},1000,currentSelection);return this;};Canvas.prototype.removeFromList=function(shape){this.currentSelection.remove(shape);if(shape.family==="CustomShape"){this.customShapes.remove(shape);}else if(shape.family==="RegularShape"){this.regularShapes.remove(shape);} return this;};Canvas.prototype.startSnappers=function(event){var shape,i,parent;this.guides=[];for(i=0;i<this.customShapes.getSize();i+=1){shape=this.customShapes.get(i);if(!this.currentSelection.find('id',shape.getID())){this.computeGuidesForElement(shape);}} return this;};Canvas.prototype.computeGuidesForElement=function(shape){var x=shape.getAbsoluteX();var y=shape.getAbsoluteY();var w=shape.getZoomWidth()-1;var h=shape.getZoomHeight()-1;this.guides.push({type:"h",x:x,y:y},{type:"h",x:x,y:y+h},{type:"v",x:x,y:y},{type:"v",x:x+w,y:y});return this;};Canvas.prototype.processGuides=function(e,ui,customShape){var guideV,guideH,distV=this.MIN_DISTANCE+1,distH=this.MIN_DISTANCE+1,offsetV,offsetH,mouseRelX,mouseRelY,pos,w=customShape.getZoomWidth()-1,h=customShape.getZoomHeight()-1,d;mouseRelY=e.originalEvent.pageY-ui.offset.top;mouseRelX=e.originalEvent.pageX-ui.offset.left;pos={top:e.originalEvent.pageY-customShape.canvas.getY()-mouseRelY +customShape.canvas.getTopScroll(),left:e.originalEvent.pageX-customShape.canvas.getX()-mouseRelX +customShape.canvas.getLeftScroll()};$.each(this.guides,function(i,guide){if(guide.type==="h"){d=Math.abs(pos.top-guide.y);if(d<distH){distH=d;guideH=guide;offsetH=0;} d=Math.abs(pos.top-guide.y+h);if(d<distH){distH=d;guideH=guide;offsetH=h;}} if(guide.type==="v"){d=Math.abs(pos.left-guide.x);if(d<distV){distV=d;guideV=guide;offsetV=0;} d=Math.abs(pos.left-guide.x+w);if(d<distV){distV=d;guideV=guide;offsetV=w;}}});if(distH<=this.MIN_DISTANCE){$("#guide-h").css("top",guideH.y).show();if(customShape.parent.family!=='canvas'){ui.position.top=guideH.y-offsetH-customShape.parent.getAbsoluteY();customShape.setPosition(ui.helper.position().left / this.zoomFactor,guideH.y-offsetH-customShape.parent.getAbsoluteY())}else{ui.position.top=guideH.y-offsetH;customShape.setPosition(ui.helper.position().left / this.zoomFactor,guideH.y-offsetH)}}else{$("#guide-h").hide();} if(distV<=this.MIN_DISTANCE){$("#guide-v").css("left",guideV.x).show();if(customShape.parent.family!=='canvas'){ui.position.left=guideV.x-offsetV-customShape.parent.getAbsoluteX();customShape.setPosition(guideV.x-offsetV-customShape.parent.getAbsoluteX(),ui.helper.position().top / this.zoomFactor);}else{ui.position.left=guideV.x-offsetV;customShape.setPosition(guideV.x-offsetV,ui.helper.position().top / this.zoomFactor);}}else{$("#guide-v").hide();} return this;};Canvas.prototype.emptyCurrentSelection=function(){var i,shape;while(this.currentSelection.getSize()>0){shape=this.currentSelection.get(0);this.removeFromSelection(shape);} this.sharedConnections.clear();return this;};Canvas.prototype.isValidSelection=function(referenceShape,newShape){if(referenceShape.parent===null){return newShape.parent===null;} if(newShape.parent===null){return false;} return newShape.parent.id===referenceShape.parent.id;};Canvas.prototype.addToSelection=function(shape){var currentSelection=this.currentSelection,firstSelected,valid,isEmpty=currentSelection.isEmpty();if(!isEmpty){firstSelected=currentSelection.get(0);valid=this.isValidSelection(firstSelected,shape);}else{valid=true;} if(!currentSelection.contains(shape)&&valid){shape.increaseZIndex();currentSelection.insert(shape);if(shape.family==="CustomShape"){this.addToSharedConnections(shape);} shape.selected=true;shape.showOrHideResizeHandlers(true);} return this;};Canvas.prototype.removeFromSelection=function(shape){shape.decreaseZIndex();this.removeFromSharedConnections(shape);this.currentSelection.remove(shape);shape.selected=false;shape.showOrHideResizeHandlers(false);return this;};Canvas.prototype.removeFromSharedConnections=function(customShape){var i,child,connection,sharedConnections=this.sharedConnections;for(i=0;i<customShape.getChildren().getSize();i+=1){child=customShape.getChildren().get(i);this.removeFromSharedConnections(child);} if(customShape.ports){for(i=0;i<customShape.ports.getSize();i+=1){connection=customShape.ports.get(i).connection;if(sharedConnections.find('id',connection.getID())){this.sharedConnections.remove(connection);}}} return this;};Canvas.prototype.findAncestorInCurrentSelection=function(shape){if(this.currentSelection.find('id',shape.getID())){return true;} if(!shape.parent){return false;} return this.findAncestorInCurrentSelection(shape.parent);};Canvas.prototype.addToSharedConnections=function(customShape){var i,child,connection,sourceShape,destShape,sharedConnections=this.sharedConnections;for(i=0;i<customShape.getChildren().getSize();i+=1){child=customShape.getChildren().get(i);this.addToSharedConnections(child);} if(customShape.ports){for(i=0;i<customShape.ports.getSize();i+=1){connection=customShape.ports.get(i).connection;sourceShape=connection.srcPort.parent;destShape=connection.destPort.parent;if(this.findAncestorInCurrentSelection(sourceShape)&&this.findAncestorInCurrentSelection(destShape)&&!sharedConnections.find('id',connection.getID())){sharedConnections.insert(connection);}}} return this;};Canvas.prototype.removeConnection=function(conn){this.connections.remove(conn);return this;};Canvas.prototype.attachListeners=function(){var $canvas=$(this.html).click(this.onClick(this)),$canvasContainer=$canvas.parent();$canvas.mousedown(this.onMouseDown(this));$canvasContainer.scroll(this.onScroll(this,$canvasContainer));$canvas.mousemove(this.onMouseMove(this));$canvas.mouseup(this.onMouseUp(this));$canvas.on("createelement",this.onCreateElement(this));$canvas.on("removeelement",this.onRemoveElement(this));$canvas.on("changeelement",this.onChangeElement(this));$canvas.on("selectelement",this.onSelectElement(this));$canvas.on("rightclick",this.onRightClick(this));$canvas.on("contextmenu",function(e){e.preventDefault();});$(document).on('keydown',onCanvasKeyDown).on('keyup',onCanvasKeyUp);this.updateBehaviors();return this;};Canvas.prototype.onCreateElementHandler=function(updatedElement){};Canvas.prototype.onCreateElement=function(canvas){return function(e,ui){canvas.onCreateElementHandler(canvas.updatedElement);};};Canvas.prototype.onRemoveElementHandler=function(updatedElement){return true;};Canvas.prototype.onRemoveElement=function(canvas){return function(e,ui){canvas.onRemoveElementHandler(canvas.updatedElement.relatedElements);};};Canvas.prototype.onChangeElementHandler=function(updatedElements){};Canvas.prototype.onChangeElement=function(canvas){return function(e,ui){canvas.onChangeElementHandler(canvas.updatedElement);};};Canvas.prototype.onSelectElementHandler=function(updatedElements){};Canvas.prototype.onSelectElement=function(canvas){return function(e,ui){canvas.onSelectElementHandler(canvas.updatedElement);};};Canvas.prototype.onRightClickHandler=function(updatedElement,x,y){};Canvas.prototype.onRightClick=function(canvas){return function(event,e,element){var x=e.pageX-canvas.x+canvas.leftScroll,y=e.pageY-canvas.y+canvas.topScroll;canvas.updatedElement=element;canvas.onRightClickHandler(canvas.updatedElement,x,y);};};Canvas.prototype.onClick=function(canvas){return function(e,ui){var currentLabel=canvas.currentLabel;if(currentLabel){currentLabel.loseFocus();$(currentLabel.textField).focusout();}};};Canvas.prototype.onMouseDown=function(canvas){return function(e,ui){var x=e.pageX-canvas.getX()+canvas.getLeftScroll(),y=e.pageY-canvas.getY()+canvas.getTopScroll();e.preventDefault();if(e.which===3){canvas.rightClick=true;$(canvas.html).trigger("rightclick",[e,canvas]);} canvas.isMouseDown=true;canvas.isMouseDownAndMove=false;if(canvas.draggingASegmentHandler){return;} canvas.emptyCurrentSelection();canvas.hideCurrentConnection();canvas.multipleSelectionHelper.reset();canvas.multipleSelectionHelper.setPosition(x / canvas.zoomFactor,y / canvas.zoomFactor);canvas.multipleSelectionHelper.oldX=x;canvas.multipleSelectionHelper.oldY=y;canvas.multipleSelectionHelper.setVisible(true);canvas.multipleSelectionHelper.changeOpacity(0.2);};};Canvas.prototype.onMouseMove=function(canvas){return function(e,ui){if(canvas.isMouseDown&&!canvas.rightClick){canvas.isMouseDownAndMove=true;var x=e.pageX-canvas.getX()+canvas.getLeftScroll(),y=e.pageY-canvas.getY()+canvas.getTopScroll(),topLeftX,topLeftY,bottomRightX,bottomRightY;topLeftX=Math.min(x,canvas.multipleSelectionHelper.oldX);topLeftY=Math.min(y,canvas.multipleSelectionHelper.oldY);bottomRightX=Math.max(x,canvas.multipleSelectionHelper.oldX);bottomRightY=Math.max(y,canvas.multipleSelectionHelper.oldY);canvas.multipleSelectionHelper.setPosition(topLeftX / canvas.zoomFactor,topLeftY / canvas.zoomFactor);canvas.multipleSelectionHelper.setDimension((bottomRightX-topLeftX)/ canvas.zoomFactor,(bottomRightY-topLeftY)/ canvas.zoomFactor);}};};Canvas.prototype.onClickHandler=function(canvas,x,y){};Canvas.prototype.onMouseUp=function(canvas){return function(e,ui){if(canvas.isMouseDownAndMove){var x=e.pageX-canvas.getX()+canvas.getLeftScroll(),y=e.pageY-canvas.getY()+canvas.getTopScroll();canvas.multipleSelectionHelper.setPosition(Math.min(x,canvas.multipleSelectionHelper.zoomX)/ canvas.zoomFactor,Math.min(y,canvas.multipleSelectionHelper.zoomY)/ canvas.zoomFactor);if(canvas.multipleSelectionHelper){canvas.multipleSelectionHelper.wrapElements();}}else{if(canvas.isMouseDown&&!canvas.rightClick){canvas.onClickHandler(canvas,x,y);} if(!canvas.multipleSelectionHelper.wasDragged){canvas.multipleSelectionHelper.reset().setVisible(false);}} canvas.isMouseDown=false;canvas.isMouseDownAndMove=false;canvas.rightClick=false;};};Canvas.prototype.onScroll=function(canvas,$canvasContainer){return function(e,ui){canvas.setLeftScroll($canvasContainer.scrollLeft()).setTopScroll($canvasContainer.scrollTop());};};Canvas.prototype.triggerSelectEvent=function(selection){var i,elements=[],current;for(i=0;i<selection.length;i+=1){current=selection[i];elements.push({id:current.id,type:current.type,relatedObject:current});} this.updatedElement=elements;$(this.html).trigger('selectelement');return this;};Canvas.prototype.triggerRightClickEvent=function(element){this.updatedElement={id:element.id,type:element.type,relatedObject:element};$(this.html).trigger('rightclick');return this;};Canvas.prototype.triggerCreateEvent=function(shape,relatedElements){this.updatedElement={id:(shape&&shape.id)||null,type:(shape&&shape.type)||null,relatedObject:shape,relatedElements:relatedElements};$(this.html).trigger('createelement');return this;};Canvas.prototype.triggerRemoveEvent=function(shape,relatedElements){this.updatedElement={id:(shape&&shape.id)||null,type:(shape&&shape.type)||null,relatedObject:shape,relatedElements:relatedElements};$(this.html).trigger('removeelement');return this;};Canvas.prototype.triggerDimensionChangeEvent=function(shape,oldWidth,oldHeight,newWidth,newHeight){this.updatedElement=[{id:shape.id,type:shape.type,fields:[{field:"width",oldVal:oldWidth,newVal:newWidth},{field:"height",oldVal:oldHeight,newVal:newHeight}],relatedObject:shape}];$(this.html).trigger('changeelement');return this;};Canvas.prototype.triggerPortChangeEvent=function(port){this.updatedElement=[{id:port.getID(),type:port.type,fields:[{field:'x',oldVal:port.getOldX(),newVal:port.getX()},{field:'y',oldVal:port.getOldY(),newVal:port.getY()},{field:'parent',oldVal:port.getOldParent().getID(),newVal:port.getParent().getID()},{field:'state',oldVal:port.connection.getOldPoints(),newVal:port.connection.savePoints()&&port.connection.getPoints()}],relatedObject:port}];$(this.html).trigger('changeelement');return this;};Canvas.prototype.triggerConnectionStateChangeEvent=function(connection){var points=[],point,i;connection.savePoints();for(i=0;i<connection.points.length;i+=1){point=connection.points[i];points.push(new Point(point.x / this.zoomFactor,point.y / this.zoomFactor));} this.updatedElement=[{id:connection.getID(),type:connection.type,fields:[{field:'state',oldVal:connection.getOldPoints(),newVal:points}],relatedObject:connection}];$(this.html).trigger('changeelement');return this;};Canvas.prototype.triggerPositionChangeEvent=function(shapes,before,after){var i,elements=[];for(i=0;i<shapes.length;i+=1){elements.push({id:shapes[i].getID(),type:shapes[i].type,fields:[{field:"x",oldVal:before[i].x,newVal:after[i].x},{field:"y",oldVal:before[i].y,newVal:after[i].y}],relatedObject:shapes[i]});} this.updatedElement=elements;$(this.html).trigger('changeelement');return this;};Canvas.prototype.triggerTextChangeEvent=function(element,oldText,newText){this.updatedElement=[{id:element.id,type:element.type,parent:element.parent,fields:[{field:"message",oldVal:oldText,newVal:newText}],relatedObject:element}];$(this.html).trigger('changeelement');return this;};Canvas.prototype.triggerParentChangeEvent=function(shapes,before,after){var i,elements=[];for(i=0;i<shapes.length;i+=1){elements.push({id:shapes[i].getID(),type:shapes[i].type,fields:[{field:"parent",oldParent:before[i].parent,newVal:after[i].parent},{field:"x",oldVal:before[i].x,newVal:after[i].x},{field:"y",oldVal:before[i].y,newVal:after[i].y}],relatedObject:shapes[i]});} this.updatedElement=elements;$(this.html).trigger('changeelement');return this;};Canvas.prototype.setTopScroll=function(newScroll){this.topScroll=newScroll;return this;};Canvas.prototype.setLeftScroll=function(newScroll){this.leftScroll=newScroll;return this;};Canvas.prototype.setZoomFactor=function(newZoom){if(typeof newZoom==="number"&&newZoom%25===0&&newZoom>0){this.zoomFactor=newZoom;} return this;};Canvas.prototype.setCurrentConnection=function(newConnection){if(newConnection.type==="Connection"){this.currentConnection=newConnection;} return this;};Canvas.prototype.setToolBarShapeFactory=function(newFunction){Canvas.prototype.toolBarShapeFactory=newFunction;return this;};Canvas.prototype.getZoomFactor=function(){return this.zoomFactor;};Canvas.prototype.getZoomPropertiesIndex=function(){return this.zoomPropertiesIndex;};Canvas.prototype.getConnectionSegment=function(){return this.connectionSegment;};Canvas.prototype.getLeftScroll=function(){return this.leftScroll;};Canvas.prototype.getTopScroll=function(){return this.topScroll;};Canvas.prototype.getCurrentConnection=function(){return this.currentConnection;};Canvas.prototype.getCurrentSelection=function(){return this.currentSelection;};Canvas.prototype.getConnections=function(){return this.connections;};Canvas.prototype.getSharedConnections=function(){return this.sharedConnections;};Canvas.prototype.getCustomShapes=function(){return this.customShapes;};Canvas.prototype.getRegularShapes=function(){return this.regularShapes;};Canvas.prototype.getMultipleSelectionHelper=function(){return this.multipleSelectionHelper;};Canvas.prototype.getHorizontalSnapper=function(){return this.horizontalSnapper;};Canvas.prototype.getVerticalSnapper=function(){return this.verticalSnapper;};Canvas.prototype.getUpdatedElement=function(){return this.updatedElement;};Canvas.prototype.isResizable=function(){return false;};Canvas.prototype.getCanvas=function(){return this;};Canvas.prototype.undo=function(){this.commandStack.undo();return this;};Canvas.prototype.redo=function(){this.commandStack.redo();return this;};Canvas.prototype.stringify=function(){var i,customShapes=[],regularShapes=[],connections=[],inheritedJSON,thisJSON;for(i=0;i<this.customShapes.getSize();i+=1){customShapes.push(this.customShapes.get(i).stringify());} for(i=0;i<this.regularShapes.getSize();i+=1){regularShapes.push(this.regularShapes.get(i).stringify());} for(i=0;i<this.connections.getSize();i+=1){connections.push(this.connections.get(i).stringify());} inheritedJSON=Shape.prototype.stringify.call(this);thisJSON={customShapes:customShapes,regularShapes:regularShapes,connections:connections};$.extend(true,inheritedJSON,thisJSON);return inheritedJSON;};Canvas.prototype.addToShapesToCopy=function(shape){var i,child;this.shapesToCopy.push(shape.stringify());for(i=0;i<shape.getChildren().getSize();i+=1){child=shape.getChildren().get(i);this.addToShapesToCopy(child);} return this;};Canvas.prototype.copy=function(){var i,shape,connection;this.shapesToCopy=[];for(i=0;i<this.getCurrentSelection().getSize();i+=1){shape=this.getCurrentSelection().get(i);this.addToShapesToCopy(shape);} this.connectionsToCopy=[];for(i=0;i<this.getSharedConnections().getSize();i+=1){connection=this.getSharedConnections().get(i);this.connectionsToCopy.push(connection.stringify());} return this;};Canvas.prototype.paste=function(){this.parse({shapes:this.shapesToCopy,connections:this.connectionsToCopy,createCommand:true,uniqueID:true,selectAfterFinish:true,prependMessage:"Copy of ",diffX:100,diffY:100});return this;};Canvas.prototype.shapeFactory=function(type,options){if(this.copyAndPasteReferences[type]){return new this.copyAndPasteReferences[type](options);} return new CustomShape(options);};Canvas.prototype.connectionFactory=function(type,options){if(type&&this.copyAndPasteReferences[type]){return new this.copyAndPasteReferences[type](options);} return new Connection(options);};Canvas.prototype.transformToTree=function(nodes){var tree={},node,i;for(i=0;i<nodes.length;i+=1){node=nodes[i];if(!tree[node.id]){tree[node.id]=[];} if(node.parent){if(!tree[node.parent]){tree[node.parent]=[];} tree[node.parent][node.order]=node.id;}} return tree;};Canvas.prototype.levelOrderTraversal=function(tree,root){var queue=[],processed=[],top,realRoot=root||this.getID(),i;queue.push(realRoot);while(queue.length>0){top=queue.shift();processed.push(top);for(i=0;i<tree[top].length;i+=1){queue.push(tree[top][i]);}} return processed;};Canvas.prototype.parse=function(options){var defaults={shapes:[],connections:[],uniqueID:false,selectAfterFinish:false,prependMessage:"",createCommand:true,diffX:0,diffY:0},i,j,id,oldID,shape,points,shapeOptions,connection,connectionOptions,sourcePort,sourcePortOptions,sourceShape,sourceBorder,destPort,destPortOptions,destShape,destBorder,command,diffX,diffY,connectionConstructor,stackCommandCreate=[],stackCommandConnect=[],canvasID=this.getID(),mapOldId={},map={},connectExtendedOptions={};$.extend(true,defaults,options);diffX=defaults.diffX;diffY=defaults.diffY;map[canvasID]=this;mapOldId[canvasID]=canvasID;if(defaults.selectAfterFinish){this.emptyCurrentSelection();} for(i=0;i<defaults.shapes.length;i+=1){shapeOptions={};$.extend(true,shapeOptions,defaults.shapes[i]);shapeOptions.canvas=this;oldID=shapeOptions.id;if(defaults.uniqueID){shapeOptions.id=Utils.generateUniqueId();} mapOldId[oldID]=shapeOptions.id;if(shapeOptions.labels){for(j=0;j<shapeOptions.labels.length;j+=1){shapeOptions.labels[j].message=defaults.prependMessage+ shapeOptions.labels[j].message;}} shape=this.shapeFactory(shapeOptions.type,shapeOptions);map[shapeOptions.id]=shape;if(!mapOldId[shapeOptions.parent]){this.addElement(shape,shapeOptions.x+diffX,shapeOptions.y+diffY,true);}else if(shapeOptions.parent!==canvasID){map[mapOldId[shapeOptions.parent]].addElement(shape,shapeOptions.x,shapeOptions.y,true);}else{map[mapOldId[shapeOptions.parent]].addElement(shape,shapeOptions.x+diffX,shapeOptions.y+diffY,true);} shape.parseHook();shape.attachListeners();command=new CommandCreate(shape);command.execute();stackCommandCreate.push(command);} for(i=0;i<defaults.connections.length;i+=1){connectionOptions={};$.extend(true,connectionOptions,defaults.connections[i]);points=connectionOptions.state||[];sourcePortOptions=connectionOptions.srcPort;sourceShape=map[mapOldId[sourcePortOptions.parent]];sourceBorder=sourceShape.getBorderConsideringLayers();destPortOptions=connectionOptions.destPort;destShape=map[mapOldId[destPortOptions.parent]];destBorder=destShape.getBorderConsideringLayers();if(points.length===0){points.push({x:sourcePortOptions.x+sourceShape.getAbsoluteX(),y:sourcePortOptions.y+sourceShape.getAbsoluteY()});points.push({x:destPortOptions.x+destShape.getAbsoluteX(),y:destPortOptions.y+destShape.getAbsoluteY()});} sourcePort=new Port({width:12,height:12});destPort=new Port({width:12,height:12});sourceShape.addPort(sourcePort,points[0].x+diffX+sourceBorder- sourceShape.getAbsoluteX(),points[0].y+diffX+sourceBorder- sourceShape.getAbsoluteY());destShape.addPort(destPort,points[points.length-1].x+diffX+destBorder- destShape.getAbsoluteX(),points[points.length-1].y+diffY+destBorder- destShape.getAbsoluteY(),false,sourcePort);connectExtendedOptions=$.extend(true,{},defaults.connections[i],{srcPort:sourcePort,destPort:destPort,canvas:this,segmentStyle:connectionOptions.segmentStyle});connection=this.connectionFactory(connectionOptions.type,connectExtendedOptions);connection.id=connectionOptions.id||Utils.generateUniqueId();if(defaults.uniqueID){connection.id=Utils.generateUniqueId();} connection.setSrcDecorator(new ConnectionDecorator({width:11,height:11,canvas:this,decoratorPrefix:connectionOptions.srcDecoratorPrefix,decoratorType:"source",parent:connection}));connection.setDestDecorator(new ConnectionDecorator({width:11,height:11,canvas:this,decoratorPrefix:connectionOptions.destDecoratorPrefix,decoratorType:"target",parent:connection}));command=new CommandConnect(connection);stackCommandConnect.push(command);if(points.length>=3){connection.connect({algorithm:'user',points:connectionOptions.state,dx:defaults.diffX,dy:defaults.diffY});}else{connection.connect();} connection.setSegmentMoveHandlers();this.addConnection(connection);connection.checkAndCreateIntersectionsWithAll();sourcePort.attachListeners(sourcePort);destPort.attachListeners(destPort);this.triggerCreateEvent(connection,[]);} if(defaults.selectAfterFinish){for(id in map){if(map.hasOwnProperty(id)){if(map[id].family!=='Canvas'){this.addToSelection(map[id]);}}}} if(defaults.createCommand){this.commandStack.add(new CommandPaste(this,{stackCommandCreate:stackCommandCreate,stackCommandConnect:stackCommandConnect}));} return this;};CustomLine=function(options){this.x1=null;this.y1=null;this.x2=null;this.y2=null;this.html=null;this.canvas=(options.canvas)?options.canvas:null;};CustomLine.prototype.type="CustomLine";CustomLine.prototype.family="CustomLine";CustomLine.prototype.setStarPoint=function(startPoint){this.x1=startPoint.x;this.y1=startPoint.y;return this;};CustomLine.prototype.setEndPoint=function(endPoint){this.x2=endPoint.x;this.y2=endPoint.y;return this;};CustomLine.prototype.setHtml=function(html){this.html=html;return this;};CustomLine.prototype.drawLine=function(x1,y1,x2,y2){var dx,dy,length,angle,transform;dx=x2-x1;dy=y2-y1;length=Math.sqrt(Math.pow(Math.abs(dx),2)+Math.pow(Math.abs(dy),2));angle=Math.atan2(dy,dx)*180 / Math.PI;var auxLine=1;var screenCssPixelRatio=(window.outerWidth-8)/ window.innerWidth;if(screenCssPixelRatio>=.20&&screenCssPixelRatio<=.34){auxLine=4;}else if(screenCssPixelRatio<=.54){auxLine=3;}else if(screenCssPixelRatio<=.92){auxLine=2;}else{auxLine=1;} if(dx===0){if(dy<0){this.createDiv(x2,y2,auxLine,length);}else{this.createDiv(x1,y1,auxLine,length);}}else if(dy===0){if(dx<0){this.createDiv(x2,y2,length,auxLine);}else{this.createDiv(x1,y1,length,auxLine);}}else{transform='rotate('+angle+'deg)';this.createDiv(x1,y1,length,auxLine,transform);} this.paint();};CustomLine.prototype.paint=function(){if(this.canvas){$(this.html).appendTo(this.canvas);} this.html="";};CustomLine.prototype.createDiv=function(x,y,w,h,transform){var orientation=(w===1?1:(h===1?0:-1)),offset;var lineWidth=w===1?2:w;var lineHeight=h===1?2:h;if(transform){offset={left:x,top:y};}else{offset={left:x-(orientation===1?1:0),top:y-(orientation===0?1:0)};} this.html=$('<div>').addClass('line').css({'animation':'none','position':'absolute'}).width(lineWidth).height(lineHeight).css(offset);if(transform){$(this.html).css({'-webkit-transform':transform,'-moz-transform':transform,'-ms-transform':transform,'transform':transform});}else{$(this.html).addClass((orientation===1?'line-vertical':(orientation===0?'line-horizontal':'')));}};CustomLine.prototype.remove=function(){if(this.html){$(this.html).remove();}};CustomLine.prototype.clear=function(){$(this.html).empty();if(this.canvas)this.canvas.innerHTML="";};function onCanvasKeyDown(e){if(activeCanvas){switch(e.which){case 16:isShift=true;break;case 17:isCtrl=true;break;case 116:e.preventDefault();window.location.reload(true);break;case 37:if(!activeCanvas.currentLabel){e.preventDefault();activeCanvas.moveElements(activeCanvas,'LEFT');} break;case 38:if(!activeCanvas.currentLabel){e.preventDefault();activeCanvas.moveElements(activeCanvas,'TOP');} break;case 39:if(!activeCanvas.currentLabel){e.preventDefault();activeCanvas.moveElements(activeCanvas,'RIGHT');} break;case 40:if(!activeCanvas.currentLabel){e.preventDefault();activeCanvas.moveElements(activeCanvas,'BOTTOM');} break;case 67:if(!activeCanvas.currentLabel&&isCtrl){if(activeCanvas.copyAndPaste){e.preventDefault();activeCanvas.copy();}} break;case 86:if(!activeCanvas.currentLabel&&isCtrl){if(activeCanvas.copyAndPaste){e.preventDefault();activeCanvas.paste();}} break;case 90:if(isCtrl){if(isShift){activeCanvas.redo();e.preventDefault();}else{activeCanvas.undo();e.preventDefault();}} break;case 8:if(activeCanvas&&(activeCanvas.currentSelection.getSize()||activeCanvas.currentConnection)){e.preventDefault();} break;}}} function onCanvasKeyUp(e){var current;if(activeCanvas){e.preventDefault();} switch(e.which){case 8:if(isCtrl||(activeCanvas&&activeCanvas.currentSelection.getSize())){if(activeCanvas&&!activeCanvas.currentLabel){activeCanvas.removeElements();}}else if(activeCanvas&&activeCanvas.currentConnection){activeCanvas.removeElements();} break;case 13:if(activeCanvas&&activeCanvas.currentLabel){activeCanvas.currentLabel.loseFocus();} break;case 46:if(activeCanvas&&!activeCanvas.currentLabel){activeCanvas.removeElements();} break;case 16:isShift=false;break;case 17:isCtrl=false;break;case 113:if(activeCanvas&&activeCanvas.getCurrentSelection().getLast()!==null){current=activeCanvas.getCurrentSelection().getLast();if(current!==undefined&¤t.label.html!==null){$(current.label.html).dblclick();$(current.label.text.html).focus();}} break;}} return{ArrayList:ArrayList,Point:Point,Geometry:Geometry,Graphics:Graphics,Utils:Utils,Command:Command,CommandStack:CommandStack,CommandResize:CommandResize,CommandConnect:CommandConnect,CommandReconnect:CommandReconnect,CommandSegmentMove:CommandSegmentMove,CommandMove:CommandMove,CommandCreate:CommandCreate,CommandSwitchContainer:CommandSwitchContainer,CommandDelete:CommandDelete,CommandPaste:CommandPaste,CommandEditLabel:CommandEditLabel,ContainerBehavior:ContainerBehavior,RegularContainerBehavior:RegularContainerBehavior,NoContainerBehavior:NoContainerBehavior,DragBehavior:DragBehavior,RegularDragBehavior:RegularDragBehavior,NoDragBehavior:NoDragBehavior,ConnectionDragBehavior:ConnectionDragBehavior,CustomShapeDragBehavior:CustomShapeDragBehavior,ResizeBehavior:ResizeBehavior,RegularResizeBehavior:RegularResizeBehavior,NoResizeBehavior:NoResizeBehavior,DropBehavior:DropBehavior,ConnectionDropBehavior:ConnectionDropBehavior,NoDropBehavior:NoDropBehavior,ContainerDropBehavior:ContainerDropBehavior,ConnectionContainerDropBehavior:ConnectionContainerDropBehavior,Color:Color,Style:Style,JCoreObject:JCoreObject,Handler:Handler,ReadOnlyLayer:ReadOnlyLayer,ResizeHandler:ResizeHandler,SegmentMoveHandler:SegmentMoveHandler,Port:Port,Router:Router,ManhattanConnectionRouter:ManhattanConnectionRouter,ConnectionDecorator:ConnectionDecorator,Connection:Connection,BehavioralElement:BehavioralElement,Layer:Layer,Shape:Shape,Label:Label,CustomShape:CustomShape,Segment:Segment,RegularShape:RegularShape,Polygon:Polygon,Rectangle:Rectangle,Oval:Oval,Arc:Arc,MultipleSelectionContainer:MultipleSelectionContainer,Intersection:Intersection,Snapper:Snapper,Canvas:Canvas,setActiveCanvas:function(canvas){activeCanvas=canvas;return this;},getActiveCanvas:function(){return activeCanvas;},getVersion:function(){return version;},dispose:function(){$(document).off('keydown',onCanvasKeyDown).off('keyup',onCanvasKeyUp);}};}(jQuery,window)); /* End of File include/javascript/pmse/lib/jcore.js */