Figure.js
Summary
No overview generated for 'Figure.js'
draw2d.Figure=function()
{
this.construct();
}
draw2d.Figure.prototype.type="Figure";
draw2d.Figure.ZOrderBaseIndex = 100;
draw2d.Figure.setZOrderBaseIndex=function( index)
{
draw2d.Figure.ZOrderBaseIndex = index;
}
draw2d.Figure.prototype.construct=function()
{
this.lastDragStartTime =0;
this.x = 0;
this.y = 0;
this.border=null;
this.setDimension(10,10);
this.id = this.generateUId();
this.html = this.createHTMLElement();
this.canvas = null;
this.workflow = null;
this.draggable = null;
this.parent = null;
this.isMoving = false;
this.canSnapToHelper = true;
this.snapToGridAnchor = new draw2d.Point(0,0);
this.timer = -1;
this.setDeleteable(true);
this.setCanDrag(true);
this.setResizeable(true);
this.setSelectable(true);
this.properties = new Object();
this.moveListener = new draw2d.ArrayList();
}
draw2d.Figure.prototype.dispose=function()
{
this.canvas = null;
this.workflow = null;
this.moveListener = null;
if(this.draggable!=null)
{
this.draggable.removeEventListener("mouseenter", this.tmpMouseEnter);
this.draggable.removeEventListener("mouseleave", this.tmpMouseLeave);
this.draggable.removeEventListener("dragend", this.tmpDragend);
this.draggable.removeEventListener("dragstart",this.tmpDragstart );
this.draggable.removeEventListener("drag",this.tmpDrag);
this.draggable.removeEventListener("dblclick",this.tmpDoubleClick );
this.draggable.node = null;
}
this.draggable = null;
if(this.border!=null)
this.border.dispose();
this.border = null;
if(this.parent!=null)
this.parent.removeChild(this);
}
draw2d.Figure.prototype.getProperties=function()
{
return this.properties;
}
draw2d.Figure.prototype.getProperty=function( key)
{
return this.properties[key];
}
draw2d.Figure.prototype.setProperty=function( key, value)
{
this.properties[key]=value;
this.setDocumentDirty();
}
draw2d.Figure.prototype.getId=function()
{
return this.id;
}
draw2d.Figure.prototype.setCanvas= function( canvas)
{
this.canvas = canvas;
}
draw2d.Figure.prototype.getWorkflow=function()
{
return this.workflow;
}
draw2d.Figure.prototype.setWorkflow= function( workflow)
{
if(this.draggable==null)
{
this.html.tabIndex="0";
var oThis = this;
this.keyDown=function(event)
{
event.cancelBubble = true;
event.returnValue = true;
oThis.onKeyDown(event.keyCode, event.ctrlKey);
}
if (this.html.addEventListener)
this.html.addEventListener("keydown", this.keyDown, false);
else if (this.html.attachEvent)
this.html.attachEvent("onkeydown", this.keyDown);
this.draggable = new draw2d.Draggable(this.html, draw2d.Draggable.DRAG_X | draw2d.Draggable.DRAG_Y);
this.draggable.node = this;
this.tmpContextMenu = function (oEvent){oThis.onContextMenu(oThis.x+oEvent.x, oEvent.y+oThis.y);};
this.tmpMouseEnter = function (oEvent){oThis.onMouseEnter();};
this.tmpMouseLeave = function (oEvent){oThis.onMouseLeave();};
this.tmpDragend = function (oEvent){oThis.onDragend();};
this.tmpDragstart = function (oEvent){
var w = oThis.workflow;
w.showMenu(null);
if(oThis.workflow.toolPalette && oThis.workflow.toolPalette.activeTool)
{
oEvent.returnValue = false;
oThis.workflow.onMouseDown(oThis.x+oEvent.x, oEvent.y+oThis.y);
oThis.workflow.onMouseUp(oThis.x+oEvent.x, oEvent.y+oThis.y);
return;
}
oEvent.returnValue = oThis.onDragstart(oEvent.x,oEvent.y);
};
this.tmpDrag = function (oEvent){oThis.onDrag();};
this.tmpDoubleClick = function (oEvent){oThis.onDoubleClick();};
this.draggable.addEventListener("contextmenu", this.tmpContextMenu);
this.draggable.addEventListener("mouseenter", this.tmpMouseEnter);
this.draggable.addEventListener("mouseleave", this.tmpMouseLeave);
this.draggable.addEventListener("dragend", this.tmpDragend);
this.draggable.addEventListener("dragstart",this.tmpDragstart );
this.draggable.addEventListener("drag",this.tmpDrag);
this.draggable.addEventListener("dblclick",this.tmpDoubleClick );
}
this.workflow = workflow;
}
draw2d.Figure.prototype.createHTMLElement=function()
{
var item = document.createElement('div');
item.id = this.id;
item.style.position="absolute";
item.style.left = this.x+"px";
item.style.top = this.y+"px";
item.style.height = this.width+"px";
item.style.width = this.height+"px";
item.style.margin = "0px";
item.style.padding= "0px";
item.style.outline= "none";
item.style.zIndex = ""+draw2d.Figure.ZOrderBaseIndex;
return item;
}
draw2d.Figure.prototype.setParent=function( parent)
{
this.parent = parent;
}
draw2d.Figure.prototype.getParent=function()
{
return this.parent;
}
draw2d.Figure.prototype.getZOrder=function()
{
return this.html.style.zIndex;
}
draw2d.Figure.prototype.setZOrder=function( index)
{
this.html.style.zIndex=index;
}
draw2d.Figure.prototype.hasFixedPosition=function()
{
return false;
}
draw2d.Figure.prototype.getMinWidth=function()
{
return 5;
}
draw2d.Figure.prototype.getMinHeight=function()
{
return 5;
}
draw2d.Figure.prototype.getHTMLElement=function()
{
if(this.html==null)
this.html = this.createHTMLElement();
return this.html;
}
draw2d.Figure.prototype.paint=function()
{
}
draw2d.Figure.prototype.setBorder=function( border)
{
if(this.border!=null)
this.border.figure=null;
this.border=border;
this.border.figure=this;
this.border.refresh();
this.setDocumentDirty();
}
draw2d.Figure.prototype.onContextMenu=function( x, y)
{
var menu = this.getContextMenu();
if(menu!=null)
this.workflow.showMenu(menu,x,y);
}
draw2d.Figure.prototype.getContextMenu=function()
{
return null;
}
draw2d.Figure.prototype.onDoubleClick=function()
{
}
draw2d.Figure.prototype.onMouseEnter=function()
{
}
draw2d.Figure.prototype.onMouseLeave=function()
{
}
draw2d.Figure.prototype.onDrag = function()
{
this.x = this.draggable.getLeft();
this.y = this.draggable.getTop();
if(this.isMoving==false)
{
this.isMoving = true;
this.setAlpha(0.5);
}
this.fireMoveEvent();
}
draw2d.Figure.prototype.onDragend = function()
{
if(this.getWorkflow().getEnableSmoothFigureHandling()==true)
{
var oFigure = this;
var slowShow = function()
{
if(oFigure.alpha<1.0)
oFigure.setAlpha(Math.min(1.0,oFigure.alpha+0.05));
else
{
window.clearInterval(oFigure.timer);
oFigure.timer = -1;
}
};
if(oFigure.timer>0)
window.clearInterval(oFigure.timer);
oFigure.timer = window.setInterval(slowShow,20);
}
else
{
this.setAlpha(1.0);
}
this.command.setPosition(this.x, this.y);
this.workflow.commandStack.execute(this.command);
this.command = null;
this.isMoving = false;
this.workflow.hideSnapToHelperLines();
this.fireMoveEvent();
}
draw2d.Figure.prototype.onDragstart = function( x, y)
{
if(!this.canDrag)
return false;
this.command = new draw2d.CommandMove(this, this.x,this.y);
return true;
}
draw2d.Figure.prototype.setCanDrag=function(flag)
{
this.canDrag= flag;
if(flag)
this.html.style.cursor="move";
else
this.html.style.cursor=null;
}
draw2d.Figure.prototype.setAlpha=function( percent)
{
if(this.alpha==percent)
return;
try
{
this.html.style.MozOpacity=percent ;
}
catch(exc){}
try
{
this.html.style.opacity=percent ;
}
catch(exc){}
try
{
var opacityValue = Math.round(percent * 100);
if(opacityValue>=99)
this.html.style.filter = "";
else
this.html.style.filter = "alpha(opacity=" + opacityValue + ")";
} catch(exc){}
this.alpha = percent;
}
draw2d.Figure.prototype.setDimension=function( w, h)
{
this.width = Math.max(this.getMinWidth(),w);
this.height= Math.max(this.getMinHeight(),h);
if(this.html==null)
return;
this.html.style.width = this.width+"px";
this.html.style.height = this.height+"px";
this.fireMoveEvent();
if(this.workflow!=null && this.workflow.getCurrentSelection()==this)
this.workflow.showResizeHandles(this);
}
draw2d.Figure.prototype.setPosition=function( xPos , yPos )
{
this.x= xPos;
this.y= yPos;
if(this.html==null)
return;
this.html.style.left = this.x+"px";
this.html.style.top = this.y+"px";
this.fireMoveEvent();
if(this.workflow!=null && this.workflow.getCurrentSelection()==this)
this.workflow.showResizeHandles(this);
}
draw2d.Figure.prototype.isResizeable=function()
{
return this.resizeable;
}
draw2d.Figure.prototype.setResizeable=function( flag)
{
this.resizeable=flag;
}
draw2d.Figure.prototype.isSelectable=function()
{
return this.selectable;
}
draw2d.Figure.prototype.setSelectable=function( flag)
{
this.selectable=flag;
}
draw2d.Figure.prototype.isStrechable=function()
{
return true;
}
draw2d.Figure.prototype.isDeleteable=function()
{
return this.deleteable;
}
draw2d.Figure.prototype.setDeleteable=function(flag)
{
this.deleteable = flag;
}
draw2d.Figure.prototype.setCanSnapToHelper=function(flag)
{
this.canSnapToHelper = flag;
}
draw2d.Figure.prototype.getCanSnapToHelper=function()
{
return this.canSnapToHelper;
}
draw2d.Figure.prototype.getSnapToGridAnchor=function()
{
return this.snapToGridAnchor;
}
draw2d.Figure.prototype.setSnapToGridAnchor=function( point)
{
this.snapToGridAnchor = point;
}
draw2d.Figure.prototype.getBounds=function()
{
return new draw2d.Dimension(this.getX(),this.getY(),this.getWidth(),this.getHeight());
}
draw2d.Figure.prototype.getWidth=function()
{
return this.width;
}
draw2d.Figure.prototype.getHeight=function()
{
return this.height;
}
draw2d.Figure.prototype.getY=function()
{
return this.y;
}
draw2d.Figure.prototype.getX=function()
{
return this.x;
}
draw2d.Figure.prototype.getAbsoluteY=function()
{
return this.y;
}
draw2d.Figure.prototype.getAbsoluteX=function()
{
return this.x;
}
draw2d.Figure.prototype.onKeyDown=function( keyCode, ctrl)
{
if(keyCode==46 && this.isDeleteable()==true)
{
this.workflow.commandStack.execute(new draw2d.CommandDelete(this));
}
if(ctrl)
{
this.workflow.onKeyDown(keyCode,ctrl);
}
}
draw2d.Figure.prototype.getPosition=function()
{
return new draw2d.Point(this.x, this.y);
}
draw2d.Figure.prototype.isOver = function ( iX , iY)
{
var x = this.getAbsoluteX();
var y = this.getAbsoluteY();
var iX2 = x + this.width;
var iY2 = y + this.height;
return (iX >= x && iX <= iX2 && iY >= y && iY <= iY2);
}
draw2d.Figure.prototype.attachMoveListener = function( figure)
{
if(figure==null || this.moveListener==null)
return;
this.moveListener.add(figure);
}
draw2d.Figure.prototype.detachMoveListener = function( figure)
{
if(figure==null || this.moveListener==null)
return;
this.moveListener.remove(figure);
}
draw2d.Figure.prototype.fireMoveEvent=function()
{
this.setDocumentDirty();
var size= this.moveListener.getSize();
for(var i=0;i<size;i++)
{
this.moveListener.get(i).onOtherFigureMoved(this);
}
}
draw2d.Figure.prototype.onOtherFigureMoved=function( figure)
{
}
draw2d.Figure.prototype.setDocumentDirty=function()
{
if(this.workflow!=null)
this.workflow.setDocumentDirty();
}
draw2d.Figure.prototype.generateUId=function()
{
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 10;
var maxTry = 10;
nbTry = 0
while (nbTry < 1000)
{
var id = '';
for (var i=0; i<string_length; i++)
{
var rnum = Math.floor(Math.random() * chars.length);
id += chars.substring(rnum,rnum+1);
}
elem = document.getElementById(id);
if (!elem)
return id
nbTry += 1
}
return null
}
draw2d.Figure.prototype.disableTextSelection=function( e)
{
if (typeof e.onselectstart!="undefined")
e.onselectstart=function(){return false}
else if (typeof e.style.MozUserSelect!="undefined")
e.style.MozUserSelect="none"
}
Documentation generated by
JSDoc on Thu Feb 7 23:45:47 2008