1 | define(["dojo/has","./shape"], function(has, shapeLib){ |
---|
2 | |
---|
3 | has.add("gfxRegistry", 1); |
---|
4 | |
---|
5 | var registry = {}; |
---|
6 | |
---|
7 | // a set of ids (keys=type) |
---|
8 | var _ids = {}; |
---|
9 | // a simple set impl to map shape<->id |
---|
10 | var hash = {}; |
---|
11 | |
---|
12 | registry.register = shapeLib.register = function(/*dojox/gfx/shape.Shape*/s){ |
---|
13 | // summary: |
---|
14 | // Register the specified shape into the graphics registry. |
---|
15 | // s: dojox/gfx/shape.Shape |
---|
16 | // The shape to register. |
---|
17 | // returns: Number |
---|
18 | // The unique id associated with this shape. |
---|
19 | |
---|
20 | // the id pattern : type+number (ex: Rect0,Rect1,etc) |
---|
21 | var t = s.declaredClass.split('.').pop(); |
---|
22 | var i = t in _ids ? ++_ids[t] : ((_ids[t] = 0)); |
---|
23 | var uid = t+i; |
---|
24 | hash[uid] = s; |
---|
25 | return uid; |
---|
26 | }; |
---|
27 | |
---|
28 | registry.byId = shapeLib.byId = function(/*String*/id){ |
---|
29 | // summary: |
---|
30 | // Returns the shape that matches the specified id. |
---|
31 | // id: String |
---|
32 | // The unique identifier for this Shape. |
---|
33 | // returns: dojox/gfx/shape.Shape |
---|
34 | return hash[id]; //dojox/gfx/shape.Shape |
---|
35 | }; |
---|
36 | |
---|
37 | registry.dispose = shapeLib.dispose = function(/*dojox/gfx/shape.Shape*/s, /*Boolean?*/recurse){ |
---|
38 | // summary: |
---|
39 | // Removes the specified shape from the registry. |
---|
40 | // s: dojox/gfx/shape.Shape |
---|
41 | // The shape to unregister. |
---|
42 | if(recurse && s.children){ |
---|
43 | for(var i=0; i< s.children.length; ++i){ |
---|
44 | registry.dispose(s.children[i], true); |
---|
45 | } |
---|
46 | } |
---|
47 | var uid = s.getUID(); |
---|
48 | hash[uid] = null; |
---|
49 | delete hash[uid]; |
---|
50 | }; |
---|
51 | |
---|
52 | return registry; |
---|
53 | }); |
---|