summaryrefslogtreecommitdiff
path: root/ao-tools/altosui/AltosLogfileChooser.java
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2010-08-23 23:15:05 -0700
committerKeith Packard <keithp@keithp.com>2010-08-23 23:15:05 -0700
commit634a550149e7c344a22a637ba484f115592b1018 (patch)
tree02a6002db9d4988d6fcbbf5736cf0cc03ef67fc0 /ao-tools/altosui/AltosLogfileChooser.java
parenta55b132668a819cc26478a609cb79bd9190deb9d (diff)
altosui: refactor logfile chooser dialog to share more code
Move file opening logic into logfile chooser as it can be shared that way. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'ao-tools/altosui/AltosLogfileChooser.java')
-rw-r--r--ao-tools/altosui/AltosLogfileChooser.java32
1 files changed, 29 insertions, 3 deletions
diff --git a/ao-tools/altosui/AltosLogfileChooser.java b/ao-tools/altosui/AltosLogfileChooser.java
index 72d21fc8..3e9e4892 100644
--- a/ao-tools/altosui/AltosLogfileChooser.java
+++ b/ao-tools/altosui/AltosLogfileChooser.java
@@ -28,16 +28,42 @@ import java.text.*;
import java.util.prefs.*;
import altosui.AltosPreferences;
+import altosui.AltosReader;
+import altosui.AltosEepromReader;
+import altosui.AltosTelemetryReader;
public class AltosLogfileChooser extends JFileChooser {
JFrame frame;
+ String filename;
- public File runDialog() {
+ public String filename() {
+ return filename;
+ }
+
+ public AltosReader runDialog() {
int ret;
ret = showOpenDialog(frame);
- if (ret == APPROVE_OPTION)
- return getSelectedFile();
+ if (ret == APPROVE_OPTION) {
+ File file = getSelectedFile();
+ if (file == null)
+ return null;
+ filename = file.getName();
+ try {
+ FileInputStream in;
+
+ in = new FileInputStream(file);
+ if (filename.endsWith("eeprom"))
+ return new AltosEepromReader(in);
+ else
+ return new AltosTelemetryReader(in);
+ } catch (FileNotFoundException fe) {
+ JOptionPane.showMessageDialog(frame,
+ filename,
+ "Cannot open file",
+ JOptionPane.ERROR_MESSAGE);
+ }
+ }
return null;
}