Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / drawing / manager / Anchors.js

History | View | Annotate | Download (6.22 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.drawing.manager.Anchors"]){
9
dojo._hasResource["dojox.drawing.manager.Anchors"]=true;
10
dojo.provide("dojox.drawing.manager.Anchors");
11
dojox.drawing.manager.Anchors=dojox.drawing.util.oo.declare(function(_1){
12
this.mouse=_1.mouse;
13
this.undo=_1.undo;
14
this.util=_1.util;
15
this.drawing=_1.drawing;
16
this.items={};
17
},{onAddAnchor:function(_2){
18
},onReset:function(_3){
19
var st=this.util.byId("drawing").stencils;
20
st.onDeselect(_3);
21
st.onSelect(_3);
22
},onRenderStencil:function(){
23
for(var nm in this.items){
24
dojo.forEach(this.items[nm].anchors,function(a){
25
a.shape.moveToFront();
26
});
27
}
28
},onTransformPoint:function(_4){
29
var _5=this.items[_4.stencil.id].anchors;
30
var _6=this.items[_4.stencil.id].item;
31
var _7=[];
32
dojo.forEach(_5,function(a,i){
33
if(_4.id==a.id||_4.stencil.anchorType!="group"){
34
}else{
35
if(_4.org.y==a.org.y){
36
a.setPoint({dx:0,dy:_4.shape.getTransform().dy-a.shape.getTransform().dy});
37
}else{
38
if(_4.org.x==a.org.x){
39
a.setPoint({dx:_4.shape.getTransform().dx-a.shape.getTransform().dx,dy:0});
40
}
41
}
42
a.shape.moveToFront();
43
}
44
var mx=a.shape.getTransform();
45
_7.push({x:mx.dx+a.org.x,y:mx.dy+a.org.y});
46
if(a.point.t){
47
_7[_7.length-1].t=a.point.t;
48
}
49
},this);
50
_6.setPoints(_7);
51
_6.onTransform(_4);
52
this.onRenderStencil();
53
},onAnchorUp:function(_8){
54
},onAnchorDown:function(_9){
55
},onAnchorDrag:function(_a){
56
},onChangeStyle:function(_b){
57
for(var nm in this.items){
58
dojo.forEach(this.items[nm].anchors,function(a){
59
a.shape.moveToFront();
60
});
61
}
62
},add:function(_c){
63
this.items[_c.id]={item:_c,anchors:[]};
64
if(_c.anchorType=="none"){
65
return;
66
}
67
var _d=_c.points;
68
dojo.forEach(_d,function(p,i){
69
if(p.noAnchor){
70
return;
71
}
72
if(i==0||i==_c.points.length-1){
73
}
74
var a=new dojox.drawing.manager.Anchor({stencil:_c,point:p,pointIdx:i,mouse:this.mouse,util:this.util});
75
this.items[_c.id]._cons=[dojo.connect(a,"onRenderStencil",this,"onRenderStencil"),dojo.connect(a,"reset",this,"onReset"),dojo.connect(a,"onAnchorUp",this,"onAnchorUp"),dojo.connect(a,"onAnchorDown",this,"onAnchorDown"),dojo.connect(a,"onAnchorDrag",this,"onAnchorDrag"),dojo.connect(a,"onTransformPoint",this,"onTransformPoint"),dojo.connect(_c,"onChangeStyle",this,"onChangeStyle")];
76
this.items[_c.id].anchors.push(a);
77
this.onAddAnchor(a);
78
},this);
79
if(_c.shortType=="path"){
80
var f=_d[0],l=_d[_d.length-1],a=this.items[_c.id].anchors;
81
if(f.x==l.x&&f.y==l.y){
82
console.warn("LINK ANVHROS",a[0],a[a.length-1]);
83
a[0].linkedAnchor=a[a.length-1];
84
a[a.length-1].linkedAnchor=a[0];
85
}
86
}
87
if(_c.anchorType=="group"){
88
dojo.forEach(this.items[_c.id].anchors,function(_e){
89
dojo.forEach(this.items[_c.id].anchors,function(a){
90
if(_e.id!=a.id){
91
if(_e.org.y==a.org.y){
92
_e.x_anchor=a;
93
}else{
94
if(_e.org.x==a.org.x){
95
_e.y_anchor=a;
96
}
97
}
98
}
99
},this);
100
},this);
101
}
102
},remove:function(_f){
103
if(!this.items[_f.id]){
104
return;
105
}
106
dojo.forEach(this.items[_f.id].anchors,function(a){
107
a.destroy();
108
});
109
dojo.forEach(this.items[_f.id]._cons,dojo.disconnect,dojo);
110
this.items[_f.id].anchors=null;
111
delete this.items[_f.id];
112
}});
113
dojox.drawing.manager.Anchor=dojox.drawing.util.oo.declare(function(_10){
114
this.defaults=dojox.drawing.defaults.copy();
115
this.mouse=_10.mouse;
116
this.point=_10.point;
117
this.pointIdx=_10.pointIdx;
118
this.util=_10.util;
119
this.id=_10.id||this.util.uid("anchor");
120
this.org=dojo.mixin({},this.point);
121
this.stencil=_10.stencil;
122
if(this.stencil.anchorPositionCheck){
123
this.anchorPositionCheck=dojo.hitch(this.stencil,this.stencil.anchorPositionCheck);
124
}
125
if(this.stencil.anchorConstrain){
126
this.anchorConstrain=dojo.hitch(this.stencil,this.stencil.anchorConstrain);
127
}
128
this._zCon=dojo.connect(this.mouse,"setZoom",this,"render");
129
this.render();
130
this.connectMouse();
131
},{y_anchor:null,x_anchor:null,render:function(){
132
this.shape&&this.shape.removeShape();
133
var d=this.defaults.anchors,z=this.mouse.zoom,b=d.width*z,s=d.size*z,p=s/2,_11={width:b,style:d.style,color:d.color,cap:d.cap};
134
var _12={x:this.point.x-p,y:this.point.y-p,width:s,height:s};
135
this.shape=this.stencil.container.createRect(_12).setStroke(_11).setFill(d.fill);
136
this.shape.setTransform({dx:0,dy:0});
137
this.util.attr(this,"drawingType","anchor");
138
this.util.attr(this,"id",this.id);
139
},onRenderStencil:function(_13){
140
},onTransformPoint:function(_14){
141
},onAnchorDown:function(obj){
142
this.selected=obj.id==this.id;
143
},onAnchorUp:function(obj){
144
this.selected=false;
145
this.stencil.onTransformEnd(this);
146
},onAnchorDrag:function(obj){
147
if(this.selected){
148
var mx=this.shape.getTransform();
149
var pmx=this.shape.getParent().getParent().getTransform();
150
var _15=this.defaults.anchors.marginZero;
151
var _16=pmx.dx+this.org.x,_17=pmx.dy+this.org.y,x=obj.x-_16,y=obj.y-_17,s=this.defaults.anchors.minSize;
152
var _18,_19,_1a,_1b;
153
var chk=this.anchorPositionCheck(x,y,this);
154
if(chk.x<0){
155
console.warn("X<0 Shift");
156
while(this.anchorPositionCheck(x,y,this).x<0){
157
this.shape.getParent().getParent().applyTransform({dx:2,dy:0});
158
}
159
}
160
if(chk.y<0){
161
console.warn("Y<0 Shift");
162
while(this.anchorPositionCheck(x,y,this).y<0){
163
this.shape.getParent().getParent().applyTransform({dx:0,dy:2});
164
}
165
}
166
if(this.y_anchor){
167
if(this.org.y>this.y_anchor.org.y){
168
_1a=this.y_anchor.point.y+s-this.org.y;
169
_1b=Infinity;
170
if(y<_1a){
171
y=_1a;
172
}
173
}else{
174
_1a=-_17+_15;
175
_1b=this.y_anchor.point.y-s-this.org.y;
176
if(y<_1a){
177
y=_1a;
178
}else{
179
if(y>_1b){
180
y=_1b;
181
}
182
}
183
}
184
}else{
185
_1a=-_17+_15;
186
if(y<_1a){
187
y=_1a;
188
}
189
}
190
if(this.x_anchor){
191
if(this.org.x>this.x_anchor.org.x){
192
_18=this.x_anchor.point.x+s-this.org.x;
193
_19=Infinity;
194
if(x<_18){
195
x=_18;
196
}
197
}else{
198
_18=-_16+_15;
199
_19=this.x_anchor.point.x-s-this.org.x;
200
if(x<_18){
201
x=_18;
202
}else{
203
if(x>_19){
204
x=_19;
205
}
206
}
207
}
208
}else{
209
_18=-_16+_15;
210
if(x<_18){
211
x=_18;
212
}
213
}
214
var _1c=this.anchorConstrain(x,y);
215
if(_1c!=null){
216
x=_1c.x;
217
y=_1c.y;
218
}
219
this.shape.setTransform({dx:x,dy:y});
220
if(this.linkedAnchor){
221
this.linkedAnchor.shape.setTransform({dx:x,dy:y});
222
}
223
this.onTransformPoint(this);
224
}
225
},anchorConstrain:function(x,y){
226
return null;
227
},anchorPositionCheck:function(x,y,_1d){
228
return {x:1,y:1};
229
},setPoint:function(mx){
230
this.shape.applyTransform(mx);
231
},connectMouse:function(){
232
this._mouseHandle=this.mouse.register(this);
233
},disconnectMouse:function(){
234
this.mouse.unregister(this._mouseHandle);
235
},reset:function(_1e){
236
},destroy:function(){
237
dojo.disconnect(this._zCon);
238
this.disconnectMouse();
239
this.shape.removeShape();
240
}});
241
}