Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / sketch / UnderlineAnnotation.js @ 12

History | View | Annotate | Download (3.31 KB)

1
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6

    
7

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