altosui: Remove ability to graph data in .csv files
[fw/altos] / ao-tools / altosui / AltosUI.java
index 29eda2ece4566f793bbe1cb386a3849d00e28596..28ed42fbe4f89848db63fcaa2d11c46cb82ef59e 100644 (file)
@@ -59,10 +59,6 @@ public class AltosUI extends JFrame {
        private AltosLog altos_log;
        private Box vbox;
 
-       private Font statusFont = new Font("SansSerif", Font.BOLD, 24);
-       private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14);
-       private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14);
-
        public AltosVoice voice = new AltosVoice();
 
        public static boolean load_library(Frame frame) {
@@ -245,6 +241,13 @@ public class AltosUI extends JFrame {
                new AltosCSVUI(AltosUI.this);
        }
 
+       /* Load a flight log CSV file and display a pretty graph.
+        */
+
+       private void GraphData() {
+               new AltosGraphUI(AltosUI.this);
+       }
+
        /* Create the AltosUI menus
         */
        private void createMenu() {
@@ -291,6 +294,14 @@ public class AltosUI extends JFrame {
                                });
                        menu.add(item);
 
+                       item = new JMenuItem("Graph Data",KeyEvent.VK_F);
+                       item.addActionListener(new ActionListener() {
+                                       public void actionPerformed(ActionEvent e) {
+                                               GraphData();
+                                       }
+                               });
+                       menu.add(item);
+
                        item = new JMenuItem("Quit",KeyEvent.VK_Q);
                        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
                                                                   ActionEvent.CTRL_MASK));
@@ -411,13 +422,6 @@ public class AltosUI extends JFrame {
 
        }
 
-       static String replace_extension(String input, String extension) {
-               int dot = input.lastIndexOf(".");
-               if (dot > 0)
-                       input = input.substring(0,dot);
-               return input.concat(extension);
-       }
-
        static AltosRecordIterable open_logfile(String filename) {
                File file = new File (filename);
                try {
@@ -434,7 +438,7 @@ public class AltosUI extends JFrame {
                }
        }
 
-       static AltosCSV open_csv(String filename) {
+       static AltosWriter open_csv(String filename) {
                File file = new File (filename);
                try {
                        return new AltosCSV(file);
@@ -444,32 +448,68 @@ public class AltosUI extends JFrame {
                }
        }
 
-       static void process_file(String input) {
-               String output = replace_extension(input,".csv");
-               if (input.equals(output)) {
-                       System.out.printf("Not processing '%s'\n", input);
-                       return;
+       static AltosWriter open_kml(String filename) {
+               File file = new File (filename);
+               try {
+                       return new AltosKML(file);
+               } catch (FileNotFoundException fe) {
+                       System.out.printf("Cannot open '%s'\n", filename);
+                       return null;
                }
-               System.out.printf("Processing \"%s\" to \"%s\"\n", input, output);
+       }
+
+       static final int process_csv = 1;
+       static final int process_kml = 2;
+
+       static void process_file(String input, int process) {
                AltosRecordIterable iterable = open_logfile(input);
                if (iterable == null)
                        return;
-               AltosCSV writer = open_csv(output);
-               if (writer == null)
-                       return;
-               writer.write(iterable);
-               writer.close();
+               if (process == 0)
+                       process = process_csv;
+               if ((process & process_csv) != 0) {
+                       String output = Altos.replace_extension(input,".csv");
+                       System.out.printf("Processing \"%s\" to \"%s\"\n", input, output);
+                       if (input.equals(output)) {
+                               System.out.printf("Not processing '%s'\n", input);
+                       } else {
+                               AltosWriter writer = open_csv(output);
+                               if (writer != null) {
+                                       writer.write(iterable);
+                                       writer.close();
+                               }
+                       }
+               }
+               if ((process & process_kml) != 0) {
+                       String output = Altos.replace_extension(input,".kml");
+                       System.out.printf("Processing \"%s\" to \"%s\"\n", input, output);
+                       if (input.equals(output)) {
+                               System.out.printf("Not processing '%s'\n", input);
+                       } else {
+                               AltosWriter writer = open_kml(output);
+                               if (writer == null)
+                                       return;
+                               writer.write(iterable);
+                               writer.close();
+                       }
+               }
        }
 
        public static void main(final String[] args) {
-
+               int     process = 0;
                /* Handle batch-mode */
                if (args.length > 0) {
-                       for (int i = 0; i < args.length; i++)
-                               process_file(args[i]);
+                       for (int i = 0; i < args.length; i++) {
+                               if (args[i].equals("--kml"))
+                                       process |= process_kml;
+                               else if (args[i].equals("--csv"))
+                                       process |= process_csv;
+                               else
+                                       process_file(args[i], process);
+                       }
                } else {
                        AltosUI altosui = new AltosUI();
                        altosui.setVisible(true);
                }
        }
-}
\ No newline at end of file
+}