注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

有你做翅膀,孤单都是坚强

生命中总要经历曲折,或许是我们不愿意,突然到最后走不通,想重新来过,记录每件小事

 
 
 

日志

 
 
关于我
K24

曾经的生涩,曾经的懵懂,曾经的自恋,都随风去吧。。。

网易考拉推荐
 
 

ravis 增加labelButton node render  

2013-02-28 10:38:00|  分类: @flex |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
打开库项目 libravis, 也适用于 flex 3 的库项目文件

第一步: 增加一个要用到的 UIComponent: 
LabelButton.as  注意包的路径, 代码如下

package org.un.cava.birdeye.ravis.utils
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import mx.core.UIComponent;

public class LabelButton extends UIComponent
{
private var txt:TextField;

public function LabelButton(label:String)
{
super();

txt = new TextField();
txt.text = label;
/*txt.wordWrap = true;*/
txt.width = txt.textWidth;
txt.height = txt.textHeight;
txt.autoSize = TextFieldAutoSize.LEFT;
txt.type = TextFieldType.DYNAMIC;
txt.setTextFormat(new TextFormat("宋体", 12, 0xffffff));
txt.mouseEnabled = false;
txt.x = txt.y = 3;

var bg:Sprite = new Sprite();
bg.graphics.beginFill(0x333333, 1);
bg.graphics.drawRoundRect(0, 0, txt.width + 6, txt.height + 6, 6, 6);
bg.graphics.endFill();
bg.addChild(txt);
addChild(bg);
bg.useHandCursor = bg.buttonMode = true;
}
}
}





第二步: 增加一种 nodeRender 
LabelButtonNodeRenderer.as 注意包的路径

package org.un.cava.birdeye.ravis.components.renderers.nodes
{
import flash.events.Event;

import mx.core.UIComponent;

import org.un.cava.birdeye.ravis.utils.LabelButton;

public class LabelButtonNodeRenderer extends EffectBaseNodeRenderer
{
public function LabelButtonNodeRenderer()
{
//TODO: implement function
super();
}

override protected function initComponent(e:Event):void{

var cc:UIComponent;

cc = new LabelButton(this.data.data.@name);

this.addChild(cc);

/*initLinkButton();*/
}

}
}


第三步: 套用这个 nodeRender

修改如下文件 src\org\un\cava\birdeye\ravis\components\ui\controls\vgraphControls\NodeRendererSelector.mxml

红色字体为修改部分

<?xml version="1.0" encoding="utf-8"?>
<!--
*
* The MIT License
*
* Copyright (c) 2008
* United Nations Office at Geneva
* Center for Advanced Visual Analytics
* http://cava.unog.ch
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
-->
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml"
height="20"
width="95%"
color="#CCCCCC"
prompt="Select node style."
toolTip="Select the type of node labels."
initialize="initData()"
change="changeNodeRenderer()" >

<mx:ArrayCollection id="nrvalues">
<mx:String>Default</mx:String>
<mx:String>Basic</mx:String>
<mx:String>Basic+Effects</mx:String>
<mx:String>SimpleCircle</mx:String>
<mx:String>SimpleCircle+Effects</mx:String>
<mx:String>Icons</mx:String>
<mx:String>Rotated Rectangle</mx:String>
<mx:String>Size by Value</mx:String>
<mx:String>WFB</mx:String>
<mx:String>Label Button</mx:String>
</mx:ArrayCollection>

<mx:Script>
<![CDATA[
import mx.utils.ObjectUtil;

import org.un.cava.birdeye.ravis.components.renderers.nodes.BaseNodeRenderer;
import org.un.cava.birdeye.ravis.components.renderers.nodes.DefaultNodeRenderer;
import org.un.cava.birdeye.ravis.components.renderers.nodes.EffectBaseNodeRenderer;
import org.un.cava.birdeye.ravis.components.renderers.nodes.FilteredSimpleCircleNodeRenderer;
import org.un.cava.birdeye.ravis.components.renderers.nodes.IconNodeRenderer;
import org.un.cava.birdeye.ravis.components.renderers.nodes.LabelButtonNodeRenderer;
import org.un.cava.birdeye.ravis.components.renderers.nodes.RotatedRectNodeRenderer;
import org.un.cava.birdeye.ravis.components.renderers.nodes.SimpleCircleNodeRenderer;
import org.un.cava.birdeye.ravis.components.renderers.nodes.SizeByValueNodeRenderer;
import org.un.cava.birdeye.ravis.components.renderers.nodes.WFBNodeRenderer;
import org.un.cava.birdeye.ravis.graphLayout.visual.VisualGraph;
import org.un.cava.birdeye.ravis.utils.LogUtil;
import org.un.cava.birdeye.ravis.utils.events.VGraphEvent;

private static const _LOG:String = "components.ui.controls.vgraphControls.NodeRendererSelector";
private var _vgraph:VisualGraph;

/**
* Provides access to the registered vgraph object.
* */
public function set vgraph(v:VisualGraph):void {
_vgraph = v;
registerListeners();
}


/**
* @private
* */
public function get vgraph():VisualGraph {
return _vgraph;
}

/**
* When enabling or disabling this component, we also
* perform some specific tasks.
* Attention do completely disable interaction
* there is also the mouseEnabled property.
*
* @inheritDoc
* */
override public function set enabled(e:Boolean):void {
if(e == true) {
this.setStyle("color",0x000000);
this.alpha=1;
} else {
this.setStyle("color",0xCCCCCC);
this.alpha=0.3;
}
/* call superclass (ComboBox) */
super.enabled = e;
}

/**
* Set the selected EdgeLabelRenderer.
* */
public function changeNodeRenderer():void {

var nr:String;

if(_vgraph == null) {
LogUtil.warn(_LOG, "Cannot change NodeRenderer, no valid vgraph!");
return;
}
/* get the currently selected orientation */
nr = this.selectedItem as String;

switch(nr) {
case "Default":
_vgraph.itemRenderer = new ClassFactory(DefaultNodeRenderer);
break;
case "Basic":
_vgraph.itemRenderer = new ClassFactory(BaseNodeRenderer);
break;
case "Basic+Effects":
_vgraph.itemRenderer = new ClassFactory(EffectBaseNodeRenderer);
break;
case "SimpleCircle":
_vgraph.itemRenderer = new ClassFactory(SimpleCircleNodeRenderer);
break;
case "SimpleCircle+Effects":
_vgraph.itemRenderer = new ClassFactory(FilteredSimpleCircleNodeRenderer);
break;
case "Icons":
_vgraph.itemRenderer = new ClassFactory(IconNodeRenderer);
break;
case "Rotated Rectangle":
_vgraph.itemRenderer = new ClassFactory(RotatedRectNodeRenderer);
break;
case "Size by Value":
_vgraph.itemRenderer = new ClassFactory(SizeByValueNodeRenderer);
break;
case "WFB":
_vgraph.itemRenderer = new ClassFactory(WFBNodeRenderer);
break;
case "Label Button":
_vgraph.itemRenderer = new ClassFactory(LabelButtonNodeRenderer);
break;


default:
LogUtil.warn(_LOG, "Illegal NodeRenderer selected:"+nr);
_vgraph.itemRenderer = new ClassFactory(DefaultNodeRenderer);
break;
}
_vgraph.draw();
}

/**
* Refresh the selector with the current EdgeLabelRenderer.
* */
public function refreshSelector(e:VGraphEvent = null):void {

var nlrClassName:String;

if(_vgraph == null) {
LogUtil.warn(_LOG, "Cannot refresh NodeRenderer, no valid vgraph!");
return;
}

if(!_vgraph || !_vgraph.itemRenderer)
return;
nlrClassName = ObjectUtil.getClassInfo(_vgraph.itemRenderer.newInstance()).name;
nlrClassName = nlrClassName.replace(/org.un.cava.birdeye.ravis.components.renderers.nodes::/,"");

switch(nlrClassName) {
case "DefaultNodeRenderer":
this.selectedIndex = 0;
break;
case "BaseNodeRenderer":
this.selectedIndex = 1;
break;
case "EffectsBaseNodeRenderer":
this.selectedIndex = 2;
break;
case "SimpleCircleNodeRenderer":
this.selectedIndex = 3;
break;
case "FilteredSimpleCircleNodeRenderer":
this.selectedIndex = 4;
break;
case "IconNodeRenderer":
this.selectedIndex = 5;
break;
case "RotatedRectNodeRenderer":
this.selectedIndex = 6;
break;
case "SizeByValueNodeRenderer":
this.selectedIndex = 7;
break;
case "WFBNodeRenderer":
this.selectedIndex = 8;
break;

case "LabelButtonNodeRenderer":

this.selectedIndex = 9;

break;

default:
LogUtil.warn(_LOG, "Illegal NodeLabelRenderer received:"+nlrClassName);
break;
}
}

/**
* initialise the selection data
* It is a bit unclear, why this seems to be necessary.
* Also register the listener.
* */
private function initData():void {
this.dataProvider = nrvalues;
}

/**
* Register event listeners
* */
private function registerListeners():void {
_vgraph.addEventListener(VGraphEvent.VGRAPH_CHANGED,refreshSelector);
}
]]>
</mx:Script>
</mx:ComboBox>



效果图如下

ravis 增加labelButton node render - K24 - 有你做翅膀,孤单都是坚强
 

  评论这张
 
阅读(122)| 评论(0)
推荐

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017