Degrafa渲染DataGrid

本文介绍了一个使用Degrafa库在DataGrid中实现视觉效果的示例。通过自定义渲染器,能够直观展示磁盘容量使用情况,包括已用和剩余空间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     在DataGrid中可以利用多种组件实现Column的渲染,这里就介绍一个Degrafa中的surface渲染Column的Demo:

    

<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:degrafa="com.degrafa.*"
    xmlns:paint="com.degrafa.paint.*"
    xmlns:geometry="com.degrafa.geometry.*" 
    layout="absolute" 
    creationComplete="generateData()"
    backgroundColor="#FFFFFF"
    backgroundGradientColors="[#999999, #FFFFFF]" viewSourceURL="srcview/index.html">
    
    <mx:Style>
        ApplicationControlBar {
           highlightAlphas: 0.7, 0.06;
           fillAlphas: 1, 1;
           fillColors: #999999, #666666;
           cornerRadius: 0;
           dropShadowEnabled: true;
           shadowDirection: center;
        }
    </mx:Style>
    
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable]
            private var dataCollection : ArrayCollection;
            
            private function generateData() : void
            {
                if ( dataCollection == null )
                    dataCollection = new ArrayCollection();
                
                dataCollection.disableAutoUpdate();
                dataCollection.removeAll();
                
                for ( var x : int = 0; x < 100; x ++ )
                {
                    var o : Object = new Object();
                    o.capacity = 500;
                    o.used = Math.random() * o.capacity;
                    o.free = o.capacity - o.used;
                    o.name = "Disk: " + x;
                    dataCollection.addItem( o );
                }
                
                dataCollection.enableAutoUpdate();
                dataCollection.refresh();
            }
        ]]>
    </mx:Script>
    
    <mx:ApplicationControlBar dock="true">
        
        <mx:Button label="Generate New Data" click="generateData()" useHandCursor="true" buttonMode="true" />
        
    </mx:ApplicationControlBar>
    
    <mx:DataGrid top="10" bottom="10" left="10" right="10" 
        dataProvider="{ dataCollection }">
        <mx:columns>
            <mx:DataGridColumn headerText="Name" dataField="name"/>
            <mx:DataGridColumn headerText="Capacity" dataField="capacity"/>
            <mx:DataGridColumn headerText="Used" dataField="used"/>
            <mx:DataGridColumn headerText="Used" dataField="used">
                <mx:itemRenderer>
                    <mx:Component>
                        <mx:Canvas>
                                
                            <degrafa:Surface>
                            
                                   <degrafa:fills>
                                    <paint:LinearGradientFill id="redGradient" angle="90">
                                        <paint:GradientStop alpha="1"  color="#FF0000"/>
                                        <paint:GradientStop alpha="1" color="#333333"/>
                                    </paint:LinearGradientFill>
                                </degrafa:fills>
                                
                                <degrafa:GeometryGroup>
                                    <geometry:RoundedRectangle 
                                        fill="{redGradient}"
                                        cornerRadius="2"
                                        width="{ width * ( data.used / data.capacity ) }"
                                        height="{ height }" />
                                </degrafa:GeometryGroup> 
                                
                                <degrafa:filters>
                                    <mx:DropShadowFilter />
                                </degrafa:filters>
                                
                            </degrafa:Surface>
                            
                        </mx:Canvas>
                    </mx:Component>
                </mx:itemRenderer>
            </mx:DataGridColumn>
            <mx:DataGridColumn headerText="Free" dataField="free"/>
            <mx:DataGridColumn headerText="Free" dataField="free">
                <mx:itemRenderer>
                    <mx:Component>
                        <mx:Canvas>
                                
                            <degrafa:Surface>
                            
                                   <degrafa:fills>
                                    <paint:LinearGradientFill id="greenGradient" angle="90">
                                        <paint:GradientStop alpha="1"  color="#00FF00"/>
                                        <paint:GradientStop alpha="1" color="#333333"/>
                                    </paint:LinearGradientFill>
                                </degrafa:fills>
                                
                                <degrafa:GeometryGroup>
                                    <geometry:RoundedRectangle 
                                        fill="{greenGradient}"
                                        cornerRadius="2"
                                        width="{ width * ( data.free / data.capacity ) }"
                                        height="{ height }" />
                                </degrafa:GeometryGroup> 
                                
                                <degrafa:filters>
                                    <mx:DropShadowFilter />
                                </degrafa:filters>
                                
                            </degrafa:Surface>
                            
                        </mx:Canvas>
                    </mx:Component>
                </mx:itemRenderer>
            </mx:DataGridColumn>
        </mx:columns>
    </mx:DataGrid>
    
    
    
</mx:Application>

 

   原文见:http://www.insideria.com/2008/03/degrafa-datagrids-visual-displ.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值