使用图形滤镜来扩展基本的组件

本文介绍了一种使用图形滤镜扩展基本TREE组件的方法,通过ColorMatrixFilter改变TREE文件夹的颜色,以此来表示不同层级的数据,从而实现数据的可视化。

使用图形滤镜来扩展基本的组件

| | Comments (0)
<!-- AddThis Bookmark Button BEGIN --> <!-- AddThis Bookmark Button END -->
folders.jpg

在前面的帖子中我曾经讲到过如何使用图形滤镜,这篇博文中我将介绍如何使用这些滤镜来增强基本组件的能力,在本示例中我将展示如何使用滤镜来改变基本的TREE组件的外观
我曾经无数次的碰到过这个问题,那就是如何通过TREE图标来表示其当前的TREE展开状态

我总是在寻找将数据可视化的方法,这里有一个非常简单的方来来扩展一个基本的TREE组件的图标所蕴含的意味,我见过无数种的实现方式,但是我认为下面的是其中最简单的一种方法,它使用了 ColorMatrixFilter 来改变TREE文件夹的颜色,你可以使用这项技巧将一些文件夹分组到一起,采用特定的颜色来表示树的不同层次,根据文件夹或者是数据来改变树图标的现实状态,当然还有更多

下面就是:

var so = new SWFObject("http://www.tricedesigns.com/portfolio/colorfolders/TreeColors.swf", "TreeColors", "425", "260", "8", "#FFFFFF"); so.write("treecolo
下面我就展示它是如何实现的,它使用了一个定制的ITEM RENDER,该render扩展了TREEITEMRENDER类,在commitProperties 方法中,应用了ColorMatrixFilter 过滤当前文件夹的图标,就是这么简单,而没有什么更换图标或者是替代之类的。


override protected functioncommitProperties(): 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图标上也可以工作
var so = new SWFObject("http://www.tricedesigns.com/portfolio/colorfolders/CustomFolderTreeColors.swf", "CustomFolderTreeColors", "425", "260", "8", "#FFFFFF"); so.write("CustomFolderTreeColors"); 源代码链接:
http://www.tricedesigns.com/portfolio/colorfolders/srcview/index.html

http://www.tricedesigns.com/portfolio/colorfolders/srcview/TreeColors.zip.html

Note: There are 2 separate files in there "TreeColors.mxml" and "CustomFolderTreeColors". The only difference between these two are the specification of custom folder icons.



Using Graphics Filters to Extend Basic Components

| | Comments (0)
<!-- AddThis Bookmark Button BEGIN --> AddThis Social Bookmark Button <!-- AddThis Bookmark Button END -->
folders.jpg
I've discussed graphics filters previously, and here's a trick to use them to extend the capabilities of basic Flex controls. In this example, graphics filters will be used to alter the appearance of a basic tree control. I've run into this scenario numerous times... How can you change the appearance of tree folder icons to imply meaning to the branches of the tree?

I'm always looking for ways to visualize data, and this is a very easy way to extend a basic tree control to add meaning to it. I've seen different implementations, but I think this is the easiest so far. This technique uses a ColorMatrixFilter to change the colors of the tree folders. You could use this technique to visually group specific folders together, show specific tree levels in specific colors, change color depending upon folder contents or data, etc... There are a lot of applications for this.

Here it is:

var so = new SWFObject("http://www.tricedesigns.com/portfolio/colorfolders/TreeColors.swf", "TreeColors", "425", "260", "8", "#FFFFFF"); so.write("treecolors");

Now, here's how it works. It uses a custom item renderer that extends the TreeItemRenderer class. Within the commitProperties method, a ColorMatrixFilter is applied to the existing folder icon (the "icon" property). It's that simple... There is no custom drawing or image substitution necessary.

override protected function commitProperties():void
{
super.commitProperties();

if ( icon )
{
var matrix:Array = new Array();

switch (TreeListData( listData ).depth )
{
case 1:
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 = [ new ColorMatrixFilter( matrix) ]
break;
case 2:
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 = [ new ColorMatrixFilter( matrix) ]
break;
case 3:
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 = [ new ColorMatrixFilter( matrix) ]
break;
default:
icon.filters = [];
break;
}
}
}

This will also work on top of custom folder icons, as you can see here:

var so = new SWFObject("http://www.tricedesigns.com/portfolio/colorfolders/CustomFolderTreeColors.swf", "CustomFolderTreeColors", "425", "260", "8", "#FFFFFF"); so.write("CustomFolderTreeColors");
You can view the full source code here:
http://www.tricedesigns.com/portfolio/colorfolders/srcview/index.html

You can download the application source code here:
http://www.tricedesigns.com/portfolio/colorfolders/srcview/TreeColors.zip.html

Note: There are 2 separate files in there "TreeColors.mxml" and "CustomFolderTreeColors". The only difference between these two are the specification of custom folder icons.
【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值