使用图形滤镜来扩展基本的组件
2008-04-28 14:36
351 查看
使用图形滤镜来扩展基本的组件
AndrewTriceApril23,2008|
在前面的帖子中我曾经讲到过如何使用图形滤镜,这篇博文中我将介绍如何使用这些滤镜来增强基本组件的能力,在本示例中我将展示如何使用滤镜来改变基本的TREE组件的外观
我曾经无数次的碰到过这个问题,那就是如何通过TREE图标来表示其当前的TREE展开状态
我总是在寻找将数据可视化的方法,这里有一个非常简单的方来来扩展一个基本的TREE组件的图标所蕴含的意味,我见过无数种的实现方式,但是我认为下面的是其中最简单的一种方法,它使用了
下面就是:
varso=newSWFObject("http://www.tricedesigns.com/portfolio/colorfolders/TreeColors.swf","TreeColors","425","260","8","#FFFFFF"); so.write("treecolo
下面我就展示它是如何实现的,它使用了一个定制的ITEMRENDER,该render扩展了TREEITEMRENDER类,在commitProperties方法中,应用了ColorMatrixFilter过滤当前文件夹的图标,就是这么简单,而没有什么更换图标或者是替代之类的。
overrideprotectedfunctioncommitProperties():void
...{
super.commitProperties();
if(icon)
...{
varmatrix:Array=newArray();
switch(TreeListData(listData).depth)
...{
case1:
matrix=matrix.concat([1,0,0,0,0]);//red
matrix=matrix.concat([0,.25,0,0,0]);//green
matrix=matrix.concat([0,0,.25,0,0]);//blue
matrix=matrix.concat([0,0,0,1,0]);//alpha
icon.filters=[newColorMatrixFilter(matrix)]
break;
case2:
matrix=matrix.concat([.25,0,0,0,0]);//red
matrix=matrix.concat([0,1,0,0,0]);//green
matrix=matrix.concat([0,0,.25,0,0]);//blue
matrix=matrix.concat([0,0,0,1,0]);//alpha
icon.filters=[newColorMatrixFilter(matrix)]
break;
case3:
matrix=matrix.concat([.25,0,0,0,0]);//red
matrix=matrix.concat([0,.25,0,0,0]);//green
matrix=matrix.concat([0,0,1,0,0]);//blue
matrix=matrix.concat([0,0,0,1,0]);//alpha
icon.filters=[newColorMatrixFilter(matrix)]
break;
default:
icon.filters=[];
break;
}
}
}
当然这些代码在定制的TREE图标上也可以工作
varso=newSWFObject("http://www.tricedesigns.com/portfolio/colorfolders/CustomFolderTreeColors.swf","CustomFolderTreeColors","425","260","8","#FFFFFF"); so.write("CustomFolderTreeColors");
源代码链接:
Note:Thereare2separatefilesinthere"TreeColors.mxml"and"CustomFolderTreeColors".Theonlydifferencebetweenthesetwoarethespecificationofcustomfoldericons.
UsingGraphicsFilterstoExtendBasicComponents
AndrewTriceApril23,2008|
I'vediscussed
I'malwayslookingforwaystovisualizedata,andthisisaveryeasywaytoextendabasictreecontroltoaddmeaningtoit.I'veseendifferentimplementations,butIthinkthisistheeasiestsofar.Thistechniqueusesa
Hereitis:
varso=newSWFObject("http://www.tricedesigns.com/portfolio/colorfolders/TreeColors.swf","TreeColors","425","260","8","#FFFFFF"); so.write("treecolors");
Now,here'showitworks.ItusesacustomitemrendererthatextendstheTreeItemRendererclass.WithinthecommitPropertiesmethod,aColorMatrixFilterisappliedtotheexistingfoldericon(the"icon"property).It'sthatsimple...Thereisnocustomdrawingorimagesubstitutionnecessary.
overrideprotectedfunctioncommitProperties():void
{
super.commitProperties();
if(icon)
{
varmatrix:Array=newArray();
switch(TreeListData(listData).depth)
{
case1:
matrix=matrix.concat([1,0,0,0,0]);//red
matrix=matrix.concat([0,.25,0,0,0]);//green
matrix=matrix.concat([0,0,.25,0,0]);//blue
matrix=matrix.concat([0,0,0,1,0]); //alpha
icon.filters=[newColorMatrixFilter(matrix)]
break;
case2:
matrix=matrix.concat([.25,0,0,0,0]);//red
matrix=matrix.concat([0,1,0,0,0]);//green
matrix=matrix.concat([0,0,.25,0,0]);//blue
matrix=matrix.concat([0,0,0,1,0]); //alpha
icon.filters=[newColorMatrixFilter(matrix)]
break;
case3:
matrix=matrix.concat([.25,0,0,0,0]);//red
matrix=matrix.concat([0,.25,0,0,0]);//green
matrix=matrix.concat([0,0,1,0,0]);//blue
matrix=matrix.concat([0,0,0,1,0]); //alpha
icon.filters=[newColorMatrixFilter(matrix)]
break;
default:
icon.filters=[];
break;
}
}
}
Thiswillalsoworkontopofcustomfoldericons,asyoucanseehere:
varso=newSWFObject("http://www.tricedesigns.com/portfolio/colorfolders/CustomFolderTreeColors.swf","CustomFolderTreeColors","425","260","8","#FFFFFF"); so.write("CustomFolderTreeColors");
Youcanviewthefullsourcecodehere:
Youcandownloadtheapplicationsourcecodehere:
Note:Thereare2separatefilesinthere"TreeColors.mxml"and"CustomFolderTreeColors".Theonlydifferencebetweenthesetwoarethespecificationofcustomfoldericons.
相关文章推荐
- 使用JavaScript进行基本图形操作与处理
- 使用自定义验证组件库扩展 Windows 窗体
- 幻世(OurDream)2D图形引擎使用教程3——基本图形的绘制
- php扩展xdebug基本使用
- 使用Node.js为其他程序编写扩展的基本方法
- 扩展方法的几个实例,扩展基本类型、接口、通过反射让扩展方法使用私有成员等
- Android 高级UI设计笔记01:使用ExpandableListView组件(ListView的扩展)
- iOS开发UI篇—Quartz2D使用(绘制基本图形)
- iOS开发UI之Quartz2D使用(绘制基本图形)
- OpenCV - 基本图形函数的使用
- Quartz2D使用(绘制基本图形)
- MEF(Managed Extensibility Framework)使用全部扩展组件
- 使用Canvas绘制图形的基本教程
- Swing之基本组件的使用(二)
- iOS开发UI篇—Quartz2D使用(绘制基本图形)
- CoreImage/滤镜的基本使用
- hgeGUI组件扩展基本步骤
- ReactiveCocoa基本组件:理解和使用RACCommand
- php扩展xdebug基本使用
- Swing基本组件使用3(JMenuBar,JMenu,JMenuItem)