2 * Copyright © 2010 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.altosuilib_14;
22 import java.awt.event.*;
25 import org.altusmetrum.altoslib_14.*;
27 public class AltosCSVUI
29 implements ActionListener
31 JFileChooser csv_chooser;
33 JComboBox<String> combo_box;
34 AltosFlightSeries series;
35 AltosCalData cal_data;
38 static String[] combo_box_items = { "Comma Separated Values (.CSV)", "Googleearth Data (.KML)" };
40 void set_default_file() {
41 File current = csv_chooser.getSelectedFile();
42 String current_name = current.getName();
43 String new_name = null;
44 String selected = (String) combo_box.getSelectedItem();
46 if (selected.contains("CSV"))
47 new_name = AltosLib.replace_extension(current_name, ".csv");
48 else if (selected.contains("KML"))
49 new_name = AltosLib.replace_extension(current_name, ".kml");
51 csv_chooser.setSelectedFile(new File(new_name));
54 public void actionPerformed(ActionEvent e) {
55 if (e.getActionCommand().equals("comboBoxChanged"))
59 public AltosCSVUI(JFrame frame, AltosFlightSeries series, File source_file) {
61 this.cal_data = series.cal_data();
62 csv_chooser = new JFileChooser(source_file);
64 accessory = new JPanel();
65 accessory.setLayout(new GridBagLayout());
67 GridBagConstraints c = new GridBagConstraints();
68 c.fill = GridBagConstraints.NONE;
71 c.insets = new Insets (4, 4, 4, 4);
73 JLabel accessory_label = new JLabel("Export File Type");
76 accessory.add(accessory_label, c);
78 combo_box = new JComboBox<String>(combo_box_items);
79 combo_box.addActionListener(this);
82 accessory.add(combo_box, c);
84 csv_chooser.setAccessory(accessory);
85 csv_chooser.setSelectedFile(source_file);
87 int ret = csv_chooser.showSaveDialog(frame);
88 if (ret == JFileChooser.APPROVE_OPTION) {
89 File file = csv_chooser.getSelectedFile();
90 String type = (String) combo_box.getSelectedItem();
92 if (type.contains("CSV"))
93 writer = new AltosCSV(file);
95 writer = new AltosKML(file);
98 } catch (FileNotFoundException ee) {
99 JOptionPane.showMessageDialog(frame,
102 JOptionPane.ERROR_MESSAGE);