`
176170847
  • 浏览: 96724 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

flex拓扑图(完整例子)(转)

    博客分类:
  • Flex
阅读更多
网上流传一个版本的拓扑图,基本是不可以使用的。又因为公司近来要搞一个相关的项目,就把该项目的代码下载下来做了修改可以使用。我现在改的一个简单例子给大家分享一下。

网元的代码(NeMap.as):

view plaincopy to clipboardprint?
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
package{    
    import flash.events.MouseEvent; 
    import flash.ui.ContextMenu; 
    import flash.ui.ContextMenuItem; 
     
    import mx.containers.Canvas; 
    import mx.controls.Image; 
    import mx.controls.Label; 
    import mx.events.MoveEvent;    
    public class NeMap extends mx.containers.Canvas {    
        private var nePic :String = "ASSETS/LSTP.PNG";//网元图    
        private var neState:String = "ASSETS/clearStatus.gif";//网元状态图    
        private var neName:String = "北京HSTPA";    
        private var lineList:Array =new Array();    
        private var lineCount:int = 0;    
        private var x_Coordinates:int = 100;    
        private var y_Coordinates:int = 100;    
            
        private var nePicImage:Image = new Image();    
        private var neStateImage:Image = new Image();    
        private var neNameLable:Label = new Label();    
            
        private var oldIndex:int = 0;    
            
        public function NeMap(x:int,y:int,ne:String){    
            this.width  = 60;    
            this.height = 60;    
            this.x = x;    
            this.y = y;    
            this.neName = ne;    
            init();    
        }    
            
            
        private function init():void{    
                    
            this.addEventListener(flash.events.MouseEvent.MOUSE_DOWN,dragBegin);    
            this.addEventListener(flash.events.MouseEvent.MOUSE_UP,dragEnd);    
            this.addEventListener(flash.events.MouseEvent.MOUSE_MOVE,dragEnd2);    
            this.addEventListener(mx.events.MoveEvent.MOVE,dragEnd1);    
            //this.addEventListener(mx.events.MoveEvent.MOVE,dragEnd1);    
            //neStateImage.addEventListener();    
                
            //this.addEventListener(flash.events.MouseEvent.ROLL_OUT,dragEnd);    
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER,selectedNe);    
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT,noSelectedNe);    
            
            this.addEventListener(flash.events.MouseEvent.CLICK ,doubleNe); 
             
            initNePic();    
            initNeState();          
            initLabel();    
                
            this.addChild(nePicImage);    
            this.addChild(neStateImage);    
            this.addChild(neNameLable);    
            this.verticalScrollPolicy = "off";    
            this.horizontalScrollPolicy = "off";    
                
            this.contextMenu = initPopMenu();               
        }    
            
        private function dragBegin(event:MouseEvent):void{    
            //Alert.show(String(this.parent.numChildren));    
            oldIndex = this.parent.getChildIndex(this);    
            this.parent.setChildIndex(this,this.parent.numChildren-1);    
            this.startDrag(false);          
        }    
            
        private function dragEnd(event:MouseEvent):void{    
            this.parent.setChildIndex(this,oldIndex);    
            this.stopDrag();                
            /*var x:int = getCenterX();  
            var y:int = getCenterY();  
            for(var i:int=0;i<lineList.length;i++){                
                var nelineFlag:NeLineFlag = lineList[i];  
                var line:ExpanLine = nelineFlag.getLine();  
                var isHeaderLine:Boolean =  nelineFlag.getFlag();  
                line.removeLine();  
                if(isHeaderLine){  
                    line.setBeginX(x);  
                    line.setBeginY(y);  
                    line.resetBeginLine(x,y);  
                }else{  
                    line.setEndX(x);  
                    line.setEndY(y);  
                    line.resetEndLine(x,y);  
                }     
            }*/         
        }    
            
        private function dragEnd1(event:MoveEvent):void{    
           refreshLine();    
        }    
            
        private function dragEnd2(event:MouseEvent):void{    
           refreshLine();    
        }    
            
        private function refreshLine():void{    
             var x:int = getCenterX();    
            var y:int = getCenterY();    
            for(var i:int=0;i<lineList.length;i++){                  
                var nelineFlag:NeLineFlag = lineList[i];    
                var line:ExpanLine = nelineFlag.getLine();    
                var isHeaderLine:Boolean =  nelineFlag.getFlag();    
                line.removeLine();    
                if(isHeaderLine){    
                    line.setBeginX(x);    
                    line.setBeginY(y);    
                    line.resetBeginLine(x,y);    
                }else{    
                    line.setEndX(x);    
                    line.setEndY(y);    
                    line.resetEndLine(x,y);    
                }       
            }           
        }    
            
        //增加边框    
        private function selectedNe(event:MouseEvent):void{    
            //this.setStyle("borderColor","#FF0000");    
            //this.setStyle("borderStyle","outset");    
        }    
            
        private function noSelectedNe(event:MouseEvent):void{    
            this.setStyle("borderColor","");    
            this.setStyle("borderStyle","");    
        }    
            
        private function initNePic():void{    
            nePicImage.source = nePic;    
            nePicImage.x = 10;    
            nePicImage.y = 0;    
            nePicImage.width = 50;    
            nePicImage.height = 46;    
        }    
            
        private function initNeState():void{    
            neStateImage.source = neState;    
            neStateImage.x = 0;    
            neStateImage.y = 0;    
            neStateImage.width = 10;    
            neStateImage.height = 10;    
        }    
            
        private function initLabel():void{    
            neNameLable.text = neName;    
            neNameLable.x = 0;    
            neNameLable.y = 30;    
            neNameLable.width = 100;    
            neNameLable.height = 20;    
        }    
            
        private function initPopMenu():ContextMenu{    
            var contextMenu : ContextMenu = new ContextMenu();    
            contextMenu.hideBuiltInItems();    
            var contextMenuItem1 : ContextMenuItem = new ContextMenuItem("网元信息");    
            var contextMenuItem2 : ContextMenuItem = new ContextMenuItem("告警信息");    
            var contextMenuItem3 : ContextMenuItem = new ContextMenuItem("历史告警");    
            contextMenu.customItems.push(contextMenuItem1);    
            contextMenu.customItems.push(contextMenuItem2);    
            contextMenu.customItems.push(contextMenuItem3);    
                
            return contextMenu;    
        }    
            
        public function getCenterX():int{    
            return this.x+10;    
        }    
            
        public function getCenterY():int{    
            return this.y+10;    
        }    
            
        public function setLine(line1:ExpanLine,flag:Boolean):void{    
            var neLineFlag:NeLineFlag = new NeLineFlag(line1,flag);    
            lineList[lineCount] = neLineFlag;    
            lineCount++;    
            //this.line = line1;    
            //this.isHeaderLine = flag;    
        }    
            
        public function setNeState(state:String):void{    
            neStateImage.source = state;    
        } 
         
        public function doubleNe(event:MouseEvent):void{ 
             // 
        }     
    }    


线路代码(ExpanLine.as):

view plaincopy to clipboardprint?
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
package     
{        
    import flash.display.Shape;    
    import mx.core.UIComponent;    
    import flash.display.Sprite;    
    import flash.ui.ContextMenu;    
    import flash.ui.ContextMenuItem;    
    import mx.containers.Canvas;    
    import mx.containers.Panel;    
    import flash.events.MouseEvent;    
    import mx.controls.Alert;    
    import mx.controls.Label;    
    import mx.managers.PopUpManager;    
    import flash.display.DisplayObject;    
    import mx.managers.ToolTipManager;    
    import mx.controls.ToolTip;    
    import flash.events.Event;    
    import flash.events.TextEvent;    
    import flash.events.TimerEvent;    
    import flash.events.SyncEvent;    
    import mx.events.ToolTipEvent;    
    import mx.core.IToolTip;    
    import mx.controls.Button;    
    import flash.net.URLRequest;    
    import flash.net.navigateToURL;    
        
    public class ExpanLine extends mx.controls.Button    
    {    
        private var line_x1:int;//连线一段    
        private var line_y1:int;    
        private var line_x2:int;//连线另一段    
        private var line_y2:int;    
        //private var lines :Sprite =  new Sprite();    
            
        private var lines:Label = new Label();    
            
        //private var myPanel:ShowFlow = null;    
            
        private var parentWindow:NetPicture;    
            
        public var myTip:IToolTip;    
            
            
            
        public function ExpanLine(x1:int,y1:int,x2:int,y2:int,parent:NetPicture){    
            line_x1 = x1;    
            line_y1 = y1;    
            line_x2 = x2;    
            line_y2 = y2;           
            parentWindow = parent;    
                
                
                
            lines.graphics.lineStyle(2,0x0099ff,1);    
            lines.graphics.moveTo(line_x1,line_y1);    
            lines.graphics.lineTo(line_x2,line_y2);     
                
            lines.toolTip = "111111111";    
                
            //lines.addEventListener(flash.events.MouseEvent.ROLL_OVER,createToopTip);    
            //lines.addEventListener(flash.events.MouseEvent.ROLL_OUT,hideToopTip);             
            //lines.addEventListener(mx.events.ToolTipEvent.TOOL_TIP_CREATE,createCustomToolTip);    
            lines.addEventListener(flash.events.MouseEvent.CLICK,doubleLineInterface);    
                
                
                
            var contextMenu : ContextMenu = new ContextMenu();    
            contextMenu.hideBuiltInItems(); // 隐藏一些内建的鼠标右键菜单项    
            var contextMenuItem1 : ContextMenuItem = new ContextMenuItem("链路信息");    
            var contextMenuItem2 : ContextMenuItem = new ContextMenuItem("告警信息");    
            var contextMenuItem3 : ContextMenuItem = new ContextMenuItem("历史告警");    
            contextMenu.customItems.push(contextMenuItem1);    
            contextMenu.customItems.push(contextMenuItem2);    
            contextMenu.customItems.push(contextMenuItem3);    
            lines.contextMenu = contextMenu;                
                
        }    
            
        public function doubleLineInterface(event:MouseEvent):void{    
            Alert.show("aaaaa");    
            //var url:URLRequest=new URLRequest("./ipInterface.do?ipInterfaceId="+interfaceId);    
            //navigateToURL(url,"_blank");    
        }    
            
        public function createToopTip(event:MouseEvent):void{    
                
            //var ptt:PanelToolTip = new PanelToolTip();    
                
                
            //ToolTipManager.toolTipClass = myTip;    
            //myTip.addEventListener(mx.events.ToolTipEvent.TOOL_TIP_CREATE,createCustomToolTip);    
            myTip = ToolTipManager.createToolTip("aaa",10,10) as IToolTip;    
                
            //ToolTipManager.currentToolTip = ptt;    
            //ToolTipManager.enabled = true;    
                
                
            //myTip = ToolTip(ptt);    
            myTip.x = event.localX;    
            myTip.y = event.localY;         
                
            //myTip.setStyle("backgroundColor",0xFFCC00);    
            //myTip.width = 150;    
            //myTip.height = 200;    
        }    
            
        public function hideToopTip(event:MouseEvent):void{    
            ToolTipManager.destroyToolTip(myTip);    
        }    
            
        public function createCustomToolTip(event:ToolTipEvent):void{    
            /*var ptt:PanelToolTip = new PanelToolTip();   
            ptt.nodeId = "10";   
            event.toolTip = ptt;   */ 
        }    
            
        public function resetBeginLine(x1:int,y1:int):void{    
            lines.graphics.clear();    
            lines.graphics.lineStyle(2,0x0099ff,1);    
            lines.graphics.moveTo(x1,y1);    
            lines.graphics.lineTo(line_x2,line_y2);    
        }    
            
        public function resetEndLine(x1:int,y1:int):void{    
            lines.graphics.clear();    
            lines.graphics.lineStyle(2,0x0099ff,1);    
            lines.graphics.moveTo(line_x1,line_y1);    
            lines.graphics.lineTo(x1,y1);    
        }    
            
        public function refreshLine():void{    
            lines.graphics.clear();    
            lines.graphics.lineStyle(2,0xFF0000,1);    
            lines.graphics.moveTo(line_x1,line_y1);    
            lines.graphics.lineTo(line_x2,line_y2);     
        }    
            
        public function removeLine():void{    
            lines.graphics.clear();    
        }    
            
        public function getLine():Sprite{    
            return lines;    
        }       
            
        public function getBeginX():int{    
            return line_x1;    
        }    
            
        public function getBeginY():int{    
            return line_y1;    
        }    
            
        public function getEndX():int{    
            return line_x2;    
        }    
            
        public function getEndY():int{    
            return line_y2;    
        }    
            
        public function setBeginX(x1:int):void{    
            line_x1 = x1;    
        }    
            
        public function setBeginY(y1:int):void{    
            line_y1 = y1;    
        }    
            
        public function setEndX(x2:int):void{    
            line_x2 = x2;    
        }    
            
        public function setEndY(y2:int):void{    
            line_y2 = y2;    
        }           
    }    


线的控制实体类(NeLineFlag.as):

view plaincopy to clipboardprint?
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
package 

    public class NeLineFlag 
    {    
        private var line:ExpanLine= null; 
        private var flag:Boolean = false; 
        public function NeLineFlag(line:ExpanLine,flag:Boolean) 
        { 
            this.line=line; 
            this.flag=flag; 
        } 
         
        public function getLine():ExpanLine{ 
            return line; 
        } 
         
        public function getFlag():Boolean{ 
            return flag; 
        } 
    } 


mxml(NetPicture.mxml):

view plaincopy to clipboardprint?
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
<?xml version="1.0" encoding="utf-8"?>    
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*" width="100%" height="100%">    
    <mx:Style>    
        AlertTitle{     
            font-size: 12pt;     
            font-weight: bold;    
        }    
        ToopTip{    
            backgroundColor:red;    
            backgroundImage:url("ASSETS/MAP.GIF");    
        }       
    </mx:Style>    
    <mx:Script>    
        <!--[CDATA[    
            import mx.events.ToolTipEvent;    
        /*import flash.display.Shape;   
        import mx.core.UIComponent;   
        import flash.display.DisplayObjectContainer;*/    
            
        public var map1:NeMap;    
        public var map2:NeMap;    
        public var map3:NeMap;    
            
        public var line:ExpanLine;    
        public var line2:ExpanLine;    
        public var line3:ExpanLine;    
        import mx.managers.PopUpManager;    
        import mx.controls.Alert;    
            
        //public var myPanel1:ShowFlow;    
            
        public function init():void{    
                
            map1 = new NeMap(400,100,"ATM交换机1");    
            map2 = new NeMap(100,200,"ATM交换机2");    
            map3 = new NeMap(600,400,"ATM交换机3");    
                
            myCanvas.setStyle("backgroundImage",'ASSETS/MAP.GIF');    
                
            line  = new ExpanLine(map1.getCenterX(),map1.getCenterY(),map2.getCenterX(),map2.getCenterY(),this);    
            line2 = new ExpanLine(map2.getCenterX(),map2.getCenterY(),map3.getCenterX(),map3.getCenterY(),this);    
            line3 = new ExpanLine(map1.getCenterX(),map1.getCenterY(),map3.getCenterX(),map3.getCenterY(),this);    
                
                
            mylabel.addChild(line.getLine());    
            mylabel.addChild(line2.getLine());    
            mylabel.addChild(line3.getLine());    
                
                
            map1.toolTip = "192.168.1.220";    
            map2.toolTip = "202.168.1.220";    
            map3.toolTip = "10.104.20.135";    
                
               
            map1.setLine(line,true);    
            map2.setLine(line,false);    
                
            map2.setLine(line2,true);    
            map3.setLine(line2,false);    
                
            map1.setLine(line3,true);    
            map3.setLine(line3,false);                
                
            myCanvas.addChild(map3);    
            myCanvas.addChild(map1);    
            myCanvas.addChild(map2);    
                
                
        }       
            
        public function createCustomToolTip(event:ToolTipEvent):void{    
            //var ptt:PanelToolTip = new PanelToolTip();    
            //event.toolTip = ptt;    
        }    
            
        public function linkAlarm():void{    
            line.refreshLine();    
        }    
            
        public function neDown():void{    
            map1.setNeState("assets/criticlaStatus.gif");    
        }        
            
        ]]-->    
    </mx:Script>    
    <mx:Canvas id="myCanvas" x="0" y="0" width="100%" height="100%" borderColor="#FF0000" borderStyle="solid" verticalScrollPolicy="off">    
        <mx:Panel x="0" y="0" width="100%" height="100%" layout="absolute" id="myPanel" alpha="0.5">    
            <mx:Label x="0" y="0" id="mylabel" initialize="init();" />     
        </mx:Panel>    
    </mx:Canvas>      
</mx:Application> 
分享到:
评论

相关推荐

    flex拓扑图

    "flex拓扑图"可能是指使用Flex技术来创建动态、交互式的网络拓扑图表。Flex是一种基于ActionScript编程语言和Adobe Flash Player运行时的开源框架,主要用于构建富互联网应用程序(Rich Internet Applications,RIAs...

    flex拓扑展示的例子1

    在这个例子1中,我们将深入探讨Flex如何被用来创建动态、交互式的拓扑图表,以及它在IT行业中的实际应用。 Flex,全称Adobe Flex,是一种用于构建富互联网应用程序(RIA)的开源框架,基于ActionScript和Flash ...

    flex 拓扑图dome

    "HopeRunTopo"这个项目很可能包含了一个完整的Flex拓扑图应用实例,你可以通过研究代码来学习如何实现上述功能。在实际开发中,可以根据具体需求进行调整和扩展,以构建适合自己应用场景的拓扑图解决方案。

    flex做的拓扑图

    在这个“flex做的拓扑图”项目中,我们可以了解到如何利用Flex技术来创建交互式的网络拓扑图表。拓扑图在IT行业中广泛应用于网络设备布局、数据流可视化以及系统架构展示等领域,它可以帮助用户直观地理解复杂的系统...

    flex手工画拓扑图例子源码

    本示例“flex手工画拓扑图例子源码”提供了一个使用Flex开发的拓扑图Demo的早期版本,这对于我们理解如何在Flex环境中手动创建和展示拓扑图具有重要的学习价值。 拓扑图在IT系统中广泛应用于网络、数据流、硬件设备...

    flex拓扑展示的例子

    在"flex拓扑展示的例子"中,我们可以探讨以下几个关键知识点: 1. **Flex架构**:Flex框架包括MXML(Markup Language for Flex)和ActionScript。MXML是声明式的,用于定义用户界面布局和组件,而ActionScript则...

    flex 拓扑绘图

    Flex,作为一种基于ActionScript 3.0的开放源代码框架,提供了强大的图形渲染和交互能力,因此成为了绘制拓扑图的优秀工具。 1. **Flex基础** Flex是Adobe公司推出的一种用于构建富互联网应用程序(RIA)的开发...

    Flex拓扑图精品文档

    ### Flex拓扑图精品文档知识点概述 #### 一、Flex拓扑图的两种实现方式 Flex拓扑图作为网络管理中的重要工具,在IT领域扮演着关键角色。它可以帮助技术人员直观地理解和管理网络结构。根据提供的文档,Flex拓扑图...

    如何使用flex 开发拓扑图

    本篇文章将详细讲解如何使用Flex来开发拓扑图。 首先,要开发拓扑图,你需要了解Flex的基本语法和组件。ActionScript是Flex的核心编程语言,它是面向对象的,与JavaScript类似但更强大。要开始开发,确保安装了Flex...

    flex4 系统拓扑图

    这个“flex4 系统拓扑图”可能是一个使用Flex4技术开发的可视化工具,用于展示和管理复杂的系统架构或者网络拓扑结构。通过这个系统,用户可能可以动态地查看、配置和监控网络设备、服务器、服务等组件的状态。 在...

    论文研究-基于Flex的实时网络拓扑图呈现系统的设计与实现 .pdf

    基于Flex的实时网络拓扑图呈现系统的设计与实现,章碧云,,本文介绍了一种基于Flex实现的实时拓扑图可视化呈现系统的设计与实现,通过XML文件实现通信接口的设计,利用MVC架构实现了Flex呈现系�

    flex做拓扑图的组件

    在Flex中,我们可以利用其强大的图形绘制能力来实现拓扑图的组件。拓扑图通常用于网络监控、系统架构可视化或者数据流展示等场景,它能够清晰地展示节点之间的连接关系。 在Flex中创建拓扑图组件,你需要了解以下几...

    Flex4 做的系统拓扑图

    这个"Flex4做的系统拓扑图"项目,结合了Flex4的技术特性与数据库设计,提供了在MyEclipse集成开发环境中可运行的应用。 Flex4的核心是ActionScript 3.0,这是一种面向对象的编程语言,它为开发人员提供了丰富的功能...

    Flex 画拓扑图两个库(Spring 和一个高人写的库)

    在本文中,我们将深入探讨如何使用Flex来绘制拓扑图,并着重介绍两个关键的库:Spring和一位高手编写的自定义库。Flex是一种强大的ActionScript框架,用于构建富互联网应用程序(RIA),它允许开发者创建交互式的、...

    Flex拓扑图组件-iolive

    免费的Flex拓扑组件,可用于拓扑图、关系图、流程图的绘制,不输与Twaver的展现效果及完善的扩展机制和中文API文档 详细效果 iolive.duapp.com

    flex 画架构图 拓扑图

    现在,我们将深入探讨Flex在构建架构图和拓扑图中的应用以及相关知识点。 首先,让我们了解一下Flex。Adobe Flex是基于MXML和ActionScript的开发工具,用于构建跨平台的桌面和移动Web应用程序。MXML是Flex的标记...

    Flex+Java开发拓扑图

    在IT行业中,Flex和Java的组合常常用于构建交互式的、图形化的用户界面,尤其是在需要展示复杂数据关系或网络拓扑图的场景下。本项目"Flex+Java开发拓扑图"是一个利用Flex作为前端展示层,Java作为后端数据处理层来...

    flex CSV解析 拓扑图绘制

    总之,使用Flex进行CSV解析和拓扑图绘制涉及到了数据读取、解析、处理和图形化展示等多个技术环节,对于理解和操作IT系统具有重要的实用价值。通过学习和实践这些技能,开发者能够创建出直观且功能强大的数据可视化...

    flex画拓扑图的第一步

    而“flex画拓扑图的第一步”则涉及到如何使用Flex来绘制拓扑结构图,这种图形通常用于表示网络、系统或流程之间的关系。 拓扑图是一种图形表示法,它以节点(代表设备、服务器、计算机等)和连接这些节点的边(代表...

    flex鱼眼显示图片的例子

    这个"flex鱼眼显示图片的例子"是一个Flex项目,它展示了如何使用Flex技术实现一个鱼眼效果的图片显示功能。鱼眼效果通常指的是将图像扭曲成类似鱼眼镜头所拍摄的弧形视野,这种效果在视觉上往往能带来独特的体验。 ...

Global site tag (gtag.js) - Google Analytics