From 82bad3d62b91e67f6089e403c4bd4983bf65e449 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 27 Feb 2021 12:51:13 -0800 Subject: [PATCH] micropeak: Use a menu for 'Download' on Mac OS X Attempts to add buttons to the menu bar fail leaving no access to the download command. Signed-off-by: Keith Packard --- micropeak/MicroPeak.java | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/micropeak/MicroPeak.java b/micropeak/MicroPeak.java index 7d3e20d8..c34e874a 100644 --- a/micropeak/MicroPeak.java +++ b/micropeak/MicroPeak.java @@ -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) { @@ -255,7 +259,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 +271,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 +289,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 +327,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); } -- 2.30.2