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.
18 package org.altusmetrum.altosuilib_11;
21 import javax.swing.border.*;
23 import java.awt.event.*;
24 import org.altusmetrum.altoslib_11.*;
26 class AltosEepromItem implements ActionListener {
32 public void actionPerformed(ActionEvent e) {
33 log.selected = action.isSelected();
36 public AltosEepromItem(AltosEepromLog in_log) {
41 text = String.format("Flight #%02d - %04d-%02d-%02d",
42 log.flight, log.year, log.month, log.day);
44 text = String.format("Flight #%02d", log.flight);
46 label = new JLabel(text);
48 action = new JCheckBox("", log.selected);
49 action.addActionListener(this);
53 public class AltosEepromSelect extends AltosUIDialog implements ActionListener {
60 /* Listen for events from our buttons */
61 public void actionPerformed(ActionEvent e) {
62 String cmd = e.getActionCommand();
69 public boolean run() {
71 setLocationRelativeTo(frame);
76 public AltosEepromSelect (JFrame in_frame,
77 AltosEepromList flights,
80 super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true);
83 /* Create the container for the dialog */
84 Container contentPane = getContentPane();
86 /* First, we create a pane containing the dialog's header/title */
87 JLabel selectLabel = new JLabel(String.format ("Select flights to %s", action), SwingConstants.CENTER);
89 JPanel labelPane = new JPanel();
90 labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS));
91 labelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
92 labelPane.add(Box.createHorizontalGlue());
93 labelPane.add(selectLabel);
94 labelPane.add(Box.createHorizontalGlue());
96 /* Add the header to the container. */
97 contentPane.add(labelPane, BorderLayout.PAGE_START);
100 /* Now we create the evilness that is a GridBag for the flight details */
101 GridBagConstraints c;
102 Insets i = new Insets(4,4,4,4);
103 JPanel flightPane = new JPanel();
104 flightPane.setLayout(new GridBagLayout());
105 flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
108 c = new GridBagConstraints();
109 c.gridx = 0; c.gridy = 0;
110 c.fill = GridBagConstraints.NONE;
112 c.anchor = GridBagConstraints.CENTER;
114 JLabel flightHeaderLabel = new JLabel("Flight");
115 flightPane.add(flightHeaderLabel, c);
117 /* Download Header */
118 c = new GridBagConstraints();
119 c.gridx = 1; c.gridy = 0;
120 c.fill = GridBagConstraints.NONE;
122 c.anchor = GridBagConstraints.CENTER;
124 JLabel downloadHeaderLabel = new JLabel(action);
125 flightPane.add(downloadHeaderLabel, c);
127 /* Add the flights to the GridBag */
128 AltosEepromItem item;
130 for (AltosEepromLog flight : flights) {
131 /* Create a flight object with handlers and
132 * appropriate UI items
134 item = new AltosEepromItem(flight);
136 /* Add a decriptive label for the flight */
137 c = new GridBagConstraints();
138 c.gridx = 0; c.gridy = itemNumber;
139 c.fill = GridBagConstraints.NONE;
141 c.anchor = GridBagConstraints.CENTER;
143 flightPane.add(item.label, c);
145 /* Add action checkbox for the flight */
146 c = new GridBagConstraints();
147 c.gridx = 1; c.gridy = itemNumber;
148 c.fill = GridBagConstraints.NONE;
150 c.anchor = GridBagConstraints.CENTER;
152 flightPane.add(item.action, c);
157 /* Add the GridBag to the container */
158 contentPane.add(flightPane, BorderLayout.CENTER);
160 /* Create the dialog buttons */
161 ok = new JButton("OK");
162 ok.addActionListener(this);
163 ok.setActionCommand("ok");
165 cancel = new JButton("Cancel");
166 cancel.addActionListener(this);
167 cancel.setActionCommand("cancel");
169 JPanel buttonPane = new JPanel();
170 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
171 buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
172 buttonPane.add(Box.createHorizontalGlue());
173 buttonPane.add(cancel);
174 buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
177 /* Add the buttons to the container */
178 contentPane.add(buttonPane, BorderLayout.PAGE_END);
180 /* Pack the window! */