source: Dev/trunk/src/client/dojox/drawing/tools/Arrow.js @ 529

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

Added Dojo 1.9.3 release.

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1define(["dojo/_base/lang", "../util/oo", "../manager/_registry", "./Line",
2"../annotations/Arrow", "../util/positioning"],
3function(lang, oo, registry, Line, AnnotationArrow, positioning){
4
5var Arrow = oo.declare(
6        Line,
7        function(options){
8                // summary:
9                //              constructor
10                if(this.arrowStart){
11                        this.begArrow = new AnnotationArrow({stencil:this, idx1:0, idx2:1});
12                }
13                if(this.arrowEnd){
14                        this.endArrow = new AnnotationArrow({stencil:this, idx1:1, idx2:0});
15                }
16                if(this.points.length){
17                        // This is protecting against cases when there are no points
18                        // not sure how that would ever happen
19                        // Render & label here instead of in base because of Arrow annotation
20                        this.render();
21                        options.label && this.setLabel(options.label);
22                }
23        },
24        {
25                // summary:
26                //              Extends stencil.Line and adds an arrow head
27                //              to the end and or start.
28
29                draws:true,
30                type:"dojox.drawing.tools.Arrow",
31                baseRender:false,
32               
33                // arrowStart: Boolean
34                //              Whether or not to place an arrow on start.
35                arrowStart:false,
36
37                // arrowEnd: Boolean
38                //              Whether or not to place an arrow on end.
39                arrowEnd:true,
40               
41                labelPosition: function(){
42                        // summary:
43                        //              The custom position used for the label
44
45                        var d = this.data;
46                        var pt = positioning.label({x:d.x1,y:d.y1},{x:d.x2,y:d.y2});
47                        return {
48                                x:pt.x,
49                                y:pt.y
50                        }
51                },
52               
53                onUp: function(/*EventObject*/obj){
54                        if(this.created || !this.shape){ return; }
55                       
56                        // if too small, need to reset
57                        var p = this.points;
58                        var len = this.util.distance(p[0].x,p[0].y,p[1].x,p[1].y);
59                        if(len<this.minimumSize){
60                                this.remove(this.shape, this.hit);
61                                return;
62                        }
63                       
64                        var pt = this.util.snapAngle(obj, this.angleSnap/180);
65                        this.setPoints([
66                                {x:p[0].x, y:p[0].y},
67                                {x:pt.x, y:pt.y}
68                        ]);
69                       
70                        this.renderedOnce = true;
71                        this.onRender(this);
72                }
73        }
74);
75
76lang.setObject("dojox.drawing.tools.Arrow", Arrow);
77Arrow.setup = {
78        name:"dojox.drawing.tools.Arrow",
79        tooltip:"Arrow Tool",
80        iconClass:"iconArrow"
81};
82
83registry.register(Arrow.setup, "tool");
84
85return Arrow;
86});
Note: See TracBrowser for help on using the repository browser.