root / trunk / web / dojo / dojox / sketch / Toolbar.js @ 12
History | View | Annotate | Download (2.23 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.Toolbar"]){ |
||
9 | dojo._hasResource["dojox.sketch.Toolbar"]=true; |
||
10 | dojo.provide("dojox.sketch.Toolbar");
|
||
11 | dojo.require("dojox.sketch.Annotation");
|
||
12 | dojo.require("dijit.Toolbar");
|
||
13 | dojo.require("dijit.form.Button");
|
||
14 | dojo.declare("dojox.sketch.ButtonGroup",null,{constructor:function(){ |
||
15 | this._childMaps={};
|
||
16 | this._children=[];
|
||
17 | },add:function(_1){ |
||
18 | this._childMaps[_1]=_1.connect(_1,"onActivate",dojo.hitch(this,"_resetGroup",_1)); |
||
19 | this._children.push(_1);
|
||
20 | },_resetGroup:function(p){ |
||
21 | var cs=this._children; |
||
22 | dojo.forEach(cs,function(c){
|
||
23 | if(p!=c&&c["attr"]){ |
||
24 | c.attr("checked",false); |
||
25 | } |
||
26 | }); |
||
27 | }}); |
||
28 | dojo.declare("dojox.sketch.Toolbar",dijit.Toolbar,{figure:null,plugins:null,postCreate:function(){ |
||
29 | this.inherited(arguments); |
||
30 | this.shapeGroup=new dojox.sketch.ButtonGroup; |
||
31 | if(!this.plugins){ |
||
32 | this.plugins=["Slider","Lead","SingleArrow","DoubleArrow","Underline","Preexisting"]; |
||
33 | } |
||
34 | this._plugins=[];
|
||
35 | dojo.forEach(this.plugins,function(_2){ |
||
36 | var _3=dojo.isString(_2)?_2:_2.name;
|
||
37 | var p=new dojox.sketch.tools[_3](_2.args||{}); |
||
38 | this._plugins.push(p);
|
||
39 | p.setToolbar(this);
|
||
40 | if(!this._defaultTool&&p.button){ |
||
41 | this._defaultTool=p;
|
||
42 | } |
||
43 | },this);
|
||
44 | },setFigure:function(f){ |
||
45 | this.figure=f;
|
||
46 | this.connect(f,"onLoad","reset"); |
||
47 | dojo.forEach(this._plugins,function(p){ |
||
48 | p.setFigure(f); |
||
49 | }); |
||
50 | },destroy:function(){ |
||
51 | dojo.forEach(this._plugins,function(p){ |
||
52 | p.destroy(); |
||
53 | }); |
||
54 | this.inherited(arguments); |
||
55 | delete this._defaultTool; |
||
56 | delete this._plugins; |
||
57 | },addGroupItem:function(_4,_5){ |
||
58 | if(_5!="toolsGroup"){ |
||
59 | console.error("not supported group "+_5);
|
||
60 | return;
|
||
61 | } |
||
62 | this.shapeGroup.add(_4);
|
||
63 | },reset:function(){ |
||
64 | this._defaultTool.activate();
|
||
65 | },_setShape:function(s){ |
||
66 | if(!this.figure.surface){ |
||
67 | return;
|
||
68 | } |
||
69 | if(this.figure.hasSelections()){ |
||
70 | for(var i=0;i<this.figure.selected.length;i++){ |
||
71 | var _6=this.figure.selected[i].serialize(); |
||
72 | this.figure.convert(this.figure.selected[i],s); |
||
73 | this.figure.history.add(dojox.sketch.CommandTypes.Convert,this.figure.selected[i],_6); |
||
74 | } |
||
75 | } |
||
76 | }}); |
||
77 | dojox.sketch.makeToolbar=function(_7,_8){ |
||
78 | var _9=new dojox.sketch.Toolbar(); |
||
79 | _9.setFigure(_8); |
||
80 | _7.appendChild(_9.domNode); |
||
81 | return _9;
|
||
82 | }; |
||
83 | } |