[Javanetsim-cvs] javaNetSim/guiUI EditRoutesDialog.java, 1.2, 1.3 MainScreen.java, 1.59, 1.60 MenuB
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2007-09-15 18:50:55
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv32627/guiUI Modified Files: EditRoutesDialog.java MainScreen.java MenuBar.java SNMPSendDataDialog.java Log Message: HTML reporting is done. HTML file chooser added. Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** MainScreen.java 15 Sep 2007 13:42:33 -0000 1.59 --- MainScreen.java 15 Sep 2007 18:50:48 -0000 1.60 *************** *** 161,164 **** --- 161,166 ---- private static final String SIM_PREFIX = "jfst"; + + private static final String HTM_PREFIX = "htm"; *************** *** 215,224 **** //Colors for console output ! private Color NETWORK_LAYER_COLOR = Color.CYAN; ! private Color LINK_LAYER_COLOR = Color.YELLOW; ! private Color TRANSPORT_LAYER_COLOR = Color.LIGHT_GRAY; ! private Color APPLICATION_LAYER_COLOR = Color.GREEN; ! private Color HARDWARE_LAYER_COLOR = Color.ORANGE; ! private Color SYSTEM_LAYER_COLOR = Color.RED ; //The File chooser class --- 217,226 ---- //Colors for console output ! private static final Color NETWORK_LAYER_COLOR = Color.CYAN; ! private static final Color LINK_LAYER_COLOR = Color.YELLOW; ! private static final Color TRANSPORT_LAYER_COLOR = Color.LIGHT_GRAY; ! private static final Color APPLICATION_LAYER_COLOR = Color.GREEN; ! private static final Color HARDWARE_LAYER_COLOR = Color.ORANGE; ! private static final Color SYSTEM_LAYER_COLOR = Color.RED ; //The File chooser class *************** *** 2221,2226 **** --- 2223,2269 ---- + /** + * Generate and save html report file + * @author gift (sourceforge.net user) + */ + public void save_html_rep(String saveas){ + chooser.setDialogTitle("Save HTML report..."); + chooser.setAcceptAllFileFilterUsed(false); + chooser.addChoosableFileFilter(new HTMLFilter()); + int returnVal; + + if(saveas == null){ + returnVal = chooser.showSaveDialog(this); + }else{ + returnVal = JFileChooser.APPROVE_OPTION; + } + + if(returnVal == JFileChooser.APPROVE_OPTION){ + + //Get Selected file for saving GUI information + File tempFile = chooser.getSelectedFile(); + + //TODO Test if prefix isnt already added!!!!! + //Set the report save file + if(saveas == null){ + if(tempFile.getPath().contains("."+HTM_PREFIX)) simSaveFile = new File(tempFile.getPath()); + else simSaveFile = new File(tempFile.getPath()+"."+HTM_PREFIX); + } + + //Generate report and save Simulation. + generate_html_report(simSaveFile.getAbsolutePath()); + + System.out.println("Generating HTML report file"); + System.out.println("Simulation was saved succesfully."); + System.out.println("File "+ simSaveFile.getName() + " has been saved to " + simSaveFile.getAbsolutePath()); + System.out.println(); + setStatus("HTML report was saved succesfully."); + } + + } + + void BuildSandbox() *************** *** 2861,2865 **** if (mConsole.getColumnCount()>0 && mConsole.getRowCount()>0) { ! out.append("<TABLE align=\"center\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\" style='border:solid windowtext 1.0pt;'>\r\n<TR bgColor=#FFFFFF>"); //Form table header for (i=0; i<mConsole.getColumnCount(); i++) --- 2904,2908 ---- if (mConsole.getColumnCount()>0 && mConsole.getRowCount()>0) { ! out.append("<!-- Console output part -->\r\n<TABLE align=\"center\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\" style='border:solid windowtext 1.0pt;'>\r\n<TR bgColor=#FFFFFF>"); //Form table header for (i=0; i<mConsole.getColumnCount(); i++) *************** *** 2931,2935 **** if (mConsole.getColumnCount()>0 && r_c>0) { ! out.append("<TABLE align=\"center\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\" style='border:solid windowtext 1.0pt;'>\r\n<TR bgColor=#FFFFFF>"); //Form table header for (i=0; i<mConsole.getColumnCount(); i++) --- 2974,2978 ---- if (mConsole.getColumnCount()>0 && r_c>0) { ! out.append("<!-- Console output part -->\r\n<TABLE align=\"center\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\" style='border:solid windowtext 1.0pt;'>\r\n<TR bgColor=#FFFFFF>"); //Form table header for (i=0; i<mConsole.getColumnCount(); i++) *************** *** 2982,2992 **** public StringBuffer generate_html_node_info(){ ! int i,j; StringBuffer out = new StringBuffer(10240); //approx 10 units in simulation ! String cur; ! if (true) ! { ! out.append("<BR />Sorry :) not implemented yet.<BR /><BR />"); } else { --- 3025,3082 ---- public StringBuffer generate_html_node_info(){ ! int i = 0; StringBuffer out = new StringBuffer(10240); //approx 10 units in simulation ! String cur_col; ! if (!GUInodeTable.isEmpty()) ! { ! Enumeration enu = GUInodeTable.keys(); ! String strCurrentNodeName = ""; ! ! out.append("<!-- Node information part -->\r\n<TABLE align=\"center\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\" style='border:solid windowtext 1.0pt;'>\r\n\r\n"); ! ! while(enu.hasMoreElements()) ! { ! try ! { ! Vector NodeData = Sim.getAllNodeInformation((String)enu.nextElement()); ! Iterator it = NodeData.iterator(); ! ! while(it.hasNext()) ! { ! Vector LineData = (Vector)it.next(); ! String strNodeName = (String)LineData.elementAt(0); ! String strDefGate = (String)LineData.elementAt(1); ! String strInterfaceName = (String)LineData.elementAt(2); ! String strMAC = (String)LineData.elementAt(3); ! String strIP = (String)LineData.elementAt(4); ! String strSubnet = (String)LineData.elementAt(5); ! String strLinkName = (String)LineData.elementAt(6); ! ! if(!strCurrentNodeName.equals(strNodeName)) ! { ! strCurrentNodeName = strNodeName; ! cur_col = ((i ^= 1) == 0) ? "<TR bgColor=#9999FF>" : "<TR bgColor=#FF9999>"; ! ! out.append("<!-- Simulation device -->\r\n" + cur_col + "\r\n" ! + "<TD>Name: " + strNodeName + "</TD>\r\n" ! + "<TD>Default gateway: " + strDefGate + "</TD>\r\n" ! + "<TD> </TD><TD> </TD><TD> </TD>\r\n</TR>\r\n\t<!-- device interfaces-->\r\n"); ! } ! out.append("\t<TR bgColor=#CCCCCC>\r\n"); ! out.append("\t<TD>Interface: " + strInterfaceName + "</TD>\r\n" + ! "\t<TD>MAC address: " + strMAC + "</TD>\r\n" + ! "\t<TD>IP address: " + strIP + "</TD>\r\n" + ! "\t<TD>Subnet mask: " + strSubnet + "</TD>\r\n" + ! "\t<TD>Link name: " + strLinkName + "</TD>\r\n"); ! out.append("\t</TR>\r\n"); ! } ! } ! catch(Exception e) ! { ! addToConsole(e.toString()); ! } ! } ! out.append("</TABLE>\r\n<!-- Node information output body -->\r\n\r\n"); } else { *************** *** 3038,3041 **** --- 3128,3152 ---- } + /** + * @author gift (sourceforge.net user) + */ + class HTMLFilter extends FileFilter{ + /** + * This method returns the Description that is in the File choosers Dialog + */ + public String getDescription(){ + return "Hypertext markup language file (*."+HTM_PREFIX+")"; + } + + /** + * This method returns true or false if a file has the prefix + */ + public boolean accept(File f) { + if(f.isDirectory() || f.getName().endsWith(HTM_PREFIX)){ + return true; + } + return false; + } + } *************** *** 3268,3277 **** * @author gift (sourceforge.net user) */ ! public void generate_html_report() { FileWriter f_out; try { ! f_out = new FileWriter("c:\\jns_rpt.htm"); f_out.write("<HTML>\r\n" + --- 3379,3388 ---- * @author gift (sourceforge.net user) */ ! public void generate_html_report(String path) { FileWriter f_out; try { ! f_out = new FileWriter(path); f_out.write("<HTML>\r\n" + *************** *** 3283,3295 **** "<!-- <LINK REL=stylesheet type=text/css href=\"style.css\"> -->\r\n" + "<TITLE>javaNetSim HTML report</TITLE>\r\n" + ! "</HEAD>\r\n\r\n"); f_out.write(generate_html_node_info().toString()); f_out.write(generate_html_console_out_rapid().toString()); ! f_out.write("\r\n<!-- close html file -->>\r\n</HTML>"); f_out.close(); } catch (IOException ex) { addToConsole(ex.toString()); ! } ! } --- 3394,3414 ---- "<!-- <LINK REL=stylesheet type=text/css href=\"style.css\"> -->\r\n" + "<TITLE>javaNetSim HTML report</TITLE>\r\n" + ! "</HEAD>\r\n\r\n"); ! f_out.write("<P>Welcome to javaNetSim report page!<BR/>" + ! "Here is the summury of the devices you used in your simulation." + ! "</P>\r\n<P>"); f_out.write(generate_html_node_info().toString()); + f_out.write("</P><BR/><BR/><P>" + + "Here is the transaction log of your simulation (taken from console)." + + "</P><P>"); f_out.write(generate_html_console_out_rapid().toString()); ! f_out.write("</P>\r\n" + ! "<!-- Appendix -->\r\n" ! + "Project page: <A HREF = \"http://sf.net/projects/javanetsim\">http://sf.net/projects/javanetsim</A>, if you found a bug, please, post it to <A HREF = \"http://sf.net/tracker/?atid=784685&group_id=152576\">http://sf.net/tracker/?atid=784685&group_id=152576</A>" + ! "<!-- close html file -->\r\n</HTML>"); f_out.close(); } catch (IOException ex) { addToConsole(ex.toString()); ! } } Index: MenuBar.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MenuBar.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** MenuBar.java 15 Sep 2007 11:34:58 -0000 1.14 --- MenuBar.java 15 Sep 2007 18:50:49 -0000 1.15 *************** *** 49,53 **** //HTML report generator menu ! private JMenuItem mnuGenRep = new JMenuItem("Generate HTML report"); //Add submenu private JMenu mnuAdd = new JMenu("Add"); //For Adding objects to simulation --- 49,53 ---- //HTML report generator menu ! private JMenuItem mnuGenRep = new JMenuItem("Generate HTML report..."); //Add submenu private JMenu mnuAdd = new JMenu("Add"); //For Adding objects to simulation *************** *** 198,202 **** mnuGenRep.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ ! controller.generate_html_report(); } }); --- 198,202 ---- mnuGenRep.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ ! controller.save_html_rep(null); } }); Index: EditRoutesDialog.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/EditRoutesDialog.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** EditRoutesDialog.java 13 Sep 2007 13:38:52 -0000 1.2 --- EditRoutesDialog.java 15 Sep 2007 18:50:48 -0000 1.3 *************** *** 125,129 **** btnCancel.setText("Cancel"); this.getRootPane().setDefaultButton(btnOk); ! this.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.setModal(true); --- 125,130 ---- btnCancel.setText("Cancel"); this.getRootPane().setDefaultButton(btnOk); ! this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); ! //this.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.setModal(true); Index: SNMPSendDataDialog.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/SNMPSendDataDialog.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SNMPSendDataDialog.java 22 Feb 2006 20:04:27 -0000 1.2 --- SNMPSendDataDialog.java 15 Sep 2007 18:50:49 -0000 1.3 *************** *** 122,126 **** this.getRootPane().setDefaultButton(btnOk); ! this.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.setModal(true); --- 122,127 ---- this.getRootPane().setDefaultButton(btnOk); ! this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); ! //this.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE); this.setLocationRelativeTo(null); this.setModal(true); |