[Javanetsim-cvs] javaNetSim/guiUI MainScreen.java, 1.61, 1.62 SandBox.java, 1.4, 1.5
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2007-09-16 15:27:32
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv21582/guiUI Modified Files: MainScreen.java SandBox.java Log Message: A try to save image file. Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** MainScreen.java 15 Sep 2007 20:39:44 -0000 1.61 --- MainScreen.java 16 Sep 2007 15:27:26 -0000 1.62 *************** *** 62,65 **** --- 62,67 ---- import java.awt.Cursor; + import java.awt.image.BufferedImage; + import java.awt.image.RenderedImage; import java.io.File; *************** *** 93,97 **** import java.util.Arrays; ! --- 95,99 ---- import java.util.Arrays; ! import javax.imageio.*; *************** *** 2254,2258 **** //Generate report and save Simulation. ! generate_html_report(simSaveFile.getAbsolutePath()); System.out.println("Generating HTML report file"); --- 2256,2260 ---- //Generate report and save Simulation. ! generate_html_report(simSaveFile.getAbsolutePath(), tempFile.getPath()+".jpg"); System.out.println("Generating HTML report file"); *************** *** 3379,3386 **** * @author gift (sourceforge.net user) */ ! public void generate_html_report(String path) { ! FileWriter f_out; ! try { f_out = new FileWriter(path); --- 3381,3388 ---- * @author gift (sourceforge.net user) */ ! public void generate_html_report(String path, String gr_path) { ! FileWriter f_out; //html file ! File g_out; //graphics file try { f_out = new FileWriter(path); *************** *** 3395,3400 **** "<TITLE>javaNetSim HTML report</TITLE>\r\n" + "</HEAD>\r\n<BODY>\r\n"); ! f_out.write("<P>Welcome to javaNetSim report page!<BR/>" + ! "Here is the summary of the devices you used in your simulation." + "</P>\r\n<P>"); f_out.write(generate_html_node_info().toString()); --- 3397,3404 ---- "<TITLE>javaNetSim HTML report</TITLE>\r\n" + "</HEAD>\r\n<BODY>\r\n"); ! f_out.write("<P>Welcome to javaNetSim report page!</P>\r\n" + ! "<P>Simulation printscreen: <BR/>"+ ! "<IMG SRC=\""+ gr_path +"\"></P>\r\n" + ! "<P>Here is the summary of the devices you used in your simulation." + "</P>\r\n<P>"); f_out.write(generate_html_node_info().toString()); *************** *** 3408,3414 **** "<!-- close html file -->\r\n</BODY>\r\n</HTML>"); f_out.close(); } catch (IOException ex) { addToConsole(ex.toString()); ! } } --- 3412,3443 ---- "<!-- close html file -->\r\n</BODY>\r\n</HTML>"); f_out.close(); + + // Get image to write to a file + int width = 1000; + int height = 1000; + BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + + // Create a graphics contents on the buffered image + Graphics2D g2d = bufferedImage.createGraphics(); + + // Draw graphics + java.awt.Component c[] = this.Sandbox.getComponentsInLayer(3); + g2d = (Graphics2D) c[0].getGraphics(); + + + // Graphics context no longer needed so dispose it + g2d.dispose(); + + // Save as PNG + //File file = new File("newimage.png"); + //ImageIO.write(rendImage, "png", file); + + // Save as JPEG + g_out = new File(gr_path); + ImageIO.write((RenderedImage) bufferedImage, "jpg", g_out); + } catch (IOException ex) { addToConsole(ex.toString()); ! } } Index: SandBox.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/SandBox.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SandBox.java 13 Sep 2007 13:38:53 -0000 1.4 --- SandBox.java 16 Sep 2007 15:27:26 -0000 1.5 *************** *** 207,211 **** this.setCursor(csrDefault); Point NodeLocation = new Point(e.getX(), e.getY()); ! controller.addExternalNAT(NodeLocation); } } --- 207,211 ---- this.setCursor(csrDefault); Point NodeLocation = new Point(e.getX(), e.getY()); ! controller.addExternalNAT(NodeLocation); } } *************** *** 248,253 **** public void componentShown(ComponentEvent arg0) { } - - } --- 248,257 ---- public void componentShown(ComponentEvent arg0) { } + + + public Graphics getGraphics() + { + return this.controller.getGraphics(); + } } |