From cead80d8c2779db314d20d31830fc4f4b46d3c1f Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Tue, 18 Feb 2014 13:37:14 -0500 Subject: [PATCH] Clean up material properties and specs. --- Source/DynamicScene/ColorMaterialProperty.js | 23 +----- Source/DynamicScene/GridMaterialProperty.js | 78 ++----------------- Source/DynamicScene/ImageMaterialProperty.js | 40 +--------- .../PolylineOutlineMaterialProperty.js | 59 ++------------ .../DynamicScene/ColorMaterialPropertySpec.js | 7 +- .../DynamicScene/GridMaterialPropertySpec.js | 20 +++-- .../DynamicScene/ImageMaterialPropertySpec.js | 10 ++- .../PolylineOutlineMaterialPropertySpec.js | 15 ++-- 8 files changed, 50 insertions(+), 202 deletions(-) diff --git a/Source/DynamicScene/ColorMaterialProperty.js b/Source/DynamicScene/ColorMaterialProperty.js index e2d285886686..2353e807abb8 100644 --- a/Source/DynamicScene/ColorMaterialProperty.js +++ b/Source/DynamicScene/ColorMaterialProperty.js @@ -5,6 +5,7 @@ define(['../Core/Color', '../Core/defineProperties', '../Core/DeveloperError', '../Core/Event', + './createDynamicPropertyDescriptor', './ConstantProperty', './Property' ], function( @@ -14,6 +15,7 @@ define(['../Core/Color', defineProperties, DeveloperError, Event, + createDynamicPropertyDescriptor, ConstantProperty, Property) { "use strict"; @@ -30,7 +32,7 @@ define(['../Core/Color', this._definitionChanged = new Event(); this._color = undefined; this._colorSubscription = undefined; - this.color = colorProperty; + this.color = defaultValue(colorProperty, new ConstantProperty(Color.WHITE)); }; /** @@ -77,24 +79,7 @@ define(['../Core/Color', * @memberof ColorMaterialProperty.prototype * @type {Property} */ - color : { - get : function() { - return this._color; - }, - set : function(value) { - if (this._color !== value) { - if (defined(this._colorSubscription)) { - this._colorSubscription(); - this._colorSubscription = undefined; - } - this._color = value; - if (defined(value)) { - this._colorSubscription = value.definitionChanged.addEventListener(ColorMaterialProperty.prototype._raiseDefinitionChanged, this); - } - this._raiseDefinitionChanged(this); - } - } - } + color : createDynamicPropertyDescriptor('color') }); /** diff --git a/Source/DynamicScene/GridMaterialProperty.js b/Source/DynamicScene/GridMaterialProperty.js index 359d6cf5ee53..6f1e9728675e 100644 --- a/Source/DynamicScene/GridMaterialProperty.js +++ b/Source/DynamicScene/GridMaterialProperty.js @@ -4,6 +4,7 @@ define(['../Core/Cartesian2', '../Core/defined', '../Core/defineProperties', '../Core/Event', + './createDynamicPropertyDescriptor', './ConstantProperty', './Property' ], function( @@ -12,6 +13,7 @@ define(['../Core/Cartesian2', defined, defineProperties, Event, + createDynamicPropertyDescriptor, ConstantProperty, Property) { "use strict"; @@ -71,93 +73,25 @@ define(['../Core/Cartesian2', * @type {Property} * @default new ConstantProperty(Color.WHITE) */ - color : { - get : function() { - return this._color; - }, - set : function(value) { - if (this._color !== value) { - if (defined(this._colorSubscription)) { - this._colorSubscription(); - this._colorSubscription = undefined; - } - this._color = value; - if (defined(value)) { - this._colorSubscription = value.definitionChanged.addEventListener(GridMaterialProperty.prototype._raiseDefinitionChanged, this); - } - this._raiseDefinitionChanged(this); - } - } - }, + color : createDynamicPropertyDescriptor('color'), /** * Gets or sets the numeric property which determines the grid cells alpha value, when combined with the color alpha. * @type {Property} * @default new ConstantProperty(0.1) */ - cellAlpha : { - get : function() { - return this._cellAlpha; - }, - set : function(value) { - if (this._cellAlpha !== value) { - if (this._cellAlphaSubscription) { - this._cellAlphaSubscription(); - this._cellAlphaSubscription = undefined; - } - this._cellAlpha = value; - if (defined(value)) { - this._cellAlphaSubscription = value.definitionChanged.addEventListener(GridMaterialProperty.prototype._raiseDefinitionChanged, this); - } - this._raiseDefinitionChanged(this); - } - } - }, + cellAlpha : createDynamicPropertyDescriptor('cellAlpha'), /** * Gets or sets the {@link Cartesian2} property which determines the number of rows and columns in the grid. * @type {Property} * @default new ConstantProperty(new Cartesian2(8, 8)) */ - lineCount : { - get : function() { - return this._lineCount; - }, - set : function(value) { - if (this._lineCount !== value) { - if (this._lineCountSubscription) { - this._lineCountSubscription(); - this._lineCountSubscription = undefined; - } - this._lineCount = value; - if (defined(value)) { - this._lineCountSubscription = value.definitionChanged.addEventListener(GridMaterialProperty.prototype._raiseDefinitionChanged, this); - } - this._raiseDefinitionChanged(this); - } - } - }, + lineCount : createDynamicPropertyDescriptor('lineCount'), /** * Gets or sets the {@link Cartesian2} property which determines the thickness of rows and columns in the grid. * @type {Property} * @default new ConstantProperty(new Cartesian2(1.0, 1.0)) */ - lineThickness : { - get : function() { - return this._lineThickness; - }, - set : function(value) { - if (this._lineThickness !== value) { - if (this._lineThicknessSubscription) { - this._lineThicknessSubscription(); - this._lineThicknessSubscription = undefined; - } - this._lineThickness = value; - if (defined(value)) { - this._lineThicknessSubscription = value.definitionChanged.addEventListener(GridMaterialProperty.prototype._raiseDefinitionChanged, this); - } - this._raiseDefinitionChanged(this); - } - } - } + lineThickness : createDynamicPropertyDescriptor('lineThickness') }); /** diff --git a/Source/DynamicScene/ImageMaterialProperty.js b/Source/DynamicScene/ImageMaterialProperty.js index 12f86df17bd6..f2109ab2377f 100644 --- a/Source/DynamicScene/ImageMaterialProperty.js +++ b/Source/DynamicScene/ImageMaterialProperty.js @@ -4,6 +4,7 @@ define([ '../Core/defined', '../Core/defineProperties', '../Core/Event', + './createDynamicPropertyDescriptor', './ConstantProperty', './Property' ], function( @@ -11,6 +12,7 @@ define([ defined, defineProperties, Event, + createDynamicPropertyDescriptor, ConstantProperty, Property) { "use strict"; @@ -58,48 +60,14 @@ define([ * @memberof ImageMaterialProperty.prototype * @type {Property} */ - image : { - get : function() { - return this._image; - }, - set : function(value) { - if (this._image !== value) { - if (this._imageSubscription) { - this._imageSubscription(); - this._imageSubscription = undefined; - } - this._image = value; - if (defined(value)) { - this._imageSubscription = value.definitionChanged.addEventListener(ImageMaterialProperty.prototype._raiseDefinitionChanged, this); - } - this._raiseDefinitionChanged(this); - } - } - }, + image : createDynamicPropertyDescriptor('image'), /** * Gets or sets the {@link Cartesian2} property which determines the number of times the image repeats in each direction. * @memberof ImageMaterialProperty.prototype * @type {Property} * @default new ConstantProperty(new Cartesian2(1, 1)) */ - repeat : { - get : function() { - return this._repeat; - }, - set : function(value) { - if (this._repeat !== value) { - if (this._repeatSubscription) { - this._repeatSubscription(); - this._repeatSubscription = undefined; - } - this._repeat = value; - if (defined(value)) { - this._repeatSubscription = value.definitionChanged.addEventListener(ImageMaterialProperty.prototype._raiseDefinitionChanged, this); - } - this._raiseDefinitionChanged(this); - } - } - } + repeat : createDynamicPropertyDescriptor('repeat') }); /** diff --git a/Source/DynamicScene/PolylineOutlineMaterialProperty.js b/Source/DynamicScene/PolylineOutlineMaterialProperty.js index 272d875f7485..a80225b7811d 100644 --- a/Source/DynamicScene/PolylineOutlineMaterialProperty.js +++ b/Source/DynamicScene/PolylineOutlineMaterialProperty.js @@ -3,6 +3,7 @@ define(['../Core/Color', '../Core/defined', '../Core/defineProperties', '../Core/Event', + './createDynamicPropertyDescriptor', './ConstantProperty', './Property' ], function( @@ -10,6 +11,7 @@ define(['../Core/Color', defined, defineProperties, Event, + createDynamicPropertyDescriptor, ConstantProperty, Property) { "use strict"; @@ -64,71 +66,20 @@ define(['../Core/Color', * @type {Property} * @default new ConstantProperty(Color.WHITE) */ - color : { - get : function() { - return this._color; - }, - set : function(value) { - if (this._color !== value) { - if (defined(this._colorSubscription)) { - this._colorSubscription(); - this._colorSubscription = undefined; - } - this._color = value; - if (defined(value)) { - this._colorSubscription = value.definitionChanged.addEventListener(PolylineOutlineMaterialProperty.prototype._raiseDefinitionChanged, this); - } - this._raiseDefinitionChanged(this); - } - } - }, + color : createDynamicPropertyDescriptor('color'), /** * Gets or sets the {@link Color} property which determines the polyline's outline color. * @memberof PolylineOutlineMaterialProperty.prototype * @type {Property} * @default new ConstantProperty(Color.BLACK) */ - outlineColor : { - get : function() { - return this._outlineColor; - }, - set : function(value) { - if (this._outlineColor !== value) { - if (this._outlineColorSubscription) { - this._outlineColorSubscription(); - this._outlineColorSubscription = undefined; - } - this._outlineColor = value; - if (defined(value)) { - this._outlineColorSubscription = value.definitionChanged.addEventListener(PolylineOutlineMaterialProperty.prototype._raiseDefinitionChanged, this); - } - this._raiseDefinitionChanged(this); - } - } - }, + outlineColor : createDynamicPropertyDescriptor('outlineColor'), /** * Gets or sets the numberic property which determines the polyline's outline width. * @type {Property} * @default new ConstantProperty(0) */ - outlineWidth : { - get : function() { - return this._outlineWidth; - }, - set : function(value) { - if (this._outlineWidth !== value) { - if (this._outlineWidthSubscription) { - this._outlineWidthSubscription(); - this._outlineWidthSubscription = undefined; - } - this._outlineWidth = value; - if (defined(value)) { - this._outlineWidthSubscription = value.definitionChanged.addEventListener(PolylineOutlineMaterialProperty.prototype._raiseDefinitionChanged, this); - } - this._raiseDefinitionChanged(this); - } - } - } + outlineWidth : createDynamicPropertyDescriptor('outlineWidth') }); /** diff --git a/Specs/DynamicScene/ColorMaterialPropertySpec.js b/Specs/DynamicScene/ColorMaterialPropertySpec.js index 058353ea13e2..b08f77699e3f 100644 --- a/Specs/DynamicScene/ColorMaterialPropertySpec.js +++ b/Specs/DynamicScene/ColorMaterialPropertySpec.js @@ -17,7 +17,7 @@ defineSuite(['DynamicScene/ColorMaterialProperty', it('constructor provides the expected defaults', function() { var property = new ColorMaterialProperty(); - expect(property.color).toBeUndefined(); + expect(property.color).toEqual(new ConstantProperty(Color.WHITE)); expect(property.getType()).toEqual('Color'); expect(property.isConstant).toBe(true); @@ -92,12 +92,13 @@ defineSuite(['DynamicScene/ColorMaterialProperty', var listener = jasmine.createSpy('listener'); property.definitionChanged.addEventListener(listener); + var oldValue = property.color; property.color = new ConstantProperty(Color.WHITE); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'color', property.color, oldValue); listener.reset(); property.color.setValue(Color.BLACK); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'color', property.color, property.color); listener.reset(); property.color = property.color; diff --git a/Specs/DynamicScene/GridMaterialPropertySpec.js b/Specs/DynamicScene/GridMaterialPropertySpec.js index bb55ec192b79..4411e42500f8 100644 --- a/Specs/DynamicScene/GridMaterialPropertySpec.js +++ b/Specs/DynamicScene/GridMaterialPropertySpec.js @@ -143,48 +143,52 @@ defineSuite(['DynamicScene/GridMaterialProperty', var listener = jasmine.createSpy('listener'); property.definitionChanged.addEventListener(listener); + var oldValue = property.color; property.color = new ConstantProperty(Color.WHITE); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'color', property.color, oldValue); listener.reset(); property.color.setValue(Color.BLACK); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'color', property.color, property.color); listener.reset(); property.color = property.color; expect(listener.callCount).toEqual(0); listener.reset(); + oldValue = property.cellAlpha; property.cellAlpha = new ConstantProperty(0.0); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'cellAlpha', property.cellAlpha, oldValue); listener.reset(); property.cellAlpha.setValue(1.0); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'cellAlpha', property.cellAlpha, property.cellAlpha); listener.reset(); property.cellAlpha = property.cellAlpha; expect(listener.callCount).toEqual(0); listener.reset(); + oldValue = property.lineCount; property.lineCount = new ConstantProperty(5.0); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'lineCount', property.lineCount, oldValue); listener.reset(); property.lineCount.setValue(10.0); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'lineCount', property.lineCount, property.lineCount); listener.reset(); property.lineCount = property.lineCount; expect(listener.callCount).toEqual(0); listener.reset(); + oldValue = property.lineThickness; property.lineThickness = new ConstantProperty(5.0); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'lineThickness', property.lineThickness, oldValue); listener.reset(); property.lineThickness.setValue(10.0); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'lineThickness', property.lineThickness, property.lineThickness); listener.reset(); property.lineThickness = property.lineThickness; diff --git a/Specs/DynamicScene/ImageMaterialPropertySpec.js b/Specs/DynamicScene/ImageMaterialPropertySpec.js index daae72415ac7..c504b4be342d 100644 --- a/Specs/DynamicScene/ImageMaterialPropertySpec.js +++ b/Specs/DynamicScene/ImageMaterialPropertySpec.js @@ -101,24 +101,26 @@ defineSuite([ var listener = jasmine.createSpy('listener'); property.definitionChanged.addEventListener(listener); + var oldValue = property.image; property.image = new ConstantProperty('http://test.invalid/image.png'); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'image', property.image, oldValue); listener.reset(); property.image.setValue('http://test.invalid/image2.png'); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'image', property.image, property.image); listener.reset(); property.image = property.image; expect(listener.callCount).toEqual(0); listener.reset(); + oldValue = property.repeat; property.repeat = new ConstantProperty(new Cartesian2(1.5, 1.5)); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'repeat', property.repeat, oldValue); listener.reset(); property.repeat.setValue(new Cartesian2(1.0, 1.0)); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'repeat', property.repeat, property.repeat); listener.reset(); property.repeat = property.repeat; diff --git a/Specs/DynamicScene/PolylineOutlineMaterialPropertySpec.js b/Specs/DynamicScene/PolylineOutlineMaterialPropertySpec.js index 9ccb767040e9..9619bd7777f8 100644 --- a/Specs/DynamicScene/PolylineOutlineMaterialPropertySpec.js +++ b/Specs/DynamicScene/PolylineOutlineMaterialPropertySpec.js @@ -106,35 +106,38 @@ defineSuite(['DynamicScene/PolylineOutlineMaterialProperty', var listener = jasmine.createSpy('listener'); property.definitionChanged.addEventListener(listener); + var oldValue = property.color; property.color = new ConstantProperty(Color.RED); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'color', property.color, oldValue); listener.reset(); property.color.setValue(Color.YELLOW); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'color', property.color, property.color); listener.reset(); property.color = property.color; expect(listener.callCount).toEqual(0); listener.reset(); + oldValue = property.outlineColor; property.outlineColor = new ConstantProperty(Color.BLUE); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'outlineColor', property.outlineColor, oldValue); listener.reset(); property.outlineColor.setValue(Color.GREEN); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'outlineColor', property.outlineColor, property.outlineColor); listener.reset(); property.outlineColor = property.outlineColor; expect(listener.callCount).toEqual(0); + oldValue = property.outlineWidth; property.outlineWidth = new ConstantProperty(2.5); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'outlineWidth', property.outlineWidth, oldValue); listener.reset(); property.outlineWidth.setValue(1.5); - expect(listener).toHaveBeenCalledWith(property); + expect(listener).toHaveBeenCalledWith(property, 'outlineWidth', property.outlineWidth, property.outlineWidth); listener.reset(); property.outlineWidth = property.outlineWidth;