*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-package org.altusmetrum.altosuilib_3;
+package org.altusmetrum.altosuilib_13;
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
-import org.altusmetrum.altoslib_5.*;
+import org.altusmetrum.altoslib_13.*;
+
+ class result_holder {
+ static int result;
+ }
public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMonitor {
JFrame owner;
JLabel file_label;
JLabel serial_value;
JLabel flight_value;
- JLabel file_value;
JButton cancel;
JProgressBar pbar;
- int min_state, max_state;
ActionListener listener;
static final int progress_max = 10000;
public AltosEepromMonitorUI(JFrame owner) {
super (owner, "Download Flight Data", false);
+ setMinimumSize(new Dimension(600, 100));
+
this.owner = owner;
GridBagConstraints c;
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;
c.insets = ib;
pane.add(pbar, c);
-
cancel = new JButton("Cancel");
c = new GridBagConstraints();
c.fill = GridBagConstraints.NONE;
listener = l;
}
- public void set_states(int min_state, int max_state) {
- this.min_state = min_state;
- this.max_state = max_state;
- }
-
public void set_thread(Thread in_eeprom_thread) {
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();
+ }
}
});
}
setVisible(true);
}
- private void set_value_internal(String state_name, int state, int state_block, int block) {
+ int max_block = 1;
+
+ public void set_block_internal(int block) {
double pos;
String s;
- if (min_state == AltosLib.ao_flight_invalid) {
- int lblock = block;
- if (lblock > 1000)
- lblock = 1000;
- pos = lblock / 1000.0;
- s = String.format("block %d", block);
- } else {
- if (state_block > 100)
- state_block = 100;
- if (state < min_state) state = min_state;
- if (state >= max_state) state = max_state - 1;
- state -= min_state;
-
- int nstate = max_state - min_state;
-
- double spos = (double) (state - min_state) / (double) nstate;
- double bpos = state_block / 100.0;
+ pos = (double) block / (double) max_block;
- pos = spos + bpos / nstate;
-
- s = String.format("block %d state %s", block, state_name);
- }
+ s = String.format("block %d of %d", block, max_block);
pbar.setString(s);
+ pbar.setStringPainted(true);
pbar.setValue((int) (pos * progress_max));
}
- public void set_value(String in_state_name, int in_state, int in_state_block, int in_block) {
- final String state_name = in_state_name;
- final int state = in_state;
- final int state_block = in_state_block;
+ public void set_max(int max_block) {
+ this.max_block = max_block;
+ }
+
+ public void set_block(int in_block) {
final int block = in_block;
Runnable r = new Runnable() {
public void run() {
try {
- set_value_internal(state_name, state, state_block, block);
+ set_block_internal(block);
} catch (Exception ex) {
}
}
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,
}
private void reset_internal() {
- set_value_internal("startup",min_state,0, 0);
+ set_max(1);
+ set_block_internal(0);
set_flight_internal(0);
- set_filename_internal("");
}
public void reset() {
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;