Thread: [Javanetsim-cvs] javaNetSim/guiUI MainScreen.java, 1.62, 1.63 SandBox.java, 1.5, 1.6
Status: Beta
Brought to you by:
darkkey
From: gift <gi...@us...> - 2007-09-16 17:44:31
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv13944/guiUI Modified Files: MainScreen.java SandBox.java Log Message: Image saving implemented. Bugs removed. Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** MainScreen.java 16 Sep 2007 15:27:26 -0000 1.62 --- MainScreen.java 16 Sep 2007 17:44:14 -0000 1.63 *************** *** 2256,2260 **** //Generate report and save Simulation. ! generate_html_report(simSaveFile.getAbsolutePath(), tempFile.getPath()+".jpg"); System.out.println("Generating HTML report file"); --- 2256,2260 ---- //Generate report and save Simulation. ! generate_html_report(simSaveFile.getAbsolutePath(), tempFile.getAbsolutePath()+".jpg"); System.out.println("Generating HTML report file"); *************** *** 3385,3388 **** --- 3385,3406 ---- FileWriter f_out; //html file File g_out; //graphics file + String gr_path2 = ""; // to insert in HTML file + + ///////////////////////////////////////////////// + //PART 1. Generate HTML file. + ///////////////////////////////////////////////// + + //Process gr_path: remove everything up to last / or \ + if (gr_path.contains("\\")) + { + gr_path2 = gr_path.substring(gr_path.lastIndexOf('\\') + 1, gr_path.length()); + } else + if (gr_path.contains("/")) + { + gr_path2 = gr_path.substring(gr_path.lastIndexOf('/') + 1, gr_path.length()); + } else + { + gr_path2 = gr_path; + } try { f_out = new FileWriter(path); *************** *** 3399,3403 **** 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>"); --- 3417,3421 ---- f_out.write("<P>Welcome to javaNetSim report page!</P>\r\n" + "<P>Simulation printscreen: <BR/>"+ ! "<IMG SRC=\""+ gr_path2 +"\"></P>\r\n" + "<P>Here is the summary of the devices you used in your simulation." + "</P>\r\n<P>"); *************** *** 3413,3419 **** 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); --- 3431,3441 ---- f_out.close(); ! ///////////////////////////////////////////////// ! //PART 2. Generate image file. ! ///////////////////////////////////////////////// ! ! // Get image to write to a file ! int width = this.getWidth(); ! int height = this.getHeight(); BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); *************** *** 3421,3440 **** 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()); --- 3443,3480 ---- Graphics2D g2d = bufferedImage.createGraphics(); ! // Draw graphics var1: printscreen ! //g2d.setColor(new Color(0xEEEEEE)); ! //g2d.setColor(new Color(0xFFFFFF)); ! //g2d.fillRect(0,0, width, height); ! //this.paint(g2d); ! //g2d.dispose(); ! // Draw graphics var2: cropped to work area ! this.paint(g2d); ! ! // Graphics context no longer needed so dispose of it g2d.dispose(); + int w = scroller.getWidth(); + int h = scroller.getHeight(); + int x = (int) (scroller.getLocationOnScreen().getX() - this.getLocationOnScreen().getX()); + int y = (int) (scroller.getLocationOnScreen().getY() - this.getLocationOnScreen().getY()); + + BufferedImage bufferedImage2 = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); + Graphics2D g2_2d = bufferedImage2.createGraphics(); + + //key's shamanism + g2_2d.drawImage(bufferedImage,0,0,w,h,x + 5, y + 5,x + w - scroller.getVerticalScrollBar().getWidth() - 5,y + h - scroller.getHorizontalScrollBar().getHeight() - 5,this); + + g2_2d.dispose(); + + // Save as PNG + //File file = new File(gr_path); + //ImageIO.write((RenderedImage) bufferedImage, "png", file); + // Save as JPEG g_out = new File(gr_path); ! ImageIO.write((RenderedImage) bufferedImage2, "jpg", g_out); ! } catch (IOException ex) { addToConsole(ex.toString()); Index: SandBox.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/SandBox.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SandBox.java 16 Sep 2007 15:27:26 -0000 1.5 --- SandBox.java 16 Sep 2007 17:44:14 -0000 1.6 *************** *** 247,257 **** public void componentMoved(ComponentEvent arg0){} public void componentShown(ComponentEvent arg0) { ! } ! - public Graphics getGraphics() - { - return this.controller.getGraphics(); - } - } --- 247,251 ---- public void componentMoved(ComponentEvent arg0){} public void componentShown(ComponentEvent arg0) { ! } } |