PageRenderTime 17ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/src/com/google/maps/extras/gradients/ValueColorGradient.as

http://gmaps-utility-library-flash.googlecode.com/
ActionScript | 98 lines | 54 code | 12 blank | 32 comment | 0 complexity | e69667a2653e4dd82839f3656d7f5c43 MD5 | raw file
 1/**
 2* Copyright 2009 Google Inc. 
 3* Licensed under the Apache License, Version 2.0:
 4*  http://www.apache.org/licenses/LICENSE-2.0
 5*/
 6
 7package com.google.maps.extras.gradients {
 8  import flash.errors.IllegalOperationError;
 9  import com.google.maps.Color;
10
11  /**
12  * ValueColorGradient is an internal class that's used by GradientControl
13  * objects for storing final gradient lists. Certain functions are declared
14  * public only so that the subclasses could have them public too.
15  *
16  * @author Simon Ilyushchenko
17  */
18
19  public class ValueColorGradient extends Range {
20
21    /** 
22    * Class constructor
23    */  
24    function ValueColorGradient() {
25      super(this);
26    }
27
28    /**
29    * Apply the scaling calculations to translate the specfied number
30    * into a color within this object's range.
31    */
32    public function colorForValue(someValue:Number):Number  {
33      var valueDict:Object = getValueDict();
34      var rgbColorDict:Object = getRgbColorDict();
35      var r:Number = GradientUtil.linearScale(
36          valueDict, rgbColorDict['r'], someValue);
37      var g:Number = GradientUtil.linearScale(
38          valueDict, rgbColorDict['g'], someValue);
39      var b:Number = GradientUtil.linearScale(
40          valueDict, rgbColorDict['b'], someValue);
41      var result:Color = new Color(0);
42      result.setRGB(r, g, b); 
43      return result.rgb;
44    }   
45
46    
47    // Percentage values are not used with ValueColorGradients
48    /**
49     * @throws flash.errors.IllegalOperationError Always.
50     */
51    public override function get minPercent():Number {
52      throw new IllegalOperationError(
53          "ValueColorGradient can't specify percentages.");
54    }   
55    /**
56     * @throws flash.errors.IllegalOperationError Always.
57     */
58    public override function set minPercent(someValue:Number):void {
59      throw new IllegalOperationError(
60          "ValueColorGradient can't specify percentages.");
61    }   
62    /**
63     * @throws flash.errors.IllegalOperationError Always.
64     */
65    public override function get maxPercent():Number {
66      throw new IllegalOperationError(
67          "ValueColorGradient can't specify percentages.");
68    }   
69    /**
70     * @throws flash.errors.IllegalOperationError Always.
71     */
72    public override function set maxPercent(someValue:Number):void {
73      throw new IllegalOperationError(
74          "ValueColorGradient can't specify percentages.");
75    }
76
77    function containsValue(someValue:Number):Boolean {
78      return someValue < maxValue;
79    }
80
81    protected function numFlatGradients():int {
82      return 1;
83    }   
84
85    protected function flatGradientAt(i:int):ValueColorGradient {
86      return this;
87    }  
88
89    public override function toString():String {
90      return ([
91        "ValueColorGradient: ",
92        "value: " + minValue.toString() + " - " + maxValue.toString(),
93        "color: " + rgbColorDictString()
94      ]).join(", ");
95    }
96
97  }
98}