Debian Codegraph @

dojox/sketch/UnderlineAnnotation.js

raw symbols SCIP
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 //this.anchors.start=new ta.Anchor(this, "start");
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 }/*else if(c.localName=="line"){
37 var stroke=this.property('stroke');
38 var style=c.getAttribute('style');
39 var m=style.match(/stroke:([^;]+);/)[1];
40 if(m){
41 stroke.color=m;
42 this.property('fill',m);
43 }
44 m=style.match(/stroke-width:([^;]+);/)[1];
45 if(m){
46 stroke.width=m;
47 }
48 this.property('stroke',stroke);
49 }*/
50 }
51 };
52
53 p.initialize=function(obj){
54 //var font=(ta.Annotation.labelFont)?ta.Annotation.labelFont:{family:"Times", size:"16px"};
55 this.apply(obj);
56
57 // create either from scratch or based on the passed node
58 this.shape=this.figure.group.createGroup();
59 this.shape.getEventSource().setAttribute("id", this.id);
60 //if(this.transform.dx || this.transform.dy){ this.shape.setTransform(this.transform); }
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 //.setFont(font)
70 //.setFill(this.property('fill'));
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 //.setStroke({ color:this.property('fill'), width:1 });
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(); //the bbox is dependent on the size of the text, so need to update it here
113 }
114 }
115 };
116 p.serialize=function(){
117 var s=this.property('stroke');
118 return '<g '+this.writeCommonAttrs()+'>'
119 //+ '<line x1="1" x2="'+this.labelShape.getTextWidth()+1+'" y1="5" y2="5" style="stroke:'+s.color+';stroke-width:'+s.width+';" />'
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 //customize AnnotationTool to place a underlilne shape onmouseup, no need
128 //to drag a box (like other shapes)
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 //zero out end so that the clickover is shown at the right pos
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 });