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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altosuilib_13;
22 import javax.swing.border.*;
24 import java.awt.event.*;
25 import org.altusmetrum.altoslib_13.*;
27 class AltosEepromItem implements ActionListener {
34 public void actionPerformed(ActionEvent e) {
35 log.download_selected = download.isSelected();
36 log.delete_selected = delete.isSelected();
37 log.graph_selected = graph.isSelected();
40 public AltosEepromItem(AltosEepromLog in_log) {
45 text = String.format("Flight #%02d", log.flight);
47 text = String.format("Corrupt #%02d", -log.flight);
49 label = new JLabel(text);
51 download = new JCheckBox("", log.download_selected);
52 download.addActionListener(this);
54 delete = new JCheckBox("", log.delete_selected);
55 delete.addActionListener(this);
57 graph = new JCheckBox("", log.graph_selected);
58 graph.addActionListener(this);
62 public class AltosEepromSelect extends AltosUIDialog 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,
89 super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true);
92 /* Create the container for the dialog */
93 Container contentPane = getContentPane();
95 /* First, we create a pane containing the dialog's header/title */
96 JLabel selectLabel = new JLabel(String.format ("Select flights"), SwingConstants.CENTER);
98 JPanel labelPane = new JPanel();
99 labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS));
100 labelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
101 labelPane.add(Box.createHorizontalGlue());
102 labelPane.add(selectLabel);
103 labelPane.add(Box.createHorizontalGlue());
105 /* Add the header to the container. */
106 contentPane.add(labelPane, BorderLayout.PAGE_START);
109 /* Now we create the evilness that is a GridBag for the flight details */
110 GridBagConstraints c;
111 Insets i = new Insets(4,4,4,4);
112 JPanel flightPane = new JPanel();
113 flightPane.setLayout(new GridBagLayout());
114 flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
117 c = new GridBagConstraints();
118 c.gridx = 0; c.gridy = 0;
119 c.fill = GridBagConstraints.NONE;
121 c.anchor = GridBagConstraints.CENTER;
123 JLabel flightHeaderLabel = new JLabel("Flight");
124 flightPane.add(flightHeaderLabel, c);
126 /* Download Header */
127 c = new GridBagConstraints();
128 c.gridx = 1; c.gridy = 0;
129 c.fill = GridBagConstraints.NONE;
131 c.anchor = GridBagConstraints.CENTER;
133 JLabel downloadHeaderLabel = new JLabel("Download");
134 flightPane.add(downloadHeaderLabel, c);
137 c = new GridBagConstraints();
138 c.gridx = 2; c.gridy = 0;
139 c.fill = GridBagConstraints.NONE;
141 c.anchor = GridBagConstraints.CENTER;
143 JLabel deleteHeaderLabel = new JLabel("Delete");
144 flightPane.add(deleteHeaderLabel, c);
148 c = new GridBagConstraints();
149 c.gridx = 3; c.gridy = 0;
150 c.fill = GridBagConstraints.NONE;
152 c.anchor = GridBagConstraints.CENTER;
154 JLabel graphHeaderLabel = new JLabel("Graph");
155 flightPane.add(graphHeaderLabel, c);
158 /* Add the flights to the GridBag */
159 AltosEepromItem item;
161 for (AltosEepromLog flight : flights) {
162 /* Create a flight object with handlers and
163 * appropriate UI items
165 item = new AltosEepromItem(flight);
167 /* Add a decriptive label for the flight */
168 c = new GridBagConstraints();
169 c.gridx = 0; c.gridy = itemNumber;
170 c.fill = GridBagConstraints.NONE;
172 c.anchor = GridBagConstraints.CENTER;
174 flightPane.add(item.label, c);
176 /* Add download checkbox for the flight */
177 c = new GridBagConstraints();
178 c.gridx = 1; c.gridy = itemNumber;
179 c.fill = GridBagConstraints.NONE;
181 c.anchor = GridBagConstraints.CENTER;
183 flightPane.add(item.download, c);
185 /* Add delete checkbox for the flight */
186 c = new GridBagConstraints();
187 c.gridx = 2; c.gridy = itemNumber;
188 c.fill = GridBagConstraints.NONE;
190 c.anchor = GridBagConstraints.CENTER;
192 flightPane.add(item.delete, c);
195 /* Add graph checkbox for the flight */
196 c = new GridBagConstraints();
197 c.gridx = 3; c.gridy = itemNumber;
198 c.fill = GridBagConstraints.NONE;
200 c.anchor = GridBagConstraints.CENTER;
202 flightPane.add(item.graph, c);
208 /* Add the GridBag to the container */
209 contentPane.add(flightPane, BorderLayout.CENTER);
211 /* Create the dialog buttons */
212 ok = new JButton("OK");
213 ok.addActionListener(this);
214 ok.setActionCommand("ok");
216 cancel = new JButton("Cancel");
217 cancel.addActionListener(this);
218 cancel.setActionCommand("cancel");
220 JPanel buttonPane = new JPanel();
221 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
222 buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
223 buttonPane.add(Box.createHorizontalGlue());
224 buttonPane.add(cancel);
225 buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
228 /* Add the buttons to the container */
229 contentPane.add(buttonPane, BorderLayout.PAGE_END);
231 /* Pack the window! */