JLabel product_value;
JLabel version_value;
JLabel serial_value;
- JMenuBar radio_frequency_menu_bar;
- AltosFreqList radio_frequency_value;
+ AltosUIFreqList radio_frequency_value;
JLabel radio_calibration_value;
JButton save;
ActionListener listener;
-
/* A window listener to catch closing events and tell the config code */
class ConfigListener extends WindowAdapter {
AltosConfigTDUI ui;
c.anchor = GridBagConstraints.LINE_START;
c.insets = ir;
c.ipady = 5;
- radio_frequency_value = new AltosFreqList(false);
+ radio_frequency_value = new AltosUIFreqList();
radio_frequency_value.addItemListener(this);
- radio_frequency_menu_bar = new JMenuBar();
- radio_frequency_menu_bar.add(radio_frequency_value);
- pane.add(radio_frequency_menu_bar, c);
+ pane.add(radio_frequency_value, c);
radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
/* Radio Calibration */
}
public void set_radio_frequency(double new_radio_frequency) {
- radio_frequency_value.set_frequency(new_radio_frequency);
+ int i;
+ for (i = 0; i < radio_frequency_value.getItemCount(); i++) {
+ AltosFrequency f = (AltosFrequency) radio_frequency_value.getItemAt(i);
+
+ if (f.close(new_radio_frequency)) {
+ radio_frequency_value.setSelectedIndex(i);
+ return;
+ }
+ }
+ for (i = 0; i < radio_frequency_value.getItemCount(); i++) {
+ AltosFrequency f = (AltosFrequency) radio_frequency_value.getItemAt(i);
+
+ if (new_radio_frequency < f.frequency)
+ break;
+ }
+ String description = String.format("%s serial %s",
+ product_value.getText(),
+ serial_value.getText());
+ AltosFrequency new_frequency = new AltosFrequency(new_radio_frequency, description);
+ AltosPreferences.add_common_frequency(new_frequency);
+ radio_frequency_value.insertItemAt(new_frequency, i);
+ radio_frequency_value.setSelectedIndex(i);
}
public double radio_frequency() {
JComboBox<String> main_deploy_value;
JComboBox<String> apogee_delay_value;
JComboBox<String> apogee_lockout_value;
- AltosFreqList radio_frequency_value;
+ AltosUIFreqList radio_frequency_value;
JTextField radio_calibration_value;
JRadioButton radio_enable_value;
JComboBox<String> aprs_interval_value;
c.anchor = GridBagConstraints.LINE_START;
c.insets = ir;
c.ipady = 5;
- radio_frequency_value = new AltosFreqList();
+ radio_frequency_value = new AltosUIFreqList();
radio_frequency_value.addItemListener(this);
-
- JMenuBar menu_bar = new JMenuBar();
- menu_bar.add(radio_frequency_value);
- pane.add(menu_bar, c);
+ pane.add(radio_frequency_value, c);
radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
row++;
exit_on_close = true;
}
- Container bag;
-
- JMenuBar menu_bar;
- AltosFreqList frequencies;
- AltosUITelemetryMenu telemetries;
+ Container bag;
+ AltosUIFreqList frequencies;
+ AltosUITelemetryList telemetries;
JLabel telemetry;
ActionListener show_timer;
public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
- super();
-
AltosUIPreferences.set_component(this);
displays = new LinkedList<AltosFlightDisplay>();
/* Stick channel selector at top of table for telemetry monitoring */
if (serial >= 0) {
-
- menu_bar = new JMenuBar();
- setJMenuBar(menu_bar);
-
- // Channel menu
- frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
+ // Frequency menu
+ frequencies = new AltosUIFreqList(AltosUIPreferences.frequency(serial));
frequencies.set_product("Monitor");
frequencies.set_serial(serial);
frequencies.addActionListener(new ActionListener() {
reader.save_frequency();
}
});
- menu_bar.add (frequencies);
-
- // Telemetry format menu
- if (reader.supports_telemetry(AltosLib.ao_telemetry_standard)) {
- telemetries = new AltosUITelemetryMenu(serial);
+ c.gridx = 0;
+ c.gridy = 0;
+ c.weightx = 0;
+ c.weighty = 0;
+ c.insets = new Insets(3, 3, 3, 3);
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.WEST;
+ bag.add (frequencies, c);
+
+ // Telemetry format list
+ if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
+ telemetries = new JComboBox<String>();
+ for (int i = 1; i <= Altos.ao_telemetry_max; i++)
+ telemetries.addItem(Altos.telemetry_name(i));
+ int telemetry = AltosPreferences.telemetry(serial);
+ if (telemetry <= Altos.ao_telemetry_off ||
+ telemetry > Altos.ao_telemetry_max)
+ telemetry = Altos.ao_telemetry_standard;
+ telemetries.setSelectedIndex(telemetry - 1);
+ telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
+ telemetries.setPreferredSize(null);
+ telemetries.revalidate();
telemetries.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- int telemetry = telemetries.get_selected();
+ int telemetry = telemetries.getSelectedIndex() + 1;
reader.set_telemetry(telemetry);
reader.save_telemetry();
}
});
- menu_bar.add(telemetries);
+ c.gridx = 1;
+ c.gridy = 0;
+ c.weightx = 0;
+ c.weighty = 0;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.WEST;
+ bag.add (telemetries, c);
+ c.insets = new Insets(0, 0, 0, 0);
} else {
String version;
version = "Telemetry: None";
telemetry = new JLabel(version);
- menu_bar.add(telemetry);
+ c.gridx = 1;
+ c.gridy = 0;
+ c.weightx = 0;
+ c.weighty = 0;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.WEST;
+ bag.add (telemetry, c);
+ c.insets = new Insets(0, 0, 0, 0);
}
}
}
Container bag;
- AltosFreqList frequencies;
+ AltosUIFreqList frequencies;
JTextField callsign_value;
/* DocumentListener interface methods */
/* Stick frequency selector at top of table for telemetry monitoring */
if (remote && serial >= 0) {
// Frequency menu
- frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
+ frequencies = new AltosUIFreqList(AltosUIPreferences.frequency(serial));
frequencies.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
double frequency = frequencies.frequency();
+++ /dev/null
-/*
- * 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);
- }
-}
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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();
+ }
+}
+
+++ /dev/null
-/*
- * 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);
- }
-}
-
AltosVoice.java \
AltosDisplayThread.java \
AltosDeviceUIDialog.java \
- AltosFreqList.java \
AltosSerial.java \
AltosSerialInUseException.java \
AltosConfigFreqUI.java \
AltosUIIndicator.java \
AltosUIUnitsIndicator.java \
AltosUIVoltageIndicator.java \
- AltosUITelemetryMenu.java \
+ AltosUIFreqList.java \
+ AltosUITelemetryList.java \
OSXAdapter.java
JAR=altosuilib_$(ALTOSUILIB_VERSION).jar
JMenu file_menu;
JMenu monitor_menu;
JMenu device_menu;
- AltosFreqList frequencies;
+ AltosUIFreqList frequencies;
ActionListener frequency_listener;
Container bag;
frequencies.set_product("Monitor");
frequencies.set_serial(serial);
frequencies.set_frequency(AltosUIPreferences.frequency(serial));
+ frequencies.setEnabled(true);
- menu_bar.add(frequencies);
- menu_bar.repaint();
}
void disable_frequency_menu() {
- if (frequency_listener == null)
- return;
- frequencies.removeActionListener(frequency_listener);
- menu_bar.remove(frequencies);
- menu_bar.repaint();
- frequency_listener = null;
+ if (frequency_listener != null) {
+ frequencies.removeActionListener(frequency_listener);
+ frequencies.setEnabled(false);
+ frequency_listener = null;
+ }
+
}
public void set_reader(AltosFlightReader reader, AltosDevice device) {
file_menu = make_menu("File", file_menu_entries);
monitor_menu = make_menu("Monitor", monitor_menu_entries);
device_menu = make_menu("Device", device_menu_entries);
- frequencies = new AltosFreqList();
+
+ frequencies = new AltosUIFreqList();
+ frequencies.setEnabled(false);
+ c.gridx = 0;
+ c.gridy = 0;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.WEST;
+ c.weightx = 0;
+ c.gridwidth = 1;
+ bag.add(frequencies, c);
displays = new LinkedList<AltosFlightDisplay>();
JLabel product_value;
JLabel version_value;
JLabel serial_value;
- AltosFreqList radio_frequency_value;
+ AltosUIFreqList radio_frequency_value;
JTextField radio_calibration_value;
JRadioButton radio_enable_value;
JComboBox<String> aprs_interval_value;
c.anchor = GridBagConstraints.LINE_START;
c.insets = ir;
c.ipady = 5;
- radio_frequency_value = new AltosFreqList();
+ radio_frequency_value = new AltosUIFreqList();
radio_frequency_value.addItemListener(this);
-
- JMenuBar menu_bar = new JMenuBar();
- menu_bar.add(radio_frequency_value);
-
- pane.add(menu_bar, c);
+ pane.add(radio_frequency_value, c);
radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
row++;