[Javanetsim-cvs] javaNetSim/guiUI WANPortProperties.java, NONE, 1.1 MainScreen.java, 1.75, 1.76 Ser
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2007-10-19 19:38:11
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21162/guiUI Modified Files: MainScreen.java SerPortProperties.java Added Files: WANPortProperties.java Log Message: Added WAN NIC properties dialog. --- NEW FILE: WANPortProperties.java --- /* Java Network Simulator (javaNetSim) Copyright (c) 2007, 2006, 2005, Ice Team; All rights reserved. Copyright (c) 2004, jFirewallSim development team; All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Canberra Institute of Technology nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package guiUI; import core.InvalidLinkNameException; import core.InvalidNetworkInterfaceNameException; import core.InvalidNodeNameException; import core.Node; import core.NetworkLayerDevice; import core.WANNetworkInterface; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.GridBagLayout; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JCheckBox; import javax.swing.JOptionPane; import java.awt.Insets; import java.awt.GridBagConstraints; import java.awt.BorderLayout; import javax.swing.JButton; import java.awt.Dimension; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JComboBox; import core.Simulation; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.Color; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.util.Arrays; import java.awt.Component; import javax.swing.SwingConstants; /** * * @author Key * * This class is a dialog that shows Serernet Port Props * */ public class WANPortProperties extends javax.swing.JDialog { private JPanel backpanel; private JLabel lblInterface, cmbInterface; private JLabel lblNodeName, cmbNodeName; private JLabel lblError; private JButton btnOk; private JLabel lblType; private JComboBox cmbType; private JLabel lblRole; private JComboBox cmbRole; private JLabel lblHost; private JTextField txtHost; private JLabel lblPort; private JTextField txtPort; private JLabel lblService; private JTextField txtService; private JLabel lblUP; private JCheckBox chkUP; private MainScreen controller; private Simulation Sim; private SandBox SBox; private String NodeName=""; private String NodeInt=""; private WANNetworkInterface wan; private boolean ErrorFlag = true; public WANPortProperties(JFrame frame, String inNodeName, String inNodeInt, Simulation Sim, SandBox SBox) { super(frame); this.NodeName = inNodeName; this.NodeInt = inNodeInt; try{ wan = (WANNetworkInterface)Sim.getNode(inNodeName).getNIC(inNodeInt); }catch(Exception e){ e.printStackTrace(); } setResizable(false); controller = (MainScreen)frame; this.Sim = Sim; this.SBox = SBox; setTitle("WAN Port Properties"); initGUI(inNodeName, inNodeInt); final JPanel panel = new JPanel(); getContentPane().add(panel, BorderLayout.SOUTH); btnOk = new JButton(); btnOk.setEnabled(true); btnOk.setToolTipText("Set options!"); btnOk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okButton(); } }); btnOk.setName("btnOK"); panel.add(btnOk); btnOk.setText("OK"); final JButton btnCancel = new JButton(); btnCancel.setToolTipText("Cancel changes"); btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancelButton(); } }); btnCancel.setName("btnCancel"); panel.add(btnCancel); btnCancel.setText("Cancel"); this.pack(); this.getRootPane().setDefaultButton(btnOk); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); this.setLocationRelativeTo(null); this.setModal(true); this.setVisible(true); } private void initGUI(String NodeName, String NodeInt) { try { setSize(350, 325); { backpanel = new JPanel(); backpanel.setMinimumSize(new Dimension(200, 10)); this.getContentPane().add(backpanel, BorderLayout.CENTER); GridBagLayout backpanelLayout = new GridBagLayout(); backpanel.setPreferredSize(new java.awt.Dimension(264, 213)); backpanelLayout.columnWeights = new double[] {}; backpanelLayout.columnWidths = new int[] {}; backpanelLayout.rowWeights = new double[] {0.0}; backpanelLayout.rowHeights = new int[] {5,5,5,5}; backpanel.setLayout(backpanelLayout); { lblNodeName = new JLabel(); backpanel.add(lblNodeName, new GridBagConstraints( 0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 21, 0)); lblNodeName.setText("Node Name:"); } { lblInterface = new JLabel(); backpanel.add(lblInterface, new GridBagConstraints( 0, 1, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 27), 0, 0)); lblInterface.setText("Interface:"); } { lblType = new JLabel(); backpanel.add(lblType, new GridBagConstraints( 0, 2, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 16), 0, 0)); lblType.setText("Connection type:"); } { lblRole = new JLabel(); backpanel.add(lblRole, new GridBagConstraints( 0, 3, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 16), 0, 0)); lblRole.setText("Connection role:"); } { lblHost = new JLabel(); backpanel.add(lblHost, new GridBagConstraints( 0, 4, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 16), 0, 0)); lblHost.setText("Host/URL:"); } { lblPort = new JLabel(); backpanel.add(lblPort, new GridBagConstraints( 0, 5, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 16), 0, 0)); lblPort.setText("Port:"); } { lblService = new JLabel(); backpanel.add(lblService, new GridBagConstraints( 0, 6, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 16), 0, 0)); lblService.setText("Service:"); } { lblUP = new JLabel(); backpanel.add(lblUP, new GridBagConstraints( 0, 7, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 16), 0, 0)); lblUP.setText("Administratively UP:"); } { cmbNodeName = new JLabel(); cmbNodeName.setMinimumSize(new Dimension(100, 0)); cmbNodeName.setText(NodeName); final GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = GridBagConstraints.LINE_START; gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 1; backpanel.add(cmbNodeName, gridBagConstraints); } { cmbInterface = new JLabel(); cmbInterface.setText(NodeInt); final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints(); gridBagConstraints_1.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_1.anchor = GridBagConstraints.LINE_START; gridBagConstraints_1.gridy = 1; gridBagConstraints_1.gridx = 1; backpanel.add(cmbInterface, gridBagConstraints_1); } cmbType = new JComboBox(); cmbType.setEnabled(true); final GridBagConstraints gridBagConstraints_3 = new GridBagConstraints(); gridBagConstraints_3.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_3.anchor = GridBagConstraints.LINE_START; gridBagConstraints_3.gridy = 2; gridBagConstraints_3.gridx = 1; backpanel.add(cmbType, gridBagConstraints_3); cmbType.addItem("TCP Socket"); cmbType.addItem("UDP Socket"); cmbType.addItem("RMI"); cmbType.addItem("CORBA"); int sel = wan.getConnType() - 1; if(sel<0) sel = 0; cmbType.setSelectedIndex( sel ); cmbRole = new JComboBox(); /*cmbRole.addFocusListener(new FocusAdapter() { public void actionPerformed(ActionEvent e) { //lblError.setVisible(false); } });*/ cmbRole.setEnabled(true); final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints(); gridBagConstraints_4.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_4.anchor = GridBagConstraints.LINE_START; gridBagConstraints_4.gridy = 3; gridBagConstraints_4.gridx = 1; backpanel.add(cmbRole, gridBagConstraints_4); cmbRole.addItem("Client"); cmbRole.addItem("Server"); if(wan.getServer()){ cmbRole.setSelectedIndex(1); }else{ cmbRole.setSelectedIndex(0); } txtHost = new JTextField(); txtHost.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { lblError.setVisible(false); } }); txtHost.setEnabled(true); final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints(); gridBagConstraints_5.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_5.anchor = GridBagConstraints.LINE_START; gridBagConstraints_5.gridy = 4; gridBagConstraints_5.gridx = 1; backpanel.add(txtHost, gridBagConstraints_5); txtHost.setText(wan.getConnHost()); txtPort = new JTextField(); txtPort.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { lblError.setVisible(false); } }); txtPort.setEnabled(true); final GridBagConstraints gridBagConstraints_6 = new GridBagConstraints(); gridBagConstraints_6.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_6.anchor = GridBagConstraints.LINE_START; gridBagConstraints_6.gridy = 5; gridBagConstraints_6.gridx = 1; backpanel.add(txtPort, gridBagConstraints_6); txtPort.setText(String.valueOf(wan.getConnPort())); txtService = new JTextField(); txtService.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { lblError.setVisible(false); } }); txtService.setEnabled(true); final GridBagConstraints gridBagConstraints_7 = new GridBagConstraints(); gridBagConstraints_7.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_7.anchor = GridBagConstraints.LINE_START; gridBagConstraints_7.gridy = 6; gridBagConstraints_7.gridx = 1; backpanel.add(txtService, gridBagConstraints_7); txtService.setText(wan.getConnService()); chkUP = new JCheckBox(); chkUP.setEnabled(true); final GridBagConstraints gridBagConstraints_8 = new GridBagConstraints(); gridBagConstraints_8.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints_8.anchor = GridBagConstraints.LINE_START; gridBagConstraints_8.gridy = 7; gridBagConstraints_8.gridx = 1; backpanel.add(chkUP, gridBagConstraints_8); chkUP.setSelected(Sim.getNode(NodeName).getNIC(NodeInt).isUP()); lblError = new JLabel(); lblError.setHorizontalTextPosition(SwingConstants.CENTER); lblError.setHorizontalAlignment(SwingConstants.CENTER); lblError.setAlignmentX(Component.CENTER_ALIGNMENT); lblError.setMinimumSize(new Dimension(100, 20)); lblError.setMaximumSize(new Dimension(100, 20)); lblError.setPreferredSize(new Dimension(100, 20)); lblError.setVisible(false); final GridBagConstraints gridBagConstraints_9 = new GridBagConstraints(); gridBagConstraints_9.anchor = GridBagConstraints.WEST; gridBagConstraints_9.insets = new Insets(0, 1, 0, 0); gridBagConstraints_9.fill = GridBagConstraints.BOTH; gridBagConstraints_9.gridwidth = 2; gridBagConstraints_9.gridy = 5; gridBagConstraints_9.gridx = 0; backpanel.add(lblError, gridBagConstraints_9); lblError.setText("Invalid MAC!"); cmbType.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectWANType(); lblError.setVisible(false); } }); selectWANType(); } } catch (Exception e) { e.printStackTrace(); } } private void selectWANType(){ switch(cmbType.getSelectedIndex() + 1){ case WANNetworkInterface.SocketTCP: case WANNetworkInterface.SocketUDP: cmbRole.setEnabled(true); txtHost.setEnabled(true); txtPort.setEnabled(true); txtService.setEnabled(false); txtService.setText(""); break; case WANNetworkInterface.RMI: cmbRole.setEnabled(false); txtHost.setEnabled(true); txtPort.setEnabled(true); txtPort.setText(""); txtService.setEnabled(true); break; case WANNetworkInterface.Corba: cmbRole.setEnabled(false); txtHost.setEnabled(true); txtPort.setEnabled(true); txtPort.setText(""); txtService.setEnabled(true); break; } } /** * This is executed when the user hit's the enter button. * @author Key * */ private void okButton(){ try { switch(cmbType.getSelectedIndex() + 1){ case WANNetworkInterface.SocketTCP: case WANNetworkInterface.SocketUDP: if(!txtPort.getText().matches("[0-9]+")){ JOptionPane.showMessageDialog(this,"Invalid Port", "Error!", JOptionPane.ERROR_MESSAGE); return; } wan.setConnType(cmbType.getSelectedIndex() + 1); wan.setConnHost(txtHost.getText()); wan.setConnPort(Integer.valueOf(txtPort.getText())); wan.setServer( cmbRole.getSelectedIndex() == 1 ); break; case WANNetworkInterface.RMI: case WANNetworkInterface.Corba: wan.setConnType(cmbType.getSelectedIndex() + 1); wan.setConnHost(txtHost.getText()); wan.setConnService(txtService.getText()); break; } if(wan.isUP()) wan.DOWN(); if(chkUP.isSelected()){ wan.UP(); } this.dispose(); } catch (Exception e) { e.printStackTrace(); } } /** * This is executed when the user hits the cancel button * @author Key * */ private void cancelButton(){ this.dispose(); } } Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -d -r1.75 -r1.76 *** MainScreen.java 19 Oct 2007 17:40:33 -0000 1.75 --- MainScreen.java 19 Oct 2007 19:38:06 -0000 1.76 *************** *** 2413,2416 **** --- 2413,2421 ---- Sim.getNode(strNodeName).addNetworkInterface(iface[0], core.NetworkInterface.WAN, false); ((core.CSUDSU)Sim.getNode(strNodeName)).setWAN(iface[0]); + ((core.WANNetworkInterface)Sim.getNode(strNodeName).getNIC(iface[0])).setConnType(Integer.valueOf(iface[4])); + ((core.WANNetworkInterface)Sim.getNode(strNodeName).getNIC(iface[0])).setServer(Boolean.valueOf(iface[5])); + ((core.WANNetworkInterface)Sim.getNode(strNodeName).getNIC(iface[0])).setConnHost(iface[6]); + ((core.WANNetworkInterface)Sim.getNode(strNodeName).getNIC(iface[0])).setConnPort(Integer.valueOf(iface[7])); + if(iface.length > 8) ((core.WANNetworkInterface)Sim.getNode(strNodeName).getNIC(iface[0])).setConnService(iface[8]); break; } *************** *** 4478,4482 **** break; case core.NetworkInterface.WAN: ! String service = JOptionPane.showInputDialog(this, "Sevice name", "Service name.", JOptionPane.QUESTION_MESSAGE); if(service == null || service == "" || service.length() < 3){ ((core.WANNetworkInterface)(temp.getNIC(IntName))).setServer(true); --- 4483,4487 ---- break; case core.NetworkInterface.WAN: ! /*String service = JOptionPane.showInputDialog(this, "Sevice name", "Service name.", JOptionPane.QUESTION_MESSAGE); if(service == null || service == "" || service.length() < 3){ ((core.WANNetworkInterface)(temp.getNIC(IntName))).setServer(true); *************** *** 4485,4489 **** } ! ((core.WANNetworkInterface)(temp.getNIC(IntName))).UP(); break; default: --- 4490,4495 ---- } ! ((core.WANNetworkInterface)(temp.getNIC(IntName))).UP(); */ ! new WANPortProperties(this, NodeName, IntName, Sim, Sandbox); break; default: Index: SerPortProperties.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/SerPortProperties.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SerPortProperties.java 19 Oct 2007 15:57:01 -0000 1.1 --- SerPortProperties.java 19 Oct 2007 19:38:06 -0000 1.2 *************** *** 102,106 **** this.Sim = Sim; this.SBox = SBox; ! setTitle("Serernet Port Properties"); initGUI(inNodeName, inNodeInt); --- 102,106 ---- this.Sim = Sim; this.SBox = SBox; ! setTitle("WAN Port Properties"); initGUI(inNodeName, inNodeInt); |