Arrow.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.drawing.tools.Arrow"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.drawing.tools.Arrow"] = true;
  8. dojo.provide("dojox.drawing.tools.Arrow");
  9. dojox.drawing.tools.Arrow = dojox.drawing.util.oo.declare(
  10. // summary:
  11. // Extends stencil.Line and adds an arrow head
  12. // to the end and or start.
  13. //
  14. dojox.drawing.tools.Line,
  15. function(options){
  16. // summary: constructor
  17. if(this.arrowStart){
  18. this.begArrow = new dojox.drawing.annotations.Arrow({stencil:this, idx1:0, idx2:1});
  19. }
  20. if(this.arrowEnd){
  21. this.endArrow = new dojox.drawing.annotations.Arrow({stencil:this, idx1:1, idx2:0});
  22. }
  23. if(this.points.length){
  24. // This is protecting against cases when there are no points
  25. // not sure how that would ever happen
  26. // Render & label here instead of in base because of Arrow annotation
  27. this.render();
  28. options.label && this.setLabel(options.label);
  29. }
  30. },
  31. {
  32. draws:true,
  33. type:"dojox.drawing.tools.Arrow",
  34. baseRender:false,
  35. // arrowStart: Boolean
  36. // Whether or not to place an arrow on start.
  37. arrowStart:false,
  38. //
  39. // arrowEnd: Boolean
  40. // Whether or not to place an arrow on end.
  41. arrowEnd:true,
  42. labelPosition: function(){
  43. // summary:
  44. // The custom position used for the label
  45. //
  46. var d = this.data;
  47. var pt = dojox.drawing.util.positioning.label({x:d.x1,y:d.y1},{x:d.x2,y:d.y2});
  48. return {
  49. x:pt.x,
  50. y:pt.y
  51. }
  52. },
  53. onUp: function(/*EventObject*/obj){
  54. // summary: See stencil._Base.onUp
  55. //
  56. if(this.created || !this.shape){ return; }
  57. // if too small, need to reset
  58. var p = this.points;
  59. var len = this.util.distance(p[0].x,p[0].y,p[1].x,p[1].y);
  60. if(len<this.minimumSize){
  61. this.remove(this.shape, this.hit);
  62. return;
  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. this.renderedOnce = true;
  70. this.onRender(this);
  71. }
  72. }
  73. );
  74. dojox.drawing.tools.Arrow.setup = {
  75. // summary: See stencil._Base ToolsSetup
  76. //
  77. name:"dojox.drawing.tools.Arrow",
  78. tooltip:"Arrow Tool",
  79. iconClass:"iconArrow"
  80. };
  81. dojox.drawing.register(dojox.drawing.tools.Arrow.setup, "tool");
  82. }