2 * Copyright © 2014 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.altosuilib_3;
22 import java.awt.event.*;
23 import org.altusmetrum.altoslib_5.*;
25 class TelemetryMenuItem extends JMenuItem {
28 public TelemetryMenuItem (int telemetry) {
29 super(AltosLib.telemetry_name(telemetry));
30 this.telemetry = telemetry;
34 public class AltosUITelemetryMenu extends JMenu implements ActionListener {
35 TelemetryMenuItem selected = null;
37 public int get_selected() {
39 return AltosLib.ao_telemetry_off;
40 return selected.telemetry;
43 public void set_selected(int telemetry) {
44 for (int i = 0; i < getItemCount(); i++) {
45 TelemetryMenuItem item = (TelemetryMenuItem) getItem(i);
46 if (item.telemetry == telemetry) {
48 String new_text = String.format("Format: %s ▾", AltosLib.telemetry_name(telemetry));
55 private LinkedList<ActionListener> action_listeners = new LinkedList<ActionListener>();
57 public void addActionListener(ActionListener l) {
58 action_listeners.add(l);
61 public void removeActionListener(ActionListener l) {
62 action_listeners.remove(l);
65 public void actionPerformed(ActionEvent e) {
66 TelemetryMenuItem item = (TelemetryMenuItem) e.getSource();
67 set_selected(item.telemetry);
68 ActionEvent my_e = new ActionEvent(selected, 0, "selected");
69 for (ActionListener l : action_listeners)
70 l.actionPerformed(my_e);
73 public AltosUITelemetryMenu(int serial) {
75 for (int i = AltosLib.ao_telemetry_min; i <= AltosLib.ao_telemetry_max; i++) {
76 TelemetryMenuItem item = new TelemetryMenuItem(i);
78 item.addActionListener(this);
82 int telemetry = AltosPreferences.telemetry(serial);
83 if (telemetry < AltosLib.ao_telemetry_min || AltosLib.ao_telemetry_max < telemetry)
84 telemetry = AltosLib.ao_telemetry_standard;
85 set_selected(telemetry);