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;
30 import org.altusmetrum.AltosLib.*;
32 class AltosEepromItem implements ActionListener {
38 public void actionPerformed(ActionEvent e) {
39 if (e.getSource() == download) {
40 log.download = download.isSelected();
41 } else if (e.getSource() == delete) {
42 log.delete = delete.isSelected();
46 public AltosEepromItem(AltosEepromLog in_log) {
51 text = String.format("Flight #%02d - %04d-%02d-%02d",
52 log.flight, log.year, log.month, log.day);
54 text = String.format("Flight #%02d", log.flight);
56 label = new JLabel(text);
58 download = new JCheckBox("", log.download);
59 download.addActionListener(this);
61 delete = new JCheckBox("", log.delete);
62 delete.addActionListener(this);
66 public class AltosEepromSelect extends AltosDialog implements ActionListener {
73 /* Listen for events from our buttons */
74 public void actionPerformed(ActionEvent e) {
75 String cmd = e.getActionCommand();
82 public boolean run() {
84 setLocationRelativeTo(frame);
89 public AltosEepromSelect (JFrame in_frame,
90 AltosEepromList flights) {
92 super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true);
95 /* Create the container for the dialog */
96 Container contentPane = getContentPane();
98 /* First, we create a pane containing the dialog's header/title */
99 JLabel selectLabel = new JLabel("Select flights to download and/or delete", SwingConstants.CENTER);
101 JPanel labelPane = new JPanel();
102 labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS));
103 labelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
104 labelPane.add(Box.createHorizontalGlue());
105 labelPane.add(selectLabel);
106 labelPane.add(Box.createHorizontalGlue());
108 /* Add the header to the container. */
109 contentPane.add(labelPane, BorderLayout.PAGE_START);
112 /* Now we create the evilness that is a GridBag for the flight details */
113 GridBagConstraints c;
114 Insets i = new Insets(4,4,4,4);
115 JPanel flightPane = new JPanel();
116 flightPane.setLayout(new GridBagLayout());
117 flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
120 c = new GridBagConstraints();
121 c.gridx = 0; c.gridy = 0;
122 c.fill = GridBagConstraints.NONE;
124 c.anchor = GridBagConstraints.CENTER;
126 JLabel flightHeaderLabel = new JLabel("Flight");
127 flightPane.add(flightHeaderLabel, c);
129 /* Download Header */
130 c = new GridBagConstraints();
131 c.gridx = 1; c.gridy = 0;
132 c.fill = GridBagConstraints.NONE;
134 c.anchor = GridBagConstraints.CENTER;
136 JLabel downloadHeaderLabel = new JLabel("Download");
137 flightPane.add(downloadHeaderLabel, c);
140 c = new GridBagConstraints();
141 c.gridx = 2; c.gridy = 0;
142 c.fill = GridBagConstraints.NONE;
144 c.anchor = GridBagConstraints.CENTER;
146 JLabel deleteHeaderLabel = new JLabel("Delete");
147 flightPane.add(deleteHeaderLabel, c);
149 /* Add the flights to the GridBag */
150 AltosEepromItem item;
152 for (AltosEepromLog flight : flights) {
153 /* Create a flight object with handlers and
154 * appropriate UI items
156 item = new AltosEepromItem(flight);
158 /* Add a decriptive label for the flight */
159 c = new GridBagConstraints();
160 c.gridx = 0; c.gridy = itemNumber;
161 c.fill = GridBagConstraints.NONE;
163 c.anchor = GridBagConstraints.CENTER;
165 flightPane.add(item.label, c);
167 /* Add a download checkbox for the flight */
168 c = new GridBagConstraints();
169 c.gridx = 1; c.gridy = itemNumber;
170 c.fill = GridBagConstraints.NONE;
172 c.anchor = GridBagConstraints.CENTER;
174 flightPane.add(item.download, c);
176 /* Add a delete checkbox for the flight */
177 c = new GridBagConstraints();
178 c.gridx = 2; c.gridy = itemNumber;
179 c.fill = GridBagConstraints.NONE;
181 c.anchor = GridBagConstraints.CENTER;
183 flightPane.add(item.delete, c);
188 /* Add the GridBag to the container */
189 contentPane.add(flightPane, BorderLayout.CENTER);
191 /* Create the dialog buttons */
192 ok = new JButton("OK");
193 ok.addActionListener(this);
194 ok.setActionCommand("ok");
196 cancel = new JButton("Cancel");
197 cancel.addActionListener(this);
198 cancel.setActionCommand("cancel");
200 JPanel buttonPane = new JPanel();
201 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
202 buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
203 buttonPane.add(Box.createHorizontalGlue());
204 buttonPane.add(cancel);
205 buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
208 /* Add the buttons to the container */
209 contentPane.add(buttonPane, BorderLayout.PAGE_END);
211 /* Pack the window! */