Flex Spark Panel 扩展成 TitleBarPanel

Summary:  由于Spark组件重新架构了,导致mx组件里的好多功能不能使用了。比如Panel: mx的Panel有titleBar,可以添加一些组件在titleBar里; 但在 spark的Panel上实现titleBar 要另辟其径了。   在网上search了半天,没有符合要求的。  只好去官方文档仔细阅读一下 spark组件的来龙去脉。 终于明白了,spark 框架的良苦用心。


Requirement: 要求spark 的Panel 可以在使用时,任意地添加组件在title上,比如:Close Button, Refresh Button, Max Button等。


Solution: 使用自定义的SparkSkin,扩展spark.components.Panel 控件, 添加 titleBarContent 属性。
1. TitleBarPanelSkin 的代码如下:
<?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 default skin class for a Spark Panel container.  

    @see spark.components.Panel

    @langversion 3.0
    @playerversion Flash 10
    @playerversion AIR 1.5
    @productversion Flex 4
-->
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:fb="http://ns.adobe.com/flashbuilder/2009" blendMode="normal" mouseEnabled="false" 
    minWidth="131" minHeight="127" alpha.disabled="0.5" alpha.disabledWithControlBar="0.5">
	<fx:Metadata>[HostComponent("com.lombardrisk.common.components.panel.TitleBarPanel")]</fx:Metadata>
    
    <fx:Script fb:purpose="styling">
        <![CDATA[
		import mx.core.FlexVersion;
		
		/* Define the skin elements that should not be colorized. 
        For panel, border and title background are skinned, but the content area, background, border, and title text are not. */
        static private const exclusions:Array = ["background", "titleDisplay", "contentGroup", "controlBarGroup", "border"];
			
		/* exclusions before Flex 4.5 for backwards-compatibility purposes */
		static private const exclusions_4_0:Array = ["background", "titleDisplay", "contentGroup", "controlBarGroup"];
		
		/**
		 * @private
		 */
		override public function get colorizeExclusions():Array 
		{
			// Since border is styleable via borderColor, no need to allow chromeColor to affect
			// the border.  This is wrapped in a compatibility flag since this change was added  
			// in Flex 4.5
			if (FlexVersion.compatibilityVersion < FlexVersion.VERSION_4_5)
			{
				return exclusions_4_0;
			}
			
			return exclusions;
		}
        
        /**
         * @private
         */
        override protected function initializationComplete():void
        {
            useChromeColor = true;
            super.initializationComplete();
        }
        
        /**
         * @private
         */
        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            if (getStyle("borderVisible") == true)
            {
                border.visible = true;
                background.left = background.top = background.right = background.bottom = 1;
                contents.left = contents.top = contents.right = contents.bottom = 1;
            }
            else
            {
                border.visible = false;
                background.left = background.top = background.right = background.bottom = 0;
               
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值