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 log.selected = action.isSelected();
41 public AltosEepromItem(AltosEepromLog in_log) {
46 text = String.format("Flight #%02d - %04d-%02d-%02d",
47 log.flight, log.year, log.month, log.day);
49 text = String.format("Flight #%02d", log.flight);
51 label = new JLabel(text);
53 action = new JCheckBox("", log.selected);
54 action.addActionListener(this);
58 public class AltosEepromSelect extends AltosDialog implements ActionListener {
65 /* Listen for events from our buttons */
66 public void actionPerformed(ActionEvent e) {
67 String cmd = e.getActionCommand();
74 public boolean run() {
76 setLocationRelativeTo(frame);
81 public AltosEepromSelect (JFrame in_frame,
82 AltosEepromList flights,
85 super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true);
88 /* Create the container for the dialog */
89 Container contentPane = getContentPane();
91 /* First, we create a pane containing the dialog's header/title */
92 JLabel selectLabel = new JLabel(String.format ("Select flights to %s", action), SwingConstants.CENTER);
94 JPanel labelPane = new JPanel();
95 labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS));
96 labelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
97 labelPane.add(Box.createHorizontalGlue());
98 labelPane.add(selectLabel);
99 labelPane.add(Box.createHorizontalGlue());
101 /* Add the header to the container. */
102 contentPane.add(labelPane, BorderLayout.PAGE_START);
105 /* Now we create the evilness that is a GridBag for the flight details */
106 GridBagConstraints c;
107 Insets i = new Insets(4,4,4,4);
108 JPanel flightPane = new JPanel();
109 flightPane.setLayout(new GridBagLayout());
110 flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
113 c = new GridBagConstraints();
114 c.gridx = 0; c.gridy = 0;
115 c.fill = GridBagConstraints.NONE;
117 c.anchor = GridBagConstraints.CENTER;
119 JLabel flightHeaderLabel = new JLabel("Flight");
120 flightPane.add(flightHeaderLabel, c);
122 /* Download Header */
123 c = new GridBagConstraints();
124 c.gridx = 1; c.gridy = 0;
125 c.fill = GridBagConstraints.NONE;
127 c.anchor = GridBagConstraints.CENTER;
129 JLabel downloadHeaderLabel = new JLabel(action);
130 flightPane.add(downloadHeaderLabel, c);
132 /* Add the flights to the GridBag */
133 AltosEepromItem item;
135 for (AltosEepromLog flight : flights) {
136 /* Create a flight object with handlers and
137 * appropriate UI items
139 item = new AltosEepromItem(flight);
141 /* Add a decriptive label for the flight */
142 c = new GridBagConstraints();
143 c.gridx = 0; c.gridy = itemNumber;
144 c.fill = GridBagConstraints.NONE;
146 c.anchor = GridBagConstraints.CENTER;
148 flightPane.add(item.label, c);
150 /* Add action checkbox for the flight */
151 c = new GridBagConstraints();
152 c.gridx = 1; c.gridy = itemNumber;
153 c.fill = GridBagConstraints.NONE;
155 c.anchor = GridBagConstraints.CENTER;
157 flightPane.add(item.action, c);
162 /* Add the GridBag to the container */
163 contentPane.add(flightPane, BorderLayout.CENTER);
165 /* Create the dialog buttons */
166 ok = new JButton("OK");
167 ok.addActionListener(this);
168 ok.setActionCommand("ok");
170 cancel = new JButton("Cancel");
171 cancel.addActionListener(this);
172 cancel.setActionCommand("cancel");
174 JPanel buttonPane = new JPanel();
175 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
176 buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
177 buttonPane.add(Box.createHorizontalGlue());
178 buttonPane.add(cancel);
179 buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
182 /* Add the buttons to the container */
183 contentPane.add(buttonPane, BorderLayout.PAGE_END);
185 /* Pack the window! */