[Javanetsim-cvs] javaNetSim/guiUI MainScreen.java, 1.100, 1.101 MenuBar.java, 1.21, 1.22
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2008-10-24 18:13:53
|
Update of /cvsroot/javanetsim/javaNetSim/guiUI In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv12939/guiUI Modified Files: MainScreen.java MenuBar.java Log Message: Index: MainScreen.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MainScreen.java,v retrieving revision 1.100 retrieving revision 1.101 diff -C2 -d -r1.100 -r1.101 *** MainScreen.java 24 Oct 2008 16:18:48 -0000 1.100 --- MainScreen.java 24 Oct 2008 18:13:48 -0000 1.101 *************** *** 159,162 **** --- 159,166 ---- private static final String HTM_PREFIX = "htm"; + + private static final String PNG_PREFIX = "png"; + + private static final String JPG_PREFIX = "png"; // File used to save simulation *************** *** 617,630 **** mConsole.setColumnIdentifiers(new Object[] { "Time", "Node", "Packet", "Layer", "Info" }); ! pnlConsole.getColumnModel().getColumn(0).setMaxWidth(100); ! pnlConsole.getColumnModel().getColumn(0).setMinWidth(100); ! pnlConsole.getColumnModel().getColumn(1).setMaxWidth(100); ! pnlConsole.getColumnModel().getColumn(1).setMinWidth(100); pnlConsole.getColumnModel().getColumn(2).setMaxWidth(200); ! pnlConsole.getColumnModel().getColumn(2).setMinWidth(200); ! pnlConsole.getColumnModel().getColumn(3).setMaxWidth(100); ! pnlConsole.getColumnModel().getColumn(3).setMinWidth(100); ! pnlConsole.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); // pnlConsole.setEnabled(false); --- 621,645 ---- mConsole.setColumnIdentifiers(new Object[] { "Time", "Node", "Packet", "Layer", "Info" }); + + pnlConsole.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + //pnlConsole.se ! //pnlConsole.getColumnModel().getColumn(0).setPreferredWidth(100); ! pnlConsole.getColumnModel().getColumn(0).setMinWidth(90); ! pnlConsole.getColumnModel().getColumn(0).setMaxWidth(200); ! //pnlConsole.getColumnModel().getColumn(1).setPreferredWidth(100); ! pnlConsole.getColumnModel().getColumn(1).setMinWidth(85); ! pnlConsole.getColumnModel().getColumn(1).setMaxWidth(200); ! //pnlConsole.getColumnModel().getColumn(2).setPreferredWidth(100); ! pnlConsole.getColumnModel().getColumn(2).setMinWidth(175); pnlConsole.getColumnModel().getColumn(2).setMaxWidth(200); ! //pnlConsole.getColumnModel().getColumn(3).setPreferredWidth(100); ! pnlConsole.getColumnModel().getColumn(3).setMinWidth(75); ! pnlConsole.getColumnModel().getColumn(3).setMaxWidth(200); ! ! pnlConsole.getColumnModel().getColumn(4).setMinWidth(400); ! ! ! //pnlConsole.setAutoResizeMode(; // pnlConsole.setEnabled(false); *************** *** 1912,1915 **** --- 1927,1981 ---- } + + public void Export(){ + JFileChooser chooser = new JFileChooser(); + + chooser.setDialogTitle("Export to..."); + chooser.setAcceptAllFileFilterUsed(false); + chooser.addChoosableFileFilter(new HTMLFilter()); + chooser.addChoosableFileFilter(new PNGFilter()); + + int returnVal = chooser.showSaveDialog(this); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + + // Get Selected file for saving GUI information + File tempFile = chooser.getSelectedFile(); + + String file = tempFile.getPath(); + + if (chooser.getFileFilter() instanceof HTMLFilter) + save_html_rep(file); + else if (chooser.getFileFilter() instanceof PNGFilter) + save_image(file, MainScreen.PNG_PREFIX); + else if (chooser.getFileFilter() instanceof JPGFilter) + save_image(file, MainScreen.JPG_PREFIX); + + } + } + + /** + * Generate and save png + * + * @author key + */ + private void save_image(String saveas, String prefix) { + // Get image to write to a file + BufferedImage bufferedImage = getDesktop(); + File file; + + if (saveas.contains("." + prefix)) + file = new File(saveas); + else + file = new File(saveas + "." + + prefix); + + // Save as PNG + try{ + ImageIO.write(bufferedImage, prefix, file); + }catch(IOException e){ e.printStackTrace(); } + + setStatus(prefix + " file was saved succesfully."); + } /** *************** *** 1918,1922 **** * @author gift (sourceforge.net user) */ ! public void save_html_rep(String saveas) { JFileChooser chooser = new JFileChooser(); --- 1984,1988 ---- * @author gift (sourceforge.net user) */ ! private void save_html_rep(String saveas) { JFileChooser chooser = new JFileChooser(); *************** *** 3342,3345 **** --- 3408,3452 ---- } } + + class PNGFilter extends FileFilter { + /** + * This method returns the Description that is in the File choosers + * Dialog + */ + public String getDescription() { + return "Portable Network Graphics image (*." + MainScreen.PNG_PREFIX + ")"; + } + + /** + * This method returns true or false if a file has the prefix + */ + public boolean accept(File f) { + if (f.isDirectory() || f.getName().endsWith(MainScreen.PNG_PREFIX)) { + return true; + } + return false; + } + } + + class JPGFilter extends FileFilter { + /** + * This method returns the Description that is in the File choosers + * Dialog + */ + public String getDescription() { + return "JPEG image (*." + MainScreen.JPG_PREFIX + ")"; + } + + /** + * This method returns true or false if a file has the prefix + */ + public boolean accept(File f) { + if (f.isDirectory() || f.getName().endsWith(MainScreen.JPG_PREFIX)) { + return true; + } + return false; + } + } + /** *************** *** 3524,3565 **** // 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); ! ! // Create a graphics contents on the buffered image ! 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 --- 3631,3635 ---- // Get image to write to a file ! BufferedImage bufferedImage = getDesktop(); // Save as PNG *************** *** 3569,3573 **** // Save as JPEG g_out = new File(gr_path); ! ImageIO.write((RenderedImage) bufferedImage2, "jpg", g_out); } catch (IOException ex) { --- 3639,3643 ---- // Save as JPEG g_out = new File(gr_path); ! ImageIO.write(bufferedImage, "jpg", g_out); } catch (IOException ex) { *************** *** 3575,3578 **** --- 3645,3691 ---- } } + + public BufferedImage getDesktop(){ + int width = this.getWidth(); + int height = this.getHeight(); + BufferedImage bufferedImage = new BufferedImage(width, height, + BufferedImage.TYPE_INT_RGB); + + // Create a graphics contents on the buffered image + 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(); + + return bufferedImage2; + } public void clearSaveAs() *************** *** 3934,3940 **** JOptionPane.PLAIN_MESSAGE, null, Sim.getNode(inNodeName).getActiveInterfaces() , (Sim.getNode(inNodeName).getActiveInterfaces())[0]); ! if(choice != null) ! ((DHCPC) ((core.ApplicationLayerDevice) Sim.getNode(inNodeName)) ! .getApp(68)).StartDHCPC(choice, ""); } catch (Exception e) { e.printStackTrace(); --- 4047,4057 ---- JOptionPane.PLAIN_MESSAGE, null, Sim.getNode(inNodeName).getActiveInterfaces() , (Sim.getNode(inNodeName).getActiveInterfaces())[0]); ! if(choice != null){ ! /*((DHCPC) ((core.ApplicationLayerDevice) Sim.getNode(inNodeName)) ! .getApp(68)).StartDHCPC(choice, "");*/ ! ! ((core.NetworkLayerDevice)Sim.getNode(inNodeName)).getConfig().executeCommand("interface " + choice + " ip dhcp client"); ! ((core.NetworkLayerDevice)Sim.getNode(inNodeName)).getConfig().executeCommand("write mem"); ! } } catch (Exception e) { e.printStackTrace(); Index: MenuBar.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/guiUI/MenuBar.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** MenuBar.java 24 Oct 2008 16:18:48 -0000 1.21 --- MenuBar.java 24 Oct 2008 18:13:48 -0000 1.22 *************** *** 49,53 **** // simulation ! private JMenuItem mnuGenRep = new JMenuItem("Export to HTML ..."); private JMenuItem mnuExit = new JMenuItem("Exit"); // Exit appliction --- 49,53 ---- // simulation ! private JMenuItem mnuGenRep = new JMenuItem("Export ..."); private JMenuItem mnuExit = new JMenuItem("Exit"); // Exit appliction *************** *** 198,202 **** mnuGenRep.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ! controller.save_html_rep(null); } }); --- 198,202 ---- mnuGenRep.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ! controller.Export(); } }); |