Created
May 15, 2012 15:05
-
-
Save liekkas/2702475 to your computer and use it in GitHub Desktop.
FLEX:Matrix Component Item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.display.BlendMode; | |
import mx.containers.Box; | |
import mx.containers.Canvas; | |
import mx.controls.Label; | |
import mx.effects.Fade; | |
import mx.effects.Move; | |
import mx.effects.Resize; | |
/*************************************************************\ | |
* 矩阵item | |
* | |
* @author liekkas.zeng | |
* @since 2012-5-10 20:50:53 | |
\*************************************************************/ | |
public class MatrixItem extends Box | |
{ | |
public static var DEFAULT_WIDTH:Number = 75; | |
public static var DEFAULT_HEIGHT:Number = 25; | |
private var _txt:Label; | |
private var itemChanged:Boolean; | |
private var _item:Object; | |
public function set item(value:Object):void | |
{ | |
_item = value; | |
itemChanged = true; | |
invalidateProperties(); | |
} | |
public function get item():Object | |
{ | |
return _item; | |
} | |
public function MatrixItem() | |
{ | |
super(); | |
this.setStyle("borderColor", "#000000"); | |
this.setStyle("borderStyle","outset"); | |
this.setStyle("borderThickness","1"); | |
this.setStyle("verticalAlign","middle"); | |
this.setStyle("horizontalAlign","center"); | |
this.width = DEFAULT_WIDTH; | |
this.height = DEFAULT_HEIGHT; | |
var fadeOut:Fade=new Fade(); | |
fadeOut.duration=200; | |
fadeOut.alphaFrom=1.0; | |
fadeOut.alphaTo=0.0; | |
var fadeIn:Fade=new Fade(); | |
fadeIn.duration=1000; | |
fadeIn.alphaFrom=0.0; | |
fadeIn.alphaTo=1.0; | |
this.setStyle("hideEffect",fadeOut); | |
this.setStyle("showEffect",fadeIn); | |
this.setStyle("addedEffect",fadeIn); | |
var reize:Resize = new Resize(); | |
this.setStyle("resizeEffect",reize); | |
// 删除时有问题,不然效果挺好 | |
// var move:Move = new Move(); | |
// this.setStyle("moveEffect",move); | |
} | |
override protected function createChildren():void | |
{ | |
super.createChildren(); | |
if(!_txt) | |
{ | |
_txt = new Label(); | |
_txt.blendMode = BlendMode.INVERT; | |
_txt.setStyle("textAlign","center"); | |
this.addChild(_txt); | |
} | |
} | |
override protected function commitProperties():void | |
{ | |
super.commitProperties(); | |
if(itemChanged) | |
{ | |
_txt.text = _item['name']; | |
_txt.data = _item; | |
var severity:String = _item['severity']; | |
if(severity) | |
{ | |
this.setStyle("backgroundColor",convertSeverity(severity)); | |
} | |
itemChanged = false; | |
} | |
} | |
protected function convertSeverity(severity:String):Number | |
{ | |
var result:Number; | |
switch(severity) | |
{ | |
case "0": | |
result = 0x00ff00; | |
break; | |
case "1": | |
result = 0xff0000; | |
break; | |
case "2": | |
result = 0xff9900; | |
break; | |
case "3": | |
result = 0xffff00; | |
break; | |
case "4": | |
result = 0x0000ff; | |
break; | |
} | |
return result; | |
} | |
public function update():void | |
{ | |
var severity:String = _item['severity']; | |
if(severity) | |
{ | |
this.setStyle("backgroundColor",convertSeverity(severity)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment