<?xml version="1.0" encoding="utf-8"?>
<!--

    ADOBE SYSTEMS INCORPORATED
    Copyright 2008 Adobe Systems Incorporated
    All Rights Reserved.

    NOTICE: Adobe permits you to use, modify, and distribute this file
    in accordance with the terms of the license agreement accompanying it.

-->
<!--- The Spark skin class for the MX Border base class. 

      @see mx.skins.Border
      
      @langversion 3.0
      @playerversion Flash 10
      @playerversion AIR 1.5
      @productversion Flex 4
-->
<local:SparkSkinForHalo xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:local="mx.skins.spark.*" implements="mx.core.IRectangularBorder" mouseEnabled="false" mouseChildren="false">
    
    <fx:Script>
        <![CDATA[
        import mx.core.EdgeMetrics;
        import mx.core.IUIComponent;
        import mx.graphics.RectangularDropShadow;
        
        /* Define the skin elements that should not be colorized. */
        static private const exclusions:Array = ["background"];
        /**
         * @private
         */
        override public function get colorizeExclusions():Array {return exclusions;}
        
        /* Define the content fill items that should be colored by the "contentBackgroundColor" style. */
        static private const contentFill:Array = ["bgFill"];
        /**
         * @private
         */
        override public function get contentItems():Array {return contentFill};

        /* Define the border item. */
        static private const borderItem:Array = ["borderStroke"];
        /**
         * @private
         */
        override protected function get borderItems():Array {return borderItem;}
        /**
         * @private
         */
        override protected function get defaultBorderItemColor():uint {return getStyle("borderColor");}
        /**
         * @private
         */
        override protected function get defaultBorderAlpha():Number {return getStyle("borderAlpha");}
        
        static private const metrics:EdgeMetrics = new EdgeMetrics(1, 1, 1, 1);
          
        [Bindable]
        /**
         * @private
         */
        public var cornerRadius:Number = 0;
            
        private var dropShadow:RectangularDropShadow;
        
        /**
         * @private
         */
        public function get borderMetrics():EdgeMetrics
        {
            if (getStyle("borderVisible") == false ||
                getStyle("borderStyle") == "none")
                return EdgeMetrics.EMPTY;
            
            return metrics;
        }
        
        /**
         * @private
         */
        public function get backgroundImageBounds():Rectangle
        {
            return null;
        }
        
        /**
         * @private
         */
        public function set backgroundImageBounds(value:Rectangle):void
        {
        
        }
        
        /**
         * @private
         */
        public function get hasBackgroundImage():Boolean
        {
            return false;
        }
        
        /**
         * @private
         */
        public function layoutBackgroundImage():void
        {
        
        }

        /**
         * @private
         */
        override protected function initializationComplete():void
        {
            useChromeColor = true;
            super.initializationComplete();
        }
                
        /**
         * @private
         */
        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            // Force a redraw to clear any existing shadow, and to force a redraw of the 
            // border/background.
            redrawRequested = true;
            
            if (getStyle("borderVisible") == false || getStyle("borderStyle") == "none")
            {
                border.visible = false;
                background.left = background.top = background.right = background.bottom = 0;
            }
            else
            {
                border.visible = true;
                background.left = background.top = background.right = background.bottom = 1;
            }
            
            border.radiusX = cornerRadius;
            background.radiusX = cornerRadius;
            
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            
            if (parent && parent is IUIComponent && !IUIComponent(parent).enabled)
                alpha = 0.5;
            else
                alpha = 1;
            
            // Draw drop shadow, if needed
            if (getStyle("dropShadowVisible") == false ||
                width == 0 || 
                height == 0)
            {
                return;
            }

            // Create a RectangularDropShadow object, set its properties,
            // and draw the shadow
            if (!dropShadow)
                dropShadow = new RectangularDropShadow();

            dropShadow.distance = 5;
            dropShadow.angle = 90;
            dropShadow.color = 0;
            dropShadow.alpha = 0.8;
            dropShadow.blurX = 20;
            dropShadow.blurY = 20;

            // Clear out any pending line style
            graphics.lineStyle();
            dropShadow.drawShadow(graphics, 0, 0, width, height);
        }
        
        private function getDropShadowAngle(distance:Number,
                                            direction:String):Number
        {
            if (direction == "left")
                return distance >= 0 ? 135 : 225;

            else if (direction == "right")
                return distance >= 0 ? 45 : 315;
        
            else // direction == "center"
                return distance >= 0 ? 90 : 270;
        }
        ]]>
    </fx:Script>
    
    <!-- border --> 
    <!--- @private --> 
    <s:Rect left="0" right="0" top="0" bottom="0" radiusX="0" id="border">
        <s:stroke>            
            <!--- @private --> 
            <s:SolidColorStroke id="borderStroke" />
        </s:stroke>
    </s:Rect>

    <!-- fill -->
    <!--- @private --> 
    <s:Rect id="background" left="1" right="1" top="1" bottom="1" radiusX="0">
        <s:fill>
            <!--- @private --> 
            <s:SolidColor id="bgFill" color="0xFFFFFF" />
        </s:fill>
    </s:Rect>
 </local:SparkSkinForHalo>
