Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / drawing / plugins / tools / Pan.js

History | View | Annotate | Download (4.06 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.plugins.tools.Pan"]){
9
dojo._hasResource["dojox.drawing.plugins.tools.Pan"]=true;
10
dojo.provide("dojox.drawing.plugins.tools.Pan");
11
dojo.require("dojox.drawing.plugins._Plugin");
12
dojox.drawing.plugins.tools.Pan=dojox.drawing.util.oo.declare(dojox.drawing.plugins._Plugin,function(_1){
13
this.domNode=_1.node;
14
var _2;
15
this.toolbar=_1.scope;
16
this.connect(this.toolbar,"onToolClick",this,function(){
17
this.onSetPan(false);
18
});
19
this.connect(this.keys,"onKeyUp",this,"onKeyUp");
20
this.connect(this.keys,"onKeyDown",this,"onKeyDown");
21
this.connect(this.keys,"onArrow",this,"onArrow");
22
this.connect(this.anchors,"onAnchorUp",this,"checkBounds");
23
this.connect(this.stencils,"register",this,"checkBounds");
24
this.connect(this.canvas,"resize",this,"checkBounds");
25
this.connect(this.canvas,"setZoom",this,"checkBounds");
26
this.connect(this.canvas,"onScroll",this,function(){
27
if(this._blockScroll){
28
this._blockScroll=false;
29
return;
30
}
31
_2&&clearTimeout(_2);
32
_2=setTimeout(dojo.hitch(this,"checkBounds"),200);
33
});
34
this._mouseHandle=this.mouse.register(this);
35
},{selected:false,keyScroll:false,type:"dojox.drawing.plugins.tools.Pan",onPanUp:function(_3){
36
if(_3.id==this.button.id){
37
this.onSetPan(false);
38
}
39
},onKeyUp:function(_4){
40
switch(_4.keyCode){
41
case 32:
42
this.onSetPan(false);
43
break;
44
case 39:
45
case 37:
46
case 38:
47
case 40:
48
clearInterval(this._timer);
49
break;
50
}
51
},onKeyDown:function(_5){
52
if(_5.keyCode==32){
53
this.onSetPan(true);
54
}
55
},interval:20,onArrow:function(_6){
56
if(this._timer){
57
clearInterval(this._timer);
58
}
59
this._timer=setInterval(dojo.hitch(this,function(_7){
60
this.canvas.domNode.parentNode.scrollLeft+=_7.x*10;
61
this.canvas.domNode.parentNode.scrollTop+=_7.y*10;
62
},_6),this.interval);
63
},onSetPan:function(_8){
64
if(_8===true||_8===false){
65
this.selected=!_8;
66
}
67
if(this.selected){
68
this.selected=false;
69
this.button.deselect();
70
}else{
71
this.selected=true;
72
this.button.select();
73
}
74
this.mouse.setEventMode(this.selected?"pan":"");
75
},onPanDrag:function(_9){
76
var x=_9.x-_9.last.x;
77
var y=_9.y-_9.last.y;
78
this.canvas.domNode.parentNode.scrollTop-=_9.move.y;
79
this.canvas.domNode.parentNode.scrollLeft-=_9.move.x;
80
this.canvas.onScroll();
81
},onUp:function(_a){
82
if(_a.withinCanvas){
83
this.keyScroll=true;
84
}else{
85
this.keyScroll=false;
86
}
87
},onStencilUp:function(_b){
88
this.checkBounds();
89
},onStencilDrag:function(_c){
90
},checkBounds:function(){
91
var _d=function(){
92
};
93
var _e=function(){
94
};
95
var t=Infinity,r=-Infinity,b=-10000,l=10000,sx=0,sy=0,dy=0,dx=0,mx=this.stencils.group?this.stencils.group.getTransform():{dx:0,dy:0},sc=this.mouse.scrollOffset(),_f=sc.left?10:0,scX=sc.top?10:0,ch=this.canvas.height,cw=this.canvas.width,z=this.canvas.zoom,pch=this.canvas.parentHeight,pcw=this.canvas.parentWidth;
96
this.stencils.withSelected(function(m){
97
var o=m.getBounds();
98
_e("SEL BOUNDS:",o);
99
t=Math.min(o.y1+mx.dy,t);
100
r=Math.max(o.x2+mx.dx,r);
101
b=Math.max(o.y2+mx.dy,b);
102
l=Math.min(o.x1+mx.dx,l);
103
});
104
this.stencils.withUnselected(function(m){
105
var o=m.getBounds();
106
_e("UN BOUNDS:",o);
107
t=Math.min(o.y1,t);
108
r=Math.max(o.x2,r);
109
b=Math.max(o.y2,b);
110
l=Math.min(o.x1,l);
111
_d("----------- B:",b,o.y2);
112
});
113
b*=z;
114
var _10=0,_11=0;
115
_d("Bottom test","b:",b,"z:",z,"ch:",ch,"pch:",pch,"top:",sc.top,"sy:",sy,"mx.dy:",mx.dy);
116
if(b>pch||sc.top){
117
_d("*bottom scroll*");
118
ch=Math.max(b,pch+sc.top);
119
sy=sc.top;
120
_10+=this.canvas.getScrollWidth();
121
}else{
122
if(!sy&&ch>pch){
123
_d("*bottom remove*");
124
ch=pch;
125
}
126
}
127
r*=z;
128
if(r>pcw||sc.left){
129
cw=Math.max(r,pcw+sc.left);
130
sx=sc.left;
131
_11+=this.canvas.getScrollWidth();
132
}else{
133
if(!sx&&cw>pcw){
134
cw=pcw;
135
}
136
}
137
cw+=_10*2;
138
ch+=_11*2;
139
this._blockScroll=true;
140
this.stencils.group&&this.stencils.group.applyTransform({dx:dx,dy:dy});
141
this.stencils.withUnselected(function(m){
142
m.transformPoints({dx:dx,dy:dy});
143
});
144
this.canvas.setDimensions(cw,ch,sx,sy);
145
}});
146
dojox.drawing.plugins.tools.Pan.setup={name:"dojox.drawing.plugins.tools.Pan",tooltip:"Pan Tool",iconClass:"iconPan",button:false};
147
dojox.drawing.register(dojox.drawing.plugins.tools.Pan.setup,"plugin");
148
}