nkcompaq.java

来自「NetGUI v0.4.1 」· Java 代码 · 共 182 行

JAVA
182
字号
/* * Copyright (C) 2005, 2006  * Santiago Carot Nemesio * * This file is part of NetGUI. * * NetGUI is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * NetGUI is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with NetGUI; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *   *//************************************************************************ Clase que representa un ordenador dentro de la red***********************************************************************/import edu.umd.cs.piccolo.*;import edu.umd.cs.piccolo.PCanvas;import edu.umd.cs.piccolo.nodes.*;import edu.umd.cs.piccolox.*;import edu.umd.cs.piccolox.nodes.*;import edu.umd.cs.piccolo.event.*;import edu.umd.cs.piccolo.util.*;import edu.umd.cs.piccolox.handles.PBoundsHandle;import java.lang.*;import java.util.*;import java.awt.geom.*;import java.awt.*;import java.awt.geom.Point2D.*;public class NKCompaq extends NKSystem{	private static final String fileImage = System.getProperty("NETLAB_HOME")+"/images/128x128/system.png";	private static final String deleteFileImage = System.getProperty("NETLAB_HOME")+"/images/128x128/systemDel.png";	private static final String fileSelectedImage = System.getProperty("NETLAB_HOME")+"/images/128x128/system_selected.png";	private static final String fileStartedImage = System.getProperty("NETLAB_HOME")+"/images/128x128/systemStarted.png";	private static final String fileSelectedStartedImage = System.getProperty("NETLAB_HOME")+"/images/128x128/systemStartedSelected.png";		//especificamos un rectangulo de delimitaci髇 (Para calcular intersecciones)	private static RectangleNodeDelimiter delimiter;	private static final String eth0 = "eth0";	private final Ethernet eth = new Ethernet (eth0);		private NKConection edge;		public NKCompaq (String name, LayersHandler handler){		super(name, fileImage, fileSelectedImage, deleteFileImage, handler);		//formatEthText(eth.getEthName());		delimiter = new RectangleNodeDelimiter(90.0,-90.0,80.0,-80.0);	}		/*************************************************************	 * A馻de una conexi髇 al nodo	 *************************************************************/	public void addEdge (NKConection edge)	{		this.edge = edge;		handler.showInterfazEth(eth);	}		/*************************************************************	 * Elimina una conexi髇 con el nodo	 *************************************************************/	public void removeEdge (NKConection edge)	{		if ((this.edge!=null)&&(this.edge.equals(edge)))		{			this.edge = null;			handler.notShowInterfazEth(eth);		}	}		/*************************************************************	 * Actualiza todas las conexiones del nodo para poder	 * representarlas en pantalla cuando el nodo es arrastrado	 *************************************************************/	public void updateEdges ()	{		if (edge != null)			edge.updateEdge();	}		/*************************************************************	 * Devuelve todas las conexiones del nodo	 *************************************************************/	public NKConection getEdge ()	{		return edge;	}		public void startNetKit ()	{ 		if (!isStarted())		{			String cmd = vstartCmdGen();			try {				Process proc;				proc = Runtime.getRuntime().exec(cmd, null);				//setStarted(true);				updateStartedImages();				TelnetConnector tc = new TelnetConnector(this, cmd);			} catch (Exception ex)				{System.out.println("Error " + ex);}		}			}		protected void updateStartedImages ()	{		changeSelectedImage (fileSelectedStartedImage);		changeNormalImage (fileStartedImage);	}		protected void updateNormalImages ()	{		changeSelectedImage (fileSelectedImage);		changeNormalImage (fileImage);		eth.setIp(null);	}		/*****************************************************************	 * Genera el comando vstart con los par醡etros necesarios para	 * arrancar netkit	 *****************************************************************/	private String vstartCmdGen()	{		String cmd;		if (edge == null)			cmd = "vstart " + getName();		else cmd = "vstart " + getName() + 						" --" + eth0 + "=" + getNetName();		//incorporar --no-log -f /workdir/nodename.disk [--new (si no existe nodename.disk)]		return processStartCmd(cmd);			}		/*****************************************************************	 * Los ordenadores se conectan a la red 鷑icamente a trav閟 de un	 * hub. El nodo accede a 閘 para obtener el nombre de red.	 *****************************************************************/	private String getNetName()	{		if (edge.getNode1().getName().equalsIgnoreCase(getName()))			return ((NKHub)edge.getNode2()).getNetName();		else return ((NKHub)edge.getNode1()).getNetName();	}		protected void updateEthLocation(NKConection edge)	{		if (edge!=null)		{			Point2D p = NetKitGeom.getGlobalIntersect(delimiter,this, edge);			//localToGlobal(p);			eth.centerFullBoundsOnPoint(p.getX(),p.getY());		}	}	public void updateEthernets (HashMap eth_ip)	{		String ip = (String)eth_ip.get(eth0);		eth.setIp(ip);	}}

⌨️ 快捷键说明

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