Home  >  

Using Graphics Filters to Extend Basic Components

Author photo
AddThis Social Bookmark Button
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:



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:


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.
___________________________________
Andrew Trice
Principal Architect
Cynergy Systems
http://www.cynergysystems.com

Read more from Andrew Trice. Andrew Trice's Atom feed

Comments

Leave a comment


Type the characters you see in the picture above.

Tag Cloud

Poll: Sci-Fi Movies

What's Your Favorite Sci-Fi Movie of All Time?

Vote | View Poll Results | Read Related Blog Entry

Latest Features

  •     Welcome back to the series. This time we are goings to build a really exciting component that will be used to simply display information about the user. Well, you might say why to we need such a component, is there... Continue Reading
  •    Welcome back to our exciting Facebook ActionScript series. In this article we will discuss one of most important (and most exciting) features of the FB platform, it's the publishing of news. We all know when we log in to facebook,... Continue Reading
  • This article provides 10 tips and best practices (in no particular order) for maximizing the benefits that Dojo can bring to your next project. For a more thorough introduction to Dojo, see the article Dojo: The JavaScript Toolkit with... Continue Reading
  •     The notifications are one of the most interesting (and important) parts of the facebook area. In order to completely understand the Flash side of it, we need to understand the basics of the facebook notification, what it is and how... Continue Reading

Development Series

Get an overview of the tools and technologies that work together to allow developers to build Rich Internet Applications (RIAs) quickly and easily.

facebook icon Facebook Application Development

Anatomy of an Enterprise Flex RIA

Recommended for You

@InsideRIA on Twitter

Archives

  • Or, visit our complete archive.  

About This Site

Welcome to the premiere community site for all things RIA sponsored by O'Reilly Media and Adobe Systems Incorporated.