📄 net.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.awt.event.*;import com.sun.java.swing.*;/** * This class describes a network element, this can contain many real nets * and hosts * @version 1.0 03 Dec 1996 * @author Roland E. Schmid */public class Net extends IconObject { /** * Initialize object and icon */ public Net() { //implicit call to super() if (checkConfig(null)) setOKIcon(null); else setNOKIcon(null); } // overriding Object methods public String toString() { return "Net: "+objectInfo(); } public boolean checkConfig(Frame parent) { if (!super.checkConfig()) return false; if (NetAddresses.empty()) { if (parent != null) UserDialog.ErrorBox("No addresses assigned to network!"); return false; } if (NetAddresses.hasBroadcastAddr() || NetAddresses.hasHostAddr()) { if (parent != null) UserDialog.ErrorBox("Host or broadcast address assigned to network!"); return false; } return true; } public void setOKIcon(DragDrop dd) { if (dd != null) erase(dd.getCanvasGraphics(), dd.offset_x, dd.offset_y); if (bNetOKSource == null) bNetOKSource = new networkOKImageSource(); icon = Toolkit.getDefaultToolkit().createImage(bNetOKSource); if (dd != null) draw(dd.getCanvasGraphics(), dd.offset_x, dd.offset_y); } public void setNOKIcon(DragDrop dd) { if (dd != null) erase(dd.getCanvasGraphics(), dd.offset_x, dd.offset_y); if (bNetSource == null) bNetSource = new networkImageSource(); icon = Toolkit.getDefaultToolkit().createImage(bNetSource); if (dd != null) draw(dd.getCanvasGraphics(), dd.offset_x, dd.offset_y); } /** * Show the network properties dialog. The drag and drop panel calls this * method when the user double clicks on the network icon in edit mode. * @param parent Parent frame (drag and drop panel) */ public void execute(DragDrop dd) { NetProperties np; Frame parent = Utils.getParentFrame(dd); if (objectID.length() > 0) np = new NetProperties(parent, "Network "+objectID, this); else np = new NetProperties(parent, "Network properties", this); np.setVisible(true); if (checkConfig(parent)) setOKIcon(dd); else setNOKIcon(dd); } // persistence methods /** * Write object data to a persistent output stream * @param ps Stream * @see PersistentOutputStream */ public void write(PersistentOutputStream ps) { super.write(ps); ps.writePersistent("NetAddresses=", NetAddresses); } /** * Read object data from a persistent input stream * @param ps Stream * @see PersistentInputStream */ public void read(PersistentInputStream ps) throws java.io.IOException { super.read(ps); NetAddresses = (AddrList)ps.readPersistent("NetAddresses="); } private static java.awt.image.ImageProducer bNetSource = null; private static java.awt.image.ImageProducer bNetOKSource = null; // network properties protected AddrList NetAddresses = new AddrList();}// Network properties dialog boxclass NetProperties extends Dialog implements ActionListener, TextListener { public NetProperties(Frame parent, String title, Net n) { super(parent, title, true); net = n; GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(5,5,5,5); setLayout(gbl); // Name panel Utils.add_component(this, new JLabel(new ImageIcon(net.icon)), gbl, gbc, 0, 0, 1, 1, 0, 0); Utils.add_component(this, new Label("Identifier: "), gbl, gbc, 1, 0, 1, 1, 0, 0); IDtext = new TextField(net.objectID); IDtext.addTextListener(this); Utils.add_component(this, IDtext, gbl, gbc, 2, 0, 3, 1, 100, 0); // Address panel Panel ap = net.NetAddresses.editPanel(); Utils.add_component(this, ap, gbl, gbc, 0, 1, 3, 8, 80, 100); // Buttons OKbutton = new Button("OK"); OKbutton.addActionListener(this); gbc.fill = GridBagConstraints.NONE; Utils.add_component(this, OKbutton, gbl, gbc, 0, 9, 5, 1, 0, 0); // Window size Graphics g = parent.getGraphics(); FontMetrics fm = g.getFontMetrics(); setSize(fm.stringWidth("255.255.255.255/255.255.255.255 ") * 2, fm.getHeight() * 20 ); g.dispose(); }class NPAdapter extends WindowAdapter { public void WindowClosing(WindowEvent we) { if (isEnabled()) dispose(); return; }} // class NPAdapter // Process Buttons public void actionPerformed(ActionEvent ae) { Object source = ae.getSource(); if (source==OKbutton) { net.objectID = IDtext.getText().trim(); dispose(); return; } } // actionPerformed // Process Textfields public void textValueChanged(TextEvent te) { Object source = te.getSource(); if (source==IDtext) { net.objectID = IDtext.getText().trim(); setTitle("Network "+net.objectID); return; } } // textValueChanged
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -