micropeak: Use altosuilib
authorKeith Packard <keithp@keithp.com>
Mon, 31 Dec 2012 19:42:57 +0000 (11:42 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 31 Dec 2012 19:42:57 +0000 (11:42 -0800)
This removes a pile of code stolen from altosui

Signed-off-by: Keith Packard <keithp@keithp.com>
micropeak/.gitignore [new file with mode: 0644]
micropeak/Makefile.am
micropeak/MicroFileChooser.java
micropeak/MicroFontListener.java [deleted file]
micropeak/MicroFrame.java
micropeak/MicroGraph.java
micropeak/MicroPeak.java
micropeak/MicroPreferences.java [deleted file]
micropeak/MicroPreferencesBackend.java [deleted file]
micropeak/MicroSerial.java
micropeak/MicroUIListener.java [deleted file]

diff --git a/micropeak/.gitignore b/micropeak/.gitignore
new file mode 100644 (file)
index 0000000..fc99b31
--- /dev/null
@@ -0,0 +1,6 @@
+*.jar
+Manifest.txt
+classes
+*.stamp
+micropeak
+micropeak-test
index 2cfd2ad3ff05b063a6af1ba5f3d3ca340f759a72..fde981a6c6bbe975f111388684feb6725736e4a5 100644 (file)
@@ -1,7 +1,7 @@
 JAVAROOT=classes
 AM_JAVACFLAGS=-encoding UTF-8 -Xlint:deprecation
 
-CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../altoslib/*:../libaltos:$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar"
+CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH=".:classes:../altoslib/*:../altosuilib/*:../libaltos:$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar"
 
 bin_SCRIPTS=micropeak
 
@@ -14,10 +14,6 @@ micropeak_JAVA= \
        MicroGraph.java \
        MicroSerial.java \
        MicroFileChooser.java \
-       MicroPreferences.java \
-       MicroPreferencesBackend.java \
-       MicroFontListener.java \
-       MicroUIListener.java \
        MicroUSB.java
 
 JFREECHART_CLASS= \
@@ -38,6 +34,9 @@ LIBALTOS= \
 ALTOSLIB_CLASS=\
        AltosLib.jar
 
+ALTOSUILIB_CLASS=\
+       AltosUILib.jar
+
 # Icons
 ICONDIR=$(top_srcdir)/icon
 
@@ -62,6 +61,7 @@ all-local: micropeak-test $(JAR)
 clean-local:
        -rm -rf classes $(JAR) $(FATJAR) \
                $(ALTOSLIB_CLASS) \
+               $(ALTOSUILIB_CLASS) \
                $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(LIBALTOS) Manifest.txt \
                micropeak micropeak-test macosx linux windows
 
@@ -75,13 +75,13 @@ micropeak-test: Makefile
        echo 'exec java -cp "./*:../libaltos/*:$(JCOMMON)/jcommon.jar:$(JFREECHART)/jfreechart.jar" -Djava.library.path="../libaltos/.libs" -jar micropeak.jar "$$@"' >> $@
        chmod +x $@
 
-$(JAR): classmicropeak.stamp Manifest.txt $(JAVA_ICONS) $(ALTOSLIB_CLASS)
+$(JAR): classmicropeak.stamp Manifest.txt $(JAVA_ICONS) $(ALTOSLIB_CLASS) $(ALTOSUILIB_CLASS)
        jar cfm $@ Manifest.txt \
                $(ICONJAR) \
                -C classes org \
                -C ../libaltos libaltosJNI
 
-$(FATJAR): classmicropeak.stamp Manifest-fat.txt $(ALTOSLIB_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(JAVA_ICONS)
+$(FATJAR): classmicropeak.stamp Manifest-fat.txt $(ALTOSLIB_CLASS) $(ALTOSUILIB_CLASS) $(JFREECHART_CLASS) $(JCOMMON_CLASS) $(JAVA_ICONS)
        jar cfm $@ Manifest-fat.txt \
                $(ICONJAR) \
                -C classes org \
@@ -122,6 +122,10 @@ $(ALTOSLIB_CLASS):
        -rm -f "$@"
        $(LN_S) ../altoslib/"$@" .
 
+$(ALTOSUILIB_CLASS):
+       -rm -f "$@"
+       $(LN_S) ../altosuilib/"$@" .
+
 $(JFREECHART_CLASS):
        -rm -f "$@"
        $(LN_S) "$(JFREECHART)"/"$@" .
@@ -132,9 +136,9 @@ $(JCOMMON_CLASS):
 
 Manifest.txt: Makefile
        echo 'Main-Class: org.altusmetrum.micropeak.MicroPeak' > $@
-       echo "Class-Path: AltosLib.jar $(JCOMMON)/jcommon.jar $(JFREECHART)/jfreechart.jar" >> $@
+       echo "Class-Path: AltosLib.jar AltosUILib.jar $(JCOMMON)/jcommon.jar $(JFREECHART)/jfreechart.jar" >> $@
 
 Manifest-fat.txt:
        echo 'Main-Class: org.altusmetrum.micropeak.MicroPeak' > $@
-       echo "Class-Path: AltosLib.jar jcommon.jar jfreechart.jar" >> $@
+       echo "Class-Path: AltosLib.jar AltosUILib.jar jcommon.jar jfreechart.jar" >> $@
 
index 0fd63a27469b74cd1194dab9249f947bca69c4a1..d254098783bb509da82dc7bbfcb6baa12cc0cd7b 100644 (file)
@@ -21,6 +21,7 @@ import javax.swing.*;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import java.io.*;
 import org.altusmetrum.AltosLib.*;
+import org.altusmetrum.altosuilib.*;
 
 public class MicroFileChooser extends JFileChooser {
        JFrame  frame;
@@ -61,5 +62,6 @@ public class MicroFileChooser extends JFileChooser {
                setDialogTitle("Select MicroPeak Data File");
                setFileFilter(new FileNameExtensionFilter("MicroPeak data file",
                                                          "mpd"));
+               setCurrentDirectory(AltosUIPreferences.logdir());
        }
 }
diff --git a/micropeak/MicroFontListener.java b/micropeak/MicroFontListener.java
deleted file mode 100644 (file)
index a902584..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 org.altusmetrum.micropeak;
-
-public interface MicroFontListener {
-       void font_size_changed(int font_size);
-}
index a9b9a37a2ea6d1f346b06ebca1d0f37b08637954..03e3af0ce7cd8e07d655bf8e07ba0018a71526b5 100644 (file)
@@ -21,21 +21,10 @@ import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import java.util.*;
+import org.altusmetrum.altosuilib.*;
 
-class MicroFrameListener extends WindowAdapter {
-       public void windowClosing (WindowEvent e) {
-               MicroPreferences.unregister_ui_listener((MicroFrame) e.getWindow());
-       }
-}
-
-public class MicroFrame extends JFrame implements MicroUIListener {
-
-       public void ui_changed(String look_and_feel) {
-               SwingUtilities.updateComponentTreeUI(this);
-               this.pack();
-       }
-
-       static final String[] icon_names = {
+public class MicroFrame extends AltosUIFrame {
+       static String[] micro_icon_names = {
                "/micropeak-16.png",
                "/micropeak-32.png",
                "/micropeak-48.png",
@@ -44,31 +33,5 @@ public class MicroFrame extends JFrame implements MicroUIListener {
                "/micropeak-256.png"
        };
 
-       public void set_icon() {
-               ArrayList<Image> icons = new ArrayList<Image>();
-               
-               for (int i = 0; i < icon_names.length; i++) {
-                       java.net.URL imgURL = MicroPeak.class.getResource(icon_names[i]);
-                       if (imgURL != null)
-                               icons.add(new ImageIcon(imgURL).getImage());
-               }
-
-               setIconImages(icons);
-       }
-                       
-       public MicroFrame() {
-               super();
-               MicroPreferences.set_component(this);
-               MicroPreferences.register_ui_listener(this);
-               addWindowListener(new MicroFrameListener());
-               set_icon();
-       }
-
-       public MicroFrame(String name) {
-               super(name);
-               MicroPreferences.set_component(this);
-               MicroPreferences.register_ui_listener(this);
-               addWindowListener(new MicroFrameListener());
-               set_icon();
-       }
+       static { set_icon_names(micro_icon_names); }
 }
index 9192cad93d35a3a82075bce0d7a1b7f29e9ad15d..38f54fe04fa7f9905327000de0f2a47721669ba0 100644 (file)
@@ -34,15 +34,47 @@ import org.jfree.chart.labels.*;
 import org.jfree.data.xy.*;
 import org.jfree.data.*;
 
-public class MicroGraph {
+class MicroSeries extends XYSeries {
+       NumberAxis      axis;
+       String          label;
+       String          units;
+       Color           color;
+       
+       String label() {
+               return String.format("%s (%s)", label, units);
+       }
+
+       void set_units(String units) {
+               this.units = units;
+
+               axis.setLabel(label());
+       }
+
+       public MicroSeries (String label, String units, Color color) {
+               super(label);
+               this.label = label;
+               this.units = units;
+               this.color = color;
+
+               axis = new NumberAxis(label());
+               axis.setLabelPaint(color);
+               axis.setTickLabelPaint(color);
+       }
+}
+
+public class MicroGraph implements AltosUnitsListener {
 
        XYPlot          plot;
        JFreeChart      chart;
        ChartPanel      panel;
        NumberAxis      xAxis;
-       XYSeries        heightSeries;
-       XYSeries        speedSeries;
-       XYSeries        accelSeries;
+       MicroSeries     heightSeries;
+        MicroSeries    speedSeries;
+       MicroSeries     accelSeries;
+
+       static final private Color red = new Color(194,31,31);
+       static final private Color green = new Color(31,194,31);
+       static final private Color blue = new Color(31,31,194);
 
        MicroData       data;
 
@@ -50,40 +82,50 @@ public class MicroGraph {
                return panel;
        }
 
-       private void addSeries(XYSeries series, int index, String label, String units) {
+       private MicroSeries addSeries(int index, String label, String units, Color color) {
+               MicroSeries             series = new MicroSeries(label, units, color);
                XYSeriesCollection      dataset = new XYSeriesCollection(series);
-               NumberAxis              axis = new NumberAxis(String.format("%s (%s)", label, units));
                XYItemRenderer          renderer = new XYLineAndShapeRenderer(true, false);
 
+               renderer.setSeriesPaint(0, color);
                renderer.setPlot(plot);
                renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})", units),
                                                                                new java.text.DecimalFormat("0.00"),
                                                                                new java.text.DecimalFormat("0.00")));
-               plot.setRangeAxis(index, axis);
+               plot.setRangeAxis(index, series.axis);
                plot.setDataset(index, dataset);
                plot.setRenderer(index, renderer);
                plot.mapDatasetToRangeAxis(index, index);
+               return series;
        }
        
-       public void setData (MicroData data) {
+       public void resetData() {
                heightSeries.clear();
                speedSeries.clear();
                accelSeries.clear();
                for (int i = 0; i < data.pressures.length; i++) {
                        double x = data.time(i);
-                       heightSeries.add(x, data.height(i));
-                       speedSeries.add(x, data.speed(i));
-                       accelSeries.add(x, data.acceleration(i));
+                       heightSeries.add(x, AltosConvert.height.value(data.height(i)));
+                       speedSeries.add(x, AltosConvert.speed.value(data.speed(i)));
+                       accelSeries.add(x, AltosConvert.accel.value(data.acceleration(i)));
                }
        }
 
-       public MicroGraph(MicroData data) {
-
+       public void setData (MicroData data) {
                this.data = data;
+               resetData();
+       }
 
-               heightSeries = new XYSeries("Height");
-               speedSeries = new XYSeries("Speed");
-               accelSeries = new XYSeries("Acceleration");
+       public void units_changed(boolean imperial_units) {
+               if (data != null) {
+                       heightSeries.set_units(AltosConvert.height.show_units());
+                       speedSeries.set_units(AltosConvert.speed.show_units());
+                       accelSeries.set_units(AltosConvert.accel.show_units());
+                       resetData();
+               }
+       }
+
+       public MicroGraph() {
 
                xAxis = new NumberAxis("Time (s)");
                
@@ -95,9 +137,9 @@ public class MicroGraph {
                plot.setDomainPannable(true);
                plot.setRangePannable(true);
 
-               addSeries(heightSeries, 0, "Height", "m");
-               addSeries(speedSeries, 1, "Speed", "m/s");
-               addSeries(accelSeries, 2, "Acceleration", "m/s²");
+               heightSeries = addSeries(0, "Height", AltosConvert.height.show_units(), red);
+               speedSeries = addSeries(1, "Speed", AltosConvert.speed.show_units(), green);
+               accelSeries = addSeries(2, "Acceleration", AltosConvert.accel.show_units(), blue);
 
                chart = new JFreeChart("Flight", JFreeChart.DEFAULT_TITLE_FONT,
                                       plot, true);
@@ -106,5 +148,7 @@ public class MicroGraph {
                panel = new ChartPanel(chart);
                panel.setMouseWheelEnabled(true);
                panel.setPreferredSize(new java.awt.Dimension(800, 500));
+
+               AltosPreferences.register_units_listener(this);
        }
 }
\ No newline at end of file
index c9074348a057aa9e8f7344b62173c4a1d7e13a6f..463238c83b1af3fd9982c67af35c3ef5344e982c 100644 (file)
@@ -24,6 +24,7 @@ import java.io.*;
 import java.util.concurrent.*;
 import java.util.*;
 import org.altusmetrum.AltosLib.*;
+import org.altusmetrum.altosuilib.*;
 
 public class MicroPeak extends MicroFrame implements ActionListener, ItemListener {
 
@@ -59,6 +60,10 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
                        RunFile(input);
        }
 
+       private void Preferences() {
+               new AltosConfigureUI(this);
+       }
+               
        private void DownloadData() {
                java.util.List<MicroUSB>        devices = MicroUSB.list();
                for (MicroUSB device : devices)
@@ -66,7 +71,6 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
        }
 
        public void actionPerformed(ActionEvent ev) {
-               System.out.printf("action %s %s\n", ev.getActionCommand(), ev.paramString());
                if ("Exit".equals(ev.getActionCommand()))
                        System.exit(0);
                else if ("Open".equals(ev.getActionCommand()))
@@ -75,6 +79,8 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
                        new MicroPeak();
                else if ("Download".equals(ev.getActionCommand()))
                        DownloadData();
+               else if ("Preferences".equals(ev.getActionCommand()))
+                       Preferences();
        }
 
        public void itemStateChanged(ItemEvent e) {
@@ -82,7 +88,7 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
 
        public MicroPeak() {
 
-               this.filename = filename;
+               AltosUIPreferences.set_component(this);
 
                pane = getContentPane();
 
@@ -106,6 +112,10 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
                fileMenu.add(downloadAction);
                downloadAction.addActionListener(this);
 
+               JMenuItem preferencesAction = new JMenuItem("Preferences");
+               fileMenu.add(preferencesAction);
+               preferencesAction.addActionListener(this);
+
                JMenuItem exitAction = new JMenuItem("Exit");
                fileMenu.add(exitAction);
                exitAction.addActionListener(this);
@@ -118,7 +128,7 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
                        }
                });
 
-               graph = new MicroGraph(data);
+               graph = new MicroGraph();
                pane.add(graph.panel);
                pane.doLayout();
                pane.validate();
@@ -136,6 +146,11 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
        public static void main(final String[] args) {
                boolean opened = false;
 
+               try {
+                       UIManager.setLookAndFeel(AltosUIPreferences.look_and_feel());
+               } catch (Exception e) {
+               }
+
                for (int i = 0; i < args.length; i++) {
                        MicroPeak m = new MicroPeak();
                        m.OpenFile(new File(args[i]));
diff --git a/micropeak/MicroPreferences.java b/micropeak/MicroPreferences.java
deleted file mode 100644 (file)
index 70c2557..0000000
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * 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 org.altusmetrum.micropeak;
-
-import java.io.*;
-import java.util.*;
-import java.awt.Component;
-import javax.swing.*;
-import java.awt.*;
-import org.altusmetrum.AltosLib.*;
-
-public class MicroPreferences extends AltosPreferences {
-
-       static final int tab_elt_pad = 5;
-
-       static Font label_font;
-       static Font value_font;
-       static Font status_font;
-       static Font table_label_font;
-       static Font table_value_font;
-
-       final static int font_size_small = 1;
-       final static int font_size_medium = 2;
-       final static int font_size_large = 3;
-
-       static void set_fonts(int size) {
-               int     brief_size;
-               int     table_size;
-               int     status_size;
-
-               switch (size) {
-               case font_size_small:
-                       brief_size = 16;
-                       status_size = 18;
-                       table_size = 11;
-                       break;
-               default:
-               case font_size_medium:
-                       brief_size = 22;
-                       status_size = 24;
-                       table_size = 14;
-                       break;
-               case font_size_large:
-                       brief_size = 26;
-                       status_size = 30;
-                       table_size = 17;
-                       break;
-               }
-               label_font = new Font("Dialog", Font.PLAIN, brief_size);
-               value_font = new Font("Monospaced", Font.PLAIN, brief_size);
-               status_font = new Font("SansSerif", Font.BOLD, status_size);
-               table_label_font = new Font("SansSerif", Font.PLAIN, table_size);
-               table_value_font = new Font("Monospaced", Font.PLAIN, table_size);
-       }
-
-       /* 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<MicroFontListener> font_listeners;
-
-       static int font_size = font_size_medium;
-
-       static LinkedList<MicroUIListener> ui_listeners;
-
-       static String look_and_feel = null;
-
-       /* Serial debug */
-       static boolean serial_debug;
-
-       public static void init() {
-               AltosPreferences.init(new MicroPreferencesBackend());
-
-               font_listeners = new LinkedList<MicroFontListener>();
-
-               font_size = backend.getInt(fontSizePreference, font_size_medium);
-               set_fonts(font_size);
-               look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
-
-               ui_listeners = new LinkedList<MicroUIListener>();
-               serial_debug = backend.getBoolean(serialDebugPreference, false);
-       }
-
-       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() {
-               synchronized (backend) {
-                       return font_size;
-               }
-       }
-
-       static void set_fonts() {
-       }
-
-       public static void set_font_size(int new_font_size) {
-               synchronized (backend) {
-                       font_size = new_font_size;
-                       backend.putInt(fontSizePreference, font_size);
-                       flush_preferences();
-                       set_fonts(font_size);
-                       for (MicroFontListener l : font_listeners)
-                               l.font_size_changed(font_size);
-               }
-       }
-
-       public static void register_font_listener(MicroFontListener l) {
-               synchronized (backend) {
-                       font_listeners.add(l);
-               }
-       }
-
-       public static void unregister_font_listener(MicroFontListener l) {
-               synchronized (backend) {
-                       font_listeners.remove(l);
-               }
-       }
-
-       public static void set_look_and_feel(String new_look_and_feel) {
-               try {
-                       UIManager.setLookAndFeel(new_look_and_feel);
-               } catch (Exception e) {
-               }
-               synchronized(backend) {
-                       look_and_feel = new_look_and_feel;
-                       backend.putString(lookAndFeelPreference, look_and_feel);
-                       flush_preferences();
-                       for (MicroUIListener l : ui_listeners)
-                               l.ui_changed(look_and_feel);
-               }
-       }
-
-       public static String look_and_feel() {
-               synchronized (backend) {
-                       return look_and_feel;
-               }
-       }
-
-       public static void register_ui_listener(MicroUIListener l) {
-               synchronized(backend) {
-                       ui_listeners.add(l);
-               }
-       }
-
-       public static void unregister_ui_listener(MicroUIListener l) {
-               synchronized (backend) {
-                       ui_listeners.remove(l);
-               }
-       }
-       public static void set_serial_debug(boolean new_serial_debug) {
-               synchronized (backend) {
-                       serial_debug = new_serial_debug;
-                       backend.putBoolean(serialDebugPreference, serial_debug);
-                       flush_preferences();
-               }
-       }
-
-       public static boolean serial_debug() {
-               synchronized (backend) {
-                       return serial_debug;
-               }
-       }
-
-}
diff --git a/micropeak/MicroPreferencesBackend.java b/micropeak/MicroPreferencesBackend.java
deleted file mode 100644 (file)
index 7d92f6b..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright © 2012 Mike Beattie <mike@ethernal.org>
- *
- * 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 org.altusmetrum.micropeak;
-
-import java.io.File;
-import java.util.prefs.*;
-import org.altusmetrum.AltosLib.*;
-import javax.swing.filechooser.FileSystemView;
-
-public class MicroPreferencesBackend implements AltosPreferencesBackend {
-
-       private Preferences _preferences = null;
-       
-       public MicroPreferencesBackend() {
-               _preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
-       }
-
-       public MicroPreferencesBackend(Preferences in_preferences) {
-               _preferences = in_preferences;
-       }
-
-       public String  getString(String key, String def) {
-               return _preferences.get(key, def);
-       }
-       public void    putString(String key, String value) {
-               _preferences.put(key, value);
-       }
-
-       public int     getInt(String key, int def) {
-               return _preferences.getInt(key, def);
-       }
-       public void    putInt(String key, int value) {
-               _preferences.putInt(key, value);
-       }
-
-       public double  getDouble(String key, double def) {
-               return _preferences.getDouble(key, def);
-       }
-       public void    putDouble(String key, double value) {
-               _preferences.putDouble(key, value);
-       }
-
-       public boolean getBoolean(String key, boolean def) {
-               return _preferences.getBoolean(key, def);
-       }
-       public void    putBoolean(String key, boolean value) {
-               _preferences.putBoolean(key, value);
-       }
-
-       public boolean nodeExists(String key) {
-               try {
-                       return _preferences.nodeExists(key);
-               } catch (BackingStoreException be) {
-                       return false;
-               }
-       }
-
-       public AltosPreferencesBackend node(String key) {
-               return new MicroPreferencesBackend(_preferences.node(key));
-       }
-
-       public String[] keys() {
-               try {
-                       return _preferences.keys();
-               } catch (BackingStoreException be) {
-                       return null;
-               }
-       }
-
-       public void remove(String key) {
-               _preferences.remove(key);
-       }
-
-       public void    flush() {
-               try {
-                       _preferences.flush();
-               } catch (BackingStoreException ee) {
-                       System.err.printf("Cannot save preferences\n");
-               }
-       }
-
-       public File homeDirectory() {
-               /* Use the file system view default directory */
-               return FileSystemView.getFileSystemView().getDefaultDirectory();
-       }
-}
index 8546276ed9dcc7c79e66cc2241f53d6ab5b46237..a1a77a1d5b3b5516f877108f4eea886737a9733d 100644 (file)
  */
 
 package org.altusmetrum.micropeak;
+
 import java.util.*;
 import java.io.*;
 import libaltosJNI.*;
+import org.altusmetrum.altosuilib.*;
 
 public class MicroSerial extends InputStream {
        SWIGTYPE_p_altos_file   file;
 
        public int read() {
                int     c = libaltos.altos_getchar(file, 0);
-               if (MicroPreferences.serial_debug)
+               if (AltosUIPreferences.serial_debug)
                        System.out.printf("%c", c);
                return c;
        }
diff --git a/micropeak/MicroUIListener.java b/micropeak/MicroUIListener.java
deleted file mode 100644 (file)
index 9aed8da..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 org.altusmetrum.micropeak;
-
-public interface MicroUIListener {
-       public void ui_changed(String look_and_feel);
-}