X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosIgniteUI.java;h=14d4eebcbaf210013215e704ae3b7849613a2161;hp=000adc980d76144b615bcebad943426e274d98d7;hb=2e28d3541b8da31ebef5a199baf8f544d238298e;hpb=2f9be009ef26e3d7539f5932d267d7a8a7bcb7eb diff --git a/altosui/AltosIgniteUI.java b/altosui/AltosIgniteUI.java index 000adc98..14d4eebc 100644 --- a/altosui/AltosIgniteUI.java +++ b/altosui/AltosIgniteUI.java @@ -20,17 +20,14 @@ package altosui; import java.awt.*; import java.awt.event.*; import javax.swing.*; -import javax.swing.filechooser.FileNameExtensionFilter; -import javax.swing.table.*; -import javax.swing.event.*; import java.io.*; -import java.util.*; import java.text.*; -import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.altoslib_1.*; +import org.altusmetrum.altosuilib_1.*; public class AltosIgniteUI - extends JDialog + extends AltosUIDialog implements ActionListener { AltosDevice device; @@ -43,6 +40,7 @@ public class AltosIgniteUI JToggleButton arm; JButton fire; javax.swing.Timer timer; + JButton close; int apogee_status; int main_status; @@ -56,8 +54,30 @@ public class AltosIgniteUI class IgniteHandler implements Runnable { AltosIgnite ignite; + JFrame owner; + + void send_exception(Exception e) { + final Exception f_e = e; + Runnable r = new Runnable() { + public void run() { + ignite_exception(f_e); + } + }; + SwingUtilities.invokeLater(r); + } public void run () { + try { + AltosSerial serial = new AltosSerial(device); + serial.set_frame(owner); + ignite = new AltosIgnite(serial, + !device.matchProduct(Altos.product_altimeter)); + + } catch (Exception e) { + send_exception(e); + return; + } + for (;;) { Runnable r; @@ -87,25 +107,44 @@ public class AltosIgniteUI ignite_reply(f_reply); } }; + SwingUtilities.invokeLater(r); } catch (Exception e) { - final Exception f_e = e; - r = new Runnable() { - public void run() { - ignite_exception(f_e); - } - }; + send_exception(e); } - SwingUtilities.invokeLater(r); } } - public IgniteHandler(AltosIgnite in_ignite) { - ignite = in_ignite; + public IgniteHandler(JFrame in_owner) { + owner = in_owner; } } void ignite_exception(Exception e) { - abort(); + if (e instanceof FileNotFoundException) { + JOptionPane.showMessageDialog(owner, + ((FileNotFoundException) e).getMessage(), + "Cannot open target device", + JOptionPane.ERROR_MESSAGE); + } else if (e instanceof AltosSerialInUseException) { + JOptionPane.showMessageDialog(owner, + String.format("Device \"%s\" already in use", + device.toShortString()), + "Device in use", + JOptionPane.ERROR_MESSAGE); + } else if (e instanceof IOException) { + IOException ee = (IOException) e; + JOptionPane.showMessageDialog(owner, + device.toShortString(), + ee.getLocalizedMessage(), + JOptionPane.ERROR_MESSAGE); + } else { + JOptionPane.showMessageDialog(owner, + String.format("Connection to \"%s\" failed", + device.toShortString()), + "Connection Failed", + JOptionPane.ERROR_MESSAGE); + } + close(); } void ignite_reply(String reply) { @@ -149,7 +188,7 @@ public class AltosIgniteUI try { command_queue.put(command); } catch (Exception ex) { - abort(); + ignite_exception(ex); } } @@ -194,15 +233,6 @@ public class AltosIgniteUI dispose(); } - void abort() { - close(); - JOptionPane.showMessageDialog(owner, - String.format("Connection to \"%s\" failed", - device.toShortString()), - "Connection Failed", - JOptionPane.ERROR_MESSAGE); - } - void tick_timer() { if (timer_running) { --time_remaining; @@ -275,33 +305,12 @@ public class AltosIgniteUI private boolean open() { command_queue = new LinkedBlockingQueue(); - device = AltosDeviceDialog.show(owner, AltosDevice.product_any); + device = AltosDeviceUIDialog.show(owner, Altos.product_any); if (device != null) { - try { - AltosIgnite ignite = new AltosIgnite(device); - IgniteHandler handler = new IgniteHandler(ignite); + IgniteHandler handler = new IgniteHandler(owner); Thread t = new Thread(handler); - ignite.set_frame(owner); t.start(); return true; - } 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", - device.toShortString()), - "Device in use", - JOptionPane.ERROR_MESSAGE); - } catch (IOException ee) { - JOptionPane.showMessageDialog(owner, - device.toShortString(), - ee.getLocalizedMessage(), - JOptionPane.ERROR_MESSAGE); - } } return false; } @@ -331,8 +340,8 @@ public class AltosIgniteUI c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.CENTER; c.insets = i; - c.weightx = 1; - c.weighty = 1; + c.weightx = 0; + c.weighty = 0; c.gridx = 0; c.gridy = 0; @@ -393,6 +402,15 @@ public class AltosIgniteUI fire.addActionListener(this); fire.setActionCommand("fire"); + c.gridx = 0; + c.gridy = 4; + c.gridwidth = 2; + c.anchor = GridBagConstraints.CENTER; + close = new JButton ("Close"); + pane.add(close, c); + close.addActionListener(this); + close.setActionCommand("close"); + pack(); setLocationRelativeTo(owner);