_Plugin.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.sketch._Plugin"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.sketch._Plugin"] = true;
  8. dojo.provide("dojox.sketch._Plugin");
  9. //dojo.require("dojox.sketch");
  10. dojo.require("dijit.form.Button");
  11. dojo.declare("dojox.sketch._Plugin", null, {
  12. // summary
  13. // This represents a "plugin" to the dojox.sketch.Figure, which is basically
  14. // a single button on the Toolbar and some associated code
  15. constructor: function(/*Object?*/args){
  16. if(args){
  17. dojo.mixin(this, args);
  18. }
  19. this._connects=[];
  20. },
  21. figure: null,
  22. iconClassPrefix: "dojoxSketchIcon",
  23. itemGroup: 'toolsGroup',
  24. button: null,
  25. queryCommand: null,
  26. shape: "",
  27. useDefaultCommand: true,
  28. buttonClass: dijit.form.ToggleButton,
  29. _initButton: function(){
  30. if(this.shape.length){
  31. //TODO: i18n
  32. // var label = dojox.sketch.shapes[this.shape];
  33. var className = this.iconClassPrefix+" "+this.iconClassPrefix + this.shape.charAt(0).toUpperCase() + this.shape.substr(1);
  34. if(!this.button){
  35. var props = {
  36. label: this.shape, //I18N
  37. showLabel: false,
  38. iconClass: className,
  39. dropDown: this.dropDown,
  40. tabIndex: "-1"
  41. };
  42. this.button = new this.buttonClass(props);
  43. this.connect(this.button,'onClick','activate');
  44. }
  45. }
  46. },
  47. attr: function(name,/*?*/value){
  48. return this.button.attr(name,value);
  49. },
  50. onActivate: function(){},
  51. activate: function(/*?*/e){
  52. this.onActivate();
  53. this.figure.setTool(this);
  54. this.attr('checked',true);
  55. },
  56. onMouseDown: function(e){},
  57. onMouseMove: function(e){},
  58. onMouseUp: function(e){},
  59. destroy: function(f){
  60. dojo.forEach(this._connects,dojo.disconnect);
  61. },
  62. connect: function(o,f,tf){
  63. this._connects.push(dojo.connect(o,f,this,tf));
  64. },
  65. setFigure: function(/*dijit._Widget*/ figure){
  66. // FIXME: detatch from previous figure!!
  67. this.figure = figure;
  68. },
  69. setToolbar: function(/*dijit._Widget*/ toolbar){
  70. // FIXME: prevent creating this if we don't need to (i.e., figure can't handle our command)
  71. this._initButton();
  72. if(this.button){
  73. toolbar.addChild(this.button);
  74. }
  75. if(this.itemGroup){
  76. toolbar.addGroupItem(this,this.itemGroup);
  77. }
  78. }
  79. });
  80. }