A combo box displays the current value, which is quite nice to
have. Add a 'toShortString' for AltosDevice so that the window frames
and error messages don't have extra spaces generated by the
altos_device toString method.
Signed-off-by: Keith Packard <keithp@keithp.com>
import java.util.prefs.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.prefs.*;
import java.util.concurrent.LinkedBlockingQueue;
-public class AltosChannelMenu extends JMenu implements ActionListener {
- ButtonGroup group;
+public class AltosChannelMenu extends JComboBox implements ActionListener {
int channel;
LinkedList<ActionListener> listeners;
int channel;
LinkedList<ActionListener> listeners;
}
public void actionPerformed(ActionEvent e) {
}
public void actionPerformed(ActionEvent e) {
- channel = Integer.parseInt(e.getActionCommand());
+ channel = getSelectedIndex();
+
+ ActionEvent newe = new ActionEvent(this, channel, e.getActionCommand());
ListIterator<ActionListener> i = listeners.listIterator();
ListIterator<ActionListener> i = listeners.listIterator();
- ActionEvent newe = new ActionEvent(this, channel, e.getActionCommand());
while (i.hasNext()) {
ActionListener listener = i.next();
listener.actionPerformed(newe);
}
while (i.hasNext()) {
ActionListener listener = i.next();
listener.actionPerformed(newe);
}
+ setMaximumSize(getPreferredSize());
}
public AltosChannelMenu(int current_channel) {
}
public AltosChannelMenu(int current_channel) {
- super("Channel", true);
- group = new ButtonGroup();
channel = current_channel;
listeners = new LinkedList<ActionListener>();
channel = current_channel;
listeners = new LinkedList<ActionListener>();
- for (int c = 0; c <= 9; c++) {
- JRadioButtonMenuItem radioitem = new JRadioButtonMenuItem(String.format("Channel %1d (%7.3fMHz)", c,
- 434.550 + c * 0.1),
- c == channel);
- radioitem.setActionCommand(String.format("%d", c));
- radioitem.addActionListener(this);
- add(radioitem);
- group.add(radioitem);
- }
+ for (int c = 0; c <= 9; c++)
+ addItem(String.format("Channel %1d (%7.3fMHz)", c, 434.550 + c * 0.1));
+ setSelectedIndex(channel);
+ setMaximumRowCount(10);
void abort() {
JOptionPane.showMessageDialog(owner,
String.format("Connection to \"%s\" failed",
void abort() {
JOptionPane.showMessageDialog(owner,
String.format("Connection to \"%s\" failed",
+ device.toShortString()),
"Connection Failed",
JOptionPane.ERROR_MESSAGE);
serial_line.close();
"Connection Failed",
JOptionPane.ERROR_MESSAGE);
serial_line.close();
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(owner,
String.format("Cannot open device \"%s\"",
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(owner,
String.format("Cannot open device \"%s\"",
+ device.toShortString()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
} catch (AltosSerialInUseException si) {
JOptionPane.showMessageDialog(owner,
String.format("Device \"%s\" already in use",
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
} catch (AltosSerialInUseException si) {
JOptionPane.showMessageDialog(owner,
String.format("Device \"%s\" already in use",
+ device.toShortString()),
"Device in use",
JOptionPane.ERROR_MESSAGE);
} catch (IOException ee) {
JOptionPane.showMessageDialog(owner,
"Device in use",
JOptionPane.ERROR_MESSAGE);
} catch (IOException ee) {
JOptionPane.showMessageDialog(owner,
+ device.toShortString(),
ee.getLocalizedMessage(),
JOptionPane.ERROR_MESSAGE);
}
ee.getLocalizedMessage(),
JOptionPane.ERROR_MESSAGE);
}
- public AltosDebug (altos_device in_device) throws FileNotFoundException, AltosSerialInUseException {
+ public AltosDebug (AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException {
super(in_device);
}
}
\ No newline at end of file
super(in_device);
}
}
\ No newline at end of file
getName(), getSerial(), getPath());
}
getName(), getSerial(), getPath());
}
+ public String toShortString() {
+ String name = getName();
+ if (name == null)
+ name = "Altus Metrum";
+ return String.format("%s %d %s",
+ name, getSerial(), getPath());
+
+ }
+
public boolean isAltusMetrum() {
if (getVendor() != vendor_altusmetrum)
return false;
public boolean isAltusMetrum() {
if (getVendor() != vendor_altusmetrum)
return false;
CaptureLog();
} catch (IOException ee) {
JOptionPane.showMessageDialog(frame,
CaptureLog();
} catch (IOException ee) {
JOptionPane.showMessageDialog(frame,
+ device.toShortString(),
ee.getLocalizedMessage(),
JOptionPane.ERROR_MESSAGE);
} catch (InterruptedException ie) {
} catch (TimeoutException te) {
JOptionPane.showMessageDialog(frame,
String.format("Connection to \"%s\" failed",
ee.getLocalizedMessage(),
JOptionPane.ERROR_MESSAGE);
} catch (InterruptedException ie) {
} catch (TimeoutException te) {
JOptionPane.showMessageDialog(frame,
String.format("Connection to \"%s\" failed",
+ device.toShortString()),
"Connection Failed",
JOptionPane.ERROR_MESSAGE);
}
"Connection Failed",
JOptionPane.ERROR_MESSAGE);
}
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(frame,
String.format("Cannot open device \"%s\"",
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(frame,
String.format("Cannot open device \"%s\"",
+ device.toShortString()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
} catch (AltosSerialInUseException si) {
JOptionPane.showMessageDialog(frame,
String.format("Device \"%s\" already in use",
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
} catch (AltosSerialInUseException si) {
JOptionPane.showMessageDialog(frame,
String.format("Device \"%s\" already in use",
+ device.toShortString()),
"Device in use",
JOptionPane.ERROR_MESSAGE);
} catch (IOException ee) {
JOptionPane.showMessageDialog(frame,
"Device in use",
JOptionPane.ERROR_MESSAGE);
} catch (IOException ee) {
JOptionPane.showMessageDialog(frame,
+ device.toShortString(),
ee.getLocalizedMessage(),
JOptionPane.ERROR_MESSAGE);
}
ee.getLocalizedMessage(),
JOptionPane.ERROR_MESSAGE);
}
} catch (AltosSerialInUseException si) {
JOptionPane.showMessageDialog(frame,
String.format("Device \"%s\" already in use",
} catch (AltosSerialInUseException si) {
JOptionPane.showMessageDialog(frame,
String.format("Device \"%s\" already in use",
- debug_dongle.toString()),
+ debug_dongle.toShortString()),
"Device in use",
JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
"Device in use",
JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
AltosFlightReader reader;
AltosDisplayThread thread;
AltosFlightReader reader;
AltosDisplayThread thread;
JTabbedPane pane;
AltosPad pad;
JTabbedPane pane;
AltosPad pad;
public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
AltosPreferences.init(this);
voice = in_voice;
reader = in_reader;
public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
AltosPreferences.init(this);
voice = in_voice;
reader = in_reader;
+ bag = getContentPane();
+ bag.setLayout(new GridBagLayout());
+
+ GridBagConstraints c = new GridBagConstraints();
+
java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
if (imgURL != null)
setIconImage(new ImageIcon(imgURL).getImage());
setTitle(String.format("AltOS %s", reader.name));
java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
if (imgURL != null)
setIconImage(new ImageIcon(imgURL).getImage());
setTitle(String.format("AltOS %s", reader.name));
- flightStatus = new AltosFlightStatus();
+ if (serial >= 0) {
+ // Channel menu
+ JComboBox channels = new AltosChannelMenu(AltosPreferences.channel(serial));
+ channels.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ int channel = Integer.parseInt(e.getActionCommand());
+ reader.set_channel(channel);
+ AltosPreferences.set_channel(serial, channel);
+ }
+ });
+ c.gridx = 0;
+ c.gridy = 0;
+ c.anchor = GridBagConstraints.WEST;
+ bag.add (channels, c);
+ }
- vbox = new Box (BoxLayout.Y_AXIS);
- vbox.add(flightStatus);
+ flightStatus = new AltosFlightStatus();
+ c.gridx = 0;
+ c.gridy = 1;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.weightx = 1;
+ bag.add(flightStatus, c);
pane = new JTabbedPane();
pane = new JTabbedPane();
flightInfoPane = new JScrollPane(flightInfo.box());
pane.add("Table", flightInfoPane);
flightInfoPane = new JScrollPane(flightInfo.box());
pane.add("Table", flightInfoPane);
- vbox.add(pane);
-
- this.add(vbox);
-
- if (serial >= 0) {
- JMenuBar menubar = new JMenuBar();
-
- // Channel menu
- {
- JMenu menu = new AltosChannelMenu(AltosPreferences.channel(serial));
- menu.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int channel = Integer.parseInt(e.getActionCommand());
- reader.set_channel(channel);
- AltosPreferences.set_channel(serial, channel);
- }
- });
- menu.setMnemonic(KeyEvent.VK_C);
- menubar.add(menu);
- }
-
- this.setJMenuBar(menubar);
- }
+ c.gridx = 0;
+ c.gridy = 2;
+ c.fill = GridBagConstraints.BOTH;
+ c.weightx = 1;
+ c.weighty = 1;
+ bag.add(pane, c);
this.setSize(this.getPreferredSize());
this.validate();
this.setSize(this.getPreferredSize());
this.validate();
close();
JOptionPane.showMessageDialog(owner,
String.format("Connection to \"%s\" failed",
close();
JOptionPane.showMessageDialog(owner,
String.format("Connection to \"%s\" failed",
+ device.toShortString()),
"Connection Failed",
JOptionPane.ERROR_MESSAGE);
}
"Connection Failed",
JOptionPane.ERROR_MESSAGE);
}
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(owner,
String.format("Cannot open device \"%s\"",
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(owner,
String.format("Cannot open device \"%s\"",
+ device.toShortString()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
} catch (AltosSerialInUseException si) {
JOptionPane.showMessageDialog(owner,
String.format("Device \"%s\" already in use",
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
} catch (AltosSerialInUseException si) {
JOptionPane.showMessageDialog(owner,
String.format("Device \"%s\" already in use",
+ device.toShortString()),
"Device in use",
JOptionPane.ERROR_MESSAGE);
} catch (IOException ee) {
JOptionPane.showMessageDialog(owner,
"Device in use",
JOptionPane.ERROR_MESSAGE);
} catch (IOException ee) {
JOptionPane.showMessageDialog(owner,
+ device.toShortString(),
ee.getLocalizedMessage(),
JOptionPane.ERROR_MESSAGE);
}
ee.getLocalizedMessage(),
JOptionPane.ERROR_MESSAGE);
}
static List<String> devices_opened = Collections.synchronizedList(new LinkedList<String>());
static List<String> devices_opened = Collections.synchronizedList(new LinkedList<String>());
SWIGTYPE_p_altos_file altos;
LinkedList<LinkedBlockingQueue<AltosLine>> monitors;
LinkedBlockingQueue<AltosLine> reply_queue;
SWIGTYPE_p_altos_file altos;
LinkedList<LinkedBlockingQueue<AltosLine>> monitors;
LinkedBlockingQueue<AltosLine> reply_queue;
}
altos = libaltos.altos_open(device);
if (altos == null)
}
altos = libaltos.altos_open(device);
if (altos == null)
- throw new FileNotFoundException(device.toString());
+ throw new FileNotFoundException(device.toShortString());
input_thread = new Thread(this);
input_thread.start();
print("~\nE 0\n");
input_thread = new Thread(this);
input_thread.start();
print("~\nE 0\n");
- public AltosSerial(altos_device in_device) throws FileNotFoundException, AltosSerialInUseException {
+ public AltosSerial(AltosDevice in_device) throws FileNotFoundException, AltosSerialInUseException {
device = in_device;
line = "";
monitor_mode = false;
device = in_device;
line = "";
monitor_mode = false;
device = in_device;
serial = new AltosSerial(device);
log = new AltosLog(serial);
device = in_device;
serial = new AltosSerial(device);
log = new AltosLog(serial);
- name = device.toString();
+ name = device.toShortString();
telem = new LinkedBlockingQueue<AltosLine>();
serial.add_monitor(telem);
telem = new LinkedBlockingQueue<AltosLine>();
serial.add_monitor(telem);
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(AltosUI.this,
String.format("Cannot open device \"%s\"",
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(AltosUI.this,
String.format("Cannot open device \"%s\"",
+ device.toShortString()),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
} catch (AltosSerialInUseException si) {
JOptionPane.showMessageDialog(AltosUI.this,
String.format("Device \"%s\" already in use",
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
} catch (AltosSerialInUseException si) {
JOptionPane.showMessageDialog(AltosUI.this,
String.format("Device \"%s\" already in use",
+ device.toShortString()),
"Device in use",
JOptionPane.ERROR_MESSAGE);
} catch (IOException ee) {
JOptionPane.showMessageDialog(AltosUI.this,
"Device in use",
JOptionPane.ERROR_MESSAGE);
} catch (IOException ee) {
JOptionPane.showMessageDialog(AltosUI.this,
+ device.toShortString(),
"Unkonwn I/O error",
JOptionPane.ERROR_MESSAGE);
}
"Unkonwn I/O error",
JOptionPane.ERROR_MESSAGE);
}