source: Dev/branches/rest-dojo-ui/client/dojox/drawing/annotations/Label.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1dojo.provide("dojox.drawing.annotations.Label");
2dojo.require("dojox.drawing.stencil.Text");
3
4dojox.drawing.annotations.Label = dojox.drawing.util.oo.declare(
5        // summary:
6        //      An annotation called internally to label an Stencil.
7        // description:
8        //      Annotation is positioned with dojox.drawing.util.positioning.label
9        //      That method should be overwritten for custom placement. Or,
10        //      add a 'setLabelCustom' method to the Stencil and it will be used.
11        //
12        dojox.drawing.stencil.Text,
13        function(/*Object*/options){
14                // arguments:
15                //      options: Object
16                //              One key value: the stencil that called this.
17                //
18                this.master = options.stencil;
19                this.labelPosition = options.labelPosition || "BR"; // TL, TR, BR, BL, or function
20                if(dojo.isFunction(this.labelPosition)){
21                        this.setLabel = this.setLabelCustom;
22                }
23                this.setLabel(options.text || "");
24                this.connect(this.master, "onTransform", this, "setLabel");
25                this.connect(this.master, "destroy", this, "destroy");
26               
27                if(this.style.labelSameColor){
28                        this.connect(this.master, "attr", this, "beforeAttr");
29                }
30        },{
31                _align:"start",
32                drawingType:"label",
33               
34                setLabelCustom: function(/* ? String */text){
35                        // summary:
36                        //      Attaches to custom positioning within a Stencil
37                        //
38                        var d = dojo.hitch(this.master, this.labelPosition)();
39                        this.setData({
40                                x:d.x,
41                                y:d.y,
42                                width:d.w || this.style.text.minWidth,
43                                height:d.h || this._lineHeight
44                        });
45                       
46                        // is an event, not text, so keep the old label:
47                        if(text && !text.split){ text = this.getText(); }
48                       
49                        this.render(this.typesetter(text));
50                },
51               
52                setLabel: function(/* String */text){
53                        // summary:
54                        //      Sets the text of the label. Not called directly. Should
55                        //      be called within Stencil. See stencil._Base
56                        //
57                        // onTransform will pass an object here
58                        var x, y, box = this.master.getBounds();
59                       
60                        if(/B/.test(this.labelPosition)){
61                                y = box.y2 - this._lineHeight;
62                        }else{
63                                y = box.y1;
64                        }
65                       
66                        if(/R/.test(this.labelPosition)){
67                                x = box.x2;
68                        }else{
69                                y = box.y1;
70                                this._align = "end";
71                        }
72                       
73                        if(!this.labelWidth || (text && text.split && text != this.getText())){
74                                this.setData({
75                                        x:x,
76                                        y:y,
77                                        height:this._lineHeight,
78                                        width:this.style.text.minWidth
79                                });
80                               
81                                this.labelWidth = this.style.text.minWidth;
82                                this.render(this.typesetter(text));
83                               
84                        }else{
85                               
86                                this.setData({
87                                        x:x,
88                                        y:y,
89                                        height:this.data.height,
90                                        width:this.data.width
91                                });
92                               
93                                this.render();
94                        }
95                       
96                },
97                beforeAttr: function(key, value){
98                        if(value!==undefined){
99                                // make it an object
100                                var k = key; key = {}; key[k] = value;
101                        }
102                        delete key.x;
103                        delete key.y;
104                        delete key.width;
105                        delete key.height;
106                        this.attr(key);
107                         // FIXME: this.created should already be set, shouldn't it?
108                        !this.created && this.render();
109                }
110        }
111
112);
Note: See TracBrowser for help on using the repository browser.