Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / sketch / PreexistingAnnotation.js @ 13

History | View | Annotate | Download (4.68 KB)

1 9 andrej.cim
/*
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.PreexistingAnnotation"]){
9
dojo._hasResource["dojox.sketch.PreexistingAnnotation"]=true;
10
dojo.provide("dojox.sketch.PreexistingAnnotation");
11
dojo.require("dojox.sketch.Annotation");
12
dojo.require("dojox.sketch.Anchor");
13
(function(){
14
var ta=dojox.sketch;
15
ta.PreexistingAnnotation=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.end={x:200,y:200};
20
this.radius=8;
21
this.textPosition={x:196,y:196};
22
this.textOffset=4;
23
this.textAlign="end";
24
this.rectShape=null;
25
this.labelShape=null;
26
this.anchors.start=new ta.Anchor(this,"start");
27
this.anchors.end=new ta.Anchor(this,"end");
28
};
29
ta.PreexistingAnnotation.prototype=new ta.Annotation;
30
var p=ta.PreexistingAnnotation.prototype;
31
p.constructor=ta.PreexistingAnnotation;
32
p.type=function(){
33
return "Preexisting";
34
};
35
p.getType=function(){
36
return ta.PreexistingAnnotation;
37
};
38
p._pos=function(){
39
var x=Math.min(this.start.x,this.end.x);
40
var y=Math.min(this.start.y,this.end.y);
41
var w=Math.max(this.start.x,this.end.x);
42
var h=Math.max(this.start.y,this.end.y);
43
this.start={x:x,y:y};
44
this.end={x:w,y:h};
45
this.textPosition={x:this.end.x-this.textOffset,y:this.end.y-this.textOffset};
46
};
47
p.apply=function(_2){
48
if(!_2){
49
return;
50
}
51
if(_2.documentElement){
52
_2=_2.documentElement;
53
}
54
this.readCommonAttrs(_2);
55
for(var i=0;i<_2.childNodes.length;i++){
56
var c=_2.childNodes[i];
57
if(c.localName=="text"){
58
this.property("label",c.childNodes.length?c.childNodes[0].nodeValue:"");
59
}else{
60
if(c.localName=="rect"){
61
if(c.getAttribute("x")!==null){
62
this.start.x=parseFloat(c.getAttribute("x"),10);
63
}
64
if(c.getAttribute("width")!==null){
65
this.end.x=parseFloat(c.getAttribute("width"),10)+parseFloat(c.getAttribute("x"),10);
66
}
67
if(c.getAttribute("y")!==null){
68
this.start.y=parseFloat(c.getAttribute("y"),10);
69
}
70
if(c.getAttribute("height")!==null){
71
this.end.y=parseFloat(c.getAttribute("height"),10)+parseFloat(c.getAttribute("y"),10);
72
}
73
if(c.getAttribute("r")!==null){
74
this.radius=parseFloat(c.getAttribute("r"),10);
75
}
76
var _3=this.property("stroke");
77
var _4=c.getAttribute("style");
78
var m=_4.match(/stroke:([^;]+);/);
79
if(m){
80
_3.color=m[1];
81
this.property("fill",m[1]);
82
}
83
m=_4.match(/stroke-width:([^;]+);/);
84
if(m){
85
_3.width=m[1];
86
}
87
this.property("stroke",_3);
88
}
89
}
90
}
91
};
92
p.initialize=function(_5){
93
this.apply(_5);
94
this._pos();
95
this.shape=this.figure.group.createGroup();
96
this.shape.getEventSource().setAttribute("id",this.id);
97
this.rectShape=this.shape.createRect({x:this.start.x,y:this.start.y,width:this.end.x-this.start.x,height:this.end.y-this.start.y,r:this.radius}).setFill([255,255,255,0.1]);
98
this.rectShape.getEventSource().setAttribute("shape-rendering","crispEdges");
99
this.labelShape=this.shape.createText({x:this.textPosition.x,y:this.textPosition.y,text:this.property("label"),align:this.textAlign}).setFill(this.property("fill"));
100
this.labelShape.getEventSource().setAttribute("id",this.id+"-labelShape");
101
this.draw();
102
};
103
p.destroy=function(){
104
if(!this.shape){
105
return;
106
}
107
this.shape.remove(this.rectShape);
108
this.shape.remove(this.labelShape);
109
this.figure.group.remove(this.shape);
110
this.shape=this.rectShape=this.labelShape=null;
111
};
112
p.getBBox=function(){
113
var x=Math.min(this.start.x,this.end.x);
114
var y=Math.min(this.start.y,this.end.y);
115
var w=Math.max(this.start.x,this.end.x)-x;
116
var h=Math.max(this.start.y,this.end.y)-y;
117
return {x:x-2,y:y-2,width:w+4,height:h+4};
118
};
119
p.draw=function(_6){
120
this.apply(_6);
121
this._pos();
122
this.shape.setTransform(this.transform);
123
this.rectShape.setShape({x:this.start.x,y:this.start.y,width:this.end.x-this.start.x,height:this.end.y-this.start.y,r:this.radius}).setFill([255,255,255,0.1]);
124
this.labelShape.setShape({x:this.textPosition.x,y:this.textPosition.y,text:this.property("label")}).setFill(this.property("fill"));
125
this.zoom();
126
};
127
p.zoom=function(_7){
128
if(this.rectShape){
129
_7=_7||this.figure.zoomFactor;
130
ta.Annotation.prototype.zoom.call(this,_7);
131
_7=dojox.gfx.renderer=="vml"?1:_7;
132
this.rectShape.setStroke({color:this.property("fill"),width:1/_7});
133
}
134
};
135
p.serialize=function(){
136
var s=this.property("stroke");
137
return "<g "+this.writeCommonAttrs()+">"+"<rect style=\"stroke:"+s.color+";stroke-width:1;fill:none;\" "+"x=\""+this.start.x+"\" "+"width=\""+(this.end.x-this.start.x)+"\" "+"y=\""+this.start.y+"\" "+"height=\""+(this.end.y-this.start.y)+"\" "+"rx=\""+this.radius+"\" "+"ry=\""+this.radius+"\" "+" />"+"<text style=\"fill:"+s.color+";text-anchor:"+this.textAlign+"\" font-weight=\"bold\" "+"x=\""+this.textPosition.x+"\" "+"y=\""+this.textPosition.y+"\">"+this.property("label")+"</text>"+"</g>";
138
};
139
ta.Annotation.register("Preexisting");
140
})();
141
}