⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 displaymanager.java

📁 nesC写的heed算法
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	          //------------------------------------------------------------------------	          //*****---ZOOM TO MOUSE DRAG RECTANGLE---******//	          //when in zoom mode, the mouse drag will zoom to the selected rectangle	public void ZoomToMouseDragRectangle(int startX, int startY, MouseEvent e)	{		int x,y, width, height;		double scale;		Dimension graphPanelSize = MainClass.mainFrame.GetGraphDisplayPanel().getSize();		Dimension scrollPaneSize = MainClass.mainFrame.GetMainScrollPane().getSize();		int endX = e.getX();		int endY = e.getY();		if(startX < endX)//use the edge of the rectangle that is longer in proportion that the proportion of the window size		{			x = startX;			width = endX-startX;		}		else		{			x = endX;			width = startX - endX;		}		if(startY < endY)		{			y = startY;			height = endY-startY;		}		else		{			y = endY;			height = startY - endY;		}		if( (height==0) || (width==0)) return;		if(width/height > graphPanelSize.getWidth()/graphPanelSize.getHeight())//zoom so that the longer of the width/height of the new rectangle is in view (Since the rect will not be the same proportion as the window)		{			scale = scrollPaneSize.getWidth()/width;		}		else		{			scale = scrollPaneSize.getHeight()/height;		}		scale = scale*MainClass.displayManager.GetScaleFactor();		this.MultiplyGraphDisplayPanelSize(scale);		MainClass.mainFrame.GetMainScrollPane().getViewport().setViewPosition(new Point(x,y));	}                                            	          //*****---ZOOM TO MOUSE DRAG RECTANGLE---******//	          //*****---FIND NEAREST NODE---******//	public LocationAnalyzer.NodeInfo FindNearestNode(int x, int y)	{		LocationAnalyzer.NodeInfo selectedNode = null;		LocationAnalyzer.NodeInfo tempNode = null;		double dist = Double.MAX_VALUE;		double bestdist = Double.MAX_VALUE;		double xDist, yDist;		GraphDisplayPanel display = MainClass.mainFrame.GetGraphDisplayPanel();		for(Enumeration nodes = MainClass.locationAnalyzer.GetNodeInfo(); nodes.hasMoreElements();) 		{			tempNode = (LocationAnalyzer.NodeInfo)nodes.nextElement();//			synchronized(tempNode)//			{				xDist = Math.pow(display.ScaleNodeXCoordToScreenCoord(tempNode.GetX()) - x,2.0);				yDist = Math.pow(display.ScaleNodeYCoordToScreenCoord(tempNode.GetY()) - y,2.0);				dist = Math.sqrt(xDist + yDist);//			}			if (dist < bestdist) {				selectedNode = tempNode;				bestdist = dist;			}		}    	return selectedNode;	}	          //*****---FIND NEAREST NODE---******//	          //*****---FIND NEAREST EDGE---******//	public LocationAnalyzer.EdgeInfo FindNearestEdge(int x, int y)	{		LocationAnalyzer.EdgeInfo selectedEdge = null;		LocationAnalyzer.EdgeInfo tempEdge = null;		double dist = Double.MAX_VALUE;		double bestdist = Double.MAX_VALUE;		GraphDisplayPanel display = MainClass.mainFrame.GetGraphDisplayPanel();				for(Enumeration edges = MainClass.locationAnalyzer.GetEdgeInfo(); edges.hasMoreElements();) 		{			double x1, y1, x2, y2, xCenter, yCenter;			tempEdge = (LocationAnalyzer.EdgeInfo)edges.nextElement();	//		synchronized(tempEdge)	//		{				Integer sourceNodeNumber = tempEdge.GetSourceNodeNumber();				Integer destinationNodeNumber = tempEdge.GetDestinationNodeNumber();				x1=MainClass.locationAnalyzer.GetX(sourceNodeNumber);				y1=MainClass.locationAnalyzer.GetY(sourceNodeNumber);				x2=MainClass.locationAnalyzer.GetX(destinationNodeNumber);				y2=MainClass.locationAnalyzer.GetY(destinationNodeNumber);				xCenter= display.ScaleNodeXCoordToScreenCoord((x1 + x2)/2);				yCenter= display.ScaleNodeYCoordToScreenCoord((y1 + y2)/2);				dist = Math.sqrt(Math.pow(xCenter-x,2) + Math.pow(yCenter-y,2));				if (dist < bestdist) {					selectedEdge = tempEdge;					bestdist = dist;				}		//	}		}		return selectedEdge;	}	          //*****---FIND NEAREST EDGE---******////------------------------------------------------------------------------			  //*****---DISPLAY NODE PROPERTY DIALOG---******////this function displays the dialog showing all node properties	protected void DisplayNodePropertyDialog(Integer pNodeNumber)	{		TabbedDialog nodeDialog = new TabbedDialog("Node Properties");				ActivePanel currentPanel;		NodeDialogContributor listener;		for(Enumeration e = nodeDialogContributors.elements(); e.hasMoreElements();)		{			listener = ((NodeDialogContributor)e.nextElement());			currentPanel = listener.GetProprietaryNodeInfoPanel(pNodeNumber);			if(currentPanel != null)//if you don't have proprietary info, return a null panel			{				if(currentPanel.GetCancelInfoDialog())				{//if you don't want a node dialog to show up, return an Active Component with this set to true					return;				}				nodeDialog.AddActivePanel(currentPanel.GetTabTitle(), currentPanel);			}		}		nodeDialog.setModal(false);		nodeDialog.show();	}			  //*****---DISPLAY NODE PROPERTY DIALOG---******//	          //------------------------------------------------------------------------			          //------------------------------------------------------------------------			  //*****---DISPLAY EDGEPROPERTY DIALOG---******//				//this function displays the dialog showing all edge properties	protected void DisplayEdgePropertyDialog(Integer pSourceNodeNumber, Integer pDestinationNodeNumber)	{		TabbedDialog edgeDialog = new TabbedDialog("Edge Properties");				ActivePanel currentPanel;				for(Enumeration e = edgeDialogContributors.elements(); e.hasMoreElements();)		{			currentPanel = ((EdgeDialogContributor)e.nextElement()).GetProprietaryEdgeInfoPanel(pSourceNodeNumber, pDestinationNodeNumber);			if(currentPanel != null)//if you don't have proprietary info, return a null panel			{				if(currentPanel.GetCancelInfoDialog())				{//if you don't want a node dialog to show up, return an Active Component with this set to true					return;				}				edgeDialog.AddActivePanel(currentPanel.GetTabTitle(),currentPanel);			}		}		edgeDialog.setModal(false);		edgeDialog.show();	}			  //*****---DISPLAY EDGEPROPERTY DIALOG---******//	          //------------------------------------------------------------------------	          //*****---refresh screen NOW---******//	          //this function will redraw the main screen with all nodes and edges in current positions	public static void RefreshScreenNow()	{		MainClass.mainFrame.repaint();	}	          //*****---refresh screen NOW---******//	              //-----------------------------------------------------------------------	          //*****---MultiplyGraphDisplayPanelSize---******//	public static void MultiplyGraphDisplayPanelSize(double factor)	{		Insets inset = MainClass.mainFrame.GetMainScrollPane().getInsets();	 		Dimension d = MainClass.mainFrame.GetMainScrollPane().getSize();			int x = (int)( (d.width-(inset.left+inset.right))*factor);		int y = (int)( (d.height-(inset.top+inset.bottom))*factor);		MainClass.mainFrame.GetGraphDisplayPanel().setSize(new Dimension(x, y));//this line makes the scroll pane put scroll bars if necessary		MainClass.mainFrame.GetGraphDisplayPanel().setPreferredSize(new Dimension(x, y));//this line changes the size, and the node coordinates are automatically rescaled		MainClass.mainFrame.GetMainScrollPane().setViewportView(MainClass.mainFrame.GetGraphDisplayPanel());//this line allows the scroll pane to reevaluate whether scroll bars are needed	}	          //*****---MultiplyGraphDisplayPanelSize---******//              //-----------------------------------------------------------------------	public void PaintUnderScreen(Graphics g)	{		ScreenPainter screenPainter;		for(Enumeration painters = screenPainters.elements(); painters.hasMoreElements();) 		{			screenPainter = (ScreenPainter)painters.nextElement();			screenPainter.PaintScreenBefore(g);		}    }	public void PaintOverScreen(Graphics g)	{		ScreenPainter screenPainter;		for(Enumeration painters = screenPainters.elements(); painters.hasMoreElements();) 		{			screenPainter = (ScreenPainter)painters.nextElement();			screenPainter.PaintScreenAfter(g);		}    }    	public void PaintAllNodes(Integer pNodeNumber, int x1, int y1, int x2, int y2, Graphics g)	{		NodePainter nodePainter;		NodeInfo displayInfo = (NodeInfo)proprietaryNodeInfo.get(pNodeNumber);		if( (displayInfo == null) || (displayInfo.GetDisplayThisNode() == false) ) return;		for(Enumeration painters = nodePainters.elements(); painters.hasMoreElements();) 		{			nodePainter = (NodePainter)painters.nextElement();			nodePainter.PaintNode(pNodeNumber, x1, y1, x2, y2, g);		}	}	public void PaintAllEdges(Integer pSourceNodeNumber, Integer pDestinationNodeNumber, int x1, int y1, int x2, int y2, Graphics g)	{		EdgePainter edgePainter;		NodeInfo sourceDisplayInfo = (NodeInfo)proprietaryNodeInfo.get(pSourceNodeNumber);		NodeInfo destinationDisplayInfo= (NodeInfo)proprietaryNodeInfo.get(pDestinationNodeNumber);		if( (sourceDisplayInfo == null) || (destinationDisplayInfo == null) || (sourceDisplayInfo.GetDisplayThisNode() == false) || (destinationDisplayInfo.GetDisplayThisNode() == false)) return;		for(Enumeration painters = edgePainters.elements(); painters.hasMoreElements();) 		{			edgePainter = (EdgePainter)painters.nextElement();			edgePainter.PaintEdge(pSourceNodeNumber, pDestinationNodeNumber, x1, y1, x2, y2, g);		}	}				    //--------------------------------------------------------------------------		        	//*****---PAINT---******//	public void PaintNode(Integer pNodeNumber, int x1, int y1, int x2, int y2, Graphics g)	{		NodeInfo nodeInfo = (NodeInfo)proprietaryNodeInfo.get(pNodeNumber);		g.setColor(Color.green);		g.setColor(new Color(0, 153, 102));		g.fillOval(x1, y1, x2-x1, y2-y1);		if(ObjectMaintainer.isBase(pNodeNumber)){		    g.drawImage(nodeInfo.GetImage(), x1, y1, x2-x1+100, y2-y1+100, null);		}				if(nodeInfo.GetDisplayNodeNumber() == true && pNodeNumber.intValue() != 121)		{			g.setColor(Color.black);			g.setFont(new Font("Times New Roman", Font.BOLD, 20));			g.drawString(String.valueOf(pNodeNumber),  (x1+x2)/2, y2-(y2-y1)/4 - 20);		}	}	void drawLine(Graphics g,              int x1, int y1,              int x2, int y2,              int lineWidth) {    if (lineWidth == 1)      g.drawLine(x1, y1, x2, y2);    else {      double angle;      double halfWidth = ((double)lineWidth)/2.0;      double deltaX = (double)(x2 - x1);      double deltaY = (double)(y2 - y1);      if (x1 == x2)        angle=Math.PI;      else        angle=Math.atan(deltaY/deltaX)+Math.PI/2;      int xOffset = (int)(halfWidth*Math.cos(angle));      int yOffset = (int)(halfWidth*Math.sin(angle));      int[] xCorners = { x1-xOffset, x2-xOffset+1,                         x2+xOffset+1, x1+xOffset };      int[] yCorners = { y1-yOffset, y2-yOffset,                         y2+yOffset+1, y1+yOffset+1 };      g.fillPolygon(xCorners, yCorners, 4);    }}	public void PaintEdge(Integer pSourceNodeNumber, Integer pDestinationNodeNumber, int x1, int y1, int x2, int y2, Graphics g)	{		g.setColor(Color.red);		drawLine(g, x1, y1, x2, y2, 1);	}		          //*****---run---******//	          //this function runs in the background and repaints the screen	          //at the user determined refresh rate	public void run()	{		while(!stopped)		try		{			sleep(refreshRate);			RefreshScreenNow();				}		catch(Exception e)		{			e.printStackTrace();		}	}			//*****---run---******//		          //------------------------------------------------------------------------			  //*****---GET/SET FUNCTIONS---******//	public  static double GetScaleFactor()	{		Dimension d1 = MainClass.mainFrame.GetMainScrollPane().getSize();			Insets inset = MainClass.mainFrame.GetMainScrollPane().getInsets();	 		Dimension d2 = MainClass.mainFrame.GetGraphDisplayPanel().getSize();	        return (d2.getHeight()+(inset.top+inset.bottom))/d1.getHeight();	}		public  static long GetRefreshRate(){return refreshRate;}	public  static void SetRefreshRate(long pRefreshRate){refreshRate = pRefreshRate;	}	public boolean GetSelectMode(){return selectMode;}	public boolean GetHandMode(){return handMode;}	public boolean GetZoomMode(){return zoomMode;}		public void SetSelectMode(boolean b){selectMode=b;}	public void SetHandMode(boolean b){handMode=b;}	public void SetZoomMode(boolean b){zoomMode=b;}		public NodeInfo GetNodeInfo(Integer nodeNumber){return (NodeInfo)proprietaryNodeInfo.get(nodeNumber);}	public EdgeInfo GetEdgeInfo(Integer sourceNumber, Integer destinationNumber){return (EdgeInfo)proprietaryEdgeInfo.get(sourceNumber,destinationNumber);}	public Enumeration GetNodeInfo(){return proprietaryNodeInfo.elements();}	public Enumeration GetEdgeInfo(){return proprietaryEdgeInfo.elements();}			  //*****---GET/SET FUNCTIONS---******//	          //------------------------------------------------------------------------	          //*****---Thread commands---******//    public void start(){ try{ refreshScreenThread=new Thread(this);refreshScreenThread.start();} catch(Exception e){e.printStackTrace();}}    // public void stop(){ try{ refreshScreenThread.stop();} catch(Exception e){e.printStackTrace();}}	public static void sleep(long p){ try{ refreshScreenThread.sleep(p);} catch(Exception e){e.printStackTrace();}}    public static void setPriority(int p) { try{refreshScreenThread.setPriority(p);} catch(Exception e){e.printStackTrace();}}    			//*****---Thread commands---******//              //------------------------------------------------------------------------	          //*****---Node Created---******//	          //this function defines what you do when a new node is created	          //It is called by net.tinyos.tinydb.topology.PacketAnalyzer.ObjectMainter    public synchronized void NodeCreated(NodeEvent e)    {    	Integer newNodeNumber = e.GetNodeNumber();//you probably want to create a new info pbject to track the data of this new node    	proprietaryNodeInfo.put(newNodeNumber, new NodeInfo(newNodeNumber));    }	          //*****---Node Created---******//              //------------------------------------------------------------------------                  //------------------------------------------------------------------------    	          //*****---Node Deleted---******//	          //this function defines what you do when a new node is deleted	          //It is called by net.tinyos.tinydb.topology.PacketAnalyzer.ObjectMainter    public synchronized void NodeDeleted(NodeEvent e)    {    	Integer deletedNodeNumber = e.GetNodeNumber();//you probably want to delete the info pbject to track the data of this new node    	proprietaryNodeInfo.remove(deletedNodeNumber);    }	          //*****---Node Deleted---******//              //------------------------------------------------------------------------              //------------------------------------------------------------------------	          //*****---Edge Created---******//	          //this function defines what you do when a new edge is created	          //It is called by net.tinyos.tinydb.topology.PacketAnalyzer.ObjectMainter    public synchronized void EdgeCreated(EdgeEvent e)    {    	Integer sourceNodeNumber = e.GetSourceNodeNumber();    	Integer destinationNodeNumber = e.GetDestinationNodeNumber();//you probably want to create a new info pbject to track the data of this new node    	proprietaryEdgeInfo.put(sourceNodeNumber, destinationNodeNumber, new EdgeInfo(sourceNodeNumber, destinationNodeNumber));    }	          //*****---Edge Created---******//              //------------------------------------------------------------------------              //------------------------------------------------------------------------	          //*****---Edge Deleted---******//	          //this function defines what you do when a new edge is deleted	          //It is called by net.tinyos.tinydb.topology.PacketAnalyzer.ObjectMainter    public synchronized void EdgeDeleted(EdgeEvent e)    {    	Integer sourceNodeNumber = e.GetSourceNodeNumber();    	Integer destinationNodeNumber = e.GetDestinationNodeNumber();//you probably want to create a new info pbject to track the data of this new node

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -