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; 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.
21 import java.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.LinkedBlockingQueue;
31 public class AltosCSVUI
33 implements ActionListener
35 JFileChooser csv_chooser;
38 AltosRecordIterable iterable;
41 static String[] combo_box_items = { "Comma Separated Values (.CSV)", "Googleearth Data (.KML)" };
43 void set_default_file() {
44 File current = csv_chooser.getSelectedFile();
45 String current_name = current.getName();
46 String new_name = null;
47 String selected = (String) combo_box.getSelectedItem();
49 if (selected.contains("CSV"))
50 new_name = Altos.replace_extension(current_name, ".csv");
51 else if (selected.contains("KML"))
52 new_name = Altos.replace_extension(current_name, ".kml");
54 csv_chooser.setSelectedFile(new File(new_name));
57 public void actionPerformed(ActionEvent e) {
58 if (e.getActionCommand().equals("comboBoxChanged"))
62 public AltosCSVUI(JFrame frame, AltosRecordIterable in_iterable, File source_file) {
63 iterable = in_iterable;
64 csv_chooser = new JFileChooser(source_file);
66 accessory = new JPanel();
67 accessory.setLayout(new GridBagLayout());
69 GridBagConstraints c = new GridBagConstraints();
70 c.fill = GridBagConstraints.NONE;
73 c.insets = new Insets (4, 4, 4, 4);
75 JLabel accessory_label = new JLabel("Export File Type");
78 accessory.add(accessory_label, c);
80 combo_box = new JComboBox(combo_box_items);
81 combo_box.addActionListener(this);
84 accessory.add(combo_box, c);
86 csv_chooser.setAccessory(accessory);
87 csv_chooser.setSelectedFile(source_file);
89 int ret = csv_chooser.showSaveDialog(frame);
90 if (ret == JFileChooser.APPROVE_OPTION) {
91 File file = csv_chooser.getSelectedFile();
92 String type = (String) combo_box.getSelectedItem();
94 if (type.contains("CSV"))
95 writer = new AltosCSV(file);
97 writer = new AltosKML(file);
98 writer.write(iterable);
100 } catch (FileNotFoundException ee) {
101 JOptionPane.showMessageDialog(frame,
104 JOptionPane.ERROR_MESSAGE);