X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosEepromSelect.java;h=66a197c9af5ac300e102121ae81078909a123a4d;hp=104d31806627848f6455f7c95114d7a5d1d2be43;hb=9a4c2c7fc6af922d052e23a1b99bf847fbf9b0e9;hpb=8801b8c1947bd39f7c985b91a2ba8dbc81bcc91a diff --git a/altosui/AltosEepromSelect.java b/altosui/AltosEepromSelect.java index 104d3180..66a197c9 100644 --- a/altosui/AltosEepromSelect.java +++ b/altosui/AltosEepromSelect.java @@ -17,51 +17,42 @@ package altosui; -import java.lang.*; -import java.util.*; import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; -import libaltosJNI.libaltos; -import libaltosJNI.altos_device; -import libaltosJNI.SWIGTYPE_p_altos_file; -import libaltosJNI.SWIGTYPE_p_altos_list; +import org.altusmetrum.altoslib_4.*; +import org.altusmetrum.altosuilib_2.*; -class AltosEepromItem extends JPanel implements ActionListener { +class AltosEepromItem implements ActionListener { AltosEepromLog log; - JCheckBox download; - JCheckBox delete; JLabel label; + JCheckBox action; + JCheckBox delete; public void actionPerformed(ActionEvent e) { - System.out.printf("eeprom item action %s %d\n", e.getActionCommand(), e.getID()); - if (e.getSource() == download) { - log.download = download.isSelected(); - System.out.printf("download set to %b\n", log.download); - } else if (e.getSource() == delete) { - log.delete = delete.isSelected(); - System.out.printf("delete set to %b\n", log.delete); - } + log.selected = action.isSelected(); } public AltosEepromItem(AltosEepromLog in_log) { log = in_log; - download = new JCheckBox("Download", log.download); - download.addActionListener(this); - add(download); - delete = new JCheckBox("Delete", log.delete); - delete.addActionListener(this); - add(delete); - label = new JLabel(String.format("Flight %d %4d-%02d-%02d", - log.flight, log.year, log.month, log.day)); - add(label); + String text; + if (log.year != 0) + text = String.format("Flight #%02d - %04d-%02d-%02d", + log.flight, log.year, log.month, log.day); + else + text = String.format("Flight #%02d", log.flight); + + label = new JLabel(text); + + action = new JCheckBox("", log.selected); + action.addActionListener(this); } } -public class AltosEepromSelect extends JDialog implements ActionListener { - private JList list; +public class AltosEepromSelect extends AltosUIDialog implements ActionListener { + //private JList list; private JFrame frame; JButton ok; JButton cancel; @@ -84,12 +75,17 @@ public class AltosEepromSelect extends JDialog implements ActionListener { } public AltosEepromSelect (JFrame in_frame, - AltosEepromList flights) { + AltosEepromList flights, + String action) { super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true); frame = in_frame; - JLabel selectLabel = new JLabel("Select flights to download and/or delete", SwingConstants.CENTER); + /* Create the container for the dialog */ + Container contentPane = getContentPane(); + + /* First, we create a pane containing the dialog's header/title */ + JLabel selectLabel = new JLabel(String.format ("Select flights to %s", action), SwingConstants.CENTER); JPanel labelPane = new JPanel(); labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS)); @@ -98,13 +94,71 @@ public class AltosEepromSelect extends JDialog implements ActionListener { labelPane.add(selectLabel); labelPane.add(Box.createHorizontalGlue()); - JPanel flightPane = new JPanel(); - flightPane.setLayout(new BoxLayout(flightPane, BoxLayout.Y_AXIS)); + /* Add the header to the container. */ + contentPane.add(labelPane, BorderLayout.PAGE_START); + + + /* Now we create the evilness that is a GridBag for the flight details */ + GridBagConstraints c; + Insets i = new Insets(4,4,4,4); + JPanel flightPane = new JPanel(); + flightPane.setLayout(new GridBagLayout()); flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); + + /* Flight Header */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.weightx = 0.5; + c.anchor = GridBagConstraints.CENTER; + c.insets = i; + JLabel flightHeaderLabel = new JLabel("Flight"); + flightPane.add(flightHeaderLabel, c); + + /* Download Header */ + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = 0; + c.fill = GridBagConstraints.NONE; + c.weightx = 0.5; + c.anchor = GridBagConstraints.CENTER; + c.insets = i; + JLabel downloadHeaderLabel = new JLabel(action); + flightPane.add(downloadHeaderLabel, c); + + /* Add the flights to the GridBag */ + AltosEepromItem item; + int itemNumber = 1; for (AltosEepromLog flight : flights) { - flightPane.add(new AltosEepromItem(flight)); + /* Create a flight object with handlers and + * appropriate UI items + */ + item = new AltosEepromItem(flight); + + /* Add a decriptive label for the flight */ + c = new GridBagConstraints(); + c.gridx = 0; c.gridy = itemNumber; + c.fill = GridBagConstraints.NONE; + c.weightx = 0.5; + c.anchor = GridBagConstraints.CENTER; + c.insets = i; + flightPane.add(item.label, c); + + /* Add action checkbox for the flight */ + c = new GridBagConstraints(); + c.gridx = 1; c.gridy = itemNumber; + c.fill = GridBagConstraints.NONE; + c.weightx = 0.5; + c.anchor = GridBagConstraints.CENTER; + c.insets = i; + flightPane.add(item.action, c); + + itemNumber++; } + /* Add the GridBag to the container */ + contentPane.add(flightPane, BorderLayout.CENTER); + + /* Create the dialog buttons */ ok = new JButton("OK"); ok.addActionListener(this); ok.setActionCommand("ok"); @@ -121,12 +175,10 @@ public class AltosEepromSelect extends JDialog implements ActionListener { buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); buttonPane.add(ok); - Container contentPane = getContentPane(); - - contentPane.add(labelPane, BorderLayout.PAGE_START); - contentPane.add(flightPane, BorderLayout.CENTER); + /* Add the buttons to the container */ contentPane.add(buttonPane, BorderLayout.PAGE_END); + /* Pack the window! */ pack(); } }