source: [view]
dojo.provide("dojox.sketch.Annotation");
dojo.require("dojox.sketch.Anchor");
dojo.require("dojox.sketch._Plugin");
(function(){
var ta=dojox.sketch;
dojo.declare("dojox.sketch.AnnotationTool", ta._Plugin, {
onMouseDown: function(e){
this._omd=true;
},
onMouseMove: function(e,rect){
if(!this._omd){
return;
}
if(this._cshape){
this._cshape.setShape(rect);
} else {
this._cshape=this.figure.surface.createRect(rect)
.setStroke({color:"#999", width:1, style:"ShortDot"})
.setFill([255,255,255,0.7]);
this._cshape.getEventSource().setAttribute("shape-rendering","crispEdges");
}
},
onMouseUp: function(e){
if(!this._omd){
return;
}
this._omd=false;
var f=this.figure;
if(this._cshape){
f.surface.remove(this._cshape);
delete this._cshape;
}
if(!(f._startPoint.x==e.pageX&&f._startPoint.y==e.pageY)){
// The minimum number of pixels one has to travel before a shape
// gets drawn.
var limit=10;
if(Math.max(
limit,
Math.abs(f._absEnd.x-f._start.x),
Math.abs(f._absEnd.y-f._start.y)
)>limit){
this._create(f._start, f._end);
}
}
},
_create: function(start,end){
// create a new shape, needs to be accessible from the
// dragging functions.
var f=this.figure;
var _=f.nextKey();
var a=new (this.annotation)(f, _);
a.transform={
dx:f._calCol(start.x/f.zoomFactor),
dy:f._calCol(start.y/f.zoomFactor)
};
a.end={
x:f._calCol(end.x/f.zoomFactor),
y:f._calCol(end.y/f.zoomFactor)
};
if(a.control){
a.control={
x:f._calCol((end.x/2)/f.zoomFactor),
y:f._calCol((end.y/2)/f.zoomFactor)
};
}
f.onBeforeCreateShape(a);
a.initialize();
f.select(a);
f.onCreateShape(a);
f.history.add(ta.CommandTypes.Create,a);
}
});
ta.Annotation=function(figure, id){
// for editing stuff.
this.id=this._key=id;
this.figure=figure;
this.mode=ta.Annotation.Modes.View;
this.shape=null; // dojox.gfx.Group
this.boundingBox=null; // rect for boundaries
this.hasAnchors=true;
this.anchors={}; // ta.Anchor
this._properties={
'stroke':{ color:"blue", width:2 },
'font': {family:"Arial", size:16, weight:"bold"},
'fill': "blue",
'label': ""
};
if(this.figure){
this.figure.add(this);
}