Browse files

first git commit

  • Loading branch information...
0 parents commit ea455ee66e2dbf29ea907c1a68106f5d516eb777 @bit101 bit101 committed Apr 9, 2011
Showing with 10,631 additions and 0 deletions.
  1. BIN src/assets/pf_ronda_seven.ttf
  2. +111 −0 src/com/bit101/charts/BarChart.as
  3. +297 −0 src/com/bit101/charts/Chart.as
  4. +110 −0 src/com/bit101/charts/LineChart.as
  5. +246 −0 src/com/bit101/charts/PieChart.as
  6. +177 −0 src/com/bit101/components/Accordion.as
  7. +292 −0 src/com/bit101/components/Calendar.as
  8. +183 −0 src/com/bit101/components/CheckBox.as
  9. +355 −0 src/com/bit101/components/ColorChooser.as
  10. +461 −0 src/com/bit101/components/ComboBox.as
  11. +260 −0 src/com/bit101/components/Component.as
  12. +144 −0 src/com/bit101/components/FPSMeter.as
  13. +179 −0 src/com/bit101/components/HBox.as
  14. +40 −0 src/com/bit101/components/HRangeSlider.as
  15. +47 −0 src/com/bit101/components/HScrollBar.as
  16. +48 −0 src/com/bit101/components/HSlider.as
  17. +96 −0 src/com/bit101/components/HUISlider.as
  18. +219 −0 src/com/bit101/components/IndicatorLight.as
  19. +226 −0 src/com/bit101/components/InputText.as
  20. +407 −0 src/com/bit101/components/Knob.as
  21. +154 −0 src/com/bit101/components/Label.as
  22. +493 −0 src/com/bit101/components/List.as
  23. +220 −0 src/com/bit101/components/ListItem.as
  24. +351 −0 src/com/bit101/components/Meter.as
  25. +309 −0 src/com/bit101/components/NumericStepper.as
  26. +243 −0 src/com/bit101/components/Panel.as
  27. +150 −0 src/com/bit101/components/ProgressBar.as
  28. +259 −0 src/com/bit101/components/PushButton.as
  29. +229 −0 src/com/bit101/components/RadioButton.as
  30. +498 −0 src/com/bit101/components/RangeSlider.as
  31. +298 −0 src/com/bit101/components/RotarySelector.as
  32. +625 −0 src/com/bit101/components/ScrollBar.as
  33. +225 −0 src/com/bit101/components/ScrollPane.as
  34. +374 −0 src/com/bit101/components/Slider.as
  35. +95 −0 src/com/bit101/components/Style.as
  36. +227 −0 src/com/bit101/components/Text.as
  37. +175 −0 src/com/bit101/components/TextArea.as
  38. +249 −0 src/com/bit101/components/UISlider.as
  39. +185 −0 src/com/bit101/components/VBox.as
  40. +40 −0 src/com/bit101/components/VRangeSlider.as
  41. +47 −0 src/com/bit101/components/VScrollBar.as
  42. +47 −0 src/com/bit101/components/VSlider.as
  43. +103 −0 src/com/bit101/components/VUISlider.as
  44. +467 −0 src/com/bit101/components/WheelMenu.as
  45. +399 −0 src/com/bit101/components/Window.as
  46. +271 −0 src/com/bit101/utils/MinimalConfigurator.as
BIN src/assets/pf_ronda_seven.ttf
Binary file not shown.
111 src/com/bit101/charts/BarChart.as
@@ -0,0 +1,111 @@
+/**
+ * BarChart.as
+ * Keith Peters
+ * version 0.9.10
+ *
+ * A chart component for graphing an array of numeric data as a bar graph.
+ *
+ * Copyright (c) 2011 Keith Peters
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.bit101.charts
+{
+ import flash.display.DisplayObjectContainer;
+
+ public class BarChart extends Chart
+ {
+ protected var _spacing:Number = 2;
+ protected var _barColor:uint = 0x999999;
+
+ /**
+ * Constructor
+ * @param parent The parent DisplayObjectContainer on which to add this Label.
+ * @param xpos The x position to place this component.
+ * @param ypos The y position to place this component.
+ * @param data The array of numeric values to graph.
+ */
+ public function BarChart(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0, data:Array=null)
+ {
+ super(parent, xpos, ypos, data);
+ }
+
+ /**
+ * Graphs the numeric data in the chart.
+ */
+ protected override function drawChart():void
+ {
+ var border:Number = 2;
+ var totalSpace:Number = _spacing * _data.length;
+ var barWidth:Number = (_width - border - totalSpace) / _data.length;
+ var chartHeight:Number = _height - border;
+ _chartHolder.x = 0;
+ _chartHolder.y = _height;
+ var xpos:Number = border;
+ var max:Number = getMaxValue();
+ var min:Number = getMinValue();
+ var scale:Number = chartHeight / (max - min);
+ for(var i:int = 0; i < _data.length; i++)
+ {
+ if(_data[i] != null)
+ {
+ _chartHolder.graphics.beginFill(_barColor);
+ _chartHolder.graphics.drawRect(xpos, 0, barWidth, (_data[i] - min) * -scale);
+ _chartHolder.graphics.endFill();
+ }
+ xpos += barWidth + _spacing;
+ }
+ }
+
+
+
+ ///////////////////////////////////
+ // getter/setters
+ ///////////////////////////////////
+
+ /**
+ * Sets/gets the amount of space shown between each bar. If this is too wide, bars may become invisible.
+ */
+ public function set spacing(value:Number):void
+ {
+ _spacing = value;
+ invalidate();
+ }
+ public function get spacing():Number
+ {
+ return _spacing;
+ }
+
+ /**
+ * Sets/gets the color of the bars.
+ */
+ public function set barColor(value:uint):void
+ {
+ _barColor = value;
+ invalidate();
+ }
+ public function get barColor():uint
+ {
+ return _barColor;
+ }
+
+
+ }
+}
297 src/com/bit101/charts/Chart.as
@@ -0,0 +1,297 @@
+/**
+ * Chart.as
+ * Keith Peters
+ * version 0.9.10
+ *
+ * A base chart component for graphing an array of numeric data.
+ *
+ * Copyright (c) 2011 Keith Peters
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.bit101.charts
+{
+
+ import com.bit101.components.Component;
+ import com.bit101.components.Label;
+ import com.bit101.components.Panel;
+
+ import flash.display.DisplayObjectContainer;
+ import flash.display.Shape;
+
+ public class Chart extends Component
+ {
+ protected var _data:Array;
+ protected var _chartHolder:Shape;
+ protected var _maximum:Number = 100;
+ protected var _minimum:Number = 0;
+ protected var _autoScale:Boolean = true;
+ protected var _maxLabel:Label;
+ protected var _minLabel:Label;
+ protected var _showScaleLabels:Boolean = false;
+ protected var _labelPrecision:int = 0;
+ protected var _panel:Panel;
+
+ /**
+ * Constructor
+ * @param parent The parent DisplayObjectContainer on which to add this Label.
+ * @param xpos The x position to place this component.
+ * @param ypos The y position to place this component.
+ * @param data The array of numeric values to graph.
+ */
+ public function Chart(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0, data:Array=null)
+ {
+ _data = data;
+ super(parent, xpos, ypos);
+ }
+
+ /**
+ * Initializes the component.
+ */
+ protected override function init() : void
+ {
+ super.init();
+ setSize(200, 100);
+ }
+
+ /**
+ * Creates and adds the child display objects of this component.
+ */
+ protected override function addChildren() : void
+ {
+ super.addChildren();
+ _panel = new Panel(this);
+
+ _chartHolder = new Shape();
+ _panel.content.addChild(_chartHolder);
+
+ _maxLabel = new Label();
+ _minLabel = new Label();
+ }
+
+ /**
+ * Graphs the numeric data in the chart. Override in subclasses.
+ */
+ protected function drawChart():void
+ {
+ }
+
+ /**
+ * Gets the highest value of the numbers in the data array.
+ */
+ protected function getMaxValue():Number
+ {
+ if(!_autoScale) return _maximum;
+ var maxValue:Number = Number.NEGATIVE_INFINITY;
+ for(var i:int = 0; i < _data.length; i++)
+ {
+ if(_data[i] != null)
+ {
+ maxValue = Math.max(_data[i], maxValue);
+ }
+ }
+ return maxValue;
+ }
+
+ /**
+ * Gets the lowest value of the numbers in the data array.
+ */
+ protected function getMinValue():Number
+ {
+ if(!_autoScale) return _minimum;
+ var minValue:Number = Number.POSITIVE_INFINITY;
+ for(var i:int = 0; i < _data.length; i++)
+ {
+ if(_data[i] != null)
+ {
+ minValue = Math.min(_data[i], minValue);
+ }
+ }
+ return minValue;
+ }
+
+ ///////////////////////////////////
+ // public methods
+ ///////////////////////////////////
+
+ /**
+ * Draws the visual ui of the component.
+ */
+ public override function draw() : void
+ {
+ super.draw();
+ _panel.setSize(width, height);
+ _panel.draw();
+ _chartHolder.graphics.clear();
+ if(_data != null)
+ {
+ drawChart();
+
+ var mult:Number = Math.pow(10, _labelPrecision);
+ var maxVal:Number = Math.round(maximum * mult) / mult;
+ _maxLabel.text = maxVal.toString();
+ _maxLabel.draw();
+ _maxLabel.x = -_maxLabel.width - 5;
+ _maxLabel.y = -_maxLabel.height * 0.5;
+
+ var minVal:Number = Math.round(minimum * mult) / mult;
+ _minLabel.text = minVal.toString();
+ _minLabel.draw();
+ _minLabel.x = -_minLabel.width - 5;
+ _minLabel.y = height - _minLabel.height * 0.5;
+ }
+ }
+
+ ///////////////////////////////////
+ // getter/setters
+ ///////////////////////////////////
+
+ /**
+ * Sets/gets the data array.
+ */
+ public function set data(value:Array):void
+ {
+ _data = value;
+ invalidate();
+ }
+ public function get data():Array
+ {
+ return _data;
+ }
+
+ /**
+ * Sets/gets the maximum value of the graph. Only used if autoScale is false.
+ */
+ public function set maximum(value:Number):void
+ {
+ _maximum = value;
+ invalidate();
+ }
+ public function get maximum():Number
+ {
+ if(_autoScale) return getMaxValue();
+ return _maximum;
+ }
+
+ /**
+ * Sets/gets the minimum value of the graph. Only used if autoScale is false.
+ */
+ public function set minimum(value:Number):void
+ {
+ _minimum = value;
+ invalidate();
+ }
+ public function get minimum():Number
+ {
+ if(_autoScale) return getMinValue();
+ return _minimum;
+ }
+
+ /**
+ * Sets/gets whether the graph will automatically set its own max and min values based on the data values.
+ */
+ public function set autoScale(value:Boolean):void
+ {
+ _autoScale = value;
+ invalidate();
+ }
+ public function get autoScale():Boolean
+ {
+ return _autoScale;
+ }
+
+ /**
+ * Sets/gets whether or not labels for max and min graph values will be shown.
+ * Note: these labels will be to the left of the x position of the chart. Chart position may need adjusting.
+ */
+ public function set showScaleLabels(value:Boolean):void
+ {
+ _showScaleLabels = value;
+ if(_showScaleLabels )
+ {
+ addChild(_maxLabel);
+ addChild(_minLabel);
+ }
+ else
+ {
+ if(contains(_maxLabel)) removeChild(_maxLabel);
+ if(contains(_minLabel)) removeChild(_minLabel);
+ }
+ }
+ public function get showScaleLabels():Boolean
+ {
+ return _showScaleLabels;
+ }
+
+ /**
+ * Sets/gets the amount of decimal places shown in the scale labels.
+ */
+ public function set labelPrecision(value:int):void
+ {
+ _labelPrecision = value;
+ invalidate();
+ }
+ public function get labelPrecision():int
+ {
+ return _labelPrecision;
+ }
+
+ /**
+ * Sets / gets the size of the grid.
+ */
+ public function set gridSize(value:int):void
+ {
+ _panel.gridSize = value;
+ invalidate();
+ }
+ public function get gridSize():int
+ {
+ return _panel.gridSize;
+ }
+
+ /**
+ * Sets / gets whether or not the grid will be shown.
+ */
+ public function set showGrid(value:Boolean):void
+ {
+ _panel.showGrid = value;
+ invalidate();
+ }
+ public function get showGrid():Boolean
+ {
+ return _panel.showGrid;
+ }
+
+ /**
+ * Sets / gets the color of the grid lines.
+ */
+ public function set gridColor(value:uint):void
+ {
+ _panel.gridColor = value;
+ invalidate();
+ }
+ public function get gridColor():uint
+ {
+ return _panel.gridColor;
+ }
+
+
+ }
+}
110 src/com/bit101/charts/LineChart.as
@@ -0,0 +1,110 @@
+/**
+ * LineChart.as
+ * Keith Peters
+ * version 0.9.10
+ *
+ * A chart component for graphing an array of numeric data as a line graph.
+ *
+ * Copyright (c) 2011 Keith Peters
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.bit101.charts
+{
+ import flash.display.DisplayObjectContainer;
+
+ public class LineChart extends Chart
+ {
+ protected var _lineWidth:Number = 1;
+ protected var _lineColor:uint = 0x999999;
+
+ /**
+ * Constructor
+ * @param parent The parent DisplayObjectContainer on which to add this Label.
+ * @param xpos The x position to place this component.
+ * @param ypos The y position to place this component.
+ * @param data The array of numeric values to graph.
+ */
+ public function LineChart(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0, data:Array=null)
+ {
+ super(parent, xpos, ypos, data);
+ }
+
+ /**
+ * Graphs the numeric data in the chart.
+ */
+ protected override function drawChart():void
+ {
+ var border:Number = 2;
+ var lineWidth:Number = (_width - border) / (_data.length - 1);
+ var chartHeight:Number = _height - border;
+ _chartHolder.x = 0;
+ _chartHolder.y = _height;
+ var xpos:Number = border;
+ var max:Number = getMaxValue();
+ var min:Number = getMinValue();
+ var scale:Number = chartHeight / (max - min);
+ _chartHolder.graphics.lineStyle(_lineWidth, _lineColor);
+ _chartHolder.graphics.moveTo(xpos, (_data[0] - min) * -scale);
+ xpos += lineWidth;
+ for(var i:int = 1; i < _data.length; i++)
+ {
+ if(_data[i] != null)
+ {
+ _chartHolder.graphics.lineTo(xpos, (_data[i] - min) * -scale);
+ }
+ xpos += lineWidth;
+ }
+ }
+
+
+
+ ///////////////////////////////////
+ // getter/setters
+ ///////////////////////////////////
+ /**
+ * Sets/gets the width of the line in the graph.
+ */
+ public function set lineWidth(value:Number):void
+ {
+ _lineWidth = value;
+ invalidate();
+ }
+ public function get lineWidth():Number
+ {
+ return _lineWidth;
+ }
+
+ /**
+ * Sets/gets the color of the line in the graph.
+ */
+ public function set lineColor(value:uint):void
+ {
+ _lineColor = value;
+ invalidate();
+ }
+ public function get lineColor():uint
+ {
+ return _lineColor;
+ }
+
+
+ }
+}
246 src/com/bit101/charts/PieChart.as
@@ -0,0 +1,246 @@
+/**
+ * PieChart.as
+ * Keith Peters
+ * version 0.9.10
+ *
+ * A chart component for graphing an array of numeric data as a pie chart.
+ *
+ * Copyright (c) 2011 Keith Peters
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.bit101.charts
+{
+ import com.bit101.components.Label;
+
+ import flash.display.DisplayObjectContainer;
+ import flash.display.Sprite;
+
+ /**
+ * Note: the data parameter of the PieChart, like the other charts, is an array.
+ * It can be a simple array of Numbers where each number represents one slice of the pie.
+ * It can also be an array of objects.
+ * If objects are used, each object represents one slice of the pie and can contain three properties:
+ * - value: The numeric value to chart.
+ * - label: The label to display next to the slice.
+ * - color: The color to make the slice.
+ */
+ public class PieChart extends Chart
+ {
+ protected var _sprite:Sprite;
+ protected var _beginningAngle:Number = 0;
+ protected var _colors:Array = [
+ 0xff9999, 0xffff99, 0x99ff99, 0x99ffff, 0x9999ff, 0xff99ff,
+ 0xffcccc, 0xffffcc, 0xccffcc, 0xccffff, 0xccccff, 0xffccff,
+ 0xff6666, 0xffff66, 0x99ff66, 0x66ffff, 0x6666ff, 0xff66ff,
+ 0xffffff
+ ];
+
+
+
+ /**
+ * Constructor
+ * @param parent The parent DisplayObjectContainer on which to add this Label.
+ * @param xpos The x position to place this component.
+ * @param ypos The y position to place this component.
+ * @param data The array of numeric values or objects to graph.
+ */
+ public function PieChart(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0, data:Array=null)
+ {
+ super(parent, xpos, ypos, data);
+ }
+
+ /**
+ * Initializes the component.
+ */
+ protected override function init() : void
+ {
+ super.init();
+ setSize(160, 120);
+ }
+
+ /**
+ * Creates and adds the child display objects of this component.
+ */
+ protected override function addChildren():void
+ {
+ super.addChildren();
+ _sprite = new Sprite();
+ _panel.content.addChild(_sprite);
+ }
+
+ /**
+ * Graphs the numeric data in the chart.
+ */
+ protected override function drawChart() : void
+ {
+ var radius:Number = Math.min(width - 40, height - 40) / 2;
+ _sprite.x = width / 2;
+ _sprite.y = height / 2;
+ _sprite.graphics.clear();
+ _sprite.graphics.lineStyle(0, 0x666666, 1);
+ while(_sprite.numChildren > 0) _sprite.removeChildAt(0);
+
+ var total:Number = getDataTotal();
+ var startAngle:Number = _beginningAngle * Math.PI / 180;
+ for(var i:int = 0; i < _data.length; i++)
+ {
+ var percent:Number = getValueForData(i) / total;
+ var endAngle:Number = startAngle + Math.PI * 2 * percent;
+ drawArc(startAngle, endAngle, radius, getColorForData(i));
+ makeLabel((startAngle + endAngle) * 0.5, radius + 10, getLabelForData(i));
+ startAngle = endAngle;
+ }
+ }
+
+ /**
+ * Creates and positions a single label.
+ * @property angle The angle in degrees to position this label.
+ * @property radius The distance from the center to position this label.
+ * @property text The text of the label.
+ */
+ protected function makeLabel(angle:Number, radius:Number, text:String):void
+ {
+ var label:Label = new Label(_sprite, 0, 0, text);
+ label.x = Math.cos(angle) * radius;
+ label.y = Math.sin(angle) * radius - label.height / 2;
+ if(label.x < 0)
+ {
+ label.x -= label.width;
+ }
+ }
+
+ /**
+ * Draws one slice of the pie.
+ * @property startAngle The beginning angle of the arc.
+ * @property endAngle The ending angle of the arc.
+ * @property radius The radius of the arc.
+ * @property color The color to draw the arc.
+ */
+ protected function drawArc(startAngle:Number, endAngle:Number, radius:Number, color:uint):void
+ {
+ _sprite.graphics.beginFill(color);
+ _sprite.graphics.moveTo(0, 0);
+ for(var i:Number = startAngle; i < endAngle; i += .01)
+ {
+ _sprite.graphics.lineTo(Math.cos(i) * radius, Math.sin(i) * radius);
+ }
+ _sprite.graphics.lineTo(Math.cos(endAngle) * radius, Math.sin(endAngle) * radius);
+ _sprite.graphics.lineTo(0, 0);
+ _sprite.graphics.endFill();
+ }
+
+ /**
+ * Determines what label to use for the specified data.
+ * @property index The index of the data to get the label for.
+ */
+ protected function getLabelForData(index:int):String
+ {
+ if(!(_data[index] is Number) && _data[index].label != null)
+ {
+ return _data[index].label;
+ }
+ var value:Number = Math.round(getValueForData(index) * Math.pow(10, _labelPrecision)) / Math.pow(10, _labelPrecision);
+ return value.toString();
+ }
+
+ /**
+ * Determines what color to use for the specified data.
+ * @property index The index of the data to get the color for.
+ */
+ protected function getColorForData(index:int):uint
+ {
+ if((!_data[index] is Number) && _data[index].color != null)
+ {
+ return _data[index].color;
+ }
+ if(index < _colors.length)
+ {
+ return _colors[index];
+ }
+ return Math.random() * 0xffffff;
+ }
+
+ /**
+ * Determines what value to use for the specified data.
+ * @property index The index of the data to get the value for.
+ */
+ protected function getValueForData(index:int):Number
+ {
+ if(_data[index] is Number)
+ {
+ return _data[index];
+ }
+ if(_data[index].value != null)
+ {
+ return _data[index].value;
+ }
+ return NaN;
+ }
+
+ /**
+ * Gets the sum of all the data values.
+ */
+ protected function getDataTotal():Number
+ {
+ var total:Number = 0;
+ for(var i:int = 0; i < _data.length; i++)
+ {
+ total += getValueForData(i);
+ }
+ return total;
+ }
+
+
+
+
+ ///////////////////////////////////
+ // getter/setters
+ ///////////////////////////////////
+
+ /**
+ * Sets/gets the default array of colors to use for each arc.
+ */
+ public function set colors(value:Array):void
+ {
+ _colors = value;
+ invalidate();
+ }
+ public function get colors():Array
+ {
+ return _colors;
+ }
+
+ /**
+ * Sets/gets the angle at which to start the first slice.
+ */
+ public function set beginningAngle(value:Number):void
+ {
+ _beginningAngle = value;
+ invalidate();
+ }
+ public function get beginningAngle():Number
+ {
+ return _beginningAngle;
+ }
+
+
+ }
+}
177 src/com/bit101/components/Accordion.as
@@ -0,0 +1,177 @@
+/**
+ * Accordion.as
+ * Keith Peters
+ * version 0.9.10
+ *
+ * Essentially a VBox full of Windows. Only one Window will be expanded at any time.
+ *
+ * Copyright (c) 2011 Keith Peters
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+package com.bit101.components
+{
+ import flash.display.DisplayObjectContainer;
+ import flash.events.Event;
+
+ public class Accordion extends Component
+ {
+ protected var _windows:Array;
+ protected var _winWidth:Number = 100;
+ protected var _winHeight:Number = 100;
+ protected var _vbox:VBox;
+
+ /**
+ * Constructor
+ * @param parent The parent DisplayObjectContainer on which to add this Panel.
+ * @param xpos The x position to place this component.
+ * @param ypos The y position to place this component.
+ */
+ public function Accordion(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0)
+ {
+ super(parent, xpos, ypos);
+ }
+
+ /**
+ * Initializes the component.
+ */
+ protected override function init():void
+ {
+ super.init();
+ setSize(100, 120);
+ }
+
+ /**
+ * Creates and adds the child display objects of this component.
+ */
+ protected override function addChildren() : void
+ {
+ _vbox = new VBox(this);
+ _vbox.spacing = 0;
+
+ _windows = new Array();
+ for(var i:int = 0; i < 2; i++)
+ {
+ var window:Window = new Window(_vbox, 0, 0, "Section " + (i + 1));
+ window.grips.visible = false;
+ window.draggable = false;
+ window.addEventListener(Event.SELECT, onWindowSelect);
+ if(i != 0) window.minimized = true;
+ _windows.push(window);
+ }
+ }
+
+ ///////////////////////////////////
+ // public methods
+ ///////////////////////////////////
+
+ /**
+ * Adds a new window to the bottom of the accordion.
+ * @param title The title of the new window.
+ */
+ public function addWindow(title:String):void
+ {
+ addWindowAt(title, _windows.length);
+ }
+
+ public function addWindowAt(title:String, index:int):void
+ {
+ index = Math.min(index, _windows.length);
+ index = Math.max(index, 0);
+ var window:Window = new Window(null, 0, 0, title);
+ _vbox.addChildAt(window, index);
+ window.minimized = true;
+ window.draggable = false;
+ window.grips.visible = false;
+ window.addEventListener(Event.SELECT, onWindowSelect);
+ _windows.splice(index, 0, window);
+ _winHeight = _height - (_windows.length - 1) * 20;
+ setSize(_winWidth, _winHeight);
+ }
+
+ /**
+ * Sets the size of the component.
+ * @param w The width of the component.
+ * @param h The height of the component.
+ */
+ override public function setSize(w:Number, h:Number) : void
+ {
+ super.setSize(w, h);
+ _winWidth = w;
+ _winHeight = h - (_windows.length - 1) * 20;
+ draw();
+ }
+
+ override public function draw():void
+ {
+ _winHeight = Math.max(_winHeight, 40);
+ for(var i:int = 0; i < _windows.length; i++)
+ {
+ _windows[i].setSize(_winWidth, _winHeight);
+ _vbox.draw();
+ }
+ }
+
+ /**
+ * Returns the Window at the specified index.
+ * @param index The index of the Window you want to get access to.
+ */
+ public function getWindowAt(index:int):Window
+ {
+ return _windows[index];
+ }
+
+
+ ///////////////////////////////////
+ // event handlers
+ ///////////////////////////////////
+
+ /**
+ * Called when any window is resized. If the window has been expanded, it closes all other windows.
+ */
+ protected function onWindowSelect(event:Event):void
+ {
+ var window:Window = event.target as Window;
+ if(window.minimized)
+ {
+ for(var i:int = 0; i < _windows.length; i++)
+ {
+ _windows[i].minimized = true;
+ }
+ window.minimized = false;
+ }
+ _vbox.draw();
+ }
+
+ public override function set width(w:Number):void
+ {
+ _winWidth = w;
+ super.width = w;
+ }
+
+ public override function set height(h:Number):void
+ {
+ _winHeight = h - (_windows.length - 1) * 20;
+ super.height = h;
+ }
+
+ }
+}
292 src/com/bit101/components/Calendar.as
@@ -0,0 +1,292 @@
+/**
+ * Component.as
+ * Keith Peters
+ * version 0.9.10
+ *
+ * Calendar component for showing and selecting a date.
+ *
+ * Copyright (c) 2011 Keith Peters
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ *
+ *
+ * Components with text make use of the font PF Ronda Seven by Yuusuke Kamiyamane
+ * This is a free font obtained from http://www.dafont.com/pf-ronda-seven.font
+ */
+
+package com.bit101.components
+{
+ import flash.display.DisplayObjectContainer;
+ import flash.display.Shape;
+ import flash.events.Event;
+ import flash.events.MouseEvent;
+
+ [Event(name="select", type="flash.events.Event")]
+ public class Calendar extends Panel
+ {
+ protected var _dateLabel:Label;
+ protected var _day:int;
+ protected var _dayButtons:Array = new Array();
+ protected var _month:int;
+ protected var _monthNames:Array = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
+ protected var _selection:Shape;
+ protected var _year:int;
+
+ /**
+ * Constructor
+ * @param parent The parent DisplayObjectContainer on which to add this component.
+ * @param xpos The x position to place this component.
+ * @param ypos The y position to place this component.
+ */
+ public function Calendar(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0)
+ {
+ super(parent, xpos, ypos);
+ }
+
+ /**
+ * Initializes the component.
+ */
+ protected override function init() : void
+ {
+ super.init();
+ setSize(140, 140);
+ var today:Date = new Date();
+ setDate(today);
+ }
+
+ /**
+ * Creates and adds the child display objects of this component.
+ */
+ protected override function addChildren() : void
+ {
+ super.addChildren();
+ for(var i:int = 0; i < 6; i++)
+ {
+ for(var j:int = 0; j < 7; j++)
+ {
+ var btn:PushButton = new PushButton(this.content, j * 20, 20 + i * 20);
+ btn.setSize(19, 19);
+ btn.addEventListener(MouseEvent.CLICK, onDayClick);
+ _dayButtons.push(btn);
+ }
+ }
+
+ _dateLabel = new Label(this.content, 25, 0);
+ _dateLabel.autoSize = true;
+
+ var prevYearBtn:PushButton = new PushButton(this.content, 2, 2, "«", onPrevYear);
+ prevYearBtn.setSize(14, 14);
+
+ var prevMonthBtn:PushButton = new PushButton(this.content, 17, 2, "<", onPrevMonth);
+ prevMonthBtn.setSize(14, 14);
+
+ var nextMonthBtn:PushButton = new PushButton(this.content, 108, 2, ">", onNextMonth);
+ nextMonthBtn.setSize(14, 14);
+
+ var nextYearBtn:PushButton = new PushButton(this.content, 124, 2, "»", onNextYear);
+ nextYearBtn.setSize(14, 14);
+
+ _selection = new Shape();
+ _selection.graphics.beginFill(0, 0.15);
+ _selection.graphics.drawRect(1, 1, 18, 18);
+ this.content.addChild(_selection);
+ }
+
+ /**
+ * Gets the last day of the specfied month and year. Needed by layout.
+ * @param month The month to get the last day of.
+ * @param year The year in which the month is in (needed for leap years).
+ * @return The last day of the month.
+ */
+ protected function getEndDay(month:int, year:int):int
+ {
+ switch(month)
+ {
+ case 0: // jan
+ case 2: // mar
+ case 4: // may
+ case 6: // july
+ case 7: // aug
+ case 9: // oct
+ case 11: // dec
+ return 31;
+ break;
+
+ case 1: // feb
+ if((year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0))) return 29;
+ return 28;
+ break;
+
+ default:
+ break;
+ }
+ // april, june, sept, nov.
+ return 30;
+ }
+
+ ///////////////////////////////////
+ // public methods
+ ///////////////////////////////////
+
+ /**
+ * Displays specified date in calendar by drawing that month and year and highlighting the day.
+ * @param date The date to display.
+ */
+ public function setDate(date:Date):void
+ {
+ _year = date.fullYear;
+ _month = date.month;
+ _day = date.date;
+ var startDay:int = new Date(_year, _month, 1).day;
+ var endDay:int = getEndDay(_month, _year);
+ for(var i:int = 0; i < 42; i++)
+ {
+ _dayButtons[i].visible = false;
+ }
+ for(i = 0; i < endDay; i++)
+ {
+ var btn:PushButton = _dayButtons[i + startDay];
+ btn.visible = true;
+ btn.label = (i + 1).toString();
+ btn.tag = i + 1;
+ if(i + 1 == _day)
+ {
+ _selection.x = btn.x;
+ _selection.y = btn.y;
+ }
+ }
+
+ _dateLabel.text = _monthNames[_month] + " " + _year;
+ _dateLabel.draw();
+ _dateLabel.x = (width - _dateLabel.width) / 2;
+ }
+
+ /**
+ * Displays specified date in calendar by drawing that month and year and highlighting the day.
+ * @param year The year to display.
+ * @param month The month to display.
+ * @param day The day to display.
+ */
+ public function setYearMonthDay(year:int, month:int, day:int):void
+ {
+ setDate(new Date(year, month, day));
+ }
+
+ ///////////////////////////////////
+ // event handlers
+ ///////////////////////////////////
+
+ /**
+ * Advances the month forward by one.
+ */
+ protected function onNextMonth(event:MouseEvent):void
+ {
+ _month++;
+ if(_month > 11)
+ {
+ _month = 0;
+ _year++;
+ }
+ _day = Math.min(_day,getEndDay(_month,_year));
+ setYearMonthDay(_year, _month, _day);
+ }
+
+ /**
+ * Moves the month back by one.
+ */
+ protected function onPrevMonth(event:MouseEvent):void
+ {
+ _month--;
+ if(_month < 0)
+ {
+ _month = 11;
+ _year--;
+ }
+ _day = Math.min(_day,getEndDay(_month,_year));
+ setYearMonthDay(_year, _month, _day);
+ }
+
+ /**
+ * Advances the year forward by one.
+ */
+ protected function onNextYear(event:MouseEvent):void
+ {
+ _year++;
+ _day = Math.min(_day,getEndDay(_month,_year));
+ setYearMonthDay(_year, _month, _day);
+ }
+
+ /**
+ * Moves the year back by one.
+ */
+ protected function onPrevYear(event:MouseEvent):void
+ {
+ _year--;
+ _day = Math.min(_day,getEndDay(_month,_year));
+ setYearMonthDay(_year, _month, _day);
+ }
+
+ /**
+ * Called when a date button is clicked. Selects that date.
+ */
+ protected function onDayClick(event:MouseEvent):void
+ {
+ _day = event.target.tag;
+ setYearMonthDay(_year, _month, _day);
+ dispatchEvent(new Event(Event.SELECT));
+ }
+
+ ///////////////////////////////////
+ // getter/setters
+ ///////////////////////////////////
+
+ /**
+ * Gets the currently selected Date.
+ */
+ public function get selectedDate():Date
+ {
+ return new Date(_year, _month, _day);
+ }
+
+ /**
+ * Gets the current month.
+ */
+ public function get month():int
+ {
+ return _month;
+ }
+
+ /**
+ * Gets the current year.
+ */
+ public function get year():int
+ {
+ return _year;
+ }
+
+ /**
+ * Gets the current day.
+ */
+ public function get day():int
+ {
+ return _day;
+ }
+ }
+}
183 src/com/bit101/components/CheckBox.as
@@ -0,0 +1,183 @@
+/**
+ * CheckBox.as
+ * Keith Peters
+ * version 0.9.10
+ *
+ * A basic CheckBox component.
+ *
+ * Copyright (c) 2011 Keith Peters
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.bit101.components
+{
+ import flash.display.DisplayObjectContainer;
+ import flash.display.Sprite;
+ import flash.events.MouseEvent;
+
+ public class CheckBox extends Component
+ {
+ protected var _back:Sprite;
+ protected var _button:Sprite;
+ protected var _label:Label;
+ protected var _labelText:String = "";
+ protected var _selected:Boolean = false;
+
+
+ /**
+ * Constructor
+ * @param parent The parent DisplayObjectContainer on which to add this CheckBox.
+ * @param xpos The x position to place this component.
+ * @param ypos The y position to place this component.
+ * @param label String containing the label for this component.
+ * @param defaultHandler The event handling function to handle the default event for this component (click in this case).
+ */
+ public function CheckBox(parent:DisplayObjectContainer = null, xpos:Number = 0, ypos:Number = 0, label:String = "", defaultHandler:Function = null)
+ {
+ _labelText = label;
+ super(parent, xpos, ypos);
+ if(defaultHandler != null)
+ {
+ addEventListener(MouseEvent.CLICK, defaultHandler);
+ }
+ }
+
+ /**
+ * Initializes the component.
+ */
+ override protected function init():void
+ {
+ super.init();
+ buttonMode = true;
+ useHandCursor = true;
+ mouseChildren = false;
+ }
+
+ /**
+ * Creates the children for this component
+ */
+ override protected function addChildren():void
+ {
+ _back = new Sprite();
+ _back.filters = [getShadow(2, true)];
+ addChild(_back);
+
+ _button = new Sprite();
+ _button.filters = [getShadow(1)];
+ _button.visible = false;
+ addChild(_button);
+
+ _label = new Label(this, 0, 0, _labelText);
+ draw();
+
+ addEventListener(MouseEvent.CLICK, onClick);
+ }
+
+
+
+
+ ///////////////////////////////////
+ // public methods
+ ///////////////////////////////////
+
+ /**
+ * Draws the visual ui of the component.
+ */
+ override public function draw():void
+ {
+ super.draw();
+ _back.graphics.clear();
+ _back.graphics.beginFill(Style.BACKGROUND);
+ _back.graphics.drawRect(0, 0, 10, 10);
+ _back.graphics.endFill();
+
+ _button.graphics.clear();
+ _button.graphics.beginFill(Style.BUTTON_FACE);
+ _button.graphics.drawRect(2, 2, 6, 6);
+
+ _label.text = _labelText;
+ _label.draw();
+ _label.x = 12;
+ _label.y = (10 - _label.height) / 2;
+ _width = _label.width + 12;
+ _height = 10;
+ }
+
+
+
+
+ ///////////////////////////////////
+ // event handler
+ ///////////////////////////////////
+
+ /**
+ * Internal click handler.
+ * @param event The MouseEvent passed by the system.
+ */
+ protected function onClick(event:MouseEvent):void
+ {
+ _selected = !_selected;
+ _button.visible = _selected;
+ }
+
+
+
+
+ ///////////////////////////////////
+ // getter/setters
+ ///////////////////////////////////
+
+ /**
+ * Sets / gets the label text shown on this CheckBox.
+ */
+ public function set label(str:String):void
+ {
+ _labelText = str;
+ invalidate();
+ }
+ public function get label():String
+ {
+ return _labelText;
+ }
+
+ /**
+ * Sets / gets the selected state of this CheckBox.
+ */
+ public function set selected(s:Boolean):void
+ {
+ _selected = s;
+ _button.visible = _selected;
+ }
+ public function get selected():Boolean
+ {
+ return _selected;
+ }
+
+ /**
+ * Sets/gets whether this component will be enabled or not.
+ */
+ public override function set enabled(value:Boolean):void
+ {
+ super.enabled = value;
+ mouseChildren = false;
+ }
+
+ }
+}
355 src/com/bit101/components/ColorChooser.as
@@ -0,0 +1,355 @@
+/**
+ * ColorChooser.as
+ * Keith Peters
+ * version 0.9.10
+ *
+ * A Color Chooser component, allowing textual input, a default gradient, or custom image.
+ *
+ * Copyright (c) 2011 Keith Peters
+ *
+ * popup color choosing code by Rashid Ghassempouri
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.bit101.components
+{
+ import flash.display.Bitmap;
+ import flash.display.BitmapData;
+ import flash.display.BlendMode;
+ import flash.display.DisplayObject;
+ import flash.display.DisplayObjectContainer;
+ import flash.display.GradientType;
+ import flash.display.Graphics;
+ import flash.display.InterpolationMethod;
+ import flash.display.SpreadMethod;
+ import flash.display.Sprite;
+ import flash.display.Stage;
+ import flash.events.Event;
+ import flash.events.MouseEvent;
+ import flash.geom.Matrix;
+ import flash.geom.Point;
+
+ [Event(name="change", type="flash.events.Event")]
+ public class ColorChooser extends Component
+ {
+ public static const TOP:String = "top";
+ public static const BOTTOM:String = "bottom";
+
+ protected var _colors:BitmapData;
+ protected var _colorsContainer:Sprite;
+ protected var _defaultModelColors:Array=[0xFF0000, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF, 0xFF00FF, 0xFF0000,0xFFFFFF,0x000000];
+ protected var _input:InputText;
+ protected var _model:DisplayObject;
+ protected var _oldColorChoice:uint = _value;
+ protected var _popupAlign:String = BOTTOM;
+ protected var _stage:Stage;
+ protected var _swatch:Sprite;
+ protected var _tmpColorChoice:uint = _value;
+ protected var _usePopup:Boolean = false;
+ protected var _value:uint = 0xff0000;
+
+
+ /**
+ * Constructor
+ * @param parent The parent DisplayObjectContainer on which to add this ColorChooser.
+ * @param xpos The x position to place this component.
+ * @param ypos The y position to place this component.
+ * @param value The initial color value of this component.
+ * @param defaultHandler The event handling function to handle the default event for this component (change in this case).
+ */
+
+ public function ColorChooser(parent:DisplayObjectContainer = null, xpos:Number = 0, ypos:Number = 0, value:uint = 0xff0000, defaultHandler:Function = null)
+ {
+ _oldColorChoice = _tmpColorChoice = _value = value;
+
+ super(parent, xpos, ypos);
+
+ if(defaultHandler != null)
+ {
+ addEventListener(Event.CHANGE, defaultHandler);
+ }
+
+ }
+
+ /**
+ * Initializes the component.
+ */
+ override protected function init():void
+ {
+
+ super.init();
+
+ _width = 65;
+ _height = 15;
+ value = _value;
+ }
+
+ override protected function addChildren():void
+ {
+ _input = new InputText();
+ _input.width = 45;
+ _input.restrict = "0123456789ABCDEFabcdef";
+ _input.maxChars = 6;
+ addChild(_input);
+ _input.addEventListener(Event.CHANGE, onChange);
+
+ _swatch = new Sprite();
+ _swatch.x = 50;
+ _swatch.filters = [getShadow(2, true)];
+ addChild(_swatch);
+
+ _colorsContainer = new Sprite();
+ _colorsContainer.addEventListener(Event.ADDED_TO_STAGE, onColorsAddedToStage);
+ _colorsContainer.addEventListener(Event.REMOVED_FROM_STAGE, onColorsRemovedFromStage);
+ _model = getDefaultModel();
+ drawColors(_model);
+ }
+
+ ///////////////////////////////////
+ // public methods
+ ///////////////////////////////////
+
+ /**
+ * Draws the visual ui of the component.
+ */
+ override public function draw():void
+ {
+ super.draw();
+ _swatch.graphics.clear();
+ _swatch.graphics.beginFill(_value);
+ _swatch.graphics.drawRect(0, 0, 16, 16);
+ _swatch.graphics.endFill();
+ }
+
+ ///////////////////////////////////
+ // event handlers
+ ///////////////////////////////////
+
+ /**
+ * Internal change handler.
+ * @param event The Event passed by the system.
+ */
+ protected function onChange(event:Event):void
+ {
+ event.stopImmediatePropagation();
+ _value = parseInt("0x" + _input.text, 16);
+ _input.text = _input.text.toUpperCase();
+ _oldColorChoice = value;
+ invalidate();
+ dispatchEvent(new Event(Event.CHANGE));
+
+ }
+
+ ///////////////////////////////////
+ // getter/setters
+ ///////////////////////////////////
+
+ /**
+ * Gets / sets the color value of this ColorChooser.
+ */
+ public function set value(n:uint):void
+ {
+ var str:String = n.toString(16).toUpperCase();
+ while(str.length < 6)
+ {
+ str = "0" + str;
+ }
+ _input.text = str;
+ _value = parseInt("0x" + _input.text, 16);
+ invalidate();
+ }
+ public function get value():uint
+ {
+ return _value;
+ }
+
+ ///////////////////////////////////
+ // COLOR PICKER MODE SUPPORT
+ ///////////////////////////////////}
+
+
+ public function get model():DisplayObject { return _model; }
+ public function set model(value:DisplayObject):void
+ {
+ _model = value;
+ if (_model!=null) {
+ drawColors(_model);
+ if (!usePopup) usePopup = true;
+ } else {
+ _model = getDefaultModel();
+ drawColors(_model);
+ usePopup = false;
+ }
+ }
+
+ protected function drawColors(d:DisplayObject):void{
+ _colors = new BitmapData(d.width, d.height);
+ _colors.draw(d);
+ while (_colorsContainer.numChildren) _colorsContainer.removeChildAt(0);
+ _colorsContainer.addChild(new Bitmap(_colors));
+ placeColors();
+ }
+
+ public function get popupAlign():String { return _popupAlign; }
+ public function set popupAlign(value:String):void {
+ _popupAlign = value;
+ placeColors();
+ }
+
+ public function get usePopup():Boolean { return _usePopup; }
+ public function set usePopup(value:Boolean):void {
+ _usePopup = value;
+
+ _swatch.buttonMode = true;
+ _colorsContainer.buttonMode = true;
+ _colorsContainer.addEventListener(MouseEvent.MOUSE_MOVE, browseColorChoice);
+ _colorsContainer.addEventListener(MouseEvent.MOUSE_OUT, backToColorChoice);
+ _colorsContainer.addEventListener(MouseEvent.CLICK, setColorChoice);
+ _swatch.addEventListener(MouseEvent.CLICK, onSwatchClick);
+
+ if (!_usePopup) {
+ _swatch.buttonMode = false;
+ _colorsContainer.buttonMode = false;
+ _colorsContainer.removeEventListener(MouseEvent.MOUSE_MOVE, browseColorChoice);
+ _colorsContainer.removeEventListener(MouseEvent.MOUSE_OUT, backToColorChoice);
+ _colorsContainer.removeEventListener(MouseEvent.CLICK, setColorChoice);
+ _swatch.removeEventListener(MouseEvent.CLICK, onSwatchClick);
+ }
+ }
+
+ /**
+ * The color picker mode Handlers
+ */
+
+ protected function onColorsRemovedFromStage(e:Event):void {
+ _stage.removeEventListener(MouseEvent.CLICK, onStageClick);
+ }
+
+ protected function onColorsAddedToStage(e:Event):void {
+ _stage = stage;
+ _stage.addEventListener(MouseEvent.CLICK, onStageClick);
+ }
+
+ protected function onStageClick(e:MouseEvent):void {
+ displayColors();
+ }
+
+
+ protected function onSwatchClick(event:MouseEvent):void
+ {
+ event.stopImmediatePropagation();
+ displayColors();
+ }
+
+ protected function backToColorChoice(e:MouseEvent):void
+ {
+ value = _oldColorChoice;
+ }
+
+ protected function setColorChoice(e:MouseEvent):void {
+ value = _colors.getPixel(_colorsContainer.mouseX, _colorsContainer.mouseY);
+ _oldColorChoice = value;
+ dispatchEvent(new Event(Event.CHANGE));
+ displayColors();
+ }
+
+ protected function browseColorChoice(e:MouseEvent):void
+ {
+ _tmpColorChoice = _colors.getPixel(_colorsContainer.mouseX, _colorsContainer.mouseY);
+ value = _tmpColorChoice;
+ }
+
+ /**
+ * The color picker mode Display functions
+ */
+
+ protected function displayColors():void
+ {
+ placeColors();
+ if (_colorsContainer.parent) _colorsContainer.parent.removeChild(_colorsContainer);
+ else stage.addChild(_colorsContainer);
+ }
+
+ protected function placeColors():void{
+ var point:Point = new Point(x, y);
+ if(parent) point = parent.localToGlobal(point);
+ switch (_popupAlign)
+ {
+ case TOP :
+ _colorsContainer.x = point.x;
+ _colorsContainer.y = point.y - _colorsContainer.height - 4;
+ break;
+ case BOTTOM :
+ _colorsContainer.x = point.x;
+ _colorsContainer.y = point.y + 22;
+ break;
+ default:
+ _colorsContainer.x = point.x;
+ _colorsContainer.y = point.y + 22;
+ break;
+ }
+ }
+
+ /**
+ * Create the default gradient Model
+ */
+
+ protected function getDefaultModel():Sprite {
+ var w:Number = 100;
+ var h:Number = 100;
+ var bmd:BitmapData = new BitmapData(w, h);
+
+ var g1:Sprite = getGradientSprite(w, h, _defaultModelColors);
+ bmd.draw(g1);
+
+ var blendmodes:Array = [BlendMode.MULTIPLY,BlendMode.ADD];
+ var nb:int = blendmodes.length;
+ var g2:Sprite = getGradientSprite(h/nb, w, [0xFFFFFF, 0x000000]);
+
+ for (var i:int = 0; i < nb; i++) {
+ var blendmode:String = blendmodes[i];
+ var m:Matrix = new Matrix();
+ m.rotate(-Math.PI / 2);
+ m.translate(0, h / nb * i + h/nb);
+ bmd.draw(g2, m, null,blendmode);
+ }
+
+ var s:Sprite = new Sprite();
+ var bm:Bitmap = new Bitmap(bmd);
+ s.addChild(bm);
+ return(s);
+ }
+
+ protected function getGradientSprite(w:Number, h:Number, gc:Array):Sprite
+ {
+ var gs:Sprite = new Sprite();
+ var g:Graphics = gs.graphics;
+ var gn:int = gc.length;
+ var ga:Array = [];
+ var gr:Array = [];
+ var gm:Matrix = new Matrix(); gm.createGradientBox(w, h, 0, 0, 0);
+ for (var i:int = 0; i < gn; i++) { ga.push(1); gr.push(0x00 + 0xFF / (gn - 1) * i); }
+ g.beginGradientFill(GradientType.LINEAR, gc, ga, gr, gm, SpreadMethod.PAD,InterpolationMethod.RGB);
+ g.drawRect(0, 0, w, h);
+ g.endFill();
+ return(gs);
+ }
+ }
+}
461 src/com/bit101/components/ComboBox.as
@@ -0,0 +1,461 @@
+/**
+ * ComboBox.as
+ * Keith Peters
+ * version 0.9.10
+ *
+ * A button that exposes a list of choices and displays the chosen item.
+ *
+ * Copyright (c) 2011 Keith Peters
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package com.bit101.components
+{
+ import flash.display.DisplayObjectContainer;
+ import flash.display.Stage;
+ import flash.events.Event;
+ import flash.events.MouseEvent;
+ import flash.geom.Point;
+ import flash.geom.Rectangle;
+
+ [Event(name="select", type="flash.events.Event")]
+ public class ComboBox extends Component
+ {
+ public static const TOP:String = "top";
+ public static const BOTTOM:String = "bottom";
+
+ protected var _defaultLabel:String = "";
+ protected var _dropDownButton:PushButton;
+ protected var _items:Array;
+ protected var _labelButton:PushButton;
+ protected var _list:List;
+ protected var _numVisibleItems:int = 6;
+ protected var _open:Boolean = false;
+ protected var _openPosition:String = BOTTOM;
+ protected var _stage:Stage;
+
+
+ /**
+ * Constructor
+ * @param parent The parent DisplayObjectContainer on which to add this List.
+ * @param xpos The x position to place this component.
+ * @param ypos The y position to place this component.
+ * @param defaultLabel The label to show when no item is selected.
+ * @param items An array of items to display in the list. Either strings or objects with label property.
+ */
+ public function ComboBox(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0, defaultLabel:String="", items:Array = null)
+ {
+ _defaultLabel = defaultLabel;
+ _items = items;
+ addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
+ addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
+ super(parent, xpos, ypos);
+ }
+
+ /**
+ * Initilizes the component.
+ */
+ protected override function init():void
+ {
+ super.init();
+ setSize(100, 20);
+ setLabelButtonLabel();
+ }
+
+ /**
+ * Creates and adds the child display objects of this component.
+ */
+ protected override function addChildren():void
+ {
+ super.addChildren();
+ _list = new List(null, 0, 0, _items);
+ _list.autoHideScrollBar = true;
+ _list.addEventListener(Event.SELECT, onSelect);
+
+ _labelButton = new PushButton(this, 0, 0, "", onDropDown);
+ _dropDownButton = new PushButton(this, 0, 0, "+", onDropDown);
+ }
+
+ /**
+ * Determines what to use for the main button label and sets it.
+ */
+ protected function setLabelButtonLabel():void
+ {
+ if(selectedItem == null)
+ {
+ _labelButton.label = _defaultLabel;
+ }
+ else if(selectedItem is String)
+ {
+ _labelButton.label = selectedItem as String;
+ }
+ else if(selectedItem.hasOwnProperty("label") && selectedItem.label is String)
+ {
+ _labelButton.label = selectedItem.label;
+ }
+ else
+ {
+ _labelButton.label = selectedItem.toString();
+ }
+ }
+
+ /**
+ * Removes the list from the stage.
+ */
+ protected function removeList():void
+ {
+ if(_stage.contains(_list)) _stage.removeChild(_list);
+ _stage.removeEventListener(MouseEvent.CLICK, onStageClick);
+ _dropDownButton.label = "+";
+ }
+
+
+
+ ///////////////////////////////////
+ // public methods
+ ///////////////////////////////////
+
+ public override function draw():void
+ {
+ super.draw();
+ _labelButton.setSize(_width - _height + 1, _height);
+ _labelButton.draw();
+
+ _dropDownButton.setSize(_height, _height);
+ _dropDownButton.draw();
+ _dropDownButton.x = _width - height;
+
+ _list.setSize(_width, _numVisibleItems * _list.listItemHeight);
+ }
+
+
+ /**
+ * Adds an item to the list.
+ * @param item The item to add. Can be a string or an object containing a string property named label.
+ */
+ public function addItem(item:Object):void
+ {
+ _list.addItem(item);
+ }
+
+ /**
+ * Adds an item to the list at the specified index.
+ * @param item The item to add. Can be a string or an object containing a string property named label.
+ * @param index The index at which to add the item.
+ */
+ public function addItemAt(item:Object, index:int):void
+ {
+ _list.addItemAt(item, index);
+ }
+
+ /**
+ * Removes the referenced item from the list.
+ * @param item The item to remove. If a string, must match the item containing that string. If an object, must be a reference to the exact same object.
+ */
+ public function removeItem(item:Object):void
+ {
+ _list.removeItem(item);
+ }
+
+ /**
+ * Removes the item from the list at the specified index
+ * @param index The index of the item to remove.
+ */
+ public function removeItemAt(index:int):void
+ {
+ _list.removeItemAt(index);
+ }
+
+ /**
+ * Removes all items from the list.
+ */
+ public function removeAll():void
+ {
+ _list.removeAll();
+ }
+
+
+
+
+ ///////////////////////////////////
+ // event handlers
+ ///////////////////////////////////
+
+ /**
+ * Called when one of the top buttons is pressed. Either opens or closes the list.
+ */
+ protected function onDropDown(event:MouseEvent):void
+ {
+ _open = !_open;
+ if(_open)
+ {
+ var point:Point = new Point();
+ if(_openPosition == BOTTOM)
+ {
+ point.y = _height;
+ }
+ else
+ {
+ point.y = -_numVisibleItems * _list.listItemHeight;
+ }
+ point = this.localToGlobal(point);
+ _list.move(point.x, point.y);
+ _stage.addChild(_list);
+ _stage.addEventListener(MouseEvent.CLICK, onStageClick);
+ _dropDownButton.label = "-";
+ }
+ else
+ {
+ removeList();
+ }
+ }
+
+ /**
+ * Called when the mouse is clicked somewhere outside of the combo box when the list is open. Closes the list.
+ */
+ protected function onStageClick(event:MouseEvent):void
+ {
+ // ignore clicks within buttons or list
+ if(event.target == _dropDownButton || event.target == _labelButton) return;
+ if(new Rectangle(_list.x, _list.y, _list.width, _list.height).contains(event.stageX, event.stageY)) return;
+
+ _open = false;
+ removeList();
+ }
+
+ /**
+ * Called when an item in the list is selected. Displays that item in the label button.
+ */
+ protected function onSelect(event:Event):void
+ {
+ _open = false;
+ _dropDownButton.label = "+";
+ if(stage != null && stage.contains(_list))
+ {
+ stage.removeChild(_list);
+ }
+ setLabelButtonLabel();
+ dispatchEvent(event);
+ }
+
+ /**
+ * Called when the component is added to the stage.
+ */
+ protected function onAddedToStage(event:Event):void
+ {
+ _stage = stage;
+ }
+
+ /**
+ * Called when the component is removed from the stage.
+ */
+ protected function onRemovedFromStage(event:Event):void
+ {
+ removeList();
+ }
+
+ ///////////////////////////////////
+ // getter/setters
+ ///////////////////////////////////
+
+ /**
+ * Sets / gets the index of the selected list item.
+ */
+ public function set selectedIndex(value:int):void
+ {
+ _list.selectedIndex = value;
+ setLabelButtonLabel();
+ }
+ public function get selectedIndex():int
+ {
+ return _list.selectedIndex;
+ }
+
+ /**
+ * Sets / gets the item in the list, if it exists.
+ */
+ public function set selectedItem(item:Object):void
+ {
+ _list.selectedItem = item;
+ setLabelButtonLabel();
+ }
+ public function get selectedItem():Object
+ {
+ return _list.selectedItem;
+ }
+
+ /**
+ * Sets/gets the default background color of list items.
+ */
+ public function set defaultColor(value:uint):void
+ {
+ _list.defaultColor = value;
+ }
+ public function get defaultColor():uint
+ {
+ return _list.defaultColor;
+ }
+
+ /**
+ * Sets/gets the selected background color of list items.
+ */
+ public function set selectedColor(value:uint):void
+ {
+ _list.selectedColor = value;
+ }
+ public function get selectedColor():uint
+ {
+ return _list.selectedColor;
+ }
+
+ /**
+ * Sets/gets the rollover background color of list items.
+ */
+ public function set rolloverColor(value:uint):void
+ {
+ _list.rolloverColor = value;
+ }
+ public function get rolloverColor():uint
+ {
+ return _list.rolloverColor;
+ }
+
+ /**
+ * Sets the height of each list item.
+ */
+ public function set listItemHeight(value:Number):void
+ {
+ _list.listItemHeight = value;
+ invalidate();
+ }
+ public function get listItemHeight():Number
+ {
+ return _list.listItemHeight;
+ }
+
+ /**
+ * Sets / gets the position the list will open on: top or bottom.
+ */
+ public function set openPosition(value:String):void
+ {
+ _openPosition = value;
+ }
+ public function get openPosition():String
+ {
+ return _openPosition;
+ }
+
+ /**
+ * Sets / gets the label that will be shown if no item is selected.
+ */
+ public function set defaultLabel(value:String):void
+ {
+ _defaultLabel = value;
+ setLabelButtonLabel();
+ }
+ public function get defaultLabel():String
+ {
+ return _defaultLabel;
+ }
+
+ /**
+ * Sets / gets the number of visible items in the drop down list. i.e. the height of the list.
+ */
+ public function set numVisibleItems(value:int):void
+ {
+ _numVisibleItems = value;
+ invalidate();
+ }
+ public function get numVisibleItems():int
+ {
+ return _numVisibleItems;
+ }
+
+ /**
+ * Sets / gets the list of items to be shown.
+ */
+ public function set items(value:Array):void
+ {
+ _list.items = value;
+ }
+ public function get items():Array
+ {
+ return _list.items;
+ }
+
+ /**
+ * Sets / gets the class used to render list items. Must extend ListItem.
+ */
+ public function set listItemClass(value:Class):void
+ {
+ _list.listItemClass = value;
+ }
+ public function get listItemClass():Class
+ {
+ return _list.listItemClass;
+ }
+
+
+ /**
+ * Sets / gets the color for alternate rows if alternateRows is set to true.
+ */
+ public function set alternateColor(value:uint):void
+ {
+ _list.alternateColor = value;
+ }
+ public function get alternateColor():uint
+ {
+ return _list.alternateColor;
+ }
+
+ /**
+ * Sets / gets whether or not every other row will be colored with the alternate color.
+ */
+ public function set alternateRows(value:Boolean):void
+ {
+ _list.alternateRows = value;
+ }
+ public function get alternateRows():Boolean
+ {
+ return _list.alternateRows;
+ }
+
+ /**
+ * Sets / gets whether the scrollbar will auto hide when there is nothing to scroll.
+ */
+ public function set autoHideScrollBar(value:Boolean):void
+ {
+ _list.autoHideScrollBar = value;
+ invalidate();
+ }
+ public function get autoHideScrollBar():Boolean
+ {
+ return _list.autoHideScrollBar;
+ }
+
+ /**
+ * Gets whether or not the combo box is currently open.
+ */
+ public function get isOpen():Boolean
+ {
+ return _open;
+ }
+ }
+}
260 src/com/bit101/components/Component.as
@@ -0,0 +1,260 @@
+/**
+ * Component.as
+ * Keith Peters
+ * version 0.9.10
+ *
+ * Base class for all components
+ *
+ * Copyright (c) 2011 Keith Peters
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ *
+ *
+ * Components with text make use of the font PF Ronda Seven by Yuusuke Kamiyamane
+ * This is a free font obtained from http://www.dafont.com/pf-ronda-seven.font