_Plugin.js 2.2 KB

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