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.
21 import javax.swing.border.*;
23 import java.awt.event.*;
24 import org.altusmetrum.altoslib_2.*;
25 import org.altusmetrum.altosuilib_1.*;
27 class AltosEepromItem implements ActionListener {
33 public void actionPerformed(ActionEvent e) {
34 log.selected = action.isSelected();
37 public AltosEepromItem(AltosEepromLog in_log) {
42 text = String.format("Flight #%02d - %04d-%02d-%02d",
43 log.flight, log.year, log.month, log.day);
45 text = String.format("Flight #%02d", log.flight);
47 label = new JLabel(text);
49 action = new JCheckBox("", log.selected);
50 action.addActionListener(this);
54 public class AltosEepromSelect extends AltosUIDialog implements ActionListener {
61 /* Listen for events from our buttons */
62 public void actionPerformed(ActionEvent e) {
63 String cmd = e.getActionCommand();
70 public boolean run() {
72 setLocationRelativeTo(frame);
77 public AltosEepromSelect (JFrame in_frame,
78 AltosEepromList flights,
81 super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true);
84 /* Create the container for the dialog */
85 Container contentPane = getContentPane();
87 /* First, we create a pane containing the dialog's header/title */
88 JLabel selectLabel = new JLabel(String.format ("Select flights to %s", action), SwingConstants.CENTER);
90 JPanel labelPane = new JPanel();
91 labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS));
92 labelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
93 labelPane.add(Box.createHorizontalGlue());
94 labelPane.add(selectLabel);
95 labelPane.add(Box.createHorizontalGlue());
97 /* Add the header to the container. */
98 contentPane.add(labelPane, BorderLayout.PAGE_START);
101 /* Now we create the evilness that is a GridBag for the flight details */
102 GridBagConstraints c;
103 Insets i = new Insets(4,4,4,4);
104 JPanel flightPane = new JPanel();
105 flightPane.setLayout(new GridBagLayout());
106 flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
109 c = new GridBagConstraints();
110 c.gridx = 0; c.gridy = 0;
111 c.fill = GridBagConstraints.NONE;
113 c.anchor = GridBagConstraints.CENTER;
115 JLabel flightHeaderLabel = new JLabel("Flight");
116 flightPane.add(flightHeaderLabel, c);
118 /* Download Header */
119 c = new GridBagConstraints();
120 c.gridx = 1; c.gridy = 0;
121 c.fill = GridBagConstraints.NONE;
123 c.anchor = GridBagConstraints.CENTER;
125 JLabel downloadHeaderLabel = new JLabel(action);
126 flightPane.add(downloadHeaderLabel, c);
128 /* Add the flights to the GridBag */
129 AltosEepromItem item;
131 for (AltosEepromLog flight : flights) {
132 /* Create a flight object with handlers and
133 * appropriate UI items
135 item = new AltosEepromItem(flight);
137 /* Add a decriptive label for the flight */
138 c = new GridBagConstraints();
139 c.gridx = 0; c.gridy = itemNumber;
140 c.fill = GridBagConstraints.NONE;
142 c.anchor = GridBagConstraints.CENTER;
144 flightPane.add(item.label, c);
146 /* Add action checkbox for the flight */
147 c = new GridBagConstraints();
148 c.gridx = 1; c.gridy = itemNumber;
149 c.fill = GridBagConstraints.NONE;
151 c.anchor = GridBagConstraints.CENTER;
153 flightPane.add(item.action, c);
158 /* Add the GridBag to the container */
159 contentPane.add(flightPane, BorderLayout.CENTER);
161 /* Create the dialog buttons */
162 ok = new JButton("OK");
163 ok.addActionListener(this);
164 ok.setActionCommand("ok");
166 cancel = new JButton("Cancel");
167 cancel.addActionListener(this);
168 cancel.setActionCommand("cancel");
170 JPanel buttonPane = new JPanel();
171 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
172 buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
173 buttonPane.add(Box.createHorizontalGlue());
174 buttonPane.add(cancel);
175 buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
178 /* Add the buttons to the container */
179 contentPane.add(buttonPane, BorderLayout.PAGE_END);
181 /* Pack the window! */