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_12;
22 import javax.swing.border.*;
24 import java.awt.event.*;
25 import org.altusmetrum.altoslib_12.*;
27 class AltosEepromItem implements ActionListener {
33 public void actionPerformed(ActionEvent e) {
34 log.selected = action.isSelected();
37 public AltosEepromItem(AltosEepromLog in_log) {
41 text = String.format("Flight #%02d", log.flight);
43 label = new JLabel(text);
45 action = new JCheckBox("", log.selected);
46 action.addActionListener(this);
50 public class AltosEepromSelect extends AltosUIDialog implements ActionListener {
57 /* Listen for events from our buttons */
58 public void actionPerformed(ActionEvent e) {
59 String cmd = e.getActionCommand();
66 public boolean run() {
68 setLocationRelativeTo(frame);
73 public AltosEepromSelect (JFrame in_frame,
74 AltosEepromList flights,
77 super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true);
80 /* Create the container for the dialog */
81 Container contentPane = getContentPane();
83 /* First, we create a pane containing the dialog's header/title */
84 JLabel selectLabel = new JLabel(String.format ("Select flights to %s", action), SwingConstants.CENTER);
86 JPanel labelPane = new JPanel();
87 labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS));
88 labelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
89 labelPane.add(Box.createHorizontalGlue());
90 labelPane.add(selectLabel);
91 labelPane.add(Box.createHorizontalGlue());
93 /* Add the header to the container. */
94 contentPane.add(labelPane, BorderLayout.PAGE_START);
97 /* Now we create the evilness that is a GridBag for the flight details */
99 Insets i = new Insets(4,4,4,4);
100 JPanel flightPane = new JPanel();
101 flightPane.setLayout(new GridBagLayout());
102 flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
105 c = new GridBagConstraints();
106 c.gridx = 0; c.gridy = 0;
107 c.fill = GridBagConstraints.NONE;
109 c.anchor = GridBagConstraints.CENTER;
111 JLabel flightHeaderLabel = new JLabel("Flight");
112 flightPane.add(flightHeaderLabel, c);
114 /* Download Header */
115 c = new GridBagConstraints();
116 c.gridx = 1; c.gridy = 0;
117 c.fill = GridBagConstraints.NONE;
119 c.anchor = GridBagConstraints.CENTER;
121 JLabel downloadHeaderLabel = new JLabel(action);
122 flightPane.add(downloadHeaderLabel, c);
124 /* Add the flights to the GridBag */
125 AltosEepromItem item;
127 for (AltosEepromLog flight : flights) {
128 /* Create a flight object with handlers and
129 * appropriate UI items
131 item = new AltosEepromItem(flight);
133 /* Add a decriptive label for the flight */
134 c = new GridBagConstraints();
135 c.gridx = 0; c.gridy = itemNumber;
136 c.fill = GridBagConstraints.NONE;
138 c.anchor = GridBagConstraints.CENTER;
140 flightPane.add(item.label, c);
142 /* Add action checkbox for the flight */
143 c = new GridBagConstraints();
144 c.gridx = 1; c.gridy = itemNumber;
145 c.fill = GridBagConstraints.NONE;
147 c.anchor = GridBagConstraints.CENTER;
149 flightPane.add(item.action, c);
154 /* Add the GridBag to the container */
155 contentPane.add(flightPane, BorderLayout.CENTER);
157 /* Create the dialog buttons */
158 ok = new JButton("OK");
159 ok.addActionListener(this);
160 ok.setActionCommand("ok");
162 cancel = new JButton("Cancel");
163 cancel.addActionListener(this);
164 cancel.setActionCommand("cancel");
166 JPanel buttonPane = new JPanel();
167 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
168 buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
169 buttonPane.add(Box.createHorizontalGlue());
170 buttonPane.add(cancel);
171 buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
174 /* Add the buttons to the container */
175 contentPane.add(buttonPane, BorderLayout.PAGE_END);
177 /* Pack the window! */