2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.micropeak;
22 import java.awt.event.*;
24 import javax.swing.filechooser.FileNameExtensionFilter;
26 import java.util.concurrent.*;
28 import org.altusmetrum.altoslib_13.*;
29 import org.altusmetrum.altosuilib_13.*;
31 public class MicroSave extends JFileChooser {
36 public static void save(File file, MicroData data) throws FileNotFoundException, IOException {
37 FileOutputStream fos = new FileOutputStream(file);
42 public boolean runDialog() {
46 ret = showSaveDialog(frame);
47 if (ret != APPROVE_OPTION)
51 file = getSelectedFile();
54 if (!file.getName().contains(".")) {
55 String fullname = file.getPath();
56 file = new File(fullname.concat(".mpd"));
58 filename = file.getName();
60 if (file.isDirectory()) {
61 JOptionPane.showMessageDialog(frame,
62 String.format("\"%s\" is a directory",
65 JOptionPane.ERROR_MESSAGE);
68 int r = JOptionPane.showConfirmDialog(frame,
69 String.format("\"%s\" already exists. Overwrite?",
72 JOptionPane.YES_NO_OPTION);
73 if (r != JOptionPane.YES_OPTION)
76 if (!file.canWrite()) {
77 JOptionPane.showMessageDialog(frame,
78 String.format("\"%s\" is not writable",
81 JOptionPane.ERROR_MESSAGE);
87 AltosUIPreferences.set_last_logdir(file.getParentFile());
88 data.set_name(filename);
90 } catch (FileNotFoundException fe) {
91 JOptionPane.showMessageDialog(frame,
94 JOptionPane.ERROR_MESSAGE);
95 } catch (IOException ioe) {
100 public MicroSave(JFrame frame, MicroData data) {
103 setDialogTitle("Save MicroPeak Data File");
104 setFileFilter(new FileNameExtensionFilter("MicroPeak data file",
106 setCurrentDirectory(AltosUIPreferences.last_logdir());
107 setSelectedFile(MicroFile.make());