source: Dev/trunk/src/client/dojox/gfx/registry.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 1.4 KB
Line 
1define(["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});
Note: See TracBrowser for help on using the repository browser.