strokeandfillelement.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2007 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview A thin wrapper around the DOM element for elements with a
  16. * stroke and fill.
  17. * @author arv@google.com (Erik Arvidsson)
  18. */
  19. goog.provide('goog.graphics.StrokeAndFillElement');
  20. goog.require('goog.graphics.Element');
  21. /**
  22. * Interface for a graphics element with a stroke and fill.
  23. * This is the base interface for ellipse, rectangle and other
  24. * shape interfaces.
  25. * You should not construct objects from this constructor. The graphics
  26. * will return an implementation of this interface for you.
  27. *
  28. * @param {Element} element The DOM element to wrap.
  29. * @param {goog.graphics.AbstractGraphics} graphics The graphics creating
  30. * this element.
  31. * @param {goog.graphics.Stroke?} stroke The stroke to use for this element.
  32. * @param {goog.graphics.Fill?} fill The fill to use for this element.
  33. * @constructor
  34. * @extends {goog.graphics.Element}
  35. * @deprecated goog.graphics is deprecated. It existed to abstract over browser
  36. * differences before the canvas tag was widely supported. See
  37. * http://en.wikipedia.org/wiki/Canvas_element for details.
  38. */
  39. goog.graphics.StrokeAndFillElement = function(element, graphics, stroke, fill) {
  40. goog.graphics.Element.call(this, element, graphics);
  41. this.setStroke(stroke);
  42. this.setFill(fill);
  43. };
  44. goog.inherits(goog.graphics.StrokeAndFillElement, goog.graphics.Element);
  45. /**
  46. * The latest fill applied to this element.
  47. * @type {goog.graphics.Fill?}
  48. * @protected
  49. */
  50. goog.graphics.StrokeAndFillElement.prototype.fill = null;
  51. /**
  52. * The latest stroke applied to this element.
  53. * @type {goog.graphics.Stroke?}
  54. * @private
  55. */
  56. goog.graphics.StrokeAndFillElement.prototype.stroke_ = null;
  57. /**
  58. * Sets the fill for this element.
  59. * @param {goog.graphics.Fill?} fill The fill object.
  60. */
  61. goog.graphics.StrokeAndFillElement.prototype.setFill = function(fill) {
  62. this.fill = fill;
  63. this.getGraphics().setElementFill(this, fill);
  64. };
  65. /**
  66. * @return {goog.graphics.Fill?} fill The fill object.
  67. */
  68. goog.graphics.StrokeAndFillElement.prototype.getFill = function() {
  69. return this.fill;
  70. };
  71. /**
  72. * Sets the stroke for this element.
  73. * @param {goog.graphics.Stroke?} stroke The stroke object.
  74. */
  75. goog.graphics.StrokeAndFillElement.prototype.setStroke = function(stroke) {
  76. this.stroke_ = stroke;
  77. this.getGraphics().setElementStroke(this, stroke);
  78. };
  79. /**
  80. * @return {goog.graphics.Stroke?} stroke The stroke object.
  81. */
  82. goog.graphics.StrokeAndFillElement.prototype.getStroke = function() {
  83. return this.stroke_;
  84. };
  85. /**
  86. * Re-strokes the element to react to coordinate size changes.
  87. */
  88. goog.graphics.StrokeAndFillElement.prototype.reapplyStroke = function() {
  89. if (this.stroke_) {
  90. this.setStroke(this.stroke_);
  91. }
  92. };