Replacing the menu with a combo box required reworking the way events
are delivered from that widget back to the channel changing
function. Just delete the old magic and use the JComboBox action
listener directly.
Signed-off-by: Keith Packard <keithp@keithp.com>
public class AltosChannelMenu extends JComboBox implements ActionListener {
int channel;
public class AltosChannelMenu extends JComboBox implements ActionListener {
int channel;
- LinkedList<ActionListener> listeners;
-
- public void addActionListener(ActionListener l) {
- listeners.add(l);
- }
-
- public void actionPerformed(ActionEvent e) {
- channel = getSelectedIndex();
-
- ActionEvent newe = new ActionEvent(this, channel, e.getActionCommand());
-
- ListIterator<ActionListener> i = listeners.listIterator();
-
- while (i.hasNext()) {
- ActionListener listener = i.next();
- listener.actionPerformed(newe);
- }
- setMaximumSize(getPreferredSize());
- }
public AltosChannelMenu(int current_channel) {
channel = current_channel;
public AltosChannelMenu(int current_channel) {
channel = current_channel;
- listeners = new LinkedList<ActionListener>();
for (int c = 0; c <= 9; c++)
addItem(String.format("Channel %1d (%7.3fMHz)", c, 434.550 + c * 0.1));
setSelectedIndex(channel);
for (int c = 0; c <= 9; c++)
addItem(String.format("Channel %1d (%7.3fMHz)", c, 434.550 + c * 0.1));
setSelectedIndex(channel);
public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
AltosPreferences.init(this);
public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
AltosPreferences.init(this);
if (serial >= 0) {
// Channel menu
if (serial >= 0) {
// Channel menu
- JComboBox channels = new AltosChannelMenu(AltosPreferences.channel(serial));
+ channels = new AltosChannelMenu(AltosPreferences.channel(serial));
channels.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
channels.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- int channel = Integer.parseInt(e.getActionCommand());
+ int channel = channels.getSelectedIndex();
reader.set_channel(channel);
AltosPreferences.set_channel(serial, channel);
}
reader.set_channel(channel);
AltosPreferences.set_channel(serial, channel);
}