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