summaryrefslogtreecommitdiff
path: root/altosuilib
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-01-10 21:48:12 -0800
committerKeith Packard <keithp@keithp.com>2013-01-10 21:48:12 -0800
commit1ed6b13e87c1cc2d6618b6ba3a293ea6e3b5752e (patch)
tree10adf6f3c6b6c1ed2bf7540a9972fe72253cfa81 /altosuilib
parentacff2f466031fd1a8533fc315411c3734a8bacc6 (diff)
parentd409417ff8e9ed9d406bf1c04542a4ecb574768b (diff)
Merge remote-tracking branch 'origin/micropeak-logging'
Diffstat (limited to 'altosuilib')
-rw-r--r--altosuilib/AltosDevice.java30
-rw-r--r--altosuilib/AltosDeviceDialog.java160
-rw-r--r--altosuilib/AltosFontListener.java22
-rw-r--r--altosuilib/AltosUIConfigure.java274
-rw-r--r--altosuilib/AltosUIDialog.java59
-rw-r--r--altosuilib/AltosUIFrame.java82
-rw-r--r--altosuilib/AltosUILib.java93
-rw-r--r--altosuilib/AltosUIListener.java22
-rw-r--r--altosuilib/AltosUIPreferences.java180
-rw-r--r--altosuilib/AltosUIPreferencesBackend.java101
-rw-r--r--altosuilib/AltosUIVersion.java.in22
-rw-r--r--altosuilib/AltosUSBDevice.java112
-rw-r--r--altosuilib/AltosUnitsListener.java22
-rw-r--r--altosuilib/Makefile.am43
14 files changed, 1222 insertions, 0 deletions
diff --git a/altosuilib/AltosDevice.java b/altosuilib/AltosDevice.java
new file mode 100644
index 00000000..69b025ba
--- /dev/null
+++ b/altosuilib/AltosDevice.java
@@ -0,0 +1,30 @@
+/*
+ * 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.altosuilib;
+
+import libaltosJNI.*;
+
+public interface AltosDevice {
+ public abstract String toString();
+ public abstract String toShortString();
+ public abstract int getSerial();
+ public abstract String getPath();
+ public abstract boolean matchProduct(int product);
+ public abstract String getErrorString();
+ public SWIGTYPE_p_altos_file open();
+}
diff --git a/altosuilib/AltosDeviceDialog.java b/altosuilib/AltosDeviceDialog.java
new file mode 100644
index 00000000..cde545a7
--- /dev/null
+++ b/altosuilib/AltosDeviceDialog.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright © 2010 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.altosuilib;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+public abstract class AltosDeviceDialog extends AltosUIDialog implements ActionListener {
+
+ private AltosDevice value;
+ private JList list;
+ private JButton cancel_button;
+ private JButton select_button;
+ public Frame frame;
+ public int product;
+ public JPanel buttonPane;
+
+ public AltosDevice getValue() {
+ return value;
+ }
+
+ public abstract AltosDevice[] devices();
+
+ public void update_devices() {
+ AltosDevice[] devices = devices();
+ list.setListData(devices);
+ select_button.setEnabled(devices.length > 0);
+ }
+
+ public void add_bluetooth() { }
+
+ public AltosDeviceDialog (Frame in_frame, Component location, int in_product) {
+ super(in_frame, "Device Selection", true);
+
+ product = in_product;
+ frame = in_frame;
+ value = null;
+
+ AltosDevice[] devices = devices();
+
+ cancel_button = new JButton("Cancel");
+ cancel_button.setActionCommand("cancel");
+ cancel_button.addActionListener(this);
+
+ select_button = new JButton("Select");
+ select_button.setActionCommand("select");
+ select_button.addActionListener(this);
+ if (devices.length == 0)
+ select_button.setEnabled(false);
+ getRootPane().setDefaultButton(select_button);
+
+ list = new JList(devices) {
+ //Subclass JList to workaround bug 4832765, which can cause the
+ //scroll pane to not let the user easily scroll up to the beginning
+ //of the list. An alternative would be to set the unitIncrement
+ //of the JScrollBar to a fixed value. You wouldn't get the nice
+ //aligned scrolling, but it should work.
+ public int getScrollableUnitIncrement(Rectangle visibleRect,
+ int orientation,
+ int direction) {
+ int row;
+ if (orientation == SwingConstants.VERTICAL &&
+ direction < 0 && (row = getFirstVisibleIndex()) != -1) {
+ Rectangle r = getCellBounds(row, row);
+ if ((r.y == visibleRect.y) && (row != 0)) {
+ Point loc = r.getLocation();
+ loc.y--;
+ int prevIndex = locationToIndex(loc);
+ Rectangle prevR = getCellBounds(prevIndex, prevIndex);
+
+ if (prevR == null || prevR.y >= r.y) {
+ return 0;
+ }
+ return prevR.height;
+ }
+ }
+ return super.getScrollableUnitIncrement(
+ visibleRect, orientation, direction);
+ }
+ };
+
+ list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
+ list.setVisibleRowCount(-1);
+ list.addMouseListener(new MouseAdapter() {
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 2) {
+ select_button.doClick(); //emulate button click
+ }
+ }
+ });
+ JScrollPane listScroller = new JScrollPane(list);
+ listScroller.setPreferredSize(new Dimension(400, 80));
+ listScroller.setAlignmentX(LEFT_ALIGNMENT);
+
+ //Create a container so that we can add a title around
+ //the scroll pane. Can't add a title directly to the
+ //scroll pane because its background would be white.
+ //Lay out the label and scroll pane from top to bottom.
+ JPanel listPane = new JPanel();
+ listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
+
+ JLabel label = new JLabel("Select Device");
+ label.setLabelFor(list);
+ listPane.add(label);
+ listPane.add(Box.createRigidArea(new Dimension(0,5)));
+ listPane.add(listScroller);
+ listPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
+
+ //Lay out the buttons from left to right.
+ buttonPane = new JPanel();
+ buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
+ buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
+ buttonPane.add(Box.createHorizontalGlue());
+ buttonPane.add(cancel_button);
+ buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
+
+ add_bluetooth();
+
+ buttonPane.add(select_button);
+
+ //Put everything together, using the content pane's BorderLayout.
+ Container contentPane = getContentPane();
+ contentPane.add(listPane, BorderLayout.CENTER);
+ contentPane.add(buttonPane, BorderLayout.PAGE_END);
+
+ //Initialize values.
+ if (devices != null && devices.length != 0)
+ list.setSelectedValue(devices[0], true);
+ pack();
+ setLocationRelativeTo(location);
+ }
+
+ //Handle clicks on the Set and Cancel buttons.
+ public void actionPerformed(ActionEvent e) {
+ if ("select".equals(e.getActionCommand())) {
+ value = (AltosDevice)(list.getSelectedValue());
+ setVisible(false);
+ }
+ if ("cancel".equals(e.getActionCommand()))
+ setVisible(false);
+ }
+
+}
diff --git a/altosuilib/AltosFontListener.java b/altosuilib/AltosFontListener.java
new file mode 100644
index 00000000..ef543264
--- /dev/null
+++ b/altosuilib/AltosFontListener.java
@@ -0,0 +1,22 @@
+/*
+ * 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.altosuilib;
+
+public interface AltosFontListener {
+ void font_size_changed(int font_size);
+}
diff --git a/altosuilib/AltosUIConfigure.java b/altosuilib/AltosUIConfigure.java
new file mode 100644
index 00000000..6c9a841e
--- /dev/null
+++ b/altosuilib/AltosUIConfigure.java
@@ -0,0 +1,274 @@
+/*
+ * Copyright © 2010 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.altosuilib;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.beans.*;
+import javax.swing.*;
+import javax.swing.event.*;
+
+class DelegatingRenderer implements ListCellRenderer {
+
+ // ...
+ public static void install(JComboBox comboBox) {
+ DelegatingRenderer renderer = new DelegatingRenderer(comboBox);
+ renderer.initialise();
+ comboBox.setRenderer(renderer);
+ }
+
+ // ...
+ private final JComboBox comboBox;
+
+ // ...
+ private ListCellRenderer delegate;
+
+ // ...
+ private DelegatingRenderer(JComboBox comboBox) {
+ this.comboBox = comboBox;
+ }
+
+ // ...
+ private void initialise() {
+ delegate = new JComboBox().getRenderer();
+ comboBox.addPropertyChangeListener("UI", new PropertyChangeListener() {
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ delegate = new JComboBox().getRenderer();
+ }
+ });
+ }
+
+ // ...
+ public Component getListCellRendererComponent(JList list,
+ Object value, int index, boolean isSelected, boolean cellHasFocus) {
+
+ return delegate.getListCellRendererComponent(list,
+ ((UIManager.LookAndFeelInfo) value).getName(),
+ index, isSelected, cellHasFocus);
+ }
+}
+
+public class AltosUIConfigure
+ extends AltosUIDialog
+{
+ public JFrame owner;
+ public Container pane;
+
+ public int row;
+
+ final static String[] font_size_names = { "Small", "Medium", "Large" };
+
+ public GridBagConstraints constraints (int x, int width, int fill) {
+ GridBagConstraints c = new GridBagConstraints();
+ Insets insets = new Insets(4, 4, 4, 4);
+
+ c.insets = insets;
+ c.fill = fill;
+ if (width == 3)
+ c.anchor = GridBagConstraints.CENTER;
+ else if (x == 2)
+ c.anchor = GridBagConstraints.EAST;
+ else
+ c.anchor = GridBagConstraints.WEST;
+ c.gridx = x;
+ c.gridwidth = width;
+ c.gridy = row;
+ return c;
+ }
+
+ public GridBagConstraints constraints(int x, int width) {
+ return constraints(x, width, GridBagConstraints.NONE);
+ }
+
+ public void add_voice() {
+ }
+
+ public void add_log_dir() {
+ /* Log directory settings */
+ pane.add(new JLabel("Log Directory"), constraints(0, 1));
+
+ final JButton configure_log = new JButton(AltosUIPreferences.logdir().getPath());
+ configure_log.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ AltosUIPreferences.ConfigureLog();
+ configure_log.setText(AltosUIPreferences.logdir().getPath());
+ }
+ });
+ pane.add(configure_log, constraints(1, 2));
+ configure_log.setToolTipText("Which directory flight logs are stored in");
+ row++;
+ }
+
+ public void add_callsign() {
+ }
+
+ public void add_units() {
+ /* Imperial units setting */
+ pane.add(new JLabel("Imperial Units"), constraints(0, 1));
+
+ JRadioButton imperial_units = new JRadioButton("Enable", AltosUIPreferences.imperial_units());
+ imperial_units.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ JRadioButton item = (JRadioButton) e.getSource();
+ boolean enabled = item.isSelected();
+ AltosUIPreferences.set_imperial_units(enabled);
+ }
+ });
+ imperial_units.setToolTipText("Use Imperial units instead of metric");
+ pane.add(imperial_units, constraints(1, 2));
+ row++;
+ }
+
+ public void add_font_size() {
+ /* Font size setting */
+ pane.add(new JLabel("Font size"), constraints(0, 1));
+
+ final JComboBox font_size_value = new JComboBox(font_size_names);
+ int font_size = AltosUIPreferences.font_size();
+ font_size_value.setSelectedIndex(font_size - AltosUILib.font_size_small);
+ font_size_value.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ int size = font_size_value.getSelectedIndex() + AltosUILib.font_size_small;
+
+ AltosUIPreferences.set_font_size(size);
+ }
+ });
+ pane.add(font_size_value, constraints(1, 2, GridBagConstraints.BOTH));
+ font_size_value.setToolTipText("Font size used in telemetry window");
+ row++;
+ }
+
+ public void add_look_and_feel() {
+ /* Look & Feel setting */
+ pane.add(new JLabel("Look & feel"), constraints(0, 1));
+
+ /*
+ class LookAndFeelRenderer extends BasicComboBoxRenderer implements ListCellRenderer {
+
+ public LookAndFeelRenderer() {
+ super();
+ }
+
+ public Component getListCellRendererComponent(
+ JList list,
+ Object value,
+ int index,
+ boolean isSelected,
+ boolean cellHasFocus)
+ {
+ super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+ setText(((UIManager.LookAndFeelInfo) value).getName());
+ return this;
+ }
+ }
+ */
+
+ final UIManager.LookAndFeelInfo[] look_and_feels = UIManager.getInstalledLookAndFeels();
+
+ final JComboBox look_and_feel_value = new JComboBox(look_and_feels);
+
+ DelegatingRenderer.install(look_and_feel_value);
+
+ 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);
+
+ look_and_feel_value.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ int id = look_and_feel_value.getSelectedIndex();
+
+ AltosUIPreferences.set_look_and_feel(look_and_feels[id].getClassName());
+ }
+ });
+ pane.add(look_and_feel_value, constraints(1, 2, GridBagConstraints.BOTH));
+ look_and_feel_value.setToolTipText("Look&feel used for new windows");
+ row++;
+ }
+
+ public void add_serial_debug() {
+ GridBagConstraints c = new GridBagConstraints();
+
+ /* Serial debug setting */
+ pane.add(new JLabel("Serial Debug"), constraints(0, 1));
+
+ JRadioButton 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();
+ AltosUIPreferences.set_serial_debug(enabled);
+ }
+ });
+ serial_debug.setToolTipText("Enable/Disable USB I/O getting sent to the console");
+ c.gridx = 1;
+ c.gridy = row++;
+ c.gridwidth = 3;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.WEST;
+ pane.add(serial_debug, c);
+ }
+
+ public void add_bluetooth() {
+ }
+
+ public void add_frequencies() {
+ }
+
+ public AltosUIConfigure(JFrame in_owner) {
+ super(in_owner, "Configure AltosUI", false);
+
+ owner = in_owner;
+ pane = getContentPane();
+ pane.setLayout(new GridBagLayout());
+
+ row = 0;
+
+ /* Nice label at the top */
+ pane.add(new JLabel ("Configure AltOS UI"),
+ constraints(0, 3));
+ row++;
+
+ pane.add(new JLabel (String.format("AltOS version %s", AltosUIVersion.version)),
+ constraints(0, 3));
+ row++;
+
+ add_voice();
+ add_log_dir();
+ add_callsign();
+ add_units();
+ add_font_size();
+ add_look_and_feel();
+ add_bluetooth();
+ add_frequencies();
+
+ /* And a close button at the bottom */
+ JButton close = new JButton("Close");
+ close.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ setVisible(false);
+ }
+ });
+ pane.add(close, constraints(0, 3));
+
+ pack();
+ setLocationRelativeTo(owner);
+ setVisible(true);
+ }
+}
diff --git a/altosuilib/AltosUIDialog.java b/altosuilib/AltosUIDialog.java
new file mode 100644
index 00000000..c0c33ba6
--- /dev/null
+++ b/altosuilib/AltosUIDialog.java
@@ -0,0 +1,59 @@
+/*
+ * 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.altosuilib;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+class AltosUIDialogListener extends WindowAdapter {
+ public void windowClosing (WindowEvent e) {
+ AltosUIPreferences.unregister_ui_listener((AltosUIDialog) e.getWindow());
+ }
+}
+
+public class AltosUIDialog extends JDialog implements AltosUIListener {
+
+ public void ui_changed(String look_and_feel) {
+ SwingUtilities.updateComponentTreeUI(this);
+ this.pack();
+ }
+
+ public AltosUIDialog() {
+ AltosUIPreferences.register_ui_listener(this);
+ addWindowListener(new AltosUIDialogListener());
+ }
+
+ public AltosUIDialog(Frame frame, String label, boolean modal) {
+ super(frame, label, modal);
+ AltosUIPreferences.register_ui_listener(this);
+ addWindowListener(new AltosUIDialogListener());
+ }
+
+ public AltosUIDialog(Dialog dialog, String label, boolean modal) {
+ super(dialog, label, modal);
+ AltosUIPreferences.register_ui_listener(this);
+ addWindowListener(new AltosUIDialogListener());
+ }
+
+ public AltosUIDialog(Frame frame, boolean modal) {
+ super(frame, modal);
+ AltosUIPreferences.register_ui_listener(this);
+ addWindowListener(new AltosUIDialogListener());
+ }
+}
diff --git a/altosuilib/AltosUIFrame.java b/altosuilib/AltosUIFrame.java
new file mode 100644
index 00000000..409aea2e
--- /dev/null
+++ b/altosuilib/AltosUIFrame.java
@@ -0,0 +1,82 @@
+/*
+ * 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.altosuilib;
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import java.util.*;
+
+class AltosUIFrameListener extends WindowAdapter {
+ public void windowClosing (WindowEvent e) {
+ AltosUIPreferences.unregister_ui_listener((AltosUIFrame) e.getWindow());
+ }
+}
+
+public class AltosUIFrame extends JFrame implements AltosUIListener {
+
+ public void ui_changed(String look_and_feel) {
+ SwingUtilities.updateComponentTreeUI(this);
+ this.pack();
+ }
+
+ static String[] altos_icon_names = {
+ "/altus-metrum-16.png",
+ "/altus-metrum-32.png",
+ "/altus-metrum-48.png",
+ "/altus-metrum-64.png",
+ "/altus-metrum-128.png",
+ "/altus-metrum-256.png"
+ };
+
+ static public String[] icon_names;
+
+ static public void set_icon_names(String[] new_icon_names) { icon_names = new_icon_names; }
+
+ public String[] icon_names() {
+ if (icon_names == null)
+ set_icon_names(altos_icon_names);
+ return icon_names;
+ }
+
+ public void set_icon() {
+ ArrayList<Image> icons = new ArrayList<Image>();
+ String[] icon_names = icon_names();
+
+ for (int i = 0; i < icon_names.length; i++) {
+ java.net.URL imgURL = AltosUIFrame.class.getResource(icon_names[i]);
+ if (imgURL != null)
+ icons.add(new ImageIcon(imgURL).getImage());
+ }
+ setIconImages(icons);
+ }
+
+
+ public AltosUIFrame() {
+ AltosUIPreferences.register_ui_listener(this);
+ addWindowListener(new AltosUIFrameListener());
+ set_icon();
+ }
+
+ public AltosUIFrame(String name) {
+ super(name);
+ AltosUIPreferences.register_ui_listener(this);
+ addWindowListener(new AltosUIFrameListener());
+ set_icon();
+ }
+}
diff --git a/altosuilib/AltosUILib.java b/altosuilib/AltosUILib.java
new file mode 100644
index 00000000..5d5f9aaa
--- /dev/null
+++ b/altosuilib/AltosUILib.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright © 2010 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.altosuilib;
+
+import java.awt.*;
+import libaltosJNI.*;
+
+import org.altusmetrum.AltosLib.*;
+
+public class AltosUILib extends AltosLib {
+
+ public static final int tab_elt_pad = 5;
+
+ public static Font label_font;
+ public static Font value_font;
+ public static Font status_font;
+ public static Font table_label_font;
+ public static Font table_value_font;
+
+ final public static int font_size_small = 1;
+ final public static int font_size_medium = 2;
+ final public 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);
+ }
+
+ static final int text_width = 20;
+
+ static public boolean initialized = false;
+ static public boolean loaded_library = false;
+
+ public static boolean load_library() {
+ if (!initialized) {
+ try {
+ System.loadLibrary("altos");
+ libaltos.altos_init();
+ loaded_library = true;
+ } catch (UnsatisfiedLinkError e) {
+ try {
+ System.loadLibrary("altos64");
+ libaltos.altos_init();
+ loaded_library = true;
+ } catch (UnsatisfiedLinkError e2) {
+ loaded_library = false;
+ }
+ }
+ initialized = true;
+ }
+ return loaded_library;
+ }
+}
diff --git a/altosuilib/AltosUIListener.java b/altosuilib/AltosUIListener.java
new file mode 100644
index 00000000..f4127f58
--- /dev/null
+++ b/altosuilib/AltosUIListener.java
@@ -0,0 +1,22 @@
+/*
+ * 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.altosuilib;
+
+public interface AltosUIListener {
+ public void ui_changed(String look_and_feel);
+}
diff --git a/altosuilib/AltosUIPreferences.java b/altosuilib/AltosUIPreferences.java
new file mode 100644
index 00000000..485cb582
--- /dev/null
+++ b/altosuilib/AltosUIPreferences.java
@@ -0,0 +1,180 @@
+/*
+ * 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.altosuilib;
+
+import java.io.*;
+import java.util.*;
+import java.awt.Component;
+import javax.swing.*;
+import org.altusmetrum.AltosLib.*;
+
+public 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 = AltosUILib.font_size_medium;
+
+ static LinkedList<AltosUIListener> ui_listeners;
+
+ static String look_and_feel = null;
+
+ /* Serial debug */
+ public static boolean serial_debug;
+
+ public static void init() {
+ AltosPreferences.init(new AltosUIPreferencesBackend());
+
+ font_listeners = new LinkedList<AltosFontListener>();
+
+ font_size = backend.getInt(fontSizePreference, AltosUILib.font_size_medium);
+ AltosUILib.set_fonts(font_size);
+ look_and_feel = backend.getString(lookAndFeelPreference, UIManager.getSystemLookAndFeelClassName());
+
+ ui_listeners = new LinkedList<AltosUIListener>();
+ serial_debug = backend.getBoolean(serialDebugPreference, false);
+ AltosLink.set_debug(serial_debug);
+ }
+
+ static { init(); }
+
+ public 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();
+ AltosUILib.set_fonts(font_size);
+ for (AltosFontListener l : font_listeners)
+ l.font_size_changed(font_size);
+ }
+ }
+
+ public static void register_font_listener(AltosFontListener l) {
+ synchronized (backend) {
+ font_listeners.add(l);
+ }
+ }
+
+ public static void unregister_font_listener(AltosFontListener 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 (AltosUIListener 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(AltosUIListener l) {
+ synchronized(backend) {
+ ui_listeners.add(l);
+ }
+ }
+
+ public static void unregister_ui_listener(AltosUIListener l) {
+ synchronized (backend) {
+ ui_listeners.remove(l);
+ }
+ }
+ public static void set_serial_debug(boolean new_serial_debug) {
+ AltosLink.set_debug(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/altosuilib/AltosUIPreferencesBackend.java b/altosuilib/AltosUIPreferencesBackend.java
new file mode 100644
index 00000000..c6c05e55
--- /dev/null
+++ b/altosuilib/AltosUIPreferencesBackend.java
@@ -0,0 +1,101 @@
+/*
+ * 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.altosuilib;
+
+import java.io.File;
+import java.util.prefs.*;
+import org.altusmetrum.AltosLib.*;
+import javax.swing.filechooser.FileSystemView;
+
+public class AltosUIPreferencesBackend implements AltosPreferencesBackend {
+
+ private Preferences _preferences = null;
+
+ public AltosUIPreferencesBackend() {
+ _preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
+ }
+
+ public AltosUIPreferencesBackend(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 AltosUIPreferencesBackend(_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();
+ }
+}
diff --git a/altosuilib/AltosUIVersion.java.in b/altosuilib/AltosUIVersion.java.in
new file mode 100644
index 00000000..6fb3b38b
--- /dev/null
+++ b/altosuilib/AltosUIVersion.java.in
@@ -0,0 +1,22 @@
+/*
+ * 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.altosuilib;
+
+public class AltosUIVersion {
+ public final static String version = "@VERSION@";
+}
diff --git a/altosuilib/AltosUSBDevice.java b/altosuilib/AltosUSBDevice.java
new file mode 100644
index 00000000..bab16fb0
--- /dev/null
+++ b/altosuilib/AltosUSBDevice.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright © 2010 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.altosuilib;
+
+import java.util.*;
+import libaltosJNI.*;
+
+public class AltosUSBDevice extends altos_device implements AltosDevice {
+
+ public String toString() {
+ String name = getName();
+ if (name == null)
+ name = "Altus Metrum";
+ return String.format("%-20.20s %4d %s",
+ name, getSerial(), getPath());
+ }
+
+ public String toShortString() {
+ String name = getName();
+ if (name == null)
+ name = "Altus Metrum";
+ return String.format("%s %d %s",
+ name, getSerial(), getPath());
+
+ }
+
+ public String getErrorString() {
+ altos_error error = new altos_error();
+
+ libaltos.altos_get_last_error(error);
+ return String.format("%s (%d)", error.getString(), error.getCode());
+ }
+
+ public SWIGTYPE_p_altos_file open() {
+ return libaltos.altos_open(this);
+ }
+
+ public boolean isAltusMetrum() {
+ if (getVendor() != AltosUILib.vendor_altusmetrum)
+ return false;
+ if (getProduct() < AltosUILib.product_altusmetrum_min)
+ return false;
+ if (getProduct() > AltosUILib.product_altusmetrum_max)
+ return false;
+ return true;
+ }
+
+ public boolean matchProduct(int want_product) {
+
+ if (!isAltusMetrum())
+ return false;
+
+ if (want_product == AltosUILib.product_any)
+ return true;
+
+ if (want_product == AltosUILib.product_basestation)
+ return matchProduct(AltosUILib.product_teledongle) ||
+ matchProduct(AltosUILib.product_teleterra) ||
+ matchProduct(AltosUILib.product_telebt) ||
+ matchProduct(AltosUILib.product_megadongle);
+
+ if (want_product == AltosUILib.product_altimeter)
+ return matchProduct(AltosUILib.product_telemetrum) ||
+ matchProduct(AltosUILib.product_megametrum);
+
+ int have_product = getProduct();
+
+ if (have_product == AltosUILib.product_altusmetrum) /* old devices match any request */
+ return true;
+
+ if (want_product == have_product)
+ return true;
+
+ return false;
+ }
+
+ static public java.util.List<AltosDevice> list(int product) {
+ if (!AltosUILib.load_library())
+ return null;
+
+ SWIGTYPE_p_altos_list list = libaltos.altos_list_start();
+
+ ArrayList<AltosDevice> device_list = new ArrayList<AltosDevice>();
+ if (list != null) {
+ for (;;) {
+ AltosUSBDevice device = new AltosUSBDevice();
+ if (libaltos.altos_list_next(list, device) == 0)
+ break;
+ if (device.matchProduct(product))
+ device_list.add(device);
+ }
+ libaltos.altos_list_finish(list);
+ }
+
+ return device_list;
+ }
+} \ No newline at end of file
diff --git a/altosuilib/AltosUnitsListener.java b/altosuilib/AltosUnitsListener.java
new file mode 100644
index 00000000..22c66cd4
--- /dev/null
+++ b/altosuilib/AltosUnitsListener.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright © 2012 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.altosuilib;
+
+public interface AltosUnitsListener {
+ public void units_changed();
+}
diff --git a/altosuilib/Makefile.am b/altosuilib/Makefile.am
new file mode 100644
index 00000000..da5fb848
--- /dev/null
+++ b/altosuilib/Makefile.am
@@ -0,0 +1,43 @@
+AM_JAVACFLAGS=-encoding UTF-8 -Xlint:deprecation
+
+JAVAROOT=bin
+
+CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH="$(JAVAROOT):../altoslib/*:../libaltos:/usr/share/java/*"
+
+SRC=.
+
+altosuilibdir = $(datadir)/java
+
+altosuilib_JAVA = \
+ AltosUIConfigure.java \
+ AltosDevice.java \
+ AltosDeviceDialog.java \
+ AltosUSBDevice.java \
+ AltosFontListener.java \
+ AltosUIDialog.java \
+ AltosUIFrame.java \
+ AltosUILib.java \
+ AltosUIListener.java \
+ AltosUIPreferencesBackend.java \
+ AltosUIPreferences.java \
+ AltosUIVersion.java \
+ AltosUnitsListener.java
+
+JAR=altosuilib.jar
+
+all-local: $(JAR)
+
+clean-local:
+ -rm -rf $(JAVAROOT) $(JAR)
+
+install-altosuilibJAVA: $(JAR)
+ @$(NORMAL_INSTALL)
+ test -z "$(altosuilibdir)" || $(MKDIR_P) "$(DESTDIR)$(altosuilibdir)"
+ echo " $(INSTALL_DATA)" "$(JAR)" "'$(DESTDIR)$(altosuilibdir)/$(JAR)"; \
+ $(INSTALL_DATA) "$(JAR)" "$(DESTDIR)$(altosuilibdir)"
+
+$(JAVAROOT):
+ mkdir -p $(JAVAROOT)
+
+$(JAR): classaltosuilib.stamp
+ jar cf $@ -C $(JAVAROOT) .