PageRenderTime 25ms CodeModel.GetById 20ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://gmaps-utility-library-flash.googlecode.com/
ActionScript | 131 lines | 78 code | 13 blank | 40 comment | 2 complexity | 618ea5e89d40e9b25d984b7cfc886160 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  * A Range is an abstract class that stores three numerical ranges
 13  * representing colors, absolute values and percentages.
 14  *   
 15  * @author Simon Ilyushchenko
 16  */  
 17
 18  public class Range {
 19    // Use this value if the start of a range is undefined.
 20    protected static var MIN_PERCENT:Number = 0;
 21    // Use this value if the end of a range is undefined.
 22    protected static var MAX_PERCENT:Number = 100;
 23
 24    // Start of a range
 25    public var minValue:Number = NaN;
 26    // End of a range
 27    public var maxValue:Number = NaN;
 28
 29    // Start of a color range
 30    public var minColor:Number = NaN;
 31    // Start of a color range
 32    public var maxColor:Number = NaN;
 33
 34    // Access to min/maxPercent will be overridden in subclasses,
 35    // hence they are not public.
 36    protected var _minPercent:Number = NaN; /** Backing for minPercent. */
 37    protected var _maxPercent:Number = NaN; /** Backing for maxPercent. */
 38
 39    /**
 40    * Class constructor
 41    * 
 42    * @param self The instance of the child being constructed
 43    *
 44    * @throws flash.errors.IllegalOperationError If this abstract class is
 45    *   instantiated directly.
 46    */
 47    public function Range(self:Range) {
 48      //only a subclass can pass a valid reference to self
 49      if (self != this) {
 50        throw new IllegalOperationError(
 51            "Abstract class did not receive reference to self. " +
 52            "MyAbstractType cannot be instantiated directly.");
 53      }
 54    }
 55
 56    /**
 57    * Start of a percentage range.
 58    */
 59    public function get minPercent():Number {
 60      return _minPercent;
 61    }   
 62    public function set minPercent(someValue:Number):void {
 63      _minPercent = someValue;
 64    }   
 65
 66    /**
 67    * End of a percentage range.
 68    */
 69    public function get maxPercent():Number {
 70      return _maxPercent;
 71    }   
 72    public function set maxPercent(someValue:Number):void {
 73      _maxPercent = someValue;
 74    }
 75
 76   /**
 77    * String representation of this object
 78    */
 79    public function toString():String {
 80      return ([
 81        "Range: ",
 82        "value: " + minValue.toString() + " - " + maxValue.toString(),
 83        "percent: " + minPercent.toString() + " - " + maxPercent.toString(),
 84        "color: " + rgbColorDictString()
 85      ]).join(", ");
 86    }
 87
 88    /**
 89    * String representation of the color ranges of this object
 90    */
 91    public function rgbColorDictString():String {
 92      var rgbColorDict:Object = getRgbColorDict();
 93      var result:Array = [];
 94      result.push(
 95          "Start: " + rgbColorDict['r']['min'].toString() + "," +
 96          rgbColorDict['g']['min'].toString() + ", " + 
 97          rgbColorDict['b']['min'].toString());
 98      result.push(
 99          "End: " + rgbColorDict['r']['max'].toString() + "," +  
100          rgbColorDict['g']['max'].toString() + ", " + 
101          rgbColorDict['b']['max'].toString());
102      return result.join(', ');
103    }
104
105    function getValueDict():Object {
106      return {
107          'min': minValue,
108          'max': maxValue
109      }
110    }
111
112    function getRgbColorDict():Object {
113      var result:Object = {};
114      var minColorObj:Color = new Color(minColor);
115      var maxColorObj:Color = new Color(maxColor);
116      result['r'] = {
117          'min': minColorObj.r,
118          'max': maxColorObj.r
119      }
120      result['g'] = {
121          'min': minColorObj.g,
122          'max': maxColorObj.g
123      }
124      result['b'] = {
125          'min': minColorObj.b,
126          'max': maxColorObj.b
127      }
128      return result;
129    }
130  }
131}