| 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 |
|
| 16 |
/** |
| 17 |
* @fileoverview A thin wrapper around the DOM element for elements with a |
| 18 |
* stroke and fill. |
| 19 |
* @author [email protected] (Erik Arvidsson) |
| 20 |
*/ |
| 21 |
|
| 22 |
|
| 23 |
goog.provide('goog.graphics.StrokeAndFillElement'); |
| 24 |
|
| 25 |
goog.require('goog.graphics.Element'); |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
/** |
| 30 |
* Interface for a graphics element with a stroke and fill. |
| 31 |
* This is the base interface for ellipse, rectangle and other |
| 32 |
* shape interfaces. |
| 33 |
* You should not construct objects from this constructor. The graphics |
| 34 |
* will return an implementation of this interface for you. |
| 35 |
* |
| 36 |
* @param {Element} element The DOM element to wrap. |
| 37 |
* @param {goog.graphics.AbstractGraphics} graphics The graphics creating |
| 38 |
* this element. |
| 39 |
* @param {goog.graphics.Stroke?} stroke The stroke to use for this element. |
| 40 |
* @param {goog.graphics.Fill?} fill The fill to use for this element. |
| 41 |
* @constructor |
| 42 |
* @extends {goog.graphics.Element} |
| 43 |
* @deprecated goog.graphics is deprecated. It existed to abstract over browser |
| 44 |
* differences before the canvas tag was widely supported. See |
| 45 |
* http://en.wikipedia.org/wiki/Canvas_element for details. |
| 46 |
*/ |
| 47 |
goog.graphics.StrokeAndFillElement = function(element, graphics, stroke, fill) { |
| 48 |
goog.graphics.Element.call(this, element, graphics); |
| 49 |
this.setStroke(stroke); |
| 50 |
this.setFill(fill); |
| 51 |
}; |
| 52 |
goog.inherits(goog.graphics.StrokeAndFillElement, goog.graphics.Element); |
| 53 |
|
| 54 |
|
| 55 |
/** |
| 56 |
* The latest fill applied to this element. |
| 57 |
* @type {goog.graphics.Fill?} |
| 58 |
* @protected |
| 59 |
*/ |
| 60 |
goog.graphics.StrokeAndFillElement.prototype.fill = null; |
| 61 |
|
| 62 |
|
| 63 |
/** |
| 64 |
* The latest stroke applied to this element. |
| 65 |
* @type {goog.graphics.Stroke?} |
| 66 |
* @private |
| 67 |
*/ |
| 68 |
goog.graphics.StrokeAndFillElement.prototype.stroke_ = null; |
| 69 |
|
| 70 |
|
| 71 |
/** |
| 72 |
* Sets the fill for this element. |
| 73 |
* @param {goog.graphics.Fill?} fill The fill object. |
| 74 |
*/ |
| 75 |
goog.graphics.StrokeAndFillElement.prototype.setFill = function(fill) { |
| 76 |
this.fill = fill; |
| 77 |
this.getGraphics().setElementFill(this, fill); |
| 78 |
}; |
| 79 |
|
| 80 |
|
| 81 |
/** |
| 82 |
* @return {goog.graphics.Fill?} fill The fill object. |
| 83 |
*/ |
| 84 |
goog.graphics.StrokeAndFillElement.prototype.getFill = function() { |
| 85 |
return this.fill; |
| 86 |
}; |
| 87 |
|
| 88 |
|
| 89 |
/** |
| 90 |
* Sets the stroke for this element. |
| 91 |
* @param {goog.graphics.Stroke?} stroke The stroke object. |
| 92 |
*/ |
| 93 |
goog.graphics.StrokeAndFillElement.prototype.setStroke = function(stroke) { |
| 94 |
this.stroke_ = stroke; |
| 95 |
this.getGraphics().setElementStroke(this, stroke); |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
/** |
| 100 |
* @return {goog.graphics.Stroke?} stroke The stroke object. |
| 101 |
*/ |
| 102 |
goog.graphics.StrokeAndFillElement.prototype.getStroke = function() { |
| 103 |
return this.stroke_; |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
/** |
| 108 |
* Re-strokes the element to react to coordinate size changes. |
| 109 |
*/ |
| 110 |
goog.graphics.StrokeAndFillElement.prototype.reapplyStroke = function() { |
| 111 |
if (this.stroke_) { |
| 112 |
this.setStroke(this.stroke_); |
| 113 |
} |
| 114 |
}; |