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; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.micropeak;
21 import java.util.ArrayList;
25 import javax.swing.filechooser.FileNameExtensionFilter;
26 import org.altusmetrum.altoslib_11.*;
27 import org.altusmetrum.altosuilib_11.*;
29 public class MicroExport extends JFileChooser {
34 public static void export(File file, MicroData data) throws FileNotFoundException, IOException {
35 FileWriter fw = new FileWriter(file);
40 public boolean runDialog() {
43 setSelectedFile(new File(AltosLib.replace_extension(data.name, ".csv")));
45 ret = showSaveDialog(frame);
46 if (ret != APPROVE_OPTION)
50 file = getSelectedFile();
53 if (!file.getName().contains(".")) {
54 String fullname = file.getPath();
55 file = new File(fullname.concat(".csv"));
57 filename = file.getName();
59 if (file.isDirectory()) {
60 JOptionPane.showMessageDialog(frame,
61 String.format("\"%s\" is a directory",
64 JOptionPane.ERROR_MESSAGE);
67 int r = JOptionPane.showConfirmDialog(frame,
68 String.format("\"%s\" already exists. Overwrite?",
71 JOptionPane.YES_NO_OPTION);
72 if (r != JOptionPane.YES_OPTION)
75 if (!file.canWrite()) {
76 JOptionPane.showMessageDialog(frame,
77 String.format("\"%s\" is not writable",
80 JOptionPane.ERROR_MESSAGE);
87 } catch (FileNotFoundException fe) {
88 JOptionPane.showMessageDialog(frame,
91 JOptionPane.ERROR_MESSAGE);
92 } catch (IOException ioe) {
97 public MicroExport(JFrame frame, MicroData data) {
100 setDialogTitle("Export MicroPeak Data File");
101 setFileFilter(new FileNameExtensionFilter("MicroPeak CSV file",
103 setCurrentDirectory(AltosUIPreferences.logdir());