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

📄 nettel.java

📁 Network Administration Visualized 网络管理可视化源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: Nettel.java 3757 2006-11-24 12:31:59Z mortenv $  * * Copyright 2000-2005 Norwegian University of Science and Technology *  * This file is part of Network Administration Visualized (NAV) *  * NAV 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. *  * NAV 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 NAV; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * * Authors: Kristian Eide <kreide@gmail.com> */import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Polygon;import java.awt.Rectangle;import java.util.Hashtable;import java.util.Vector;class Nettel{	// konfigurasjons-variabler	public static int sizeX = 45;	public static int sizeY = 50;	public static int FONT_SIZE = 9;	public static int POPUP_FONT_SIZE = 13;	Font nf = new Font("Helvetica",Font.PLAIN, FONT_SIZE);	public static Font popupFont = new Font("Arial",Font.PLAIN, POPUP_FONT_SIZE);	private static int canvasTopSpaceY = 25; // plass til overskrift	private static int topSpace = 0;	private static int leftSpace = 3;	private static int rightSpace = 2;	private static int bottomSpace = 10;	public static int vlanBoxSizeX = 24;	public static int vlanBoxSizeY = 12;	public static int lastBoxDivider = 4;	public static int lastBoxSpaceX = 4;	public static int lastBoxSpaceY = 2;	// statiske variabler	Com com;	Graphics graph;	boolean isGraphSet = false;	NettelIcon nettelIcon;	String name;	String fullName;	String kat;	int boksid;	int vlan;	String hashKey;	int clickId;	String clickKat;	boolean groupMember = false;	boolean isClickable = false;	int group = 0;	Vector linkNettel = new Vector();	Vector link = new Vector();	// Hver boks har sin egen PopupMessage	Hashtable keywords = new Hashtable();	PopupMessage desc;	String descText;	boolean popupUpToDate = false;	int descSizeX, descSizeY; // størrelse på	Polygon nettel; 	// selve boxen	Polygon nettelLast; // last på boxen	// state-variabler for objektet	boolean isVisible = true;	boolean iconVisible = true;	boolean click = false;	boolean setMove = false;	boolean setSelected = false;	boolean mouseOver = false;	boolean threadCreated = false;	boolean drawPopup = false;	//boolean drawVlan = true;	boolean drawVlan = false;	int mouseOverX;	int mouseOverY;	int mouseOverLink;	NettelAction nc = null;	int x = 0,y = 25; // koordinater, y settes lik 25 som default så den kommer under knappene på toppen	int lastX = 0, lastY = 0;	boolean locationSet = false;	// stats	double nettelLastPst = -1.0;	public Nettel(Com com, int boksid, String name, String kat, String InNum, int vlan)	{		this.com = com;		setBoksid(boksid);		setName(name);		setKat(kat);		this.vlan = vlan;		if (kat.equals("gw") || kat.equals("gsw") || kat.equals("sw") || kat.equals("edge") ) isClickable = true;	}	private void setBoksid(int i)	{		boksid = i;		keywords.put("boksid".toLowerCase(), String.valueOf(boksid));	}	public int getBoksid() { return boksid; }	public String getBoksidS() { return String.valueOf(boksid); }	public int getClickId() { return clickId; }	public void setClickId(int i) { clickId = i; }	public String getClickKat() { return clickKat != null ? clickKat : getKat(); }	public void setClickKat(String s) { clickKat = s; }	public boolean isCore() {		return boksid < 0;	}	public void setName(String s)	{		fullName = s;		name = s;		int k;		while ((k=name.indexOf(Net.domainSuffix)) >= 0) {			name = name.substring(0, k) + name.substring(k+Net.domainSuffix.length(), name.length());		}		keywords.put("sysname".toLowerCase(), name);	}	public String getName() { return name; }	public String getFullName() { return fullName; }	public String getShowName() { return name; }	public void setKat(String s)	{				if (kat == null || !kat.equals(s)) {			kat = s;			com.d("Nettel.setKat(): Creating new nettelIcon for nettel: " + getName() + " Kat: " + kat, 5);			nettelIcon = new NettelIcon(com, kat, this);			nettelIcon.setXY(x, y);		}	}	public String getKat() { return kat; }	public int getVlan() { return vlan; }	public void setVlan(int i) { vlan = i; }	public Font getFont()	{ return nf; }	public boolean getGroupMember() { return groupMember; }	public void setGroupMember(boolean InGroupMember) { groupMember = InGroupMember; }	public int getGroup() { return group; }	public void setGroup(int InGroup) { group = InGroup; }	public void setNettelLast(double InNettelLast)	{		nettelLastPst = InNettelLast;		keywords.put("boksLast".toLowerCase(), String.valueOf(nettelLastPst)+"%");	}	public void setIsClickable(boolean InIsClickable) { isClickable = InIsClickable; }	public boolean getIsClickable() { return isClickable; }	public int compareTo(Object o)	{		Nettel n = (Nettel)o;		if (vlan < n.getVlan()) return -1;		if (vlan > n.getVlan()) return 1;		return 0;	}	public void drawSelf(Graphics g, int pass)	{		if (!isVisible) return;		if (!isGraphSet)		{			graph = g;			isGraphSet = true;		}		if (pass == 1)		{			// tegn alle linjer			for (int i = 0; i < link.size(); i++)			{				Link l = (Link)link.elementAt(i);				l.drawSelf(g);			}		} else		if (pass == 2)		{			// Tegn selve iconet for nettel-boksen			if (iconVisible) {				nettelIcon.drawSelf(g, com.getNet() );			}		} else		if (pass == 3 && iconVisible)		{			// Navn-tegning er felles for alle enheter			int spaceX = 2;			int spaceY = 4;			// ikke skriv navn for FDDI-ringen			if (name.equalsIgnoreCase("fddi")) return;			g.setFont(nf);			FontMetrics fontMetrics = g.getFontMetrics(nf);			String text = getShowName();			int fontWidth = fontMetrics.stringWidth(text);			Polygon p = new Polygon();				p.addPoint(x+nettelIcon.getSizeX()/2-fontWidth/2-spaceX, y+nettelIcon.getSizeY() );				p.addPoint(x+nettelIcon.getSizeX()/2+fontWidth/2+spaceX, y+nettelIcon.getSizeY() );				p.addPoint(x+nettelIcon.getSizeX()/2+fontWidth/2+spaceX, y+nettelIcon.getSizeY()+fontMetrics.getHeight()/2+spaceY );				p.addPoint(x+nettelIcon.getSizeX()/2-fontWidth/2-spaceX, y+nettelIcon.getSizeY()+fontMetrics.getHeight()/2+spaceY );			g.setColor(new Color(255, 255, 225) );			g.fillPolygon(p);			if (nettelLastPst > 0) {				// Nettel-bokser skal alltid farges relativt				LastColor.setTmpSkala(LastColor.RELATIV_SKALA);				g.setColor(LastColor.getColor(nettelLastPst) );				LastColor.unsetTmpSkala();				g.drawPolygon(p);				p.translate(-1, 0);				g.drawPolygon(p);				p.translate(1, -1);				g.drawPolygon(p);			} else {				g.setColor(Color.black);				g.drawPolygon(p);			}			g.setColor(Color.black);			g.drawString(text, x+nettelIcon.getSizeX()/2-fontWidth/2, y+nettelIcon.getSizeY()+fontMetrics.getHeight()-fontMetrics.getHeight()/2+spaceY/2 );		} else if (pass == 4) {			// kalkuler og tegn alle vlan til andre boxer			for (int i = 0; i < linkNettel.size(); i++) {				// Hvis ikke linken er synlig er det ingenting å gjøre				if (!((Link)link.elementAt(i)).isVisible()) continue;				Nettel n = (Nettel)linkNettel.elementAt(i);				int fromX = x + sizeX/2;				int fromY = y + sizeY/2;				int toX = n.getX() + n.getSizeX()/2;				int toY = n.getY() + n.getSizeY()/2;				int tx = (toX - fromX)/2 +fromX -vlanBoxSizeX/2;				int ty = (toY - fromY)/2 +fromY -vlanBoxSizeY/2;				// temp hack				{					boolean b = false;					if (fromX+fromY < toX+toY)					{						b = true;					} else					if (fromX+fromY == toX+toY)					{						if (fromX < toX)						{							b = true;						}					}					if (b)					{						tx = (fromX - toX)/2 +toX -vlanBoxSizeX/2;						ty = (fromY - toY)/2 +toY -vlanBoxSizeY/2;					}					if (drawVlan) {						g.setColor(new Color(255, 255, 225) );						g.fillRect(tx, ty, vlanBoxSizeX, vlanBoxSizeY);						g.setColor(Color.black);						g.drawRect(tx, ty, vlanBoxSizeX, vlanBoxSizeY);						g.setColor(Color.black);						int vlanNr;						if (vlan != 0) {							vlanNr = vlan;						} else {							vlanNr = n.getVlan();						}						g.drawString("" + vlanNr, tx+1, ty-1 +vlanBoxSizeY);					} else if (((Link)link.elementAt(i)).getIsTrunk() && vlan != 0 ) {						String text = "Trunk";						FontMetrics fontMetrics = g.getFontMetrics(nf);						int fontWidth = fontMetrics.stringWidth(text);						tx = (toX - fromX)/2 +fromX -(fontWidth+2)/2;						Rectangle vlanRect = new Rectangle(tx, ty, fontWidth+2, vlanBoxSizeY);						((Link)link.elementAt(i)).setVlanRect(vlanRect);						g.setColor(new Color(255, 255, 225) );						g.fillRect(tx, ty, fontWidth+2, vlanBoxSizeY);						g.setColor(Color.black);						g.drawRect(tx, ty, fontWidth+2, vlanBoxSizeY);						g.setColor(Color.black);						g.drawString(text, tx+1, ty-1 +vlanBoxSizeY);					}				}			}		}		if (pass == 5)		{			// tegn bokser som bare dukker opp ved å holde musen over noe i en viss tid			if (desc != null) desc.drawSelf(g);			for (int i = 0; i < link.size(); i++) {				Link l = (Link)link.elementAt(i);				l.drawPopup(g);			}		}	}	public void setHashKey(String s) { hashKey = s; }	public String getHashKey() { return hashKey; }

⌨️ 快捷键说明

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