<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()">
<fx:Style> Application{
fontSize:12;
fontFamily:myFont;
}
</fx:Style>
<fx:Script> <![CDATA[
import com.twobowl.component.manualTopo.Nodes;
import com.twobowl.component.manualTopo.line.ILine;
import com.twobowl.component.manualTopo.main.TopoManager;
import com.twobowl.component.manualTopo.node.INode;
import com.twobowl.component.manualTopo.node.Node;
import com.twobowl.component.manualTopo.renderer.lineRenderer.ILineRenderer;
import com.twobowl.component.manualTopo.renderer.lineRenderer.SimpleLineRenderer;
import com.twobowl.component.manualTopo.renderer.nodeRenderer.SimpleNodeRenderer; import flash.utils.flash_proxy;
import flash.utils.getTimer; import mx.charts.renderers.LineRenderer;
import mx.collections.ArrayCollection;
import mx.collections.ArrayList;
import mx.collections.XMLListCollection;
import mx.containers.Panel;
import mx.controls.Alert;
import mx.core.Container;
import mx.core.DragSource;
import mx.core.IFlexDisplayObject;
import mx.core.UIComponent;
import mx.events.DragEvent;
import mx.events.ItemClickEvent;
import mx.managers.DragManager;
import mx.managers.PopUpManager;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.remoting.RemoteObject;
import mx.utils.ObjectUtil;
[Bindable]
private var manager:TopoManager;
[Bindable]
private var array:ArrayList;
[Bindable]
var data:ArrayCollection;
[Bindable]
var str:XML;
var lable:Panel=new Panel;;
var time:Timer;
private var isDragging:Boolean;//推断是否在拖动中的标志
//var isDoubleClick:Boolean = false;//推断是否是双击的标志 private function init():void{
time=new Timer(100);
time.addEventListener(TimerEvent.TIMER,mov);
remote.getXml();
manager=new TopoManager(); manager.drawSpace=drawSpace;
manager.createFromXML(xmldata);
//registerButton();
manager.status=TopoManager.S_NORMAL;
//registerButton();
drawSpace.doubleClickEnabled=true;
Alert.show(drawSpace.getChildren()[0].toString()); for each(var child:Object in drawSpace.getChildren()){
if( child instanceof SimpleLineRenderer){
(child as DisplayObject).addEventListener(MouseEvent.MOUSE_OVER,createLineWindow);
(child as DisplayObject).addEventListener(MouseEvent.MOUSE_OUT,removeLineWindow);
}else{ (child as DisplayObject).addEventListener(MouseEvent.MOUSE_DOWN, innerStartDragging,false,0,true);
(child as DisplayObject).addEventListener(MouseEvent.MOUSE_UP, innerStopDragging,false,0,true);
//(child as DisplayObject).addEventListener(MouseEvent.MOUSE_UP, click_stopDrag,false,0,true);
(child as DisplayObject).addEventListener(MouseEvent.DOUBLE_CLICK, doubleInnerStartDragging);
//(child as DisplayObject).addEventListener(MouseEvent.MOUSE_MOVE,createWindow);
//(child as DisplayObject).addEventListener(MouseEvent.MOUSE_DOWN, mouseDown_startDrag);
(child as DisplayObject).addEventListener(MouseEvent.CLICK, oneInnerStartDragging);
(child as DisplayObject).removeEventListener(MouseEvent.MOUSE_DOWN,addLine);
} }
}
//private function onOverHand(e:Event):void{ //} public var firstWindow:FirstWindow = new FirstWindow();
public var linetWindow:LineRender = new LineRender();
//使用组件对象打开弹出式窗体的最大优点是能够重用组件并保持所以的状态值.
private function createWindow(e:MouseEvent):void
{
firstWindow.addEventListener("pop",getWindowData);
PopUpManager.addPopUp(firstWindow, this, false);
PopUpManager.centerPopUp(firstWindow);
windowInnerStartDragging(e); }
private function getWindowData(e:Event):void
{
createNodeforward(e);
//Alert.show(firstWindow.logs);
//Alert.show(firstWindow.labelPosition.selectedItem.toString());
//Alert.show("color:" + firstWindow.labelColor.selectedColor);
} private function createLineWindow(e:MouseEvent):void
{
//firstWindow.addEventListener("pop",getLineWindowData);
//PopUpManager.addPopUp(linetWindow, this, false);
//PopUpManager.centerPopUp(linetWindow);
//windowLineStartDragging(e);
//Alert.show(e.currentTarget.toString());
//e.currentTarget.lineColor="0xCC336";
lable.x=this.mouseX+5;
lable.y=this.mouseY+5;
//lable.width=100;
//lable.height=40; lable.title="wode"; PopUpManager.addPopUp(lable,this,false);
//time.start(); } //shubiao 窗体移动时间 //Timer监听函数
public function mov(ti:TimerEvent):void{
if(lable.x!=this.mouseX+5||lable.y!=this.mouseY+5)
lable.move(this.mouseX+5,this.mouseY+5); } public function removeLineWindow(e:MouseEvent):void{
//Alert.show("");
PopUpManager.removePopUp(lable); //time.stop();
}
private function getLineWindowData(e:Event):void
{
createNodeforward(e);
//Alert.show(firstWindow.logs);
//Alert.show(firstWindow.labelPosition.selectedItem.toString());
//Alert.show("color:" + firstWindow.labelColor.selectedColor);
} //private var openner:Object;
//private function createWindow(e:MouseEvent):void
//{
// openner = PopUpManager.createPopUp(this, FirstWindow, false);
// PopUpManager.centerPopUp(openner as IFlexDisplayObject);
// openner.setData(new Array("bobo", "huhu", "coco")); // //openner.addEventListener("pop",getWindowData2);
//
//private function getWindowData2(e:Event):void
//{
//Alert.show(openner.logs);
// Alert.show(openner.labelPosition.selectedItem.toString());
// Alert.show("color:" + openner.labelColor.selectedColor);
//}
//private function onMouseDown(event:MouseEvent):void{
//isDragging = false ; //bla bla bla~~
//for each(var child:Object in drawSpace.getChildren()){
// childs.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
//childs.addEventListener(MouseEvent.MOUSE_UP, innerStopDragging);
//}
//}
//private function onMouseMove(event:MouseEvent):void {
//isDragging = true ;
//bla bla bla~~
//innerStartDragging(event);
//} //private function onClick(event:MouseEvent):void {
//if (isDragging == false) {
//bla bla bla~
/// doubleInnerStartDragging(event);
//}
//}
private function getArraylistFromXMLList(data:XMLList):ArrayList
{
array=new ArrayList();
for(var i:int=0;i<data.length();i++)
{
var obj:Object=new Object();
for(var j:int=0;j<data[i].children().length();j++)
{
var dataColoum:String=data[i].children()[j].localName();
obj[dataColoum]=data[i].children()[j].toString(); }
array.addItem(obj);
}
return array;
} private function registerButton():void{
//itemSource1.addEventListener(MouseEvent.MOUSE_DOWN,doItemSourceDrag);
//itemSource2.addEventListener(MouseEvent.MOUSE_DOWN,doItemSourceDrag);
///itemSource3.addEventListener(MouseEvent.MOUSE_DOWN,doItemSourceDrag);
//itemSource4.addEventListener(MouseEvent.MOUSE_DOWN,doItemSourceDrag); //this.addEventListener(MouseEvent.MOUSE_UP,mouseUPHandle,false,0,true);
}
private function unregisterButton():void{
//itemSource1.removeEventListener(MouseEvent.MOUSE_DOWN,doItemSourceDrag);
//itemSource2.removeEventListener(MouseEvent.MOUSE_DOWN,doItemSourceDrag);
//itemSource3.removeEventListener(MouseEvent.MOUSE_DOWN,doItemSourceDrag);
//itemSource4.removeEventListener(MouseEvent.MOUSE_DOWN,doItemSourceDrag); //this.addEventListener(MouseEvent.MOUSE_UP,mouseUPHandle,false,0,true);
}
public function doItemSourceDrag(event:MouseEvent):void{ //var dragItem:Image=ObjectUtil.copy(event.currentTarget) as Image;
//var dragInitiator:Image=Image(event.currentTarget); var ds:DragSource = new DragSource();
//ds.addData(dragInitiator, "itemSource");
//var dragProxy:Image=new Image();
//dragProxy.source=dragInitiator.source;
//dragProxy.width=dragInitiator.width;
//dragProxy.height=dragInitiator.height;
//DragManager.doDrag(dragInitiator, ds, event,dragProxy,0,0,1); } //var mySprite:Sprite = new Sprite(); //mySprite.addEventListener(MouseEvent.CLICK, onClick);
//mySprite.addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClick);
//private function onDoubleClick(event:MouseEvent):void {
// isDoubleClick = true;
//}
///private function onClick(event:MouseEvent):void {
//isDoubleClick = false;
//if (isDragging == false) {
//var timer:Timer = new Timer(260, 1);
//timer.start();//也就是说两次单击间隔在260毫秒之内的就被觉得是双击
//timer.addEventListener(TimerEvent.TIMER, function(evt:Event):void {
//Alert.show(isDoubleClick.toString());
//if(isDoubleClick){ // doubleInnerStartDragging(event);//调用双击响应函数
//}else{
// oneInnerStartDragging(event);//调用单击响应函数
//}
//});
//}//这边的clickOrDouble也能够写成匿名函数,把mouseEvent传进去
//}
//private function clickOrDouble(event:MouseEvent):void {
//if(isDoubleClick){
// doubleInnerStartDragging(event);//调用双击响应函数
//}else{
// oneInnerStartDragging(event);//调用单击响应函数
//}
//}
// Called when the user moves the drag proxy onto the drop target. private function dragEnterHandler(event:DragEvent):void { if (event.dragSource.hasFormat('itemSource')) {
var dropTarget:Canvas=Canvas(event.currentTarget);
// Accept the drop.
DragManager.acceptDragDrop(dropTarget);
} }
//加入node
private function dragDropHandler(event:DragEvent):void { var data:Object = event.dragSource.dataForFormat('itemSource');
var dragItem:SimpleNodeRenderer=new SimpleNodeRenderer();
//var dragItem:Image=new Image();
//dragItem.source=(data as Image).source;
//Canvas(event.currentTarget).addChild(dragItem);
var tData:XML=<node id="undifine" name="unknow" desc="unknow" x="200" y="600" imgUrl=""/>;
tData.@id=getTimer();
tData.@x=Canvas(event.currentTarget).mouseX;
tData.@y=Canvas(event.currentTarget).mouseY;
//tData.@imgUrl=(data as Image).source+"";;
//dragItem.data=data;
manager.createNode(tData,dragItem);
//dragItem.addEventListener(MouseEvent.MOUSE_DOWN, innerStartDragging);
//dragItem.addEventListener(MouseEvent.MOUSE_UP, innerStopDragging); }
// 按下鼠标按键时会调用此函数。 private function innerStartDragging(event:MouseEvent):void
{ var parent:Container=(event.currentTarget as UIComponent).parent as Container;
parent.removeChild(event.currentTarget as UIComponent);
parent.addChild(event.currentTarget as UIComponent); event.currentTarget.startDrag(); }
private function doubleInnerStartDragging(e:MouseEvent):void
{
//var remotes:RemoteObject = new RemoteObject();
//调用在J2EE端remoting-config.xml中配置的暴露出的类的名称 id
//Alert.show(e.currentTarget.data.message);非常重要 remote.destination = "service";
//调用J2EE端类中的方法
remote.getXmls();
//监听调用成功事件
remote.addEventListener(ResultEvent.RESULT,result);
//监听失败事件
remote.addEventListener(FaultEvent.FAULT,fault);
createWindow(e);
//var str:XML=new XML(remote.getXmls());
//trace(str.toString());
//var s:String=remote.getXmls();
//Alert.show(s);
//var xmlList:XMLListCollection = new XMLListCollection(str.children());
//data.source = xmlList.toArray();
//getArraylistFromXMLList(xmllist); //for(var i:int=0;i<data.length;i++){
//// var o:Object = data.getItemAt(i);
// trace(o["id"],o["source"],o["x"]);
//}
//event.currentTarget.startDrag(); }
private function oneInnerStartDragging(e:MouseEvent):void
{
//var remotes:RemoteObject = new RemoteObject();
//调用在J2EE端remoting-config.xml中配置的暴露出的类的名称 id
//Alert.show(e.currentTarget.data.id);
remote.destination = "service";
//调用J2EE端类中的方法
remote.getXmls();
//监听调用成功事件
remote.addEventListener(ResultEvent.RESULT,result);
//监听失败事件
remote.addEventListener(FaultEvent.FAULT,fault); //var str:XML=new XML(remote.getXmls());
//trace(str.toString());
//var s:String=remote.getXmls();
//Alert.show(s);
//var xmlList:XMLListCollection = new XMLListCollection(str.children());
//data.source = xmlList.toArray();
//getArraylistFromXMLList(xmllist); //for(var i:int=0;i<data.length;i++){
//// var o:Object = data.getItemAt(i);
// trace(o["id"],o["source"],o["x"]);
//}
//event.currentTarget.startDrag(); }
private function result(evt:ResultEvent):void{
//Alert.show(str);
str=new XML(evt.result.toString());
// var xmlList:XMLList=new XMLList();
//var xmlListCollection:XMLListCollection=new XMLListCollection();
// var provider:ArrayCollection;
//xmlList=str.elements("node");
//xmlListCollection.source=xmlList; //provider=new ArrayCollection(xmlListCollection.toArray());
//var str:XML=new XML(evt.result.toString());
//var xmlList:XMLListCollection = new XMLListCollection(str.children());
//data.source = xmlList.toArray();
//data=new ArrayCollection(xmlList.toArray());
//getArraylistFromXMLList(xmllist);
//for(var i:int=0;i<data.length;i++){
// var o:Object = data.getItemAt(i);
//trace(o["id"],o["source"],o["x"]);
//Alert.show(o["id"]);
//}
//Alert.show(xmlList.source);
} private function fault(evt:FaultEvent):void{
Alert.show("调用失败。");
} private function windowInnerStartDragging(e:MouseEvent):void
{ //var remotes:RemoteObject = new RemoteObject();
//调用在J2EE端remoting-config.xml中配置的暴露出的类的名称 id
remote.destination = "service";
//调用J2EE端类中的方法
remote.getXmls();
//监听调用成功事件
remote.addEventListener(ResultEvent.RESULT,windowresult);
//监听失败事件
remote.addEventListener(FaultEvent.FAULT,windowfault);
//var str:XML=new XML(remote.getXmls());
//trace(str.toString());
//var s:String=remote.getXmls();
//Alert.show(s);
//var xmlList:XMLListCollection = new XMLListCollection(str.children());
//data.source = xmlList.toArray();
//getArraylistFromXMLList(xmllist); //for(var i:int=0;i<data.length;i++){
//// var o:Object = data.getItemAt(i);
// trace(o["id"],o["source"],o["x"]);
//}
//event.currentTarget.startDrag(); } private function windowresult(evt:ResultEvent):void{
str=new XML(evt.result.toString());
firstWindow.setData(str);
} private function windowfault(evt:FaultEvent):void{
Alert.show("调用失败!");
}
private function windowLineStartDragging(e:MouseEvent):void
{ remote.destination = "service";
//调用J2EE端类中的方法
remote.getXmls();
//监听调用成功事件
remote.addEventListener(ResultEvent.RESULT,lineresult);
//监听失败事件
remote.addEventListener(FaultEvent.FAULT,linefault); } private function lineresult(evt:ResultEvent):void{
var strs :XML=new XML(evt.result.toString()); linetWindow.setData(strs);
} private function linefault(evt:FaultEvent):void{
Alert.show("调用失败! ");
}
// 松开鼠标按键时会调用此函数。 private function innerStopDragging(event:MouseEvent):void
{ manager.updateLineRendererForNodeUI(event.currentTarget as UIComponent);
event.currentTarget.stopDrag();
}
//暂时画线
private function doDrawLine(event:MouseEvent):void
{
var x:int =Canvas(event.currentTarget).mouseX;
var y:int =Canvas(event.currentTarget).mouseY;
var lineToPoint:Point=new Point(x,y);
curLine.freeDraw(lineFromPoint,lineToPoint);
}
private var lineFromPoint:Point;
private var fromNode:INode;
private var curLine:SimpleLineRenderer;
//加入一条线
private function addLine(event:MouseEvent):void{
if(curLine!=null){
curLine.parent.removeChild(curLine);
curLine=null;
} fromNode=manager.getNodeByUI(event.currentTarget as UIComponent);
if(fromNode){
for each(var child:Object in drawSpace.getChildren()){
if(child!=event.currentTarget){
(child as DisplayObject).addEventListener(MouseEvent.MOUSE_UP,completeDrawLine);
} }
curLine=new SimpleLineRenderer();
drawSpace.addChildAt(curLine,0);
var parent:Canvas=((event.currentTarget as UIComponent).parent) as Canvas;
var x:int =parent.mouseX;
var y:int =parent.mouseY;
lineFromPoint=new Point(x,y);
curLine.freeDraw(lineFromPoint,lineFromPoint);
drawSpace.addEventListener(MouseEvent.MOUSE_MOVE,doDrawLine,false,0,true);
drawSpace.addEventListener(MouseEvent.MOUSE_UP,stopDrawLineAndRemove,false,0,true);
} }
//完毕画线,正式加入一条边
private function completeDrawLine(event:MouseEvent):void{
var toNode:INode=manager.getNodeByUI(event.currentTarget as UIComponent); var tData:XML=<line id="" fromNode="" toNode=""/>;
tData.@id=getTimer();
tData.@fromNode=fromNode.data.@id;
tData.@toNode=toNode.data.@id; //dragItem.data=data;
var newLine:ILine=manager.createLine(tData,curLine);
newLine.viewRenderer.draw(newLine);
removeDrawLineListner();
}
//停止画线
private function stopDrawLineAndRemove(event:MouseEvent):void{
curLine.parent.removeChild(curLine);
removeDrawLineListner(); //curLine.clearDraw(); }
//停止画线监听
private function removeDrawLineListner():void{ drawSpace.removeEventListener(MouseEvent.MOUSE_MOVE,doDrawLine);
drawSpace.removeEventListener(MouseEvent.MOUSE_UP,stopDrawLineAndRemove);
for each(var child:Object in drawSpace.getChildren()){
(child as DisplayObject).removeEventListener(MouseEvent.MOUSE_UP,completeDrawLine); }
curLine=null; }
private function forward(event:MouseEvent):void{
var javaeyeUrl:URLRequest = new URLRequest("topic.html");
navigateToURL(javaeyeUrl);
}
private function createNodeforward(event:Event):void{
var javaeyeUrl:URLRequest = new URLRequest("createNode.html");
navigateToURL(javaeyeUrl);
}
private function forwardJianKong(event:MouseEvent):void{
var javaeyeUrl:URLRequest = new URLRequest("workPieChart.html");
navigateToURL(javaeyeUrl);
} ]]>
</fx:Script>
<fx:Declarations> <s:RemoteObject id="remote" destination="service" >
</s:RemoteObject>
<fx:XML id="xmldata" source="D://testNode.xml"/> </fx:Declarations> <s:BorderContainer width="100%" height="100%"> <s:VGroup x="0" y="0" width="953" height="598"> <s:Group width="100%" height="5%" >
<mx:LinkButton x="23" y="10" label="首页" click="forward(event)"/>
<mx:LinkButton x="138" y="10" label="监控图" paddingLeft="0" paddingRight="0" click="forwardJianKong(event)"/>
<mx:LinkButton x="234" y="10" label="页面"/>
</s:Group>
<s:HGroup width="100%" height="90%">
<s:Group width="100%" height="100%">
</s:Group>
<s:Group width="458" height="533">
<mx:Canvas id="drawSpace" x="-467" y="-1" width="100%" height="100%"
borderVisible="false" dragDrop="dragDropHandler(event);"
dragEnter="dragEnterHandler(event);" horizontalScrollPolicy="off"
verticalScrollPolicy="off"> </mx:Canvas>
<mx:AdvancedDataGrid id="adg1" borderStyle="none" designViewDataType="flat" sortExpertMode="true" sortableColumns="true" width="100%" height="100%">
<mx:dataProvider>
<mx:HierarchicalData id="hd" source="{str.node}"/>
</mx:dataProvider>
<mx:groupedColumns> <mx:AdvancedDataGridColumnGroup headerText="节点统计" >
<mx:AdvancedDataGridColumn headerText="序号 " dataField="@id"/>
<mx:AdvancedDataGridColumn headerText="节点名称" dataField="@source" /> <mx:AdvancedDataGridColumn headerText="提供数据" dataField="@x"/>
<mx:AdvancedDataGridColumn headerText="使用数据" dataField="@y"/>
</mx:AdvancedDataGridColumnGroup>
</mx:groupedColumns>
</mx:AdvancedDataGrid>
</s:Group>
</s:HGroup> </s:VGroup>
</s:BorderContainer> </s:Application>

版权声明:本文博主原创文章,博客,未经同意不得转载。

04-25 03:34