[Javanetsim-cvs] javaNetSim/guiUI Terminal.java,1.4,1.5
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2007-10-16 23:02:38
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv24483/guiUI Modified Files: Terminal.java Log Message: config saving partially works Index: Terminal.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/Terminal.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Terminal.java 15 Oct 2007 21:41:43 -0000 1.4 --- Terminal.java 16 Oct 2007 23:02:31 -0000 1.5 *************** *** 23,31 **** import java.awt.Color; import java.awt.event.WindowEvent; - import core.TransportLayerException; import java.awt.Font; import java.awt.event.KeyListener; - import java.util.regex.*; - import core.protocolsuite.tcp_ip.*; import java.util.Vector; import core.CommandsTree; --- 23,28 ---- *************** *** 36,43 **** import core.Pair; import core.CommandProcessor; ! import java.awt.Toolkit; ! import java.awt.event.FocusEvent; ! import java.awt.event.FocusListener; ! import javax.swing.SwingUtilities; /** --- 33,37 ---- import core.Pair; import core.CommandProcessor; ! import core.InvalidNetworkInterfaceNameException; /** *************** *** 61,64 **** --- 55,60 ---- private int device_type; private CommandProcessor cmdproc; + private boolean interface_mode = false; + private String interface_name = ""; private clear_terminal_CommandClass clear_terminal_Command = new clear_terminal_CommandClass(); *************** *** 67,70 **** --- 63,67 ---- private configure_terminal_CommandClass configure_terminal_Command = new configure_terminal_CommandClass(); private exit_CommandClass exit_Command = new exit_CommandClass(); + private interface_CommandClass interface_Command = new interface_CommandClass(); private logout_CommandClass logout_Command = new logout_CommandClass(); private ping_CommandClass ping_Command = new ping_CommandClass(); *************** *** 79,83 **** current_mode = CommandsTree.STD_MODE; ! if(device.getClass().equals(ApplicationLayerDevice.class)){ device_type = CommandsTree.APPLICATION_LAYER; } --- 76,80 ---- current_mode = CommandsTree.STD_MODE; ! if(device instanceof core.ApplicationLayerDevice){ device_type = CommandsTree.APPLICATION_LAYER; } *************** *** 92,95 **** --- 89,95 ---- cmdproc.add("configure terminal", configure_terminal_Command, cmdproc.STD_MODE | cmdproc.NO_LAYER, "<cr>", "Configure from the terminal"); cmdproc.add("exit", exit_Command, cmdproc.STD_CONF_MODE | cmdproc.NO_LAYER, "<cr>", "Exit from current mode"); + cmdproc.add("interface", interface_Command, cmdproc.CONF_MODE | cmdproc.NETWORK_LAYER, "<interface>", ""); + cmdproc.add("interface *", interface_Command, cmdproc.CONF_MODE | cmdproc.NETWORK_LAYER, "<cr>", ""); + cmdproc.add("interface * exit", exit_Command, cmdproc.CONF_MODE | cmdproc.NETWORK_LAYER, "<cr>", ""); cmdproc.add("logout", logout_Command, cmdproc.STD_MODE | cmdproc.NO_LAYER, "<cr>", "Exit from the console"); cmdproc.add("ping", ping_Command, cmdproc.STD_CONF_MODE | cmdproc.NETWORK_LAYER, "<ip>", "Send echo messages"); *************** *** 153,157 **** text += data+"\n"+device.NodeProtocolStack.getParentNodeName(); if(current_mode == cmdproc.CONF_MODE){ ! text += "(config)"; } text += "# "; --- 153,161 ---- text += data+"\n"+device.NodeProtocolStack.getParentNodeName(); if(current_mode == cmdproc.CONF_MODE){ ! text += "(config"; ! if(interface_mode){ ! text += "-if"; ! } ! text += ")"; } text += "# "; *************** *** 181,185 **** } appendToTerminal(cmdline.getText() + "\n"); ! String tmptext = cmdproc.call(cmdline.getText(), current_mode | device_type); if(tmptext==null){ tmptext = "% Incomplete command.\n"; --- 185,189 ---- } appendToTerminal(cmdline.getText() + "\n"); ! String tmptext = cmdproc.call(cmdline.getText(), current_mode | device_type, interface_name); if(tmptext==null){ tmptext = "% Incomplete command.\n"; *************** *** 201,205 **** addToTerminal(cmdline.getText()); int caretPos = cmdline.getCaretPosition(); ! String compl_str = cmdproc.complete(cmdline.getText().substring(0,caretPos), current_mode | device_type); //String last_str = cmdline.getText().substring(caretPos); if(compl_str!=null && !compl_str.endsWith(" ")){ --- 205,209 ---- addToTerminal(cmdline.getText()); int caretPos = cmdline.getCaretPosition(); ! String compl_str = cmdproc.complete(cmdline.getText().substring(0,caretPos), current_mode | device_type, interface_name); //String last_str = cmdline.getText().substring(caretPos); if(compl_str!=null && !compl_str.endsWith(" ")){ *************** *** 211,215 **** case '?': { String tmptext = cmdline.getText() + "?\n"; ! Vector<Pair> tmpv = cmdproc.help(cmdline.getText().substring(0,cmdline.getCaretPosition()), current_mode | device_type); if(tmpv!=null){ for(int i=0; i<tmpv.size(); i++){ --- 215,219 ---- case '?': { String tmptext = cmdline.getText() + "?\n"; ! Vector<Pair> tmpv = cmdproc.help(cmdline.getText().substring(0,cmdline.getCaretPosition()), current_mode | device_type, interface_name); if(tmpv!=null){ for(int i=0; i<tmpv.size(); i++){ *************** *** 331,336 **** public String call(Vector<String> params){ if(current_mode == cmdproc.CONF_MODE){ ! current_mode = cmdproc.STD_MODE; ! device.getConfig().working_config = DeviceConfig.RUNNING_CONFIG; } else if(current_mode == cmdproc.STD_MODE){ --- 335,346 ---- public String call(Vector<String> params){ if(current_mode == cmdproc.CONF_MODE){ ! if(interface_mode){ ! interface_mode = false; ! interface_name = ""; ! } ! else{ ! current_mode = cmdproc.STD_MODE; ! device.getConfig().working_config = DeviceConfig.RUNNING_CONFIG; ! } } else if(current_mode == cmdproc.STD_MODE){ *************** *** 340,343 **** --- 350,373 ---- } }; + class interface_CommandClass implements CommandInterface{ + public String call(Vector<String> params){ + String out = ""; + if(params.size()==1){ + try { + device.getNetworkInterface(params.get(0)); + if(!interface_mode){ + interface_mode = true; + interface_name = "interface "+params.get(0); + } + } catch (InvalidNetworkInterfaceNameException ex) { + out += "error: invalid inferface\n"; + } + } + else{ + out += "Invalid parameters\n"; + } + return out; + } + }; class logout_CommandClass implements CommandInterface{ public String call(Vector<String> params){ |