@Override public void actionPerformed(ActionEvent e) { Preferences pref = Preferences.userNodeForPackage(FSFrame.class); String saveDirName = pref.get(SAVE_DIR, System.getProperty("user.dir")); JFileChooser fileChooser = new JFileChooser(saveDirName); int result = fileChooser.showSaveDialog(FSFrame.this); if (result != JFileChooser.APPROVE_OPTION) { return; } File file = fileChooser.getSelectedFile(); if (!file.getName().toLowerCase().endsWith(".fsext")) { file = new File(file.getAbsolutePath() + ".fsext"); } if (file.exists()) { result = JOptionPane.showConfirmDialog( FSFrame.this, FSResource.getString("file_exists"), "", JOptionPane.YES_NO_OPTION); if (result != JOptionPane.YES_OPTION) { return; } } pref.put(SAVE_DIR, file.getAbsolutePath()); FileOutputStream fos = null; try { fos = new FileOutputStream(file); new Parser().write(panel.getModel(), fos); } catch (IOException ex) { JOptionPane.showMessageDialog( FSFrame.this, FSResource.resourceBundle.getString("failed_to_output")); ex.printStackTrace(); } }
@Override public void actionPerformed(ActionEvent e) { Preferences pref = Preferences.userNodeForPackage(FSFrame.class); String saveDirName = pref.get(SAVE_IMAGE_DIR, System.getProperty("user.dir")); JFileChooser fileChooser = new JFileChooser(saveDirName); int result = fileChooser.showSaveDialog(FSFrame.this); if (result != JFileChooser.APPROVE_OPTION) { return; } File file = fileChooser.getSelectedFile(); if (!file.getName().toLowerCase().endsWith(".png")) { file = new File(file.getAbsolutePath() + ".png"); } if (file.exists()) { result = JOptionPane.showConfirmDialog( FSFrame.this, FSResource.getString("file_exists"), "", JOptionPane.YES_NO_OPTION); if (result != JOptionPane.YES_OPTION) { return; } } pref.put(SAVE_IMAGE_DIR, file.getAbsolutePath()); BufferedImage image = panel.toImage(drawPmCode); try { if (drawPmCode) { BufferedImage pmCode = createPMCode(); Graphics g = image.getGraphics(); Point p = panel .getModel() .getPmCodePosition() .getPoint(panel.getSize(), new Dimension(pmCode.getWidth(), pmCode.getHeight())); g.drawImage(pmCode, p.x, p.y, image.getHeight() / 2, image.getHeight() / 2, FSFrame.this); pmCode.flush(); } ImageIO.write(image, "png", file); } catch (IOException ex) { JOptionPane.showConfirmDialog( FSFrame.this, FSResource.resourceBundle.getString("failed_to_output_file")); ex.printStackTrace(); } finally { image.flush(); } }
PagePrefAction() { super( FSResource.getString("page_preference"), new ImageIcon(FSFrame.this.getClass().getResource("/resource/buttons/prefs.png"))); }
SelectAction() { super( FSResource.getString("select"), new ImageIcon(FSFrame.this.getClass().getResource("/resource/buttons/arrow.png"))); }