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

📄 displaymanager.java

📁 nesC写的heed算法
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
// $Id: DisplayManager.java,v 1.2.14.7 2003/08/22 16:57:50 idgay Exp $/*									tab:4 * "Copyright (c) 2000-2003 The Regents of the University  of California.   * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. *  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Copyright (c) 2002-2003 Intel Corporation * All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE      * file. If you do not find these files, copies can be found by writing to * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,  * 94704.  Attention:  Intel License Inquiry. *//** * @author Wei Hong *///***********************************************************************//***********************************************************************//this class is listening to the main panel on the mainFrame//and generates events whenever a node or edge are clicked//it can also be used for scrolling or zooming.//This class could have been integrated with the MainFrame class//but I wanted to leave that class to VisualCafe//***********************************************************************//***********************************************************************package net.tinyos.tinydb.topology;import java.awt.event.*;import java.util.*;import javax.swing.*;import net.tinyos.tinydb.topology.event.*;import java.lang.Math;import net.tinyos.tinydb.topology.Dialog.*;import net.tinyos.tinydb.topology.util.*;import java.awt.*;import net.tinyos.tinydb.topology.PacketAnalyzer.*;public class DisplayManager implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, Runnable, NodePainter, EdgePainter, NodeEventListener, EdgeEventListener, NodeClickedEventListener, EdgeClickedEventListener, NodeDialogContributor, EdgeDialogContributor{  //these vectors hold all people that want to paint on the edge, nodes, or over the entire screen	protected Vector nodePainters;//a list of all objects that want to paint nodes	protected Vector edgePainters;//a list of all objects that want to paint edges	protected Vector screenPainters;//a list of all objects that want to paint the screen		          //these vectors contain all people who want to add to the node/edge properties dialog	protected Vector nodeDialogContributors;//a list of all objects that want to add to the node properties Dialog		protected Vector edgeDialogContributors;//a list of all objects that want to add to the edge properties dialog		//these vectors contain all the registered listeners for node and edge click events	protected Vector NodeClickedEventListeners;	protected Vector EdgeClickedEventListeners;	          //these hashtables hold nodeInfo and edgeInfo objects, which hold display information about specific nodes and edges (e.g. color, image)	protected static Hashtable proprietaryNodeInfo;	protected static TwoKeyHashtable proprietaryEdgeInfo;              //these variables describe how the mouse interacts with the network	boolean selectMode;	boolean handMode;	boolean zoomMode;	private boolean stopped = false;	int pressedXCoord=-1;	int pressedYCoord=-1;	protected static long refreshRate;//refresh rate	double zoomFactor;//the factor by which the screen is enlarged	protected static Thread refreshScreenThread;//the thread that runs in the background and refreshes the screen periodically              //------------------------------------------------------------------              //CONSTRUCTOR	DisplayManager(MainFrame pMainFrame)	{		nodePainters = new Vector();		edgePainters = new Vector();		screenPainters = new Vector();		nodeDialogContributors = new Vector();		edgeDialogContributors = new Vector();		NodeClickedEventListeners = new Vector();		EdgeClickedEventListeners = new Vector();			proprietaryNodeInfo = new Hashtable();		proprietaryEdgeInfo = new TwoKeyHashtable();		              //register to recieve all mouse clicks on the display panel		pMainFrame.GetGraphDisplayPanel().addMouseListener(this);		pMainFrame.GetGraphDisplayPanel().addMouseMotionListener(this);              //register (with myself) to paint nodes and edges and display info panels		this.AddNodePainter(this);//paint the nodes		this.AddEdgePainter(this);//paint the edges			//register myself to recieve NodeClickedEvents and EdgeClickedEvents		// this.AddNodeDialogContributor(this);		this.AddEdgeDialogContributor(this);              //register to be notified of nodes and edges being created or deleted              //this is done in MainClass constructor because this object is instantiated before the Object Maintainer//		MainClass.objectMaintainer.AddEdgeEventListener(this);//listen to node events//		MainClass.objectMaintainer.AddNodeEventListener(this);//listen to edge event		selectMode=true;		handMode=false;		zoomMode=false;		refreshRate = 512;//this is the number of milliseconds that it waits before redrawing the screen again        refreshScreenThread = new Thread(this);//this thread runs continually in the background to redraw the screen		try{			refreshScreenThread.setPriority(Thread.MIN_PRIORITY);			refreshScreenThread.start(); //recall that start() calls the run() method defined in this class		}		catch(Exception e){e.printStackTrace();}	}              //CONSTRUCTOR              //------------------------------------------------------------------              //------------------------------------------------------------------			//MOUSE CLICKED	public void mouseClicked(MouseEvent e){}	public void mouseClickedCustom(MouseEvent e)	{		if (javax.swing.SwingUtilities.isLeftMouseButton(e))		{			LocationAnalyzer.NodeInfo nodeLocationInfo= FindNearestNode(e.getX(), e.getY());			if(nodeLocationInfo == null) return;			TriggerNodeClickedEvent(nodeLocationInfo.GetNodeNumber());			DisplayNodePropertyDialog(nodeLocationInfo.GetNodeNumber());		}		else		{			LocationAnalyzer.EdgeInfo edgeLocationInfo = FindNearestEdge(e.getX(), e.getY());			TriggerEdgeClickedEvent(edgeLocationInfo.GetSourceNodeNumber(), edgeLocationInfo.GetDestinationNodeNumber());			DisplayEdgePropertyDialog(edgeLocationInfo.GetSourceNodeNumber(), edgeLocationInfo.GetDestinationNodeNumber());		}	}			//MOUSE CLICKED              //------------------------------------------------------------------              //------------------------------------------------------------------			//MOUSE DRAGGED	public void mouseDragged(MouseEvent e) 	{		// DrawCoords(e);	}//even though using this method instead of my custom method would make the graphics look better	          //I use a custom mouse dragged method because otherwise handling all the events overwhelms the system and all the nodes might time-out		public void mouseDraggedCustom(int startX, int startY, MouseEvent e)    {		if (javax.swing.SwingUtilities.isLeftMouseButton(e))		{			if(selectMode)			{				DragNearestNode(startX, startY, e);			}			else if(handMode)			{				ScrollWithMouseDrag(startX, startY, e);			}			else if(zoomMode)			{				ZoomToMouseDragRectangle(startX, startY, e);			}		}		else if (javax.swing.SwingUtilities.isMiddleMouseButton(e))		{			ScrollWithMouseDrag(startX, startY, e);		}		else if (javax.swing.SwingUtilities.isRightMouseButton(e))		{			ZoomToMouseDragRectangle(startX, startY, e);		}    }			//MOUSE DRAGGED              //------------------------------------------------------------------	public void mouseEntered(MouseEvent e)	{	}			public void mouseExited(MouseEvent e)	{         //leave these lines if you don't want the custom mouse click to fire after the mouse has left and re-entered the screen//		pressedXCoord = -1;//		pressedYCoord = -1;	}				      //this function triggers an event for a mouse press	public void mousePressed(MouseEvent e)	{		pressedXCoord = e.getX();		pressedYCoord = e.getY();	}			public void mouseReleased(MouseEvent e)	{		if((pressedXCoord == -1) || (pressedYCoord == -1))		{			return;		}				int x = e.getX();		int y = e.getY();		if((pressedXCoord == x) && (pressedYCoord == y))		{     //if a mouse click			mouseClickedCustom(e);		}		else		{     //if it was a drag, pass the original coords and the final coords			mouseDraggedCustom(pressedXCoord, pressedYCoord, e);		}		pressedXCoord = -1;//reset		pressedYCoord = -1;	}		    public void mouseMoved(MouseEvent e)    {		// DrawCoords(e);    }		      //this function adds the node dialog contributors	public  void AddNodeDialogContributor(NodeDialogContributor pContributor)	{		nodeDialogContributors.add(pContributor);	}	public  void RemoveNodeDialogContributor(NodeDialogContributor pContributor)	{		nodeDialogContributors.remove(pContributor);	}		      //this function adds the edge dialog contributors	public  void AddEdgeDialogContributor(EdgeDialogContributor pContributor)	{		edgeDialogContributors.add(pContributor);	}	public  void RemoveEdgeDialogContributor(EdgeDialogContributor pContributor)	{		edgeDialogContributors.remove(pContributor);	}		      //this function adds the nodeclicked Listeners	public  void AddNodeClickedEventListener(NodeClickedEventListener pListener)	{		NodeClickedEventListeners.add(pListener);	}	public  void RemoveNodeClickedEventListener(NodeClickedEventListener pListener)	{		NodeClickedEventListeners.remove(pListener);	}              //this function adds the edge clicked Listeners	public  void AddEdgeClickedEventListener(EdgeClickedEventListener pListener)	{		EdgeClickedEventListeners.add(pListener);	}			public  void RemoveEdgeClickedEventListener(EdgeClickedEventListener pListener)	{		EdgeClickedEventListeners.remove(pListener);	}								          //*************************************************************	          //*************************************************************	          //this is where we register the node, edge and screen painters	          //*************************************************************	          //*************************************************************	          	public void AddNodePainter(NodePainter painter)	{		nodePainters.add(painter);//add the painters to the painter list	}	public void RemoveNodePainter(NodePainter painter)	{		nodePainters.remove(painter);//add the painters to the painter list	}	public void AddEdgePainter(EdgePainter painter)	{		edgePainters.add(painter);//add the painters to the painter list	}	public void RemoveEdgePainter(EdgePainter painter)	{		edgePainters.remove(painter);//add the painters to the painter list	}                            	public void AddScreenPainter(ScreenPainter painter)	{		screenPainters.add(painter);//add the painters to the painter list	}	public void RemoveScreenPainter(ScreenPainter painter)	{		screenPainters.remove(painter);//add the painters to the painter list	}		          //------------------------------------------------------------------------	          //*****---TRIGGER NODE CLICKED EVENT---******//		      //this function sends an event to all node clicked listeners	protected void TriggerNodeClickedEvent(Integer pNodeNumber)	{		for(int index = 0; index < NodeClickedEventListeners.size(); index++)		{			NodeClickedEvent e = new NodeClickedEvent(this, pNodeNumber, Calendar.getInstance().getTime());			((NodeClickedEventListener)NodeClickedEventListeners.get(index)).NodeClicked(e);		}	}	          //*****---TRIGGER NODE CLICKED EVENT---******//	          //------------------------------------------------------------------------					          //------------------------------------------------------------------------	          //*****---TRIGGER EDGE CLICKED EVENT---******//		      //this function sends an event to all edge-clicked listeners	protected void TriggerEdgeClickedEvent(Integer pSourceNodeNumber, Integer pDestinationNodeNumber)	{		for(int index = 0; index < EdgeClickedEventListeners.size(); index++)		{			EdgeClickedEvent e = new EdgeClickedEvent(this, pSourceNodeNumber, pDestinationNodeNumber, Calendar.getInstance().getTime());			((EdgeClickedEventListener)EdgeClickedEventListeners.get(index)).EdgeClicked(e);		}	}	          //*****---TRIGGER EDGE CLICKED EVENT---******//	          //------------------------------------------------------------------------	          //------------------------------------------------------------------------	          //*****---DRAG NEAREST NODE---******//	          //when in select mode, the mouse draw will drag the nearest node with it	public void DragNearestNode(int startX, int startY, MouseEvent e)	{		LocationAnalyzer.NodeInfo selectedNode = FindNearestNode(startX, startY);				if(selectedNode!=null)		{   			selectedNode.SetX(MainClass.mainFrame.GetGraphDisplayPanel().ScaleScreenXCoordToNodeCoord(e.getX()).doubleValue());			selectedNode.SetY(MainClass.mainFrame.GetGraphDisplayPanel().ScaleScreenYCoordToNodeCoord(e.getY()).doubleValue());			selectedNode.SetFixed(true);			// selectedNode.RecordLocation();			this.RefreshScreenNow();		}	}	          //*****---DRAG NEAREST NODE---******//			  //	          //*****---SCROLL WITH MOUSE DRAG---******//	          //------------------------------------------------------------------------	          //------------------------------------------------------------------------	          //*****---SCROLL WITH MOUSE DRAG---******//	          //when in hand mode, the mouse draw will scroll the screen	public void ScrollWithMouseDrag(int startX, int startY, MouseEvent e)	{		int endX = e.getX();		int endY = e.getY();		Point currentPosition = MainClass.mainFrame.GetMainScrollPane().getViewport().getViewPosition();		Point newPosition = new Point(currentPosition.x +(endX-startX), currentPosition.y +(endY-startY));		MainClass.mainFrame.GetMainScrollPane().getViewport().setViewPosition(newPosition);	}	          //*****---SCROLL WITH MOUSE DRAG---******//	          //------------------------------------------------------------------------

⌨️ 快捷键说明

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