summaryrefslogtreecommitdiff
path: root/altosuilib
diff options
context:
space:
mode:
Diffstat (limited to 'altosuilib')
-rw-r--r--altosuilib/AltosEepromDelete.java2
-rw-r--r--altosuilib/AltosEepromManage.java72
-rw-r--r--altosuilib/AltosEepromMonitorUI.java77
-rw-r--r--altosuilib/AltosEepromSelect.java74
4 files changed, 145 insertions, 80 deletions
diff --git a/altosuilib/AltosEepromDelete.java b/altosuilib/AltosEepromDelete.java
index 87e80a51..d7dde6df 100644
--- a/altosuilib/AltosEepromDelete.java
+++ b/altosuilib/AltosEepromDelete.java
@@ -84,7 +84,7 @@ public class AltosEepromDelete implements Runnable {
serial_line.start_remote();
for (AltosEepromLog log : flights) {
- if (log.selected) {
+ if (log.delete_selected) {
DeleteLog(log);
}
}
diff --git a/altosuilib/AltosEepromManage.java b/altosuilib/AltosEepromManage.java
index 93827139..1adf1f0a 100644
--- a/altosuilib/AltosEepromManage.java
+++ b/altosuilib/AltosEepromManage.java
@@ -33,6 +33,7 @@ public class AltosEepromManage implements ActionListener {
AltosEepromList flights;
AltosEepromDownload download;
AltosEepromDelete delete;
+ AltosEepromGrapher grapher;
public void finish() {
if (serial_line != null) {
@@ -48,7 +49,7 @@ public class AltosEepromManage implements ActionListener {
private int countDeletedFlights() {
int count = 0;
for (AltosEepromLog flight : flights) {
- if (flight.selected)
+ if (flight.delete_selected)
count++;
}
return count;
@@ -58,7 +59,7 @@ public class AltosEepromManage implements ActionListener {
String result = "";
for (AltosEepromLog flight : flights) {
- if (flight.selected) {
+ if (flight.delete_selected) {
if (result.equals(""))
result = String.format("%d", flight.flight);
else
@@ -68,38 +69,49 @@ public class AltosEepromManage implements ActionListener {
return result;
}
- public boolean download_done() {
- AltosEepromSelect select = new AltosEepromSelect(frame, flights, "Delete");
-
- if (select.run()) {
- boolean any_selected = false;
- for (AltosEepromLog flight : flights)
- any_selected = any_selected || flight.selected;
- if (any_selected) {
- delete = new AltosEepromDelete(frame,
- serial_line,
- remote,
- flights);
- delete.addActionListener(this);
- /*
- * Start flight log delete
- */
-
- delete.start();
- return true;
- }
+ public boolean delete_start() {
+
+ boolean any_selected = false;
+ for (AltosEepromLog flight : flights)
+ any_selected = any_selected || flight.delete_selected;
+ if (any_selected) {
+ delete = new AltosEepromDelete(frame,
+ serial_line,
+ remote,
+ flights);
+ delete.addActionListener(this);
+ /*
+ * Start flight log delete
+ */
+
+ delete.start();
+ return true;
}
return false;
}
+ public void graph_start() {
+ boolean any_selected = false;
+ for (AltosEepromLog flight : flights) {
+ if (!flight.download_selected)
+ flight.graph_selected = false;
+ any_selected = any_selected || flight.graph_selected;
+ }
+ if (any_selected && grapher != null)
+ grapher.graph_flights(flights);
+ }
+
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
boolean success = e.getID() != 0;
boolean running = false;
if (cmd.equals("download")) {
- if (success)
- running = download_done();
+ if (success) {
+ running = delete_start();
+ if (!running)
+ graph_start();
+ }
} else if (cmd.equals("delete")) {
if (success) {
JOptionPane.showMessageDialog(frame,
@@ -108,6 +120,7 @@ public class AltosEepromManage implements ActionListener {
showDeletedFlights()),
serial_line.device.toShortString(),
JOptionPane.INFORMATION_MESSAGE);
+ graph_start();
}
}
if (!running)
@@ -126,12 +139,12 @@ public class AltosEepromManage implements ActionListener {
serial_line.device.toShortString(),
JOptionPane.INFORMATION_MESSAGE);
} else {
- AltosEepromSelect select = new AltosEepromSelect(frame, flights, "Download");
+ AltosEepromSelect select = new AltosEepromSelect(frame, flights, grapher != null);
if (select.run()) {
boolean any_selected = false;
for (AltosEepromLog flight : flights)
- any_selected = any_selected || flight.selected;
+ any_selected = any_selected || flight.download_selected;
if (any_selected) {
AltosEepromMonitorUI monitor = new AltosEepromMonitorUI(frame);
monitor.addActionListener(this);
@@ -147,7 +160,9 @@ public class AltosEepromManage implements ActionListener {
download.start();
running = true;
} else {
- running = download_done();
+ running = delete_start();
+ if (!running)
+ graph_start();
}
}
}
@@ -205,11 +220,12 @@ public class AltosEepromManage implements ActionListener {
}
}
- public AltosEepromManage(JFrame given_frame, int product) {
+ public AltosEepromManage(JFrame given_frame, AltosEepromGrapher grapher, int product) {
//boolean running = false;
frame = given_frame;
+ this.grapher = grapher;
device = AltosDeviceUIDialog.show(frame, product);
remote = false;
diff --git a/altosuilib/AltosEepromMonitorUI.java b/altosuilib/AltosEepromMonitorUI.java
index 3427fe0f..fc6c95c6 100644
--- a/altosuilib/AltosEepromMonitorUI.java
+++ b/altosuilib/AltosEepromMonitorUI.java
@@ -18,11 +18,18 @@
package org.altusmetrum.altosuilib_12;
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.altusmetrum.altoslib_12.*;
+ class result_holder {
+ static int result;
+ }
+
public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMonitor {
JFrame owner;
Container pane;
@@ -32,7 +39,6 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
JLabel file_label;
JLabel serial_value;
JLabel flight_value;
- JLabel file_value;
JButton cancel;
JProgressBar pbar;
ActionListener listener;
@@ -42,6 +48,8 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
public AltosEepromMonitorUI(JFrame owner) {
super (owner, "Download Flight Data", false);
+ setMinimumSize(new Dimension(600, 100));
+
this.owner = owner;
GridBagConstraints c;
@@ -85,30 +93,11 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
flight_value = new JLabel("");
pane.add(flight_value, c);
- c = new GridBagConstraints();
- c.fill = GridBagConstraints.NONE;
- c.gridx = 0; c.gridy = 2;
- c.anchor = GridBagConstraints.LINE_START;
- c.insets = il;
- file_label = new JLabel("File:");
- pane.add(file_label, c);
-
- c = new GridBagConstraints();
- c.fill = GridBagConstraints.HORIZONTAL;
- c.weightx = 1;
- c.gridx = 1; c.gridy = 2;
- c.anchor = GridBagConstraints.LINE_START;
- c.insets = ir;
- file_value = new JLabel("");
- pane.add(file_value, c);
-
pbar = new JProgressBar();
pbar.setMinimum(0);
pbar.setMaximum(progress_max);
- pbar.setValue(0);
- pbar.setString("startup");
pbar.setStringPainted(true);
- pbar.setPreferredSize(new Dimension(600, 20));
+ set_block_internal(0);
c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
@@ -118,7 +107,6 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
c.insets = ib;
pane.add(pbar, c);
-
cancel = new JButton("Cancel");
c = new GridBagConstraints();
c.fill = GridBagConstraints.NONE;
@@ -141,8 +129,9 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
final Thread eeprom_thread = in_eeprom_thread;
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- if (eeprom_thread != null)
+ if (eeprom_thread != null) {
eeprom_thread.interrupt();
+ }
}
});
}
@@ -162,6 +151,7 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
s = String.format("block %d of %d", block, max_block);
pbar.setString(s);
+ pbar.setStringPainted(true);
pbar.setValue((int) (pos * progress_max));
}
@@ -216,23 +206,6 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
SwingUtilities.invokeLater(r);
}
- private void set_filename_internal(String filename) {
- file_value.setText(String.format("%s", filename));
- }
-
- public void set_filename(String in_filename) {
- final String filename = in_filename;
- Runnable r = new Runnable() {
- public void run() {
- try {
- set_filename_internal(filename);
- } catch (Exception ex) {
- }
- }
- };
- SwingUtilities.invokeLater(r);
- }
-
private void done_internal(boolean success) {
listener.actionPerformed(new ActionEvent(this,
success ? 1 : 0,
@@ -258,7 +231,6 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
set_max(1);
set_block_internal(0);
set_flight_internal(0);
- set_filename_internal("");
}
public void reset() {
@@ -293,6 +265,29 @@ public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMo
joption_message_type);
}
+ public Boolean check_overwrite(File in_file) {
+ final Semaphore check_overwrite_done = new Semaphore(0);
+ final File file = in_file;
+ final result_holder result = new result_holder();
+
+ Runnable r = new Runnable() {
+ public void run() {
+ result_holder.result = JOptionPane.showConfirmDialog(owner,
+ String.format("\"%s\" already exists, overwrite?",
+ file.toString()),
+ "Overwrite Existing File?",
+ JOptionPane.YES_NO_OPTION);
+ check_overwrite_done.release();
+ }
+ };
+
+ SwingUtilities.invokeLater(r);
+ try {
+ check_overwrite_done.acquire();
+ } catch (Exception e) {}
+ return result_holder.result == JOptionPane.YES_OPTION;
+ }
+
public void show_message(String in_message, String in_title, int in_message_type) {
final String message = in_message;
final String title = in_title;
diff --git a/altosuilib/AltosEepromSelect.java b/altosuilib/AltosEepromSelect.java
index 0c890c8b..f88f2bd6 100644
--- a/altosuilib/AltosEepromSelect.java
+++ b/altosuilib/AltosEepromSelect.java
@@ -27,23 +27,35 @@ import org.altusmetrum.altoslib_12.*;
class AltosEepromItem implements ActionListener {
AltosEepromLog log;
JLabel label;
- JCheckBox action;
+ JCheckBox download;
JCheckBox delete;
+ JCheckBox graph;
public void actionPerformed(ActionEvent e) {
- log.selected = action.isSelected();
+ log.download_selected = download.isSelected();
+ log.delete_selected = delete.isSelected();
+ log.graph_selected = graph.isSelected();
}
public AltosEepromItem(AltosEepromLog in_log) {
log = in_log;
String text;
- text = String.format("Flight #%02d", log.flight);
+ if (log.flight >= 0)
+ text = String.format("Flight #%02d", log.flight);
+ else
+ text = String.format("Corrupt #%02d", -log.flight);
label = new JLabel(text);
- action = new JCheckBox("", log.selected);
- action.addActionListener(this);
+ download = new JCheckBox("", log.download_selected);
+ download.addActionListener(this);
+
+ delete = new JCheckBox("", log.delete_selected);
+ delete.addActionListener(this);
+
+ graph = new JCheckBox("", log.graph_selected);
+ graph.addActionListener(this);
}
}
@@ -72,7 +84,7 @@ public class AltosEepromSelect extends AltosUIDialog implements ActionListener {
public AltosEepromSelect (JFrame in_frame,
AltosEepromList flights,
- String action) {
+ boolean has_graph) {
super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true);
frame = in_frame;
@@ -81,7 +93,7 @@ public class AltosEepromSelect extends AltosUIDialog implements ActionListener {
Container contentPane = getContentPane();
/* First, we create a pane containing the dialog's header/title */
- JLabel selectLabel = new JLabel(String.format ("Select flights to %s", action), SwingConstants.CENTER);
+ JLabel selectLabel = new JLabel(String.format ("Select flights"), SwingConstants.CENTER);
JPanel labelPane = new JPanel();
labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS));
@@ -118,9 +130,31 @@ public class AltosEepromSelect extends AltosUIDialog implements ActionListener {
c.weightx = 0.5;
c.anchor = GridBagConstraints.CENTER;
c.insets = i;
- JLabel downloadHeaderLabel = new JLabel(action);
+ JLabel downloadHeaderLabel = new JLabel("Download");
flightPane.add(downloadHeaderLabel, c);
+ /* Delete Header */
+ c = new GridBagConstraints();
+ c.gridx = 2; c.gridy = 0;
+ c.fill = GridBagConstraints.NONE;
+ c.weightx = 0.5;
+ c.anchor = GridBagConstraints.CENTER;
+ c.insets = i;
+ JLabel deleteHeaderLabel = new JLabel("Delete");
+ flightPane.add(deleteHeaderLabel, c);
+
+ if (has_graph) {
+ /* Graph Header */
+ c = new GridBagConstraints();
+ c.gridx = 3; c.gridy = 0;
+ c.fill = GridBagConstraints.NONE;
+ c.weightx = 0.5;
+ c.anchor = GridBagConstraints.CENTER;
+ c.insets = i;
+ JLabel graphHeaderLabel = new JLabel("Graph");
+ flightPane.add(graphHeaderLabel, c);
+ }
+
/* Add the flights to the GridBag */
AltosEepromItem item;
int itemNumber = 1;
@@ -139,14 +173,34 @@ public class AltosEepromSelect extends AltosUIDialog implements ActionListener {
c.insets = i;
flightPane.add(item.label, c);
- /* Add action checkbox for the flight */
+ /* Add download checkbox for the flight */
c = new GridBagConstraints();
c.gridx = 1; c.gridy = itemNumber;
c.fill = GridBagConstraints.NONE;
c.weightx = 0.5;
c.anchor = GridBagConstraints.CENTER;
c.insets = i;
- flightPane.add(item.action, c);
+ flightPane.add(item.download, c);
+
+ /* Add delete checkbox for the flight */
+ c = new GridBagConstraints();
+ c.gridx = 2; c.gridy = itemNumber;
+ c.fill = GridBagConstraints.NONE;
+ c.weightx = 0.5;
+ c.anchor = GridBagConstraints.CENTER;
+ c.insets = i;
+ flightPane.add(item.delete, c);
+
+ if (has_graph) {
+ /* Add graph checkbox for the flight */
+ c = new GridBagConstraints();
+ c.gridx = 3; c.gridy = itemNumber;
+ c.fill = GridBagConstraints.NONE;
+ c.weightx = 0.5;
+ c.anchor = GridBagConstraints.CENTER;
+ c.insets = i;
+ flightPane.add(item.graph, c);
+ }
itemNumber++;
}