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.util.ArrayList;
26 import javax.swing.filechooser.FileNameExtensionFilter;
27 import org.altusmetrum.altoslib_14.*;
28 import org.altusmetrum.altosuilib_14.*;
30 public class MicroExport extends JFileChooser {
35 public static void export(File file, MicroData data) throws FileNotFoundException, IOException {
36 FileWriter fw = new FileWriter(file);
41 public boolean runDialog() {
44 setSelectedFile(new File(AltosLib.replace_extension(data.name, ".csv")));
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(".csv"));
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);
88 } catch (FileNotFoundException fe) {
89 JOptionPane.showMessageDialog(frame,
92 JOptionPane.ERROR_MESSAGE);
93 } catch (IOException ioe) {
98 public MicroExport(JFrame frame, MicroData data) {
101 setDialogTitle("Export MicroPeak Data File");
102 setFileFilter(new FileNameExtensionFilter("MicroPeak CSV file",
104 setCurrentDirectory(AltosUIPreferences.logdir());