altosui: Remove spurious colons from eeprom selection headers
[fw/altos] / altosui / AltosEepromSelect.java
1 /*
2  * Copyright © 2011 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 package altosui;
19
20 import java.lang.*;
21 import java.util.*;
22 import javax.swing.*;
23 import javax.swing.border.*;
24 import java.awt.*;
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;
30
31 class AltosEepromItem implements ActionListener {
32         AltosEepromLog  log;
33         JLabel          label;
34         JCheckBox       download;
35         JCheckBox       delete;
36
37         public void actionPerformed(ActionEvent e) {
38                 System.out.printf("eeprom item action %s %d\n", e.getActionCommand(), e.getID());
39                 if (e.getSource() == download) {
40                         log.download = download.isSelected();
41                         System.out.printf("download for flight %d set to %b\n", log.flight, log.download);
42                 } else if (e.getSource() == delete) {
43                         log.delete = delete.isSelected();
44                         System.out.printf("delete for flight %d set to %b\n", log.flight, log.delete);
45                 }
46         }
47
48         public AltosEepromItem(AltosEepromLog in_log) {
49                 log = in_log;
50
51                 label = new JLabel(String.format("Flight #%02d - %04d-%02d-%02d",
52                                                  log.flight, log.year, log.month, log.day));
53
54                 download = new JCheckBox("", log.download);
55                 download.addActionListener(this);
56
57                 delete = new JCheckBox("", log.delete);
58                 delete.addActionListener(this);
59         }
60 }
61
62 public class AltosEepromSelect extends JDialog implements ActionListener {
63         private JList                   list;
64         private JFrame                  frame;
65         JButton                         ok;
66         JButton                         cancel;
67         boolean                         success;
68
69         /* Listen for events from our buttons */
70         public void actionPerformed(ActionEvent e) {
71                 String  cmd = e.getActionCommand();
72
73                 if (cmd.equals("ok"))
74                         success = true;
75                 setVisible(false);
76         }
77
78         public boolean run() {
79                 success = false;
80                 setLocationRelativeTo(frame);
81                 setVisible(true);
82                 return success;
83         }
84
85         public AltosEepromSelect (JFrame in_frame,
86                                   AltosEepromList flights) {
87
88                 super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true);
89                 frame = in_frame;
90
91                 /* Create the container for the dialog */
92                 Container contentPane = getContentPane();
93
94                 /* First, we create a pane containing the dialog's header/title */
95                 JLabel  selectLabel = new JLabel("Select flights to download and/or delete", SwingConstants.CENTER);
96
97                 JPanel  labelPane = new JPanel();
98                 labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS));
99                 labelPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
100                 labelPane.add(Box.createHorizontalGlue());
101                 labelPane.add(selectLabel);
102                 labelPane.add(Box.createHorizontalGlue());
103
104                 /* Add the header to the container. */
105                 contentPane.add(labelPane, BorderLayout.PAGE_START);
106
107
108                 /* Now we create the evilness that is a GridBag for the flight details */
109                 GridBagConstraints c;
110                 Insets i = new Insets(4,4,4,4);
111                 JPanel flightPane = new JPanel();
112                 flightPane.setLayout(new GridBagLayout());
113                 flightPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
114
115                 /* Flight Header */
116                 c = new GridBagConstraints();
117                 c.gridx = 0; c.gridy = 0;
118                 c.fill = GridBagConstraints.NONE;
119                 c.weightx = 0.5;
120                 c.anchor = GridBagConstraints.CENTER;
121                 c.insets = i;
122                 JLabel flightHeaderLabel = new JLabel("Flight");
123                 flightPane.add(flightHeaderLabel, c);
124
125                 /* Download Header */
126                 c = new GridBagConstraints();
127                 c.gridx = 1; c.gridy = 0;
128                 c.fill = GridBagConstraints.NONE;
129                 c.weightx = 0.5;
130                 c.anchor = GridBagConstraints.CENTER;
131                 c.insets = i;
132                 JLabel downloadHeaderLabel = new JLabel("Download");
133                 flightPane.add(downloadHeaderLabel, c);
134
135                 /* Delete Header */
136                 c = new GridBagConstraints();
137                 c.gridx = 2; c.gridy = 0;
138                 c.fill = GridBagConstraints.NONE;
139                 c.weightx = 0.5;
140                 c.anchor = GridBagConstraints.CENTER;
141                 c.insets = i;
142                 JLabel deleteHeaderLabel = new JLabel("Delete");
143                 flightPane.add(deleteHeaderLabel, c);
144
145                 /* Add the flights to the GridBag */
146                 AltosEepromItem item;
147                 int itemNumber = 1;
148                 for (AltosEepromLog flight : flights) {
149                         /* Create a flight object with handlers and
150                          * appropriate UI items
151                          */
152                         item = new AltosEepromItem(flight);
153
154                         /* Add a decriptive label for the flight */
155                         c = new GridBagConstraints();
156                         c.gridx = 0; c.gridy = itemNumber;
157                         c.fill = GridBagConstraints.NONE;
158                         c.weightx = 0.5;
159                         c.anchor = GridBagConstraints.CENTER;
160                         c.insets = i;
161                         flightPane.add(item.label, c);
162
163                         /* Add a download checkbox for the flight */
164                         c = new GridBagConstraints();
165                         c.gridx = 1; c.gridy = itemNumber;
166                         c.fill = GridBagConstraints.NONE;
167                         c.weightx = 0.5;
168                         c.anchor = GridBagConstraints.CENTER;
169                         c.insets = i;
170                         flightPane.add(item.download, c);
171
172                         /* Add a delete checkbox for the flight */
173                         c = new GridBagConstraints();
174                         c.gridx = 2; c.gridy = itemNumber;
175                         c.fill = GridBagConstraints.NONE;
176                         c.weightx = 0.5;
177                         c.anchor = GridBagConstraints.CENTER;
178                         c.insets = i;
179                         flightPane.add(item.delete, c);
180
181                         itemNumber++;
182                 }
183
184                 /* Add the GridBag to the container */
185                 contentPane.add(flightPane, BorderLayout.CENTER);
186
187                 /* Create the dialog buttons */
188                 ok = new JButton("OK");
189                 ok.addActionListener(this);
190                 ok.setActionCommand("ok");
191
192                 cancel = new JButton("Cancel");
193                 cancel.addActionListener(this);
194                 cancel.setActionCommand("cancel");
195
196                 JPanel  buttonPane = new JPanel();
197                 buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS));
198                 buttonPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
199                 buttonPane.add(Box.createHorizontalGlue());
200                 buttonPane.add(cancel);
201                 buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
202                 buttonPane.add(ok);
203
204                 /* Add the buttons to the container */
205                 contentPane.add(buttonPane, BorderLayout.PAGE_END);
206
207                 /* Pack the window! */
208                 pack();
209         }
210 }