| 1 |
define(["./Annotation", "./Anchor"], function(){ |
| 2 |
var ta=dojox.sketch; |
| 3 |
ta.UnderlineAnnotation=function(figure, id){ |
| 4 |
ta.Annotation.call(this, figure, id); |
| 5 |
this.transform={dx:0, dy:0}; |
| 6 |
this.start={x:0, y:0}; |
| 7 |
this.property('label','#'); |
| 8 |
this.labelShape=null; |
| 9 |
this.lineShape=null; |
| 10 |
|
| 11 |
}; |
| 12 |
ta.UnderlineAnnotation.prototype=new ta.Annotation; |
| 13 |
var p=ta.UnderlineAnnotation.prototype; |
| 14 |
p.constructor=ta.UnderlineAnnotation; |
| 15 |
|
| 16 |
p.type=function(){ return 'Underline'; }; |
| 17 |
p.getType=function(){ return ta.UnderlineAnnotation; }; |
| 18 |
|
| 19 |
p.apply=function(obj){ |
| 20 |
if(!obj){ return; } |
| 21 |
if(obj.documentElement){ obj=obj.documentElement; } |
| 22 |
this.readCommonAttrs(obj); |
| 23 |
|
| 24 |
for(var i=0; i<obj.childNodes.length; i++){ |
| 25 |
var c=obj.childNodes[i]; |
| 26 |
if(c.localName=="text"){ |
| 27 |
this.property('label',c.childNodes[0].nodeValue); |
| 28 |
var style=c.getAttribute('style'); |
| 29 |
var m=style.match(/fill:([^;]+);/); |
| 30 |
if(m){ |
| 31 |
var stroke=this.property('stroke'); |
| 32 |
stroke.collor=m[1]; |
| 33 |
this.property('stroke',stroke); |
| 34 |
this.property('fill',stroke.collor); |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
} |
| 51 |
}; |
| 52 |
|
| 53 |
p.initialize=function(obj){ |
| 54 |
|
| 55 |
this.apply(obj); |
| 56 |
|
| 57 |
|
| 58 |
this.shape=this.figure.group.createGroup(); |
| 59 |
this.shape.getEventSource().setAttribute("id", this.id); |
| 60 |
|
| 61 |
|
| 62 |
this.labelShape=this.shape.createText({ |
| 63 |
x:0, |
| 64 |
y:0, |
| 65 |
text:this.property('label'), |
| 66 |
decoration:"underline", |
| 67 |
align:"start" |
| 68 |
}) |
| 69 |
|
| 70 |
|
| 71 |
this.labelShape.getEventSource().setAttribute('id',this.id+"-labelShape"); |
| 72 |
|
| 73 |
this.lineShape=this.shape.createLine({ |
| 74 |
x1:1, |
| 75 |
x2:this.labelShape.getTextWidth(), |
| 76 |
y1:2, |
| 77 |
y2:2 |
| 78 |
}) |
| 79 |
|
| 80 |
this.lineShape.getEventSource().setAttribute("shape-rendering","crispEdges"); |
| 81 |
this.draw(); |
| 82 |
}; |
| 83 |
p.destroy=function(){ |
| 84 |
if(!this.shape){ return; } |
| 85 |
this.shape.remove(this.labelShape); |
| 86 |
this.shape.remove(this.lineShape); |
| 87 |
this.figure.group.remove(this.shape); |
| 88 |
this.shape=this.lineShape=this.labelShape=null; |
| 89 |
}; |
| 90 |
p.getBBox=function(){ |
| 91 |
var b=this.getTextBox(); |
| 92 |
var z=this.figure.zoomFactor; |
| 93 |
|
| 94 |
return { x:0, y:(b.h*-1+4)/z, width:(b.w+2)/z, height:b.h/z }; |
| 95 |
}; |
| 96 |
p.draw=function(obj){ |
| 97 |
this.apply(obj); |
| 98 |
this.shape.setTransform(this.transform); |
| 99 |
this.labelShape.setShape({ x:0, y:0, text:this.property('label') }) |
| 100 |
.setFill(this.property('fill')); |
| 101 |
this.zoom(); |
| 102 |
}; |
| 103 |
p.zoom=function(pct){ |
| 104 |
if(this.labelShape){ |
| 105 |
pct = pct || this.figure.zoomFactor; |
| 106 |
var textwidthadj=dojox.gfx.renderer=='vml'?0:2/pct; |
| 107 |
ta.Annotation.prototype.zoom.call(this,pct); |
| 108 |
pct = dojox.gfx.renderer=='vml'?1:pct; |
| 109 |
this.lineShape.setShape({ x1:0, x2:this.getBBox().width-textwidthadj, y1:2, y2:2 }) |
| 110 |
.setStroke({ color:this.property('fill'), width:1/pct }); |
| 111 |
if(this.mode==ta.Annotation.Modes.Edit){ |
| 112 |
this.drawBBox(); |
| 113 |
} |
| 114 |
} |
| 115 |
}; |
| 116 |
p.serialize=function(){ |
| 117 |
var s=this.property('stroke'); |
| 118 |
return '<g '+this.writeCommonAttrs()+'>' |
| 119 |
|
| 120 |
+ '<text style="fill:'+this.property('fill')+';" font-weight="bold" text-decoration="underline" ' |
| 121 |
+ 'x="0" y="0">' |
| 122 |
+ this.property('label') |
| 123 |
+ '</text>' |
| 124 |
+ '</g>'; |
| 125 |
}; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
dojo.declare("dojox.sketch.UnderlineAnnotationTool", ta.AnnotationTool, { |
| 130 |
onMouseDown: function(){}, |
| 131 |
onMouseUp: function(){ |
| 132 |
var f=this.figure; |
| 133 |
if(!f._start){ |
| 134 |
return; |
| 135 |
} |
| 136 |
|
| 137 |
f._end={x:0,y:0}; |
| 138 |
this._create(f._start,{x:f._start.x+10,y:f._start.y+10}); |
| 139 |
}, |
| 140 |
onMouseMove: function(){} |
| 141 |
}); |
| 142 |
ta.Annotation.register("Underline", ta.UnderlineAnnotationTool); |
| 143 |
return dojox.sketch.UnderlineAnnotation; |
| 144 |
}); |