diff options
| -rw-r--r-- | altoslib/AltosFlash.java (renamed from altosui/AltosFlash.java) | 59 | ||||
| -rw-r--r-- | altoslib/AltosFlashListener.java | 22 | ||||
| -rw-r--r-- | altoslib/Makefile.am | 2 | ||||
| -rw-r--r-- | altosui/AltosFlashUI.java | 21 | ||||
| -rw-r--r-- | altosui/Makefile.am | 1 | 
5 files changed, 61 insertions, 44 deletions
| diff --git a/altosui/AltosFlash.java b/altoslib/AltosFlash.java index b409a611..010274b9 100644 --- a/altosui/AltosFlash.java +++ b/altoslib/AltosFlash.java @@ -15,24 +15,19 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package altosui; +package org.altusmetrum.altoslib_1; -import java.awt.event.*; -import javax.swing.*;  import java.io.*; -import org.altusmetrum.altoslib_1.*; -import org.altusmetrum.altosuilib_1.*;  public class AltosFlash { -	File		file; -	FileInputStream	input; -	AltosHexfile	image; -	JFrame		frame; -	AltosDevice	debug_dongle; -	AltosDebug	debug; -	AltosRomconfig	rom_config; -	ActionListener	listener; -	boolean		aborted; +	File			file; +	FileInputStream		input; +	AltosHexfile		image; +	AltosLink		link; +	AltosDebug		debug; +	AltosRomconfig		rom_config; +	boolean			aborted; +	AltosFlashListener	listener;  	static final byte MOV_direct_data	= (byte) 0x75;  	static final byte MOV_DPTR_data16	= (byte) 0x90; @@ -206,22 +201,9 @@ public class AltosFlash {  		}  	} -	void action(String in_s, int in_percent) { -		final String s = in_s; -		final int percent = in_percent; -		if (listener != null && !aborted) { -			Runnable r = new Runnable() { -					public void run() { -						try { -							listener.actionPerformed(new ActionEvent(this, -												 percent, -												 s)); -						} catch (Exception ex) { -						} -					} -				}; -			SwingUtilities.invokeLater(r); -		} +	void action(String s, int percent) { +		if (listener != null && !aborted) +			listener.position(s, percent);  	}  	void action(int part, int total) { @@ -336,10 +318,6 @@ public class AltosFlash {  		close();  	} -	public void addActionListener(ActionListener l) { -		listener = l; -	} -  	public boolean check_rom_config() {  		if (debug == null)  			return true; @@ -358,12 +336,13 @@ public class AltosFlash {  		return rom_config;  	} -	public AltosFlash(File in_file, AltosDevice in_debug_dongle) -		throws IOException, FileNotFoundException, AltosSerialInUseException, InterruptedException { -		file = in_file; -		debug_dongle = in_debug_dongle; -		if (debug_dongle != null) -			debug = new AltosDebug(new AltosSerial(in_debug_dongle)); +	public AltosFlash(File file, AltosLink link, AltosFlashListener listener) +		throws IOException, FileNotFoundException, InterruptedException { +		this.file = file; +		this.link = link; +		this.listener = listener; +		if (link != null) +			debug = new AltosDebug(link);  		input = new FileInputStream(file);  		image = new AltosHexfile(input);  		if (debug != null && !debug.check_connection()) { diff --git a/altoslib/AltosFlashListener.java b/altoslib/AltosFlashListener.java new file mode 100644 index 00000000..ab50b74a --- /dev/null +++ b/altoslib/AltosFlashListener.java @@ -0,0 +1,22 @@ +/* + * Copyright © 2013 Keith Packard <keithp@keithp.com> + * + * 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. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.altoslib_1; + +public interface AltosFlashListener { +	public void position(String label, int percent); +} diff --git a/altoslib/Makefile.am b/altoslib/Makefile.am index db0236a1..18b028d6 100644 --- a/altoslib/Makefile.am +++ b/altoslib/Makefile.am @@ -25,6 +25,8 @@ altoslib_JAVA = \  	AltosEepromRecord.java \  	AltosEepromTeleScience.java \  	AltosFile.java \ +	AltosFlash.java \ +	AltosFlashListener.java \  	AltosFlightReader.java \  	AltosFrequency.java \  	AltosGPS.java \ diff --git a/altosui/AltosFlashUI.java b/altosui/AltosFlashUI.java index e5176278..f4e52218 100644 --- a/altosui/AltosFlashUI.java +++ b/altosui/AltosFlashUI.java @@ -215,15 +215,30 @@ public class AltosFlashUI  		}  	} -	class flash_task implements Runnable { +	class flash_task implements Runnable, AltosFlashListener {  		AltosFlashUI	ui;  		Thread		t;  		AltosFlash	flash; +		public void position(String in_s, int in_percent) { +			final String s = in_s; +			final int percent = in_percent; +			Runnable r = new Runnable() { +					public void run() { +						try { +							ui.actionPerformed(new ActionEvent(this, +											   percent, +											   s)); +						} catch (Exception ex) { +						} +					} +				}; +			SwingUtilities.invokeLater(r); +		} +  		public void run () {  			try { -				flash = new AltosFlash(ui.file, ui.debug_dongle); -				flash.addActionListener(ui); +				flash = new AltosFlash(ui.file, new AltosSerial(ui.debug_dongle), this);  				final AltosRomconfig	current_config = flash.romconfig(); diff --git a/altosui/Makefile.am b/altosui/Makefile.am index 56554697..d59e3082 100644 --- a/altosui/Makefile.am +++ b/altosui/Makefile.am @@ -39,7 +39,6 @@ altosui_JAVA = \  	AltosEepromManage.java \  	AltosEepromMonitor.java \  	AltosEepromSelect.java \ -	AltosFlash.java \  	AltosFlashUI.java \  	AltosFlightDisplay.java \  	AltosFlightInfoTableModel.java \ | 
