mxCellTracker.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /**
  2. * Copyright (c) 2006-2015, JGraph Ltd
  3. * Copyright (c) 2006-2015, Gaudenz Alder
  4. */
  5. /**
  6. * Class: mxCellTracker
  7. *
  8. * Event handler that highlights cells. Inherits from <mxCellMarker>.
  9. *
  10. * Example:
  11. *
  12. * (code)
  13. * new mxCellTracker(graph, '#00FF00');
  14. * (end)
  15. *
  16. * For detecting dragEnter, dragOver and dragLeave on cells, the following
  17. * code can be used:
  18. *
  19. * (code)
  20. * graph.addMouseListener(
  21. * {
  22. * cell: null,
  23. * mouseDown: function(sender, me) { },
  24. * mouseMove: function(sender, me)
  25. * {
  26. * var tmp = me.getCell();
  27. *
  28. * if (tmp != this.cell)
  29. * {
  30. * if (this.cell != null)
  31. * {
  32. * this.dragLeave(me.getEvent(), this.cell);
  33. * }
  34. *
  35. * this.cell = tmp;
  36. *
  37. * if (this.cell != null)
  38. * {
  39. * this.dragEnter(me.getEvent(), this.cell);
  40. * }
  41. * }
  42. *
  43. * if (this.cell != null)
  44. * {
  45. * this.dragOver(me.getEvent(), this.cell);
  46. * }
  47. * },
  48. * mouseUp: function(sender, me) { },
  49. * dragEnter: function(evt, cell)
  50. * {
  51. * mxLog.debug('dragEnter', cell.value);
  52. * },
  53. * dragOver: function(evt, cell)
  54. * {
  55. * mxLog.debug('dragOver', cell.value);
  56. * },
  57. * dragLeave: function(evt, cell)
  58. * {
  59. * mxLog.debug('dragLeave', cell.value);
  60. * }
  61. * });
  62. * (end)
  63. *
  64. * Constructor: mxCellTracker
  65. *
  66. * Constructs an event handler that highlights cells.
  67. *
  68. * Parameters:
  69. *
  70. * graph - Reference to the enclosing <mxGraph>.
  71. * color - Color of the highlight. Default is blue.
  72. * funct - Optional JavaScript function that is used to override
  73. * <mxCellMarker.getCell>.
  74. */
  75. function mxCellTracker(graph, color, funct)
  76. {
  77. mxCellMarker.call(this, graph, color);
  78. this.graph.addMouseListener(this);
  79. if (funct != null)
  80. {
  81. this.getCell = funct;
  82. }
  83. // Automatic deallocation of memory
  84. if (mxClient.IS_IE)
  85. {
  86. mxEvent.addListener(window, 'unload', mxUtils.bind(this, function()
  87. {
  88. this.destroy();
  89. }));
  90. }
  91. };
  92. /**
  93. * Extends mxCellMarker.
  94. */
  95. mxUtils.extend(mxCellTracker, mxCellMarker);
  96. /**
  97. * Function: mouseDown
  98. *
  99. * Ignores the event. The event is not consumed.
  100. */
  101. mxCellTracker.prototype.mouseDown = function(sender, me) { };
  102. /**
  103. * Function: mouseMove
  104. *
  105. * Handles the event by highlighting the cell under the mousepointer if it
  106. * is over the hotspot region of the cell.
  107. */
  108. mxCellTracker.prototype.mouseMove = function(sender, me)
  109. {
  110. if (this.isEnabled())
  111. {
  112. this.process(me);
  113. }
  114. };
  115. /**
  116. * Function: mouseUp
  117. *
  118. * Handles the event by reseting the highlight.
  119. */
  120. mxCellTracker.prototype.mouseUp = function(sender, me) { };
  121. /**
  122. * Function: destroy
  123. *
  124. * Destroys the object and all its resources and DOM nodes. This doesn't
  125. * normally need to be called. It is called automatically when the window
  126. * unloads.
  127. */
  128. mxCellTracker.prototype.destroy = function()
  129. {
  130. if (!this.destroyed)
  131. {
  132. this.destroyed = true;
  133. this.graph.removeMouseListener(this);
  134. mxCellMarker.prototype.destroy.apply(this);
  135. }
  136. };
  137. __mxOutput.mxCellTracker = typeof mxCellTracker !== 'undefined' ? mxCellTracker : undefined;