protected void fileSaveSimple() { JFileChooser chooser = null; if (currentFile == null) { chooser = new JFileChooser(startDirectory); } else { chooser = new JFileChooser(currentFile); if (!currentFile.isDirectory()) { chooser.setSelectedFile(currentFile); } } int returnVal = chooser.showSaveDialog(gw); if (returnVal == JFileChooser.APPROVE_OPTION) { currentFile = chooser.getSelectedFile(); graph.saveSimple(currentFile); } }
protected void filePNG() { JFileChooser chooser = null; File pngFile = null; if (currentFile == null) { chooser = new JFileChooser(startDirectory); } else { pngFile = new File(currentFile.getName() + ".png"); chooser = new JFileChooser(pngFile); if (!currentFile.isDirectory()) { chooser.setSelectedFile(currentFile); } } if (pngFile == null) return; try { BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); paint(image.getGraphics()); ImageIO.write(image, "png", pngFile); } catch (Exception e) { } return; /* JFileChooser chooser = null; File pngFile = null; if (currentFile == null) { chooser = new JFileChooser(startDirectory); } else { pngFile = new File(currentFile.getName()+".png"); chooser = new JFileChooser(pngFile); if (!currentFile.isDirectory()) { chooser.setSelectedFile(currentFile); } } int returnVal = chooser.showSaveDialog(gw); if (returnVal == JFileChooser.APPROVE_OPTION) { File pngFile = chooser.getSelectedFile(); int maxX = Integer.MIN_VALUE; int minX = Integer.MAX_VALUE; int maxY = Integer.MIN_VALUE; int minY = Integer.MAX_VALUE; while(Node node : getNodes()) { if(node.getX() > maxX) { maxX = node.getX(); } if(node.getX() < minX) { minX = node.getX(); } if(node.getY() > maxY) { maxY = node.getY(); } if(node.getY() < minY) { minY = node.getY(); } } BufferedImage image = new BufferedImage(maxX-minX+50,maxY-minY+50,BufferedImage.TYPE_INT_RGB); ImageIO.write(image,"png",pngFile); } */ }