//>>built
define("dojox/sketch/Annotation","dojo/_base/kernel dojo/_base/lang dojo/_base/declare dojo/_base/json ./Anchor ./_Plugin".split(" "),function(e){e.declare("dojox.sketch.AnnotationTool",dojox.sketch._Plugin,{onMouseDown:function(a){this._omd=!0},onMouseMove:function(a,b){this._omd&&(this._cshape?this._cshape.setShape(b):(this._cshape=this.figure.surface.createRect(b).setStroke({color:"#999",width:1,style:"ShortDot"}).setFill([255,255,255,.7]),this._cshape.getEventSource().setAttribute("shape-rendering",
"crispEdges")))},onMouseUp:function(a){if(this._omd){this._omd=!1;var b=this.figure;this._cshape&&(b.surface.remove(this._cshape),delete this._cshape);(b._startPoint.x!=a.pageX||b._startPoint.y!=a.pageY)&&10<Math.max(10,Math.abs(b._absEnd.x-b._start.x),Math.abs(b._absEnd.y-b._start.y))&&this._create(b._start,b._end)}},_create:function(a,b){var d=this.figure,c=d.nextKey(),c=new this.annotation(d,c);c.transform={dx:d._calCol(a.x/d.zoomFactor),dy:d._calCol(a.y/d.zoomFactor)};c.end={x:d._calCol(b.x/d.zoomFactor),
y:d._calCol(b.y/d.zoomFactor)};c.control&&(c.control={x:d._calCol(b.x/2/d.zoomFactor),y:d._calCol(b.y/2/d.zoomFactor)});d.onBeforeCreateShape(c);c.initialize();d.select(c);d.onCreateShape(c);d.history.add(dojox.sketch.CommandTypes.Create,c)}});dojox.sketch.Annotation=function(a,b){this.id=this._key=b;this.figure=a;this.mode=dojox.sketch.Annotation.Modes.View;this.boundingBox=this.shape=null;this.hasAnchors=!0;this.anchors={};this._properties={stroke:{color:"blue",width:2},font:{family:"Arial",size:16,
weight:"bold"},fill:"blue",label:""};this.figure&&this.figure.add(this)};var c=dojox.sketch.Annotation.prototype;c.constructor=dojox.sketch.Annotation;c.type=function(){return""};c.getType=function(){return dojox.sketch.Annotation};c.onRemove=function(a){this.figure.history.add(dojox.sketch.CommandTypes.Delete,this,this.serialize())};c.property=function(a,b){var c;a=a.toLowerCase();void 0!==this._properties[a]&&(c=this._properties[a]);if(1<arguments.length&&(this._properties[a]=b,c!=b))this.onPropertyChange(a,
c);return c};c.onPropertyChange=function(a,b){};c.onCreate=function(){this.figure.history.add(dojox.sketch.CommandTypes.Create,this)};c.onDblClick=function(a){a=prompt("Set new text:",this.property("label"));!1!==a&&(this.beginEdit(dojox.sketch.CommandTypes.Modify),this.property("label",a),this.draw(),this.endEdit())};c.initialize=function(){};c.destroy=function(){};c.draw=function(){};c.apply=function(a){};c.serialize=function(){};c.getBBox=function(){};c.beginEdit=function(a){this._type||(this._type=
a||dojox.sketch.CommandTypes.Move,this._prevState=this.serialize())};c.endEdit=function(){this._prevState!=this.serialize()&&this.figure.history.add(this._type,this,this._prevState);this._type=this._prevState=""};c.calculate={slope:function(a,b){return a.x-b.x?(a.y-b.y)/(a.x-b.x):0},dx:function(a,b,c){a=this.slope(a,b);return 0==a?a:c/a},dy:function(a,b,c){return this.slope(a,b)*c}};c.drawBBox=function(){var a=this.getBBox();this.boundingBox?this.boundingBox.setShape(a):(this.boundingBox=this.shape.createRect(a).moveToBack().setStroke({color:"#999",
width:1,style:"Dash"}).setFill([238,238,238,.3]),this.boundingBox.getEventSource().setAttribute("id",this.id+"-boundingBox"),this.boundingBox.getEventSource().setAttribute("shape-rendering","crispEdges"),this.figure._add(this))};c.setBinding=function(a){this.transform.dx+=a.dx;this.transform.dy+=a.dy;this.draw()};c.getTextBox=function(a){var b=this.property("font"),b={fontFamily:b.family,fontSize:b.size,fontWeight:b.weight};a&&(b.fontSize=Math.floor(b.fontSize/a));return dojox.gfx._base._getTextBox(this.property("label"),
b)};c.setMode=function(a){if(this.mode!=a){this.mode=a;var b="disable";a==dojox.sketch.Annotation.Modes.Edit&&(b="enable");"enable"==b?(this.drawBBox(),this.figure._add(this)):this.boundingBox&&(this.shape&&this.shape.remove(this.boundingBox),this.boundingBox=null);for(var c in this.anchors)this.anchors[c][b]()}};c.zoom=function(a){a=a||this.figure.zoomFactor;if(this.labelShape){var b=e.clone(this.property("font"));b.size=Math.ceil(b.size/a)+"px";this.labelShape.setFont(b)}for(var c in this.anchors)this.anchors[c].zoom(a);
"vml"==dojox.gfx.renderer&&(a=1);this.pathShape&&(b=e.clone(this.property("stroke")),b.width=1<a?b.width:Math.ceil(b.width/a)+"px",this.pathShape.setStroke(b))};c.writeCommonAttrs=function(){return'id\x3d"'+this.id+'" dojoxsketch:type\x3d"'+this.type()+'" transform\x3d"translate('+this.transform.dx+","+this.transform.dy+')"'+(this.data?" \x3e\x3c![CDATA[data:"+e.toJson(this.data)+"]]":"")};c.readCommonAttrs=function(a){for(var b=0,c=a.childNodes,f;f=c[b++];)4==f.nodeType&&("properties:"==f.nodeValue.substr(0,
11)?this._properties=e.fromJson(f.nodeValue.substr(11)):"data:"==f.nodeValue.substr(0,5)?this.data=e.fromJson(f.nodeValue.substr(5)):console.error("unknown CDATA node in node ",a));a.getAttribute("transform")&&(a=a.getAttribute("transform").replace("translate(","").split(","),this.transform.dx=parseFloat(a[0],10),this.transform.dy=parseFloat(a[1],10))};dojox.sketch.Annotation.Modes={View:0,Edit:1};dojox.sketch.Annotation.register=function(a,b){var c=dojox.sketch[a+"Annotation"];dojox.sketch.registerTool(a,
function(d){e.mixin(d,{shape:a,annotation:c});return new (b||dojox.sketch.AnnotationTool)(d)})};return dojox.sketch.Annotation});