📄 manageobject.java
字号:
/* ---------------------------------------------------------------------- The SINUS Firewall -- a TCP/IP packet filter for Linux Written within the SINUS project at the University of Zurich, SWITCH, Telekurs Payserv AG, ETH Zurich. originally based on the sf Firewall Software (C) 1996 by Robert Muchsel and Roland Schmid. This program 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. This program 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 this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. SINUS Firewall resources: SINUS Homepage: http://www.ifi.unizh.ch/ikm/SINUS/ Firewall Homepage: http://www.ifi.unizh.ch/ikm/SINUS/firewall.html Frequently asked questions: http://www.ifi.unizh.ch/ikm/SINUS/sf_faq.html Mailing list for comments, questions, bug reports: firewall@ifi.unizh.ch ---------------------------------------------------------------------- */
package sfclasses;
import java.awt.*;
import java.io.*;
import java.util.*;
/**
* ManageObject is the superclass of all objects belonging to the topology
* of the firewall configuration, e.g. firewalls, hosts, networks, ...
* For the graphical representation of the objects, ManageObject implements
* DragDropObj, thus they can be displayed using DragDrop.
* @version 1.0 03 Dec 1996
* @author Roland E. Schmid
* @see DragDrop
*/
public class ManageObject implements DragDropObj, Persistent {
// public constructors
/**
* default constructor for ManageObject
*/
public ManageObject() {
// initialize private Drag-and-Drop fields
dX = 10;
dY = 10;
gridX = 5;
gridY = 5;
isHighlighted = false;
}
public void initImage(Component target, MediaTracker mt) {
}
// DragDropObj methods
/**
* @see DragDropObj
*/
public boolean hasFocus(int x, int y) {
return ((Math.abs(x-actX) <= dX) && (Math.abs(y-actY) <= dY));
}
/**
* @see DragDropObj
*/
public void setCoordinates(int x, int y) {
actX = Math.round((float)x/(float)gridX)*gridX;
actY = Math.round((float)y/(float)gridY)*gridY;
if (actX < dX)
actX = dX;
if (actY < dY)
actY = dY;
}
/**
* @see DragDropObj
*/
public int getX() {
return actX;
}
/**
* @see DragDropObj
*/
public int getY() {
return actY;
}
/**
* @see DragDropObj
*/
public Point connectionCoord(Point destination) {
int dx = destination.x - actX;
int dy = destination.y - actY;
if (dx == 0) // avoid division by zero
if (dy > 0) // south
return new Point(actX, actY+dY+2);
else // north
return new Point(actX, actY-dY-2);
double a = Math.atan2((double)dx, (double)dy);
double pi4 = Math.PI/4;
if (a < -3*pi4 || a > 3*pi4) // north
return new Point(actX, actY-dY-2);
if (a < -pi4) // west
return new Point(actX-dX-2, actY);
if (a > pi4) // east
return new Point(actX+dX+2, actY);
// else south
return new Point(actX, actY+dY+2);
}
/**
* This method should be overridden by subclasses
* @see DragDropObj
*/
public void draw(Graphics g, int x_offset, int y_offset) {
Color savecolor = g.getColor();
if (isHighlighted)
g.setColor(Color.blue);
g.fillRect(actX-x_offset-dX, actY-y_offset-dY, 2*dX+1, 2*dY+1);
if (isHighlighted)
g.setColor(savecolor);
}
/**
* @see DragDropObj
*/
public void erase(Graphics g, int x_offset, int y_offset) {
// XOR paint mode is set by calling method in DragDrop class
draw(g, x_offset, y_offset);
}
/**
* @see DragDropObj
*/
public void highlight(Graphics g, int x_offset, int y_offset, boolean highlight) {
erase(g, x_offset, y_offset);
isHighlighted = highlight;
draw(g, x_offset, y_offset);
}
/**
* @see DragDropObj
*/
public boolean isHighlight() {
return isHighlighted;
}
/**
* @see DragDropObj
*/
public boolean canConnectTo(DragDropObj dd) {
return true;
}
/**
* @see DragDropObj
*/
public void connectError(Frame parent) {
}
/**
* @see DragDropObj
*/
public void execute(DragDrop dd) {
}
/**
* @see DragDropObj
*/
public boolean confirmDelete() {
return true;
}
/**
* @see DragDropObj
*/
public void userAction(Frame parent, Graphics g, int x_offset, int y_offset) {
}
/**
*@see DragDropObj
*/
public String getObjectID() {
if (level == -1)
return objectID;
else
return objectID+", Level "+level;
}
/**
* create unique identification string, e.g. for hyperlinks
*/
public String identString() {
return Integer.toString(actX)+Integer.toString(actY);
}
/**
* Check configuration of ManageObject
* @return true if O.K. false if malconfigured
*/
public boolean checkConfig() {
return true;
}
// overriding Object methods
public String toString() {
return "ManageObject: "+objectInfo();
}
// persistence methods
public void write(PersistentOutputStream ps) {
ps.writeInt("actX=", actX);
ps.writeInt("actY=", actY);
ps.writeString("objectID=", objectID);
ps.writeInt("level=",level);
}
public void read(PersistentInputStream ps) throws java.io.IOException {
actX = ps.readInt("actX=");
actY = ps.readInt("actY=");
objectID = ps.readString("objectID=");
level = ps.readInt("level=");
}
// protected methods
protected String objectInfo() {
return new String("ID="+objectID+" x="+actX+" y="+actY+" highlight="+isHighlighted+" level="+level);
}
// private data
// data used for DragDropObj methods
protected int level = -1; // autoconfiguration level
protected transient boolean visited = false; // used in autoconfiguration graph taversal
protected transient int uniqueID = 0; // used in topology export
protected String objectID = new String(); // descriptor string
protected ManageDomain mgDomain; // domain the object belongs to
protected int actX, actY; // current object coordinates
protected transient int dX, dY; // distance from edge to center
protected transient int gridX, gridY; // grid
protected transient boolean isHighlighted; // object is currently highlighted
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -