first cut at turnon scripts for EasyTimer v2
[fw/altos] / micropeak / MicroPeak.java
index 7d3e20d8d1a4f308692ebe9158582a370aa408be..96fb33ba132d6a368e2436dfedb11fd98eaae256 100644 (file)
@@ -61,6 +61,10 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
        final static String     download_command = "download";
        final static String     download_label = "Download";
 
+       static final String[][] download_menu_entries = new String[][] {
+               { download_label,       download_command }
+       };
+
        MicroPeak SetData(MicroData data) {
                MicroPeak       mp = this;
                if (this.data != null) {
@@ -132,9 +136,18 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
 
        private void DownloadData() {
                AltosDevice     device = MicroDeviceDialog.show(this);
+               MicroSerial     serial = null;
+               try {
+                       serial = new MicroSerial(device);
+               } catch (FileNotFoundException fe) {
+                       JOptionPane.showMessageDialog(this,
+                                                     fe.getMessage(),
+                                                     "Cannot open device",
+                                                     JOptionPane.ERROR_MESSAGE);
+                       return;
+               }
 
-               if (device != null)
-                       new MicroDownload(this, device);
+               new MicroDownload(this, device, serial);
        }
 
        private void no_data() {
@@ -255,7 +268,7 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
        }
 
 
-       private JMenu make_menu(String label, String[][] items) {
+       private void make_menu(String label, String[][] items) {
                JMenu   menu = new JMenu(label);
                for (int i = 0; i < items.length; i++) {
                        if (MAC_OS_X) {
@@ -267,7 +280,6 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
                        add_menu(menu, items[i][0], items[i][1]);
                }
                menu_bar.add(menu);
-               return menu;
        }
 
        public MicroPeak() {
@@ -286,12 +298,16 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
                menu_bar = new JMenuBar();
                setJMenuBar(menu_bar);
 
-               JMenu file_menu = make_menu("File", file_menu_entries);
+               make_menu("File", file_menu_entries);
 
-               JButton download_button = new JButton (download_label);
-               download_button.setActionCommand(download_command);
-               download_button.addActionListener(this);
-               menu_bar.add(download_button);
+               if (MAC_OS_X) {
+                       make_menu(download_label, download_menu_entries);
+               } else {
+                       JButton download_button = new JButton (download_label);
+                       download_button.setActionCommand(download_command);
+                       download_button.addActionListener(this);
+                       menu_bar.add(download_button);
+               }
 
                setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                addWindowListener(new WindowAdapter() {
@@ -320,6 +336,11 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene
                container.validate();
                doLayout();
                validate();
+               Insets i = getInsets();
+               Dimension ps = pane.getPreferredSize();
+               ps.width += i.left + i.right;
+               ps.height += i.top + i.bottom;
+               setSize(ps);
                pack();
                setVisible(true);
        }