Source: core/drawing/shape/abstract/shapeStylable.js

  1. /**
  2. * @fileoverview An abstract class describing style information for shapes.
  3. * @private
  4. */
  5. goog.provide('xrx.shape.Style');
  6. goog.require('goog.Disposable');
  7. goog.require('xrx.shape');
  8. /**
  9. * A class describing style information for shapes.
  10. * @constructor
  11. */
  12. xrx.shape.Style = function() {
  13. goog.base(this);
  14. /**
  15. * Object describing the fill style.
  16. * @type {Object}
  17. * @private
  18. */
  19. this.fill_ = {
  20. color: '',
  21. opacity: 0
  22. };
  23. /**
  24. * Object describing the stroke style.
  25. * @type {Object}
  26. * @private
  27. */
  28. this.stroke_ = {
  29. color: 'black',
  30. width: 1
  31. };
  32. };
  33. goog.inherits(xrx.shape.Style, goog.Disposable);
  34. /**
  35. * Sets a stylable object for this shape.
  36. * @param {xrx.shape.Style} style
  37. */
  38. xrx.shape.Style.prototype.setStyle = function(stylable) {
  39. this.stroke_.color = stylable.getStrokeColor();
  40. this.stroke_.width = stylable.getStrokeWidth();
  41. this.fill_.color = stylable.getFillColor();
  42. this.fill_.opacity = stylable.getFillOpacity();
  43. };
  44. /**
  45. * Returns the stroke width of this shape.
  46. * @return {number} The stroke width.
  47. */
  48. xrx.shape.Style.prototype.getStrokeWidth = function() {
  49. return this.stroke_.width;
  50. };
  51. /**
  52. * Sets the stroke width of this shape.
  53. * @param {number} width The stroke width.
  54. */
  55. xrx.shape.Style.prototype.setStrokeWidth = function(width) {
  56. if (width !== undefined) this.stroke_.width = width;
  57. };
  58. /**
  59. * Returns the stroke color of this shape.
  60. * @return {string} The stroke color.
  61. */
  62. xrx.shape.Style.prototype.getStrokeColor = function() {
  63. return this.stroke_.color;
  64. };
  65. /**
  66. * Sets the stroke color of this shape.
  67. * @param {string} color The stroke color.
  68. */
  69. xrx.shape.Style.prototype.setStrokeColor = function(color) {
  70. if (color !== undefined) this.stroke_.color = color;
  71. };
  72. /**
  73. * Returns the fill color of this shape.
  74. * @return {string} The fill color.
  75. */
  76. xrx.shape.Style.prototype.getFillColor = function() {
  77. return this.fill_.color;
  78. };
  79. /**
  80. * Sets the fill color of this shape.
  81. * @param {string} color The fill color.
  82. */
  83. xrx.shape.Style.prototype.setFillColor = function(color) {
  84. if (this.fill_.opacity === 0) this.fill_.opacity = 1;
  85. if (color !== undefined) this.fill_.color = color;
  86. };
  87. /**
  88. * Returns the fill opacity of this shape.
  89. * @return {number} The fill opacity.
  90. */
  91. xrx.shape.Style.prototype.getFillOpacity = function() {
  92. return this.fill_.opacity;
  93. };
  94. /**
  95. * Sets the fill opacity of this shape.
  96. * @param {number} factor The fill opacity.
  97. */
  98. xrx.shape.Style.prototype.setFillOpacity = function(factor) {
  99. if (factor !== undefined) this.fill_.opacity = factor;
  100. };
  101. /**
  102. * Disposes this style information object.
  103. */
  104. xrx.shape.Style.prototype.disposeInternal = function() {
  105. this.fill_ = null;
  106. this.stroke_ = null;
  107. goog.base(this, 'disposeInternal');
  108. };