2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 import javax.swing.border.*;
25 import java.awt.event.*;
26 import libaltosJNI.libaltos;
27 import libaltosJNI.altos_device;
28 import libaltosJNI.SWIGTYPE_p_altos_file;
29 import libaltosJNI.SWIGTYPE_p_altos_list;
31 class AltosEepromItem extends JPanel implements ActionListener {
37 public void actionPerformed(ActionEvent e) {
38 System.out.printf("eeprom item action %s %d\n", e.getActionCommand(), e.getID());
39 if (e.getSource() == download) {
40 log.download = download.isSelected();
41 System.out.printf("download for flight %d set to %b\n", log.flight, log.download);
42 } else if (e.getSource() == delete) {
43 log.delete = delete.isSelected();
44 System.out.printf("delete for flight %d set to %b\n", log.flight, log.delete);
48 public AltosEepromItem(AltosEepromLog in_log) {
51 label = new JLabel(String.format("Flight #%02d - %04d-%02d-%02d",
52 log.flight, log.year, log.month, log.day));
53 label.setPreferredSize(new Dimension(170, 15));
55 download = new JCheckBox("", log.download);
56 download.addActionListener(this);
57 download.setPreferredSize(new Dimension(100, 15));
58 download.setHorizontalAlignment(SwingConstants.CENTER);
60 delete = new JCheckBox("", log.delete);
61 delete.addActionListener(this);
62 delete.setPreferredSize(new Dimension(70, 15));
63 delete.setHorizontalAlignment(SwingConstants.CENTER);
68 public class AltosEepromSelect extends JDialog implements ActionListener {
75 /* Listen for events from our buttons */
76 public void actionPerformed(ActionEvent e) {
77 String cmd = e.getActionCommand();
84 public boolean run() {
86 setLocationRelativeTo(frame);
91 public AltosEepromSelect (JFrame in_frame,
92 AltosEepromList flights) {
94 super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true);
97 JLabel selectLabel = new JLabel("Select flights to download and/or delete", SwingConstants.CENTER);
99 JPanel labelPane = new JPanel();
100 labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS));
101 labelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
102 labelPane.add(Box.createHorizontalGlue());
103 labelPane.add(selectLabel);
104 labelPane.add(Box.createHorizontalGlue());
106 JLabel flightHeaderLabel = new JLabel("Flight", SwingConstants.CENTER);
107 flightHeaderLabel.setPreferredSize(new Dimension(170, 15));
109 JLabel downloadHeaderLabel = new JLabel("Download", SwingConstants.CENTER);
110 downloadHeaderLabel.setPreferredSize(new Dimension(100, 15));
112 JLabel deleteHeaderLabel = new JLabel("Delete", SwingConstants.CENTER);
113 deleteHeaderLabel.setPreferredSize(new Dimension(70, 15));
115 JPanel headerPane = new JPanel();
116 headerPane.add(flightHeaderLabel);
117 headerPane.add(downloadHeaderLabel);
118 headerPane.add(deleteHeaderLabel);
120 JPanel flightPane = new JPanel();
121 flightPane.setLayout(new BoxLayout(flightPane, BoxLayout.Y_AXIS));
122 flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
123 flightPane.add(headerPane);
124 for (AltosEepromLog flight : flights) {
125 flightPane.add(new AltosEepromItem(flight));
128 ok = new JButton("OK");
129 ok.addActionListener(this);
130 ok.setActionCommand("ok");
132 cancel = new JButton("Cancel");
133 cancel.addActionListener(this);
134 cancel.setActionCommand("cancel");
136 JPanel buttonPane = new JPanel();
137 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
138 buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
139 buttonPane.add(Box.createHorizontalGlue());
140 buttonPane.add(cancel);
141 buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
144 Container contentPane = getContentPane();
146 contentPane.add(labelPane, BorderLayout.PAGE_START);
147 contentPane.add(flightPane, BorderLayout.CENTER);
148 contentPane.add(buttonPane, BorderLayout.PAGE_END);