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 log.selected = action.isSelected();
42 public AltosEepromItem(AltosEepromLog in_log) {
47 text = String.format("Flight #%02d - %04d-%02d-%02d",
48 log.flight, log.year, log.month, log.day);
50 text = String.format("Flight #%02d", log.flight);
52 label = new JLabel(text);
54 action = new JCheckBox("", log.selected);
55 action.addActionListener(this);
59 public class AltosEepromSelect extends AltosDialog implements ActionListener {
66 /* Listen for events from our buttons */
67 public void actionPerformed(ActionEvent e) {
68 String cmd = e.getActionCommand();
75 public boolean run() {
77 setLocationRelativeTo(frame);
82 public AltosEepromSelect (JFrame in_frame,
83 AltosEepromList flights,
86 super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true);
89 /* Create the container for the dialog */
90 Container contentPane = getContentPane();
92 /* First, we create a pane containing the dialog's header/title */
93 JLabel selectLabel = new JLabel(String.format ("Select flights to %s", action), SwingConstants.CENTER);
95 JPanel labelPane = new JPanel();
96 labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS));
97 labelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
98 labelPane.add(Box.createHorizontalGlue());
99 labelPane.add(selectLabel);
100 labelPane.add(Box.createHorizontalGlue());
102 /* Add the header to the container. */
103 contentPane.add(labelPane, BorderLayout.PAGE_START);
106 /* Now we create the evilness that is a GridBag for the flight details */
107 GridBagConstraints c;
108 Insets i = new Insets(4,4,4,4);
109 JPanel flightPane = new JPanel();
110 flightPane.setLayout(new GridBagLayout());
111 flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
114 c = new GridBagConstraints();
115 c.gridx = 0; c.gridy = 0;
116 c.fill = GridBagConstraints.NONE;
118 c.anchor = GridBagConstraints.CENTER;
120 JLabel flightHeaderLabel = new JLabel("Flight");
121 flightPane.add(flightHeaderLabel, c);
123 /* Download Header */
124 c = new GridBagConstraints();
125 c.gridx = 1; c.gridy = 0;
126 c.fill = GridBagConstraints.NONE;
128 c.anchor = GridBagConstraints.CENTER;
130 JLabel downloadHeaderLabel = new JLabel(action);
131 flightPane.add(downloadHeaderLabel, c);
133 /* Add the flights to the GridBag */
134 AltosEepromItem item;
136 for (AltosEepromLog flight : flights) {
137 /* Create a flight object with handlers and
138 * appropriate UI items
140 item = new AltosEepromItem(flight);
142 /* Add a decriptive label for the flight */
143 c = new GridBagConstraints();
144 c.gridx = 0; c.gridy = itemNumber;
145 c.fill = GridBagConstraints.NONE;
147 c.anchor = GridBagConstraints.CENTER;
149 flightPane.add(item.label, c);
151 /* Add action checkbox for the flight */
152 c = new GridBagConstraints();
153 c.gridx = 1; c.gridy = itemNumber;
154 c.fill = GridBagConstraints.NONE;
156 c.anchor = GridBagConstraints.CENTER;
158 flightPane.add(item.action, c);
163 /* Add the GridBag to the container */
164 contentPane.add(flightPane, BorderLayout.CENTER);
166 /* Create the dialog buttons */
167 ok = new JButton("OK");
168 ok.addActionListener(this);
169 ok.setActionCommand("ok");
171 cancel = new JButton("Cancel");
172 cancel.addActionListener(this);
173 cancel.setActionCommand("cancel");
175 JPanel buttonPane = new JPanel();
176 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
177 buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
178 buttonPane.add(Box.createHorizontalGlue());
179 buttonPane.add(cancel);
180 buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
183 /* Add the buttons to the container */
184 contentPane.add(buttonPane, BorderLayout.PAGE_END);
186 /* Pack the window! */