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 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));
54 download = new JCheckBox("", log.download);
55 download.addActionListener(this);
57 delete = new JCheckBox("", log.delete);
58 delete.addActionListener(this);
62 public class AltosEepromSelect extends JDialog implements ActionListener {
69 /* Listen for events from our buttons */
70 public void actionPerformed(ActionEvent e) {
71 String cmd = e.getActionCommand();
78 public boolean run() {
80 setLocationRelativeTo(frame);
85 public AltosEepromSelect (JFrame in_frame,
86 AltosEepromList flights) {
88 super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true);
91 /* Create the container for the dialog */
92 Container contentPane = getContentPane();
94 /* First, we create a pane containing the dialog's header/title */
95 JLabel selectLabel = new JLabel("Select flights to download and/or delete", SwingConstants.CENTER);
97 JPanel labelPane = new JPanel();
98 labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS));
99 labelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
100 labelPane.add(Box.createHorizontalGlue());
101 labelPane.add(selectLabel);
102 labelPane.add(Box.createHorizontalGlue());
104 /* Add the header to the container. */
105 contentPane.add(labelPane, BorderLayout.PAGE_START);
108 /* Now we create the evilness that is a GridBag for the flight details */
109 GridBagConstraints c;
110 Insets i = new Insets(4,4,4,4);
111 JPanel flightPane = new JPanel();
112 flightPane.setLayout(new GridBagLayout());
113 flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
116 c = new GridBagConstraints();
117 c.gridx = 0; c.gridy = 0;
118 c.fill = GridBagConstraints.NONE;
120 c.anchor = GridBagConstraints.CENTER;
122 JLabel flightHeaderLabel = new JLabel("Flight");
123 flightPane.add(flightHeaderLabel, c);
125 /* Download Header */
126 c = new GridBagConstraints();
127 c.gridx = 1; c.gridy = 0;
128 c.fill = GridBagConstraints.NONE;
130 c.anchor = GridBagConstraints.CENTER;
132 JLabel downloadHeaderLabel = new JLabel("Download");
133 flightPane.add(downloadHeaderLabel, c);
136 c = new GridBagConstraints();
137 c.gridx = 2; c.gridy = 0;
138 c.fill = GridBagConstraints.NONE;
140 c.anchor = GridBagConstraints.CENTER;
142 JLabel deleteHeaderLabel = new JLabel("Delete");
143 flightPane.add(deleteHeaderLabel, c);
145 /* Add the flights to the GridBag */
146 AltosEepromItem item;
148 for (AltosEepromLog flight : flights) {
149 /* Create a flight object with handlers and
150 * appropriate UI items
152 item = new AltosEepromItem(flight);
154 /* Add a decriptive label for the flight */
155 c = new GridBagConstraints();
156 c.gridx = 0; c.gridy = itemNumber;
157 c.fill = GridBagConstraints.NONE;
159 c.anchor = GridBagConstraints.CENTER;
161 flightPane.add(item.label, c);
163 /* Add a download checkbox for the flight */
164 c = new GridBagConstraints();
165 c.gridx = 1; c.gridy = itemNumber;
166 c.fill = GridBagConstraints.NONE;
168 c.anchor = GridBagConstraints.CENTER;
170 flightPane.add(item.download, c);
172 /* Add a delete checkbox for the flight */
173 c = new GridBagConstraints();
174 c.gridx = 2; c.gridy = itemNumber;
175 c.fill = GridBagConstraints.NONE;
177 c.anchor = GridBagConstraints.CENTER;
179 flightPane.add(item.delete, c);
184 /* Add the GridBag to the container */
185 contentPane.add(flightPane, BorderLayout.CENTER);
187 /* Create the dialog buttons */
188 ok = new JButton("OK");
189 ok.addActionListener(this);
190 ok.setActionCommand("ok");
192 cancel = new JButton("Cancel");
193 cancel.addActionListener(this);
194 cancel.setActionCommand("cancel");
196 JPanel buttonPane = new JPanel();
197 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
198 buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
199 buttonPane.add(Box.createHorizontalGlue());
200 buttonPane.add(cancel);
201 buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
204 /* Add the buttons to the container */
205 contentPane.add(buttonPane, BorderLayout.PAGE_END);
207 /* Pack the window! */