altosui: Split out UI-specific preferences
authorKeith Packard <keithp@keithp.com>
Mon, 2 Jan 2012 23:45:14 +0000 (15:45 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 3 Jun 2012 02:09:09 +0000 (19:09 -0700)
Prepare to create library shared with android application.

Signed-off-by: Keith Packard <keithp@keithp.com>
23 files changed:
altosui/AltosBTKnown.java
altosui/AltosConfig.java
altosui/AltosConfigFreqUI.java
altosui/AltosConfigUI.java
altosui/AltosConfigureUI.java
altosui/AltosDataChooser.java
altosui/AltosDialog.java
altosui/AltosFile.java
altosui/AltosFlashUI.java
altosui/AltosFlightUI.java
altosui/AltosFrame.java
altosui/AltosFreqList.java
altosui/AltosIdleMonitorUI.java
altosui/AltosLaunchUI.java
altosui/AltosPreferences.java
altosui/AltosScanUI.java
altosui/AltosSerial.java
altosui/AltosSiteMap.java
altosui/AltosTelemetryReader.java
altosui/AltosUI.java
altosui/AltosUIPreferences.java [new file with mode: 0644]
altosui/AltosVoice.java
altosui/Makefile.am

index 95830637407fa5d5aedc83af5422f36eb9166242..e30be05765598d1c034b1ee9613be44b93f8a36e 100644 (file)
@@ -23,7 +23,7 @@ import java.util.prefs.*;
 
 public class AltosBTKnown implements Iterable<AltosBTDevice> {
        LinkedList<AltosBTDevice>       devices = new LinkedList<AltosBTDevice>();
-       Preferences                     bt_pref = AltosPreferences.bt_devices();
+       Preferences                     bt_pref = AltosUIPreferences.bt_devices();
 
        private String get_address(String name) {
                return bt_pref.get(name, "");
@@ -57,7 +57,7 @@ public class AltosBTKnown implements Iterable<AltosBTDevice> {
        }
 
        private void flush() {
-               AltosPreferences.flush_preferences();
+               AltosUIPreferences.flush_preferences();
        }
 
        public void set(Iterable<AltosBTDevice> new_devices) {
@@ -91,7 +91,7 @@ public class AltosBTKnown implements Iterable<AltosBTDevice> {
 
        public AltosBTKnown() {
                devices = new LinkedList<AltosBTDevice>();
-               bt_pref = AltosPreferences.bt_devices();
+               bt_pref = AltosUIPreferences.bt_devices();
                load();
        }
 }
\ No newline at end of file
index 58da405fc12d24d57bef727a045d6e39820bf73f..bd9302068ffa6ec853ca0ab72117f2fe0ab2ce15 100644 (file)
@@ -299,7 +299,7 @@ public class AltosConfig implements ActionListener {
                                if (remote) {
                                        serial_line.stop_remote();
                                        serial_line.set_radio_frequency(frequency);
-                                       AltosPreferences.set_frequency(device.getSerial(), frequency);
+                                       AltosUIPreferences.set_frequency(device.getSerial(), frequency);
                                        serial_line.start_remote();
                                }
                                serial_line.printf("c c %s\n", callsign.get());
index c6eabc536cbb17950d0374eaa40f29610c451e1e..ecb554495b21940ed109bca100e1f0499a177b0f 100644 (file)
@@ -246,7 +246,7 @@ public class AltosConfigFreqUI extends AltosDialog implements ActionListener {
        FrequencyList   frequencies;
 
        void save_frequencies() {
-               AltosPreferences.set_common_frequencies(frequencies.frequencies());
+               AltosUIPreferences.set_common_frequencies(frequencies.frequencies());
        }
 
        JButton add, edit, remove;
@@ -411,7 +411,7 @@ public class AltosConfigFreqUI extends AltosDialog implements ActionListener {
                Frame   frame = JOptionPane.getFrameForComponent(frameComp);
                AltosConfigFreqUI       dialog;
 
-               dialog = new AltosConfigFreqUI(frame, AltosPreferences.common_frequencies());
+               dialog = new AltosConfigFreqUI(frame, AltosUIPreferences.common_frequencies());
                dialog.setVisible(true);
        }
 
index b0cd7f27d8336211cd8d44310418fbb189728139..eddb223ffda155a942facc12b87f05d7d24114ff 100644 (file)
@@ -434,7 +434,7 @@ public class AltosConfigUI
                c.anchor = GridBagConstraints.LINE_START;
                c.insets = ir;
                c.ipady = 5;
-               callsign_value = new JTextField(AltosPreferences.callsign());
+               callsign_value = new JTextField(AltosUIPreferences.callsign());
                callsign_value.getDocument().addDocumentListener(this);
                pane.add(callsign_value, c);
                callsign_value.setToolTipText("Callsign reported in telemetry data");
@@ -689,7 +689,7 @@ public class AltosConfigUI
                                                    product_value.getText(),
                                                    serial_value.getText());
                AltosFrequency  new_frequency = new AltosFrequency(new_radio_frequency, description);
-               AltosPreferences.add_common_frequency(new_frequency);
+               AltosUIPreferences.add_common_frequency(new_frequency);
                radio_frequency_value.insertItemAt(new_frequency, i);
                radio_frequency_value.setSelectedIndex(i);
        }
index 06b5745c7d493196fa170d6493dfd0db47f0bce3..1789cd25c59de70fb341b51b2ccfa46759ff03b5 100644 (file)
@@ -105,7 +105,7 @@ public class AltosConfigureUI
 
        /* DocumentListener interface methods */
        public void changedUpdate(DocumentEvent e) {
-               AltosPreferences.set_callsign(callsign_value.getText());
+               AltosUIPreferences.set_callsign(callsign_value.getText());
        }
 
        public void insertUpdate(DocumentEvent e) {
@@ -158,12 +158,12 @@ public class AltosConfigureUI
                c.anchor = GridBagConstraints.WEST;
                pane.add(new JLabel("Voice"), c);
 
-               enable_voice = new JRadioButton("Enable", AltosPreferences.voice());
+               enable_voice = new JRadioButton("Enable", AltosUIPreferences.voice());
                enable_voice.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        JRadioButton item = (JRadioButton) e.getSource();
                                        boolean enabled = item.isSelected();
-                                       AltosPreferences.set_voice(enabled);
+                                       AltosUIPreferences.set_voice(enabled);
                                        if (enabled)
                                                voice.speak_always("Enable voice.");
                                        else
@@ -202,11 +202,11 @@ public class AltosConfigureUI
                c.anchor = GridBagConstraints.WEST;
                pane.add(new JLabel("Log Directory"), c);
 
-               configure_log = new JButton(AltosPreferences.logdir().getPath());
+               configure_log = new JButton(AltosUIPreferences.logdir().getPath());
                configure_log.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
-                                       AltosPreferences.ConfigureLog();
-                                       configure_log.setText(AltosPreferences.logdir().getPath());
+                                       AltosUIPreferences.ConfigureLog();
+                                       configure_log.setText(AltosUIPreferences.logdir().getPath());
                                }
                        });
                c.gridx = 1;
@@ -225,7 +225,7 @@ public class AltosConfigureUI
                c.anchor = GridBagConstraints.WEST;
                pane.add(new JLabel("Callsign"), c);
 
-               callsign_value = new JTextField(AltosPreferences.callsign());
+               callsign_value = new JTextField(AltosUIPreferences.callsign());
                callsign_value.getDocument().addDocumentListener(this);
                c.gridx = 1;
                c.gridy = row++;
@@ -244,13 +244,13 @@ public class AltosConfigureUI
                pane.add(new JLabel("Font size"), c);
 
                font_size_value = new JComboBox(font_size_names);
-               int font_size = AltosPreferences.font_size();
+               int font_size = AltosUIPreferences.font_size();
                font_size_value.setSelectedIndex(font_size - Altos.font_size_small);
                font_size_value.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        int     size = font_size_value.getSelectedIndex() + Altos.font_size_small;
 
-                                       AltosPreferences.set_font_size(size);
+                                       AltosUIPreferences.set_font_size(size);
                                }
                        });
                c.gridx = 1;
@@ -295,7 +295,7 @@ public class AltosConfigureUI
 
                DelegatingRenderer.install(look_and_feel_value);
 
-               String look_and_feel  = AltosPreferences.look_and_feel();
+               String look_and_feel  = AltosUIPreferences.look_and_feel();
                for (int i = 0; i < look_and_feels.length; i++)
                        if (look_and_feel.equals(look_and_feels[i].getClassName()))
                                look_and_feel_value.setSelectedIndex(i);
@@ -304,7 +304,7 @@ public class AltosConfigureUI
                                public void actionPerformed(ActionEvent e) {
                                        int     id = look_and_feel_value.getSelectedIndex();
 
-                                       AltosPreferences.set_look_and_feel(look_and_feels[id].getClassName());
+                                       AltosUIPreferences.set_look_and_feel(look_and_feels[id].getClassName());
                                }
                        });
                c.gridx = 1;
@@ -323,12 +323,12 @@ public class AltosConfigureUI
                c.anchor = GridBagConstraints.WEST;
                pane.add(new JLabel("Serial Debug"), c);
 
-               serial_debug = new JRadioButton("Enable", AltosPreferences.serial_debug());
+               serial_debug = new JRadioButton("Enable", AltosUIPreferences.serial_debug());
                serial_debug.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        JRadioButton item = (JRadioButton) e.getSource();
                                        boolean enabled = item.isSelected();
-                                       AltosPreferences.set_serial_debug(enabled);
+                                       AltosUIPreferences.set_serial_debug(enabled);
                                }
                        });
                serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
index 488e1068b18bad58958726d00ffd0c19ef4a2696..c4a46d01c2e7ca02262fa7c841064bd68dcc01bd 100644 (file)
@@ -77,6 +77,6 @@ public class AltosDataChooser extends JFileChooser {
                setDialogTitle("Select Flight Record File");
                setFileFilter(new FileNameExtensionFilter("Flight data file",
                                                          "telem", "eeprom"));
-               setCurrentDirectory(AltosPreferences.logdir());
+               setCurrentDirectory(AltosUIPreferences.logdir());
        }
 }
index c30b575798b11bc168cbe0e4d5c9fcff87b21478..1e8e538cea9005d7ef1a1b7a6d8e3d5b0b1e2bd5 100644 (file)
@@ -32,7 +32,7 @@ import libaltosJNI.*;
 
 class AltosDialogListener extends WindowAdapter {
        public void windowClosing (WindowEvent e) {
-               AltosPreferences.unregister_ui_listener((AltosDialog) e.getWindow());
+               AltosUIPreferences.unregister_ui_listener((AltosDialog) e.getWindow());
        }
 }
 
@@ -44,19 +44,19 @@ public class AltosDialog extends JDialog implements AltosUIListener {
        }
 
        public AltosDialog() {
-               AltosPreferences.register_ui_listener(this);
+               AltosUIPreferences.register_ui_listener(this);
                addWindowListener(new AltosDialogListener());
        }
 
        public AltosDialog(Frame frame, String label, boolean modal) {
                super(frame, label, modal);
-               AltosPreferences.register_ui_listener(this);
+               AltosUIPreferences.register_ui_listener(this);
                addWindowListener(new AltosDialogListener());
        }
 
        public AltosDialog(Frame frame, boolean modal) {
                super(frame, modal);
-               AltosPreferences.register_ui_listener(this);
+               AltosUIPreferences.register_ui_listener(this);
                addWindowListener(new AltosDialogListener());
        }
 }
index 2e33b271dded901ca6a453ded9efa9326262e400..e2b6d5a65b09b58c4f725e54c65bb05f23af9a3f 100644 (file)
@@ -24,7 +24,7 @@ import java.util.*;
 class AltosFile extends File {
 
        public AltosFile(int year, int month, int day, int serial, int flight, String extension) {
-               super (AltosPreferences.logdir(),
+               super (AltosUIPreferences.logdir(),
                       String.format("%04d-%02d-%02d-serial-%03d-flight-%03d.%s",
                                     year, month, day, serial, flight, extension));
        }
index 704ce35c9fca4227a830c60dd3a51525e0409ec8..f91c542dfd5e7b24cc1b53b762a5f04ddd407b54 100644 (file)
@@ -161,7 +161,7 @@ public class AltosFlashUI
        boolean select_source_file() {
                JFileChooser    hexfile_chooser = new JFileChooser();
 
-               File firmwaredir = AltosPreferences.firmwaredir();
+               File firmwaredir = AltosUIPreferences.firmwaredir();
                if (firmwaredir != null)
                        hexfile_chooser.setCurrentDirectory(firmwaredir);
 
@@ -174,7 +174,7 @@ public class AltosFlashUI
                file = hexfile_chooser.getSelectedFile();
                if (file == null)
                        return false;
-               AltosPreferences.set_firmwaredir(file.getParentFile());
+               AltosUIPreferences.set_firmwaredir(file.getParentFile());
                return true;
        }
 
index b2ae485801212dc4198ffb03e91513866f4c581c..5c6e06297abe54aa4ddf5ad56338bf392d1758a0 100644 (file)
@@ -159,7 +159,7 @@ public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, Alt
        ActionListener  show_timer;
 
        public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
-               AltosPreferences.set_component(this);
+               AltosUIPreferences.set_component(this);
 
                voice = in_voice;
                reader = in_reader;
@@ -178,7 +178,7 @@ public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, Alt
                /* Stick channel selector at top of table for telemetry monitoring */
                if (serial >= 0) {
                        // Channel menu
-                       frequencies = new AltosFreqList(AltosPreferences.frequency(serial));
+                       frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
                        frequencies.set_product("Monitor");
                        frequencies.set_serial(serial);
                        frequencies.addActionListener(new ActionListener() {
@@ -298,7 +298,7 @@ public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, Alt
 
                setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
 
-               AltosPreferences.register_font_listener(this);
+               AltosUIPreferences.register_font_listener(this);
 
                addWindowListener(new WindowAdapter() {
                                @Override
@@ -306,7 +306,7 @@ public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, Alt
                                        disconnect();
                                        setVisible(false);
                                        dispose();
-                                       AltosPreferences.unregister_font_listener(AltosFlightUI.this);
+                                       AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
                                        if (exit_on_close)
                                                System.exit(0);
                                }
index f8cc4f526e0a0511609e1ab333a955f1d95c96ed..36ddcae986503f60ad1eddcf5d3a4436410d618e 100644 (file)
@@ -32,7 +32,7 @@ import libaltosJNI.*;
 
 class AltosFrameListener extends WindowAdapter {
        public void windowClosing (WindowEvent e) {
-               AltosPreferences.unregister_ui_listener((AltosFrame) e.getWindow());
+               AltosUIPreferences.unregister_ui_listener((AltosFrame) e.getWindow());
        }
 }
 
@@ -44,13 +44,13 @@ public class AltosFrame extends JFrame implements AltosUIListener {
        }
 
        public AltosFrame() {
-               AltosPreferences.register_ui_listener(this);
+               AltosUIPreferences.register_ui_listener(this);
                addWindowListener(new AltosFrameListener());
        }
 
        public AltosFrame(String name) {
                super(name);
-               AltosPreferences.register_ui_listener(this);
+               AltosUIPreferences.register_ui_listener(this);
                addWindowListener(new AltosFrameListener());
        }
 }
index 59b0e1278a91a97e066ff796a8cdd80aee57e4ff..e4135df7c7a41c81eef01a2a2bc401b7fb9e32f9 100644 (file)
@@ -52,7 +52,7 @@ public class AltosFreqList extends JComboBox {
                }
                String  description = String.format("%s serial %d", product, serial);
                AltosFrequency  frequency = new AltosFrequency(new_frequency, description);
-               AltosPreferences.add_common_frequency(frequency);
+               AltosUIPreferences.add_common_frequency(frequency);
                insertItemAt(frequency, i);
                setMaximumRowCount(getItemCount());
        }
@@ -73,7 +73,7 @@ public class AltosFreqList extends JComboBox {
        }
 
        public AltosFreqList () {
-               super(AltosPreferences.common_frequencies());
+               super(AltosUIPreferences.common_frequencies());
                setMaximumRowCount(getItemCount());
                setEditable(false);
                product = "Unknown";
index d877be4d7d23f2ba789cd2bd91074f17bfcf75ec..8eb0d520c339f88ad5d99c5a87d1f9561e580dfd 100644 (file)
@@ -342,12 +342,12 @@ public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay
                /* Stick frequency selector at top of table for telemetry monitoring */
                if (remote && serial >= 0) {
                        // Frequency menu
-                       frequencies = new AltosFreqList(AltosPreferences.frequency(serial));
+                       frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
                        frequencies.addActionListener(new ActionListener() {
                                        public void actionPerformed(ActionEvent e) {
                                                double frequency = frequencies.frequency();
                                                thread.set_frequency(frequency);
-                                               AltosPreferences.set_frequency(device.getSerial(),
+                                               AltosUIPreferences.set_frequency(device.getSerial(),
                                                                               frequency);
                                        }
                        });
@@ -391,7 +391,7 @@ public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay
 
                setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
 
-               AltosPreferences.register_font_listener(this);
+               AltosUIPreferences.register_font_listener(this);
 
                addWindowListener(new WindowAdapter() {
                                @Override
@@ -399,7 +399,7 @@ public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay
                                        disconnect();
                                        setVisible(false);
                                        dispose();
-                                       AltosPreferences.unregister_font_listener(AltosIdleMonitorUI.this);
+                                       AltosUIPreferences.unregister_font_listener(AltosIdleMonitorUI.this);
                                }
                        });
 
index 73fae16bf23ca3df1351cdacec507674c0048ba6..a6c3660424e464ed0afc7f9bcdaa3be635506859 100644 (file)
@@ -316,7 +316,7 @@ public class AltosLaunchUI
        void set_serial() {
                try {
                        launcher_serial = Integer.parseInt(launcher_serial_text.getText());
-                       AltosPreferences.set_launcher_serial(launcher_serial);
+                       AltosUIPreferences.set_launcher_serial(launcher_serial);
                        send_command("set_remote");
                } catch (NumberFormatException ne) {
                        launcher_serial_text.setText(String.format("%d", launcher_serial));
@@ -326,7 +326,7 @@ public class AltosLaunchUI
        void set_channel() {
                try {
                        launcher_channel = Integer.parseInt(launcher_channel_text.getText());
-                       AltosPreferences.set_launcher_serial(launcher_channel);
+                       AltosUIPreferences.set_launcher_serial(launcher_channel);
                        send_command("set_remote");
                } catch (NumberFormatException ne) {
                        launcher_channel_text.setText(String.format("%d", launcher_channel));
@@ -388,8 +388,8 @@ public class AltosLaunchUI
 
        public AltosLaunchUI(JFrame in_owner) {
 
-               launcher_channel = AltosPreferences.launcher_channel();
-               launcher_serial = AltosPreferences.launcher_serial();
+               launcher_channel = AltosUIPreferences.launcher_channel();
+               launcher_serial = AltosUIPreferences.launcher_serial();
                owner = in_owner;
                armed_status = AltosLaunch.Unknown;
                igniter_status = AltosLaunch.Unknown;
index cc2b1a95acbe76ccacc095bd6987ebaeac0de7d3..7510c7c2b289e51782aef2fa8ed48df668122a4b 100644 (file)
@@ -26,7 +26,7 @@ import javax.swing.*;
 import javax.swing.filechooser.FileSystemView;
 
 class AltosPreferences {
-       static Preferences preferences;
+       public static Preferences preferences;
 
        /* logdir preference name */
        final static String logdirPreference = "LOGDIR";
@@ -55,24 +55,15 @@ class AltosPreferences {
        /* scanning telemetry preferences name */
        final static String scanningTelemetryPreference = "SCANNING-TELEMETRY";
 
-       /* font size preferences name */
-       final static String fontSizePreference = "FONT-SIZE";
-
        /* Launcher serial preference name */
        final static String launcherSerialPreference = "LAUNCHER-SERIAL";
 
        /* Launcher channel preference name */
        final static String launcherChannelPreference = "LAUNCHER-CHANNEL";
        
-       /* Look&Feel preference name */
-       final static String lookAndFeelPreference = "LOOK-AND-FEEL";
-
        /* Default logdir is ~/TeleMetrum */
        final static String logdirName = "TeleMetrum";
 
-       /* UI Component to pop dialogs up */
-       static Component component;
-
        /* Log directory */
        static File logdir;
 
@@ -100,14 +91,6 @@ class AltosPreferences {
        /* Scanning telemetry */
        static int scanning_telemetry;
 
-       static LinkedList<AltosFontListener> font_listeners;
-
-       static int font_size = Altos.font_size_medium;
-
-       static LinkedList<AltosUIListener> ui_listeners;
-
-       static String look_and_feel = null;
-
        /* List of frequencies */
        final static String common_frequencies_node_name = "COMMON-FREQUENCIES";
        static AltosFrequency[] common_frequencies;
@@ -187,11 +170,6 @@ class AltosPreferences {
 
                scanning_telemetry = preferences.getInt(scanningTelemetryPreference,(1 << Altos.ao_telemetry_standard));
 
-               font_listeners = new LinkedList<AltosFontListener>();
-
-               font_size = preferences.getInt(fontSizePreference, Altos.font_size_medium);
-               Altos.set_fonts(font_size);
-
                launcher_serial = preferences.getInt(launcherSerialPreference, 0);
 
                launcher_channel = preferences.getInt(launcherChannelPreference, 0);
@@ -207,27 +185,22 @@ class AltosPreferences {
 
                common_frequencies = load_common_frequencies();
 
-               look_and_feel = preferences.get(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
-
-               ui_listeners = new LinkedList<AltosUIListener>();
        }
 
        static { init(); }
 
-       static void set_component(Component in_component) {
-               component = in_component;
-       }
-
        static void flush_preferences() {
                try {
                        preferences.flush();
                } catch (BackingStoreException ee) {
+/*
                        if (component != null)
                                JOptionPane.showMessageDialog(component,
                                                              preferences.absolutePath(),
                                                              "Cannot save prefernces",
                                                              JOptionPane.ERROR_MESSAGE);
                        else
+*/
                                System.err.printf("Cannot save preferences\n");
                }
        }
@@ -243,41 +216,6 @@ class AltosPreferences {
                }
        }
 
-       private static boolean check_dir(File dir) {
-               if (!dir.exists()) {
-                       if (!dir.mkdirs()) {
-                               JOptionPane.showMessageDialog(component,
-                                                             dir.getName(),
-                                                             "Cannot create directory",
-                                                             JOptionPane.ERROR_MESSAGE);
-                               return false;
-                       }
-               } else if (!dir.isDirectory()) {
-                       JOptionPane.showMessageDialog(component,
-                                                     dir.getName(),
-                                                     "Is not a directory",
-                                                     JOptionPane.ERROR_MESSAGE);
-                       return false;
-               }
-               return true;
-       }
-
-       /* Configure the log directory. This is where all telemetry and eeprom files
-        * will be written to, and where replay will look for telemetry files
-        */
-       public static void ConfigureLog() {
-               JFileChooser    logdir_chooser = new JFileChooser(logdir.getParentFile());
-
-               logdir_chooser.setDialogTitle("Configure Data Logging Directory");
-               logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
-
-               if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) {
-                       File dir = logdir_chooser.getSelectedFile();
-                       if (check_dir(dir))
-                               set_logdir(dir);
-               }
-       }
-
        public static File logdir() {
                return logdir;
        }
@@ -371,65 +309,6 @@ class AltosPreferences {
                return firmwaredir;
        }
 
-       public static int font_size() {
-               return font_size;
-       }
-
-       static void set_fonts() {
-       }
-
-       public static void set_font_size(int new_font_size) {
-               font_size = new_font_size;
-               synchronized (preferences) {
-                       preferences.putInt(fontSizePreference, font_size);
-                       flush_preferences();
-                       Altos.set_fonts(font_size);
-                       for (AltosFontListener l : font_listeners)
-                               l.font_size_changed(font_size);
-               }
-       }
-
-       public static void register_font_listener(AltosFontListener l) {
-               synchronized (preferences) {
-                       font_listeners.add(l);
-               }
-       }
-
-       public static void unregister_font_listener(AltosFontListener l) {
-               synchronized (preferences) {
-                       font_listeners.remove(l);
-               }
-       }
-
-       public static void set_look_and_feel(String new_look_and_feel) {
-               look_and_feel = new_look_and_feel;
-               try {
-                       UIManager.setLookAndFeel(look_and_feel);
-               } catch (Exception e) {
-               }
-               synchronized(preferences) {
-                       preferences.put(lookAndFeelPreference, look_and_feel);
-                       flush_preferences();
-                       for (AltosUIListener l : ui_listeners)
-                               l.ui_changed(look_and_feel);
-               }
-       }
-
-       public static String look_and_feel() {
-               return look_and_feel;
-       }
-
-       public static void register_ui_listener(AltosUIListener l) {
-               synchronized(preferences) {
-                       ui_listeners.add(l);
-               }
-       }
-
-       public static void unregister_ui_listener(AltosUIListener l) {
-               synchronized (preferences) {
-                       ui_listeners.remove(l);
-               }
-       }
        public static void set_serial_debug(boolean new_serial_debug) {
                serial_debug = new_serial_debug;
                AltosSerial.set_debug(serial_debug);
index e188834e64aa76a204d8026a42324273b800c29a..2b9137d80c4f2c1d47301cf4631556f64560e758 100644 (file)
@@ -267,7 +267,7 @@ public class AltosScanUI
                                        scanning_telemetry |= (1 << Altos.ao_telemetry_standard);
                                        telemetry_boxes[Altos.ao_telemetry_standard - Altos.ao_telemetry_min].setSelected(true);
                                }
-                               AltosPreferences.set_scanning_telemetry(scanning_telemetry);
+                               AltosUIPreferences.set_scanning_telemetry(scanning_telemetry);
                        }
 
                        if (cmd.equals("monitor")) {
@@ -359,7 +359,7 @@ public class AltosScanUI
 
                owner = in_owner;
 
-               frequencies = AltosPreferences.common_frequencies();
+               frequencies = AltosUIPreferences.common_frequencies();
                frequency_index = 0;
                telemetry = Altos.ao_telemetry_min;
 
@@ -400,7 +400,7 @@ public class AltosScanUI
                c.gridy = 2;
                pane.add(telemetry_label, c);
 
-               int     scanning_telemetry = AltosPreferences.scanning_telemetry();
+               int     scanning_telemetry = AltosUIPreferences.scanning_telemetry();
                telemetry_boxes = new JCheckBox[Altos.ao_telemetry_max - Altos.ao_telemetry_min + 1];
                for (int k = Altos.ao_telemetry_min; k <= Altos.ao_telemetry_max; k++) {
                        int j = k - Altos.ao_telemetry_min;
index 77c926b1f9629f9a9e171e6a4377e8ff84e1eba9..afb9f21a2c3d189a00a2586c262b739df168ca26 100644 (file)
@@ -438,9 +438,9 @@ public class AltosSerial implements Runnable {
                if (debug)
                        System.out.printf("start remote %7.3f\n", frequency);
                if (frequency == 0.0)
-                       frequency = AltosPreferences.frequency(device.getSerial());
+                       frequency = AltosUIPreferences.frequency(device.getSerial());
                set_radio_frequency(frequency);
-               set_callsign(AltosPreferences.callsign());
+               set_callsign(AltosUIPreferences.callsign());
                printf("p\nE 0\n");
                flush_input();
                remote = true;
index 63995c402eac5fdb520e9cfaa9788cd58246fce9..93c54d0236ed231cd5b315c236fb3cbe00464609 100644 (file)
@@ -250,7 +250,7 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay {
                char chlng = lng < 0 ? 'W' : 'E';
                if (lat < 0) lat = -lat;
                if (lng < 0) lng = -lng;
-               return new File(AltosPreferences.mapdir(),
+               return new File(AltosUIPreferences.mapdir(),
                                String.format("map-%c%.6f,%c%.6f-%d.png",
                                              chlat, lat, chlng, lng, zoom));
        }
index 85dc9cbc57d9f7f219a759c360552626d5871e1f..dde60dc931a353bc416698f518816a9a940a7271 100644 (file)
@@ -84,7 +84,7 @@ class AltosTelemetryReader extends AltosFlightReader {
        }
 
        void save_frequency() {
-               AltosPreferences.set_frequency(device.getSerial(), frequency);
+               AltosUIPreferences.set_frequency(device.getSerial(), frequency);
        }
 
        void set_telemetry(int in_telemetry) {
@@ -93,7 +93,7 @@ class AltosTelemetryReader extends AltosFlightReader {
        }
 
        void save_telemetry() {
-               AltosPreferences.set_telemetry(device.getSerial(), telemetry);
+               AltosUIPreferences.set_telemetry(device.getSerial(), telemetry);
        }
 
        File backing_file() {
@@ -109,11 +109,11 @@ class AltosTelemetryReader extends AltosFlightReader {
                previous = null;
 
                telem = new LinkedBlockingQueue<AltosLine>();
-               frequency = AltosPreferences.frequency(device.getSerial());
+               frequency = AltosUIPreferences.frequency(device.getSerial());
                set_frequency(frequency);
-               telemetry = AltosPreferences.telemetry(device.getSerial());
+               telemetry = AltosUIPreferences.telemetry(device.getSerial());
                set_telemetry(telemetry);
-               serial.set_callsign(AltosPreferences.callsign());
+               serial.set_callsign(AltosUIPreferences.callsign());
                serial.add_monitor(telem);
        }
 }
index 7d4b2edbf4708892fd3e46d83665de6525745a1b..a2816a3a6dc4cf7158e28d6273b3a7a298613f73 100644 (file)
@@ -108,7 +108,7 @@ public class AltosUI extends AltosFrame {
                if (imgURL != null)
                        setIconImage(new ImageIcon(imgURL).getImage());
 
-               AltosPreferences.set_component(this);
+               AltosUIPreferences.set_component(this);
 
                pane = getContentPane();
                gridbag = new GridBagLayout();
@@ -262,9 +262,9 @@ public class AltosUI extends AltosFrame {
                String  result;
                result = JOptionPane.showInputDialog(AltosUI.this,
                                                     "Configure Callsign",
-                                                    AltosPreferences.callsign());
+                                                    AltosUIPreferences.callsign());
                if (result != null)
-                       AltosPreferences.set_callsign(result);
+                       AltosUIPreferences.set_callsign(result);
        }
 
        void ConfigureTeleMetrum() {
@@ -538,7 +538,7 @@ public class AltosUI extends AltosFrame {
        
        public static void main(final String[] args) {
                try {
-                       UIManager.setLookAndFeel(AltosPreferences.look_and_feel());
+                       UIManager.setLookAndFeel(AltosUIPreferences.look_and_feel());
                } catch (Exception e) {
                }
                /* Handle batch-mode */
diff --git a/altosui/AltosUIPreferences.java b/altosui/AltosUIPreferences.java
new file mode 100644 (file)
index 0000000..da6c396
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package altosui;
+
+import java.io.*;
+import java.util.*;
+import java.text.*;
+import java.util.prefs.*;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.awt.Component;
+import javax.swing.*;
+import javax.swing.filechooser.FileSystemView;
+
+/* import org.altusmetrum.AltosLib.*; */
+
+class AltosUIPreferences extends AltosPreferences {
+
+       /* font size preferences name */
+       final static String fontSizePreference = "FONT-SIZE";
+
+       /* Look&Feel preference name */
+       final static String lookAndFeelPreference = "LOOK-AND-FEEL";
+
+       /* UI Component to pop dialogs up */
+       static Component component;
+
+       static LinkedList<AltosFontListener> font_listeners;
+
+       static int font_size = Altos.font_size_medium;
+
+       static LinkedList<AltosUIListener> ui_listeners;
+
+       static String look_and_feel = null;
+
+       public static void init() {
+               font_listeners = new LinkedList<AltosFontListener>();
+
+               font_size = preferences.getInt(fontSizePreference, Altos.font_size_medium);
+               Altos.set_fonts(font_size);
+               look_and_feel = preferences.get(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
+
+               ui_listeners = new LinkedList<AltosUIListener>();
+       }
+
+       static { init(); }
+
+       static void set_component(Component in_component) {
+               component = in_component;
+       }
+
+       private static boolean check_dir(File dir) {
+               if (!dir.exists()) {
+                       if (!dir.mkdirs()) {
+                               JOptionPane.showMessageDialog(component,
+                                                             dir.getName(),
+                                                             "Cannot create directory",
+                                                             JOptionPane.ERROR_MESSAGE);
+                               return false;
+                       }
+               } else if (!dir.isDirectory()) {
+                       JOptionPane.showMessageDialog(component,
+                                                     dir.getName(),
+                                                     "Is not a directory",
+                                                     JOptionPane.ERROR_MESSAGE);
+                       return false;
+               }
+               return true;
+       }
+
+       /* Configure the log directory. This is where all telemetry and eeprom files
+        * will be written to, and where replay will look for telemetry files
+        */
+       public static void ConfigureLog() {
+               JFileChooser    logdir_chooser = new JFileChooser(logdir.getParentFile());
+
+               logdir_chooser.setDialogTitle("Configure Data Logging Directory");
+               logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+
+               if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) {
+                       File dir = logdir_chooser.getSelectedFile();
+                       if (check_dir(dir))
+                               set_logdir(dir);
+               }
+       }
+       public static int font_size() {
+               return font_size;
+       }
+
+       static void set_fonts() {
+       }
+
+       public static void set_font_size(int new_font_size) {
+               font_size = new_font_size;
+               synchronized (preferences) {
+                       preferences.putInt(fontSizePreference, font_size);
+                       flush_preferences();
+                       Altos.set_fonts(font_size);
+                       for (AltosFontListener l : font_listeners)
+                               l.font_size_changed(font_size);
+               }
+       }
+
+       public static void register_font_listener(AltosFontListener l) {
+               synchronized (preferences) {
+                       font_listeners.add(l);
+               }
+       }
+
+       public static void unregister_font_listener(AltosFontListener l) {
+               synchronized (preferences) {
+                       font_listeners.remove(l);
+               }
+       }
+
+       public static void set_look_and_feel(String new_look_and_feel) {
+               look_and_feel = new_look_and_feel;
+               try {
+                       UIManager.setLookAndFeel(look_and_feel);
+               } catch (Exception e) {
+               }
+               synchronized(preferences) {
+                       preferences.put(lookAndFeelPreference, look_and_feel);
+                       flush_preferences();
+                       for (AltosUIListener l : ui_listeners)
+                               l.ui_changed(look_and_feel);
+               }
+       }
+
+       public static String look_and_feel() {
+               return look_and_feel;
+       }
+
+       public static void register_ui_listener(AltosUIListener l) {
+               synchronized(preferences) {
+                       ui_listeners.add(l);
+               }
+       }
+
+       public static void unregister_ui_listener(AltosUIListener l) {
+               synchronized (preferences) {
+                       ui_listeners.remove(l);
+               }
+       }
+}
\ No newline at end of file
index ac13ee14e81176c69d46587392340c3a8018ba62..ab74e0b3f8de562f372804f74fc9981d936be559 100644 (file)
@@ -65,7 +65,7 @@ public class AltosVoice implements Runnable {
        }
 
        public void speak(String s) {
-               if (AltosPreferences.voice())
+               if (AltosUIPreferences.voice())
                        speak_always(s);
        }
 
index 16b57d401ae1b756fd30af77ea8576fecd5a7e71..c3fd6bb644061f89ade2704a907b3be99800d55b 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS=libaltos
+SUBDIRS=libaltos altoslib
 JAVAROOT=classes
 AM_JAVACFLAGS=-encoding UTF-8 -Xlint:deprecation
 
@@ -87,7 +87,9 @@ altosui_JAVA = \
        AltosLog.java \
        AltosPad.java \
        AltosParse.java \
+       AltosUIPreferences.java \
        AltosPreferences.java \
+       AltosUIPreferences.java \
        AltosReader.java \
        AltosRecord.java \
        AltosRecordCompanion.java \