summaryrefslogtreecommitdiff
path: root/altosuilib
diff options
context:
space:
mode:
Diffstat (limited to 'altosuilib')
-rw-r--r--altosuilib/AltosFreqList.java206
-rw-r--r--altosuilib/AltosUIFreqList.java85
-rw-r--r--altosuilib/AltosUITelemetryList.java47
-rw-r--r--altosuilib/AltosUITelemetryMenu.java88
-rw-r--r--altosuilib/Makefile.am4
5 files changed, 134 insertions, 296 deletions
diff --git a/altosuilib/AltosFreqList.java b/altosuilib/AltosFreqList.java
deleted file mode 100644
index 293ce032..00000000
--- a/altosuilib/AltosFreqList.java
+++ /dev/null
@@ -1,206 +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.altosuilib_3;
-
-import java.util.*;
-import javax.swing.*;
-import java.awt.event.*;
-import org.altusmetrum.altoslib_5.*;
-
-class FreqEntry extends JMenuItem {
- AltosFrequency frequency;
-
- public FreqEntry(AltosFrequency frequency) {
- super(frequency.toShortString());
- this.frequency = frequency;
- }
-}
-
-public class AltosFreqList extends JMenu implements ActionListener {
-
- String product;
- int serial;
- int calibrate;
-
- AltosFrequency[] frequencies = new AltosFrequency[0];
-
- int selected = -1;
-
- LinkedList<ActionListener> action_listeners = new LinkedList<ActionListener>();
-
- public void addActionListener(ActionListener listener) {
- action_listeners.add(listener);
- }
-
- public void removeActionListener(ActionListener listener) {
- action_listeners.remove(listener);
- }
-
- public void actionPerformed(ActionEvent ev) {
- FreqEntry e = (FreqEntry) ev.getSource();
- set_selected(e.frequency);
- ActionEvent event = new ActionEvent(e.frequency, 0, "selected");
- for (ActionListener l : action_listeners)
- l.actionPerformed(event);
- }
-
- boolean label = true;
-
- public void set_label(boolean label) {
- this.label = label;
- set_label();
- }
-
- private void set_label() {
- String new_text = "";
- if (0 <= selected && selected < frequencies.length) {
- AltosFrequency frequency = frequencies[selected];
- new_text = String.format("%s%7.3f MHz (%s) ▾",
- label ? "Frequency: " : "",
- frequency.frequency,
- frequency.description);
- }
- setText(new_text);
- }
-
- private void set_selected(AltosFrequency frequency) {
- for (int i = 0; i < frequencies.length; i++) {
- if (frequencies[i].frequency == frequency.frequency) {
- selected = i;
- set_label();
- }
- }
- }
-
- private AltosFrequency get_selected() {
- if (0 <= selected && selected < frequencies.length)
- return frequencies[selected];
- return null;
- }
-
- private void add(AltosFrequency add) {
- int insert;
-
- for (insert = 0; insert < frequencies.length; insert++) {
- if (frequencies[insert].frequency == add.frequency)
- return;
- if (add.frequency < frequencies[insert].frequency)
- break;
- }
-
- AltosFrequency[] new_frequencies = new AltosFrequency[frequencies.length + 1];
-
- for (int before = 0; before < insert; before++)
- new_frequencies[before] = frequencies[before];
- new_frequencies[insert] = add;
-
- for (int after = insert; after < frequencies.length; after++)
- new_frequencies[after+1] = frequencies[after];
-
- frequencies = new_frequencies;
-
- FreqEntry e = new FreqEntry(add);
- add(e, insert);
- e.addActionListener(this);
- }
-
- private void remove(AltosFrequency remove) {
- int delete;
- for (delete = 0; delete < frequencies.length; delete++) {
- if (frequencies[delete].frequency == remove.frequency)
- break;
- if (remove.frequency < frequencies[delete].frequency)
- return;
- }
-
- remove(delete);
-
- AltosFrequency[] new_frequencies = new AltosFrequency[frequencies.length - 1];
-
- for (int before = 0; before < delete; before++)
- new_frequencies[before] = frequencies[before];
-
- for (int after = delete + 1; after < frequencies.length; after++)
- new_frequencies[after-1] = frequencies[after];
- frequencies = new_frequencies;
- }
-
- public void set_frequency(double new_frequency) {
- int i;
-
- if (new_frequency < 0) {
- setVisible(false);
- return;
- }
-
- for (i = 0; i < frequencies.length; i++) {
- AltosFrequency f = frequencies[i];
-
- if (f.close(new_frequency)) {
- set_selected(f);
- return;
- }
- }
-
- String description = String.format("%s serial %d", product, serial);
- AltosFrequency frequency = new AltosFrequency(new_frequency, description);
- AltosUIPreferences.add_common_frequency(frequency);
-
- add(frequency);
- set_selected(frequency);
- }
-
- public void set_product(String new_product) {
- product = new_product;
- }
-
- public void set_serial(int new_serial) {
- serial = new_serial;
- }
-
- public double frequency() {
- AltosFrequency f = get_selected();
- if (f != null)
- return f.frequency;
- return 434.550;
- }
-
- public AltosFreqList(double in_frequency, boolean label) {
- super();
- this.label = label;
-
- for (AltosFrequency frequency: AltosUIPreferences.common_frequencies())
- add(frequency);
- product = "Unknown";
- serial = 0;
-
- if (in_frequency != 0)
- set_frequency(in_frequency);
- }
- public AltosFreqList(double in_frequency) {
- this(in_frequency, true);
- }
-
- public AltosFreqList (boolean label) {
- this(0, label);
- }
-
- public AltosFreqList () {
- this(0, true);
- }
-}
diff --git a/altosuilib/AltosUIFreqList.java b/altosuilib/AltosUIFreqList.java
new file mode 100644
index 00000000..f1f83dd5
--- /dev/null
+++ b/altosuilib/AltosUIFreqList.java
@@ -0,0 +1,85 @@
+/*
+ * 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_3;
+
+import javax.swing.*;
+import org.altusmetrum.altoslib_5.*;
+
+public class AltosUIFreqList extends JComboBox<AltosFrequency> {
+
+ String product;
+ int serial;
+ int calibrate;
+
+ public void set_frequency(double new_frequency) {
+ int i;
+
+ if (new_frequency < 0) {
+ setVisible(false);
+ return;
+ }
+
+ for (i = 0; i < getItemCount(); i++) {
+ AltosFrequency f = (AltosFrequency) getItemAt(i);
+
+ if (f.close(new_frequency)) {
+ setSelectedIndex(i);
+ return;
+ }
+ }
+ for (i = 0; i < getItemCount(); i++) {
+ AltosFrequency f = (AltosFrequency) getItemAt(i);
+
+ if (new_frequency < f.frequency)
+ break;
+ }
+ String description = String.format("%s serial %d", product, serial);
+ AltosFrequency frequency = new AltosFrequency(new_frequency, description);
+ AltosUIPreferences.add_common_frequency(frequency);
+ insertItemAt(frequency, i);
+ setMaximumRowCount(getItemCount());
+ }
+
+ public void set_product(String new_product) {
+ product = new_product;
+ }
+
+ public void set_serial(int new_serial) {
+ serial = new_serial;
+ }
+
+ public double frequency() {
+ AltosFrequency f = (AltosFrequency) getSelectedItem();
+ if (f != null)
+ return f.frequency;
+ return 434.550;
+ }
+
+ public AltosUIFreqList () {
+ super(AltosUIPreferences.common_frequencies());
+ setMaximumRowCount(getItemCount());
+ setEditable(false);
+ product = "Unknown";
+ serial = 0;
+ }
+
+ public AltosUIFreqList(double in_frequency) {
+ this();
+ set_frequency(in_frequency);
+ }
+}
diff --git a/altosuilib/AltosUITelemetryList.java b/altosuilib/AltosUITelemetryList.java
new file mode 100644
index 00000000..facfdcde
--- /dev/null
+++ b/altosuilib/AltosUITelemetryList.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2014 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_3;
+
+import java.util.*;
+import javax.swing.*;
+import org.altusmetrum.altoslib_5.*;
+
+
+public class AltosUITelemetryList extends JComboBox<String> {
+ public int get_selected() {
+ return getSelectedIndex() + 1;
+ }
+
+ public void set_selected(int telemetry) {
+ setSelectedIndex(telemetry-1);
+ }
+
+ public AltosUITelemetryList(int serial) {
+ super();
+ for (int i = AltosLib.ao_telemetry_min; i <= AltosLib.ao_telemetry_max; i++)
+ addItem(AltosLib.telemetry_name(i));
+
+ int telemetry = AltosPreferences.telemetry(serial);
+ if (telemetry < AltosLib.ao_telemetry_min || AltosLib.ao_telemetry_max < telemetry)
+ telemetry = AltosLib.ao_telemetry_standard;
+ setMaximumRowCount(AltosLib.ao_telemetry_max);
+ set_selected(telemetry);
+ revalidate();
+ }
+}
+
diff --git a/altosuilib/AltosUITelemetryMenu.java b/altosuilib/AltosUITelemetryMenu.java
deleted file mode 100644
index 893c3c44..00000000
--- a/altosuilib/AltosUITelemetryMenu.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright © 2014 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_3;
-
-import java.util.*;
-import javax.swing.*;
-import java.awt.event.*;
-import org.altusmetrum.altoslib_5.*;
-
-class TelemetryMenuItem extends JMenuItem {
- public int telemetry;
-
- public TelemetryMenuItem (int telemetry) {
- super(AltosLib.telemetry_name(telemetry));
- this.telemetry = telemetry;
- }
-}
-
-public class AltosUITelemetryMenu extends JMenu implements ActionListener {
- TelemetryMenuItem selected = null;
-
- public int get_selected() {
- if (selected == null)
- return AltosLib.ao_telemetry_off;
- return selected.telemetry;
- }
-
- public void set_selected(int telemetry) {
- for (int i = 0; i < getItemCount(); i++) {
- TelemetryMenuItem item = (TelemetryMenuItem) getItem(i);
- if (item.telemetry == telemetry) {
- selected = item;
- String new_text = String.format("Format: %s ▾", AltosLib.telemetry_name(telemetry));
- setText(new_text);
- break;
- }
- }
- }
-
- private LinkedList<ActionListener> action_listeners = new LinkedList<ActionListener>();
-
- public void addActionListener(ActionListener l) {
- action_listeners.add(l);
- }
-
- public void removeActionListener(ActionListener l) {
- action_listeners.remove(l);
- }
-
- public void actionPerformed(ActionEvent e) {
- TelemetryMenuItem item = (TelemetryMenuItem) e.getSource();
- set_selected(item.telemetry);
- ActionEvent my_e = new ActionEvent(selected, 0, "selected");
- for (ActionListener l : action_listeners)
- l.actionPerformed(my_e);
- }
-
- public AltosUITelemetryMenu(int serial) {
- super();
- for (int i = AltosLib.ao_telemetry_min; i <= AltosLib.ao_telemetry_max; i++) {
- TelemetryMenuItem item = new TelemetryMenuItem(i);
-
- item.addActionListener(this);
- add(item);
- }
-
- int telemetry = AltosPreferences.telemetry(serial);
- if (telemetry < AltosLib.ao_telemetry_min || AltosLib.ao_telemetry_max < telemetry)
- telemetry = AltosLib.ao_telemetry_standard;
- set_selected(telemetry);
- }
-}
-
diff --git a/altosuilib/Makefile.am b/altosuilib/Makefile.am
index 56b01ec5..40e6dda5 100644
--- a/altosuilib/Makefile.am
+++ b/altosuilib/Makefile.am
@@ -36,7 +36,6 @@ altosuilib_JAVA = \
AltosVoice.java \
AltosDisplayThread.java \
AltosDeviceUIDialog.java \
- AltosFreqList.java \
AltosSerial.java \
AltosSerialInUseException.java \
AltosConfigFreqUI.java \
@@ -82,7 +81,8 @@ altosuilib_JAVA = \
AltosUIIndicator.java \
AltosUIUnitsIndicator.java \
AltosUIVoltageIndicator.java \
- AltosUITelemetryMenu.java \
+ AltosUIFreqList.java \
+ AltosUITelemetryList.java \
OSXAdapter.java
JAR=altosuilib_$(ALTOSUILIB_VERSION).jar