diff options
| author | Bdale Garbee <bdale@gag.com> | 2015-07-16 13:36:59 -0600 | 
|---|---|---|
| committer | Bdale Garbee <bdale@gag.com> | 2015-07-16 13:36:59 -0600 | 
| commit | f4f0f044df1251d64d44bf62d25b488fd04a05c8 (patch) | |
| tree | 12efee1447a67d8cf37b6f447c011708264b8266 /altosuilib | |
| parent | b25690062ac04a588ad4d11740597c20e516eb1a (diff) | |
| parent | 570daace9caf7647a09c53d5c75593cc4c98b93b (diff) | |
Merge branch 'branch-1.6' into debian
Diffstat (limited to 'altosuilib')
80 files changed, 862 insertions, 2398 deletions
diff --git a/altosuilib/.gitignore b/altosuilib/.gitignore index 4ad8a77a..943408ec 100644 --- a/altosuilib/.gitignore +++ b/altosuilib/.gitignore @@ -1,4 +1,3 @@ -AltosUIVersion.java  bin  classaltosuilib.stamp  altosuilib*.jar diff --git a/altosuilib/AltosBTDevice.java b/altosuilib/AltosBTDevice.java index 0dd1cab2..0d7d07c0 100644 --- a/altosuilib/AltosBTDevice.java +++ b/altosuilib/AltosBTDevice.java @@ -15,10 +15,10 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import libaltosJNI.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosBTDevice extends altos_bt_device implements AltosDevice { @@ -104,17 +104,20 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice {  		return false;  	} +	public int hashCode() { +		return getName().hashCode() ^ getAddr().hashCode(); +	} +  	public boolean equals(Object o) { +		if (o == null) +			return false; +  		if (!(o instanceof AltosBTDevice))  			return false;  		AltosBTDevice other = (AltosBTDevice) o;  		return getName().equals(other.getName()) && getAddr().equals(other.getAddr());  	} -	public int hashCode() { -		return getName().hashCode() ^ getAddr().hashCode(); -	} -  	public AltosBTDevice(String name, String addr) {  		AltosUILib.load_library();  		libaltos.altos_bt_fill_in(name, addr,this); diff --git a/altosuilib/AltosBTDeviceIterator.java b/altosuilib/AltosBTDeviceIterator.java index eebad36b..ca6c436e 100644 --- a/altosuilib/AltosBTDeviceIterator.java +++ b/altosuilib/AltosBTDeviceIterator.java @@ -15,11 +15,11 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.util.*;  import libaltosJNI.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosBTDeviceIterator implements Iterator<AltosBTDevice> {  	AltosBTDevice	current; diff --git a/altosuilib/AltosBTKnown.java b/altosuilib/AltosBTKnown.java index 73ee473f..0d10fafd 100644 --- a/altosuilib/AltosBTKnown.java +++ b/altosuilib/AltosBTKnown.java @@ -15,10 +15,10 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.util.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosBTKnown implements Iterable<AltosBTDevice> {  	LinkedList<AltosBTDevice>	devices = new LinkedList<AltosBTDevice>(); diff --git a/altosuilib/AltosBTManage.java b/altosuilib/AltosBTManage.java index c4ac363f..8a912c94 100644 --- a/altosuilib/AltosBTManage.java +++ b/altosuilib/AltosBTManage.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*; @@ -23,7 +23,7 @@ import javax.swing.*;  import javax.swing.plaf.basic.*;  import java.util.*;  import java.util.concurrent.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosBTManage extends AltosUIDialog implements ActionListener, Iterable<AltosBTDevice> {  	LinkedBlockingQueue<AltosBTDevice> found_devices; diff --git a/altosuilib/AltosCSVUI.java b/altosuilib/AltosCSVUI.java index 94d523fe..281a9081 100644 --- a/altosuilib/AltosCSVUI.java +++ b/altosuilib/AltosCSVUI.java @@ -15,13 +15,13 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*;  import javax.swing.*;  import java.io.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosCSVUI  	extends AltosUIDialog diff --git a/altosuilib/AltosConfigFreqUI.java b/altosuilib/AltosConfigFreqUI.java index 6253e3e4..04d93f6e 100644 --- a/altosuilib/AltosConfigFreqUI.java +++ b/altosuilib/AltosConfigFreqUI.java @@ -15,13 +15,14 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*; +import java.text.*;  import java.awt.event.*;  import javax.swing.*;  import java.util.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  class AltosEditFreqUI extends AltosUIDialog implements ActionListener {  	Frame		frame; @@ -51,10 +52,10 @@ class AltosEditFreqUI extends AltosUIDialog implements ActionListener {  		String	d_s = description.getText();  		try { -			double	f_d = Double.parseDouble(f_s); +			double	f_d = AltosParse.parse_double_locale(f_s);  			return new AltosFrequency(f_d, d_s); -		} catch (NumberFormatException ne) { +		} catch (ParseException ne) {  		}  		return null;  	} diff --git a/altosuilib/AltosDataChooser.java b/altosuilib/AltosDataChooser.java index 3fe76687..d30aec3f 100644 --- a/altosuilib/AltosDataChooser.java +++ b/altosuilib/AltosDataChooser.java @@ -15,12 +15,12 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import javax.swing.*;  import javax.swing.filechooser.FileNameExtensionFilter;  import java.io.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosDataChooser extends JFileChooser {  	JFrame	frame; diff --git a/altosuilib/AltosDevice.java b/altosuilib/AltosDevice.java index 401387a4..64a99596 100644 --- a/altosuilib/AltosDevice.java +++ b/altosuilib/AltosDevice.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import libaltosJNI.*; diff --git a/altosuilib/AltosDeviceDialog.java b/altosuilib/AltosDeviceDialog.java index 5fb1331e..a3c5d283 100644 --- a/altosuilib/AltosDeviceDialog.java +++ b/altosuilib/AltosDeviceDialog.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import javax.swing.*;  import java.awt.*; diff --git a/altosuilib/AltosDeviceUIDialog.java b/altosuilib/AltosDeviceUIDialog.java index 9618895e..aa6d323f 100644 --- a/altosuilib/AltosDeviceUIDialog.java +++ b/altosuilib/AltosDeviceUIDialog.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import javax.swing.*;  import java.awt.*; diff --git a/altosuilib/AltosDisplayThread.java b/altosuilib/AltosDisplayThread.java index ccf8b3ef..73d85698 100644 --- a/altosuilib/AltosDisplayThread.java +++ b/altosuilib/AltosDisplayThread.java @@ -15,13 +15,13 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import javax.swing.*;  import java.io.*;  import java.text.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosDisplayThread extends Thread { diff --git a/altosuilib/AltosEepromDelete.java b/altosuilib/AltosEepromDelete.java index 9fb21cf4..7648382d 100644 --- a/altosuilib/AltosEepromDelete.java +++ b/altosuilib/AltosEepromDelete.java @@ -15,13 +15,13 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.event.*;  import javax.swing.*;  import java.io.*;  import java.util.concurrent.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosEepromDelete implements Runnable {  	AltosEepromList		flights; diff --git a/altosuilib/AltosEepromManage.java b/altosuilib/AltosEepromManage.java index 47a62ef7..d97edd12 100644 --- a/altosuilib/AltosEepromManage.java +++ b/altosuilib/AltosEepromManage.java @@ -15,13 +15,13 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.event.*;  import javax.swing.*;  import java.io.*;  import java.util.concurrent.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosEepromManage implements ActionListener { diff --git a/altosuilib/AltosEepromMonitor.java b/altosuilib/AltosEepromMonitor.java index 83c5c1d0..28fa734d 100644 --- a/altosuilib/AltosEepromMonitor.java +++ b/altosuilib/AltosEepromMonitor.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*; diff --git a/altosuilib/AltosEepromMonitorUI.java b/altosuilib/AltosEepromMonitorUI.java index ac39fb1d..5f0df7d3 100644 --- a/altosuilib/AltosEepromMonitorUI.java +++ b/altosuilib/AltosEepromMonitorUI.java @@ -15,12 +15,12 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosEepromMonitorUI extends AltosUIDialog implements AltosEepromMonitor {  	JFrame		owner; diff --git a/altosuilib/AltosEepromSelect.java b/altosuilib/AltosEepromSelect.java index b291c35a..56b10ef0 100644 --- a/altosuilib/AltosEepromSelect.java +++ b/altosuilib/AltosEepromSelect.java @@ -15,13 +15,13 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import javax.swing.*;  import javax.swing.border.*;  import java.awt.*;  import java.awt.event.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  class AltosEepromItem implements ActionListener {  	AltosEepromLog	log; diff --git a/altosuilib/AltosFlashUI.java b/altosuilib/AltosFlashUI.java index 6e497c42..0ab085cf 100644 --- a/altosuilib/AltosFlashUI.java +++ b/altosuilib/AltosFlashUI.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*; @@ -23,7 +23,7 @@ import javax.swing.*;  import javax.swing.filechooser.FileNameExtensionFilter;  import java.io.*;  import java.util.concurrent.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosFlashUI  	extends AltosUIDialog @@ -54,7 +54,7 @@ public class AltosFlashUI  	// Flash controller  	AltosProgrammer	programmer; -	private static String[] pair_programmed = { +	private static final String[] pair_programmed_files = {  		"teleballoon",  		"telebt-v1",  		"teledongle-v0", @@ -67,20 +67,34 @@ public class AltosFlashUI  		"teleterra"  	}; +	private static final String[] pair_programmed_devices = { +		"TeleBalloon", +		"TeleBT-v1", +		"TeleDongle-v0", +		"TeleFire", +		"TeleMetrum-v0", +		"TeleMetrum-v1", +		"TeleMini", +		"TeleNano", +		"TeleShield", +		"TeleTerra" +	}; +  	private boolean is_pair_programmed() {  		if (file != null) {  			String	name = file.getName(); -			for (int i = 0; i < pair_programmed.length; i++) { -				if (name.startsWith(pair_programmed[i])) +			for (int i = 0; i < pair_programmed_files.length; i++) { +				if (name.startsWith(pair_programmed_files[i]))  					return true;  			}  		}  		if (device != null) { -			if (!device.matchProduct(AltosLib.product_altusmetrum) && -			    (device.matchProduct(AltosLib.product_teledongle) || -			     device.matchProduct(AltosLib.product_telebt))) -				return true; +			String	name = device.toString(); +			for (int i = 0; i < pair_programmed_devices.length; i++) { +				if (name.startsWith(pair_programmed_devices[i])) +					return true; +			}  		}  		return false;  	} diff --git a/altosuilib/AltosFlightDisplay.java b/altosuilib/AltosFlightDisplay.java deleted file mode 100644 index ac65c49e..00000000 --- a/altosuilib/AltosFlightDisplay.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright © 2010 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.altosuilib_6; - -import org.altusmetrum.altoslib_6.*; - -public interface AltosFlightDisplay extends AltosUnitsListener, AltosFontListener { -	void reset(); - -	void show(AltosState state, AltosListenerState listener_state); - -	String getName(); -} diff --git a/altosuilib/AltosFlightInfoTableModel.java b/altosuilib/AltosFlightInfoTableModel.java index f9d7d180..e55004e4 100644 --- a/altosuilib/AltosFlightInfoTableModel.java +++ b/altosuilib/AltosFlightInfoTableModel.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import javax.swing.table.*; diff --git a/altosuilib/AltosFlightStatsTable.java b/altosuilib/AltosFlightStatsTable.java index 8a686646..9c613365 100644 --- a/altosuilib/AltosFlightStatsTable.java +++ b/altosuilib/AltosFlightStatsTable.java @@ -15,12 +15,12 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import javax.swing.*;  import java.util.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosFlightStatsTable extends JComponent implements AltosFontListener {  	GridBagLayout	layout; diff --git a/altosuilib/AltosFontListener.java b/altosuilib/AltosFontListener.java deleted file mode 100644 index 93625278..00000000 --- a/altosuilib/AltosFontListener.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © 2011 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.altosuilib_6; - -public interface AltosFontListener { -	void font_size_changed(int font_size); -} diff --git a/altosuilib/AltosGraph.java b/altosuilib/AltosGraph.java index d7739228..be013d57 100644 --- a/altosuilib/AltosGraph.java +++ b/altosuilib/AltosGraph.java @@ -15,14 +15,14 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.io.*;  import java.util.ArrayList;  import java.awt.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  import org.jfree.ui.*;  import org.jfree.chart.*; diff --git a/altosuilib/AltosGraphDataPoint.java b/altosuilib/AltosGraphDataPoint.java index 47989d0e..30d436ae 100644 --- a/altosuilib/AltosGraphDataPoint.java +++ b/altosuilib/AltosGraphDataPoint.java @@ -15,9 +15,9 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosGraphDataPoint implements AltosUIDataPoint { diff --git a/altosuilib/AltosGraphDataSet.java b/altosuilib/AltosGraphDataSet.java index b9c9d2a8..7902f407 100644 --- a/altosuilib/AltosGraphDataSet.java +++ b/altosuilib/AltosGraphDataSet.java @@ -15,12 +15,12 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.lang.*;  import java.io.*;  import java.util.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  class AltosGraphIterator implements Iterator<AltosUIDataPoint> {  	AltosGraphDataSet	dataSet; diff --git a/altosuilib/AltosInfoTable.java b/altosuilib/AltosInfoTable.java index 89a656c9..d87c38e2 100644 --- a/altosuilib/AltosInfoTable.java +++ b/altosuilib/AltosInfoTable.java @@ -15,13 +15,13 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*;  import javax.swing.*;  import javax.swing.table.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosInfoTable extends JTable implements AltosFlightDisplay, HierarchyListener {  	private AltosFlightInfoTableModel model; @@ -137,6 +137,8 @@ public class AltosInfoTable extends JTable implements AltosFlightDisplay, Hierar  		if (state != null) {  			if (state.device_type != AltosLib.MISSING)  				info_add_row(0, "Device", "%s", AltosLib.product_name(state.device_type)); +			else if (state.product != null) +				info_add_row(0, "Device", "%s", state.product);  			if (state.altitude() != AltosLib.MISSING)  				info_add_row(0, "Altitude", "%6.0f    m", state.altitude());  			if (state.ground_altitude() != AltosLib.MISSING) diff --git a/altosuilib/AltosLed.java b/altosuilib/AltosLed.java index fa33c4b6..b47aa493 100644 --- a/altosuilib/AltosLed.java +++ b/altosuilib/AltosLed.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import javax.swing.*; diff --git a/altosuilib/AltosLights.java b/altosuilib/AltosLights.java index 05d06ac4..8cbd1d10 100644 --- a/altosuilib/AltosLights.java +++ b/altosuilib/AltosLights.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import javax.swing.*; diff --git a/altosuilib/AltosPositionListener.java b/altosuilib/AltosPositionListener.java index 1274a64a..0c900787 100644 --- a/altosuilib/AltosPositionListener.java +++ b/altosuilib/AltosPositionListener.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  public interface AltosPositionListener {  	public void position_changed(int position); diff --git a/altosuilib/AltosRomconfigUI.java b/altosuilib/AltosRomconfigUI.java index 99e4d004..257674dc 100644 --- a/altosuilib/AltosRomconfigUI.java +++ b/altosuilib/AltosRomconfigUI.java @@ -15,12 +15,12 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosRomconfigUI  	extends AltosUIDialog diff --git a/altosuilib/AltosScanUI.java b/altosuilib/AltosScanUI.java index 5a7e21b1..e2efd4b3 100644 --- a/altosuilib/AltosScanUI.java +++ b/altosuilib/AltosScanUI.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*; @@ -25,7 +25,7 @@ import java.io.*;  import java.util.*;  import java.text.*;  import java.util.concurrent.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  class AltosScanResult {  	String		callsign; @@ -62,9 +62,18 @@ class AltosScanResult {  		rate = in_rate;  	} -	public boolean equals(AltosScanResult other) { +	public int hashCode() { +		return serial ^ frequency.hashCode() ^ telemetry ^ rate; +	} + +	public boolean equals(Object o) { +		if (o == null) +			return false; +		if (!(o instanceof AltosScanResult)) +			return false; +		AltosScanResult other = (AltosScanResult) o;  		return (serial == other.serial && -			frequency.frequency == other.frequency.frequency && +			frequency.equals(other.frequency) &&  			telemetry == other.telemetry &&  			rate == other.rate);  	} diff --git a/altosuilib/AltosSerial.java b/altosuilib/AltosSerial.java index 95815a7b..ff8d900a 100644 --- a/altosuilib/AltosSerial.java +++ b/altosuilib/AltosSerial.java @@ -19,13 +19,13 @@   * Deal with TeleDongle on a serial port   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.io.*;  import java.util.*;  import java.awt.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  import libaltosJNI.*;  /* diff --git a/altosuilib/AltosSerialInUseException.java b/altosuilib/AltosSerialInUseException.java index 0487e146..2b198aec 100644 --- a/altosuilib/AltosSerialInUseException.java +++ b/altosuilib/AltosSerialInUseException.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  public class AltosSerialInUseException extends Exception {  	public AltosDevice	device; diff --git a/altosuilib/AltosUIAxis.java b/altosuilib/AltosUIAxis.java index 89f5493b..155e7ed6 100644 --- a/altosuilib/AltosUIAxis.java +++ b/altosuilib/AltosUIAxis.java @@ -15,14 +15,14 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.io.*;  import java.util.ArrayList;  import java.awt.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  import org.jfree.ui.*;  import org.jfree.chart.*; diff --git a/altosuilib/AltosUIConfigure.java b/altosuilib/AltosUIConfigure.java index b022aeec..146acda8 100644 --- a/altosuilib/AltosUIConfigure.java +++ b/altosuilib/AltosUIConfigure.java @@ -15,13 +15,14 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*;  import java.beans.*;  import javax.swing.*;  import javax.swing.event.*; +import org.altusmetrum.altoslib_8.*;  class DelegatingRenderer implements ListCellRenderer<Object> { @@ -269,8 +270,8 @@ public class AltosUIConfigure  		row++;  		pane.add(new JLabel (String.format("AltOS version %s (%smaps key)", -						   AltosUIVersion.version, -						   AltosUIVersion.has_google_maps_api_key() ? "" : "no ")), +						   AltosVersion.version, +						   AltosVersion.has_google_maps_api_key() ? "" : "no ")),  			 constraints(0, 3));  		row++; diff --git a/altosuilib/AltosUIDataMissing.java b/altosuilib/AltosUIDataMissing.java index a0e41fef..39b8f900 100644 --- a/altosuilib/AltosUIDataMissing.java +++ b/altosuilib/AltosUIDataMissing.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  public class AltosUIDataMissing extends Exception {  	public int	id; diff --git a/altosuilib/AltosUIDataPoint.java b/altosuilib/AltosUIDataPoint.java index 82ce862f..793fabfb 100644 --- a/altosuilib/AltosUIDataPoint.java +++ b/altosuilib/AltosUIDataPoint.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  public interface AltosUIDataPoint {  	public abstract double x() throws AltosUIDataMissing; diff --git a/altosuilib/AltosUIDataSet.java b/altosuilib/AltosUIDataSet.java index 6293911d..b7472000 100644 --- a/altosuilib/AltosUIDataSet.java +++ b/altosuilib/AltosUIDataSet.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  public interface AltosUIDataSet {  	public abstract String name(); diff --git a/altosuilib/AltosUIDialog.java b/altosuilib/AltosUIDialog.java index 77e549c4..cfbf2cd3 100644 --- a/altosuilib/AltosUIDialog.java +++ b/altosuilib/AltosUIDialog.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*; diff --git a/altosuilib/AltosUIEnable.java b/altosuilib/AltosUIEnable.java index 481e5b87..b4d8d81e 100644 --- a/altosuilib/AltosUIEnable.java +++ b/altosuilib/AltosUIEnable.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*; @@ -23,7 +23,7 @@ import javax.swing.*;  import java.io.*;  import java.util.concurrent.*;  import java.util.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  import org.jfree.ui.*;  import org.jfree.chart.*; diff --git a/altosuilib/AltosUIFlightTab.java b/altosuilib/AltosUIFlightTab.java index ea4f0cb0..a2a3e367 100644 --- a/altosuilib/AltosUIFlightTab.java +++ b/altosuilib/AltosUIFlightTab.java @@ -15,13 +15,13 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.util.*;  import java.awt.*;  import java.awt.event.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public abstract class AltosUIFlightTab extends JComponent implements AltosFlightDisplay, HierarchyListener {  	public GridBagLayout	layout; diff --git a/altosuilib/AltosUIFrame.java b/altosuilib/AltosUIFrame.java index 39b1eb73..79015103 100644 --- a/altosuilib/AltosUIFrame.java +++ b/altosuilib/AltosUIFrame.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*; @@ -207,6 +207,62 @@ public class AltosUIFrame extends JFrame implements AltosUIListener, AltosPositi  			}  		}  	} + +	int row = 0; + +	public void next_row() { +		row++; +	} + +	int inset = 0; + +	public void set_inset(int i) { +		inset = i; +	} + +	public GridBagConstraints constraints (int x, int width, int fill, int anchor, double weightx, double weighty) { +		return new GridBagConstraints(x,			/* x */ +					      row,			/* y */ +					      width,			/* width */ +					      1,			/* height */ +					      weightx,			/* weightx */ +					      weighty,			/* weighty */ +					      anchor,			/* anchor */ +					      fill,			/* fill */ +					      new Insets(inset,inset,inset,inset),	/* insets */ +					      0,			/* ipadx */ +					      0);			/* ipady */ +	} + +	public GridBagConstraints constraints (int x, int width, int fill, int anchor) { +		double	weightx = 0; +		double	weighty = 0; + +		if (fill == GridBagConstraints.NONE) { +			weightx = 0; +			weighty = 0; +		} else if (fill == GridBagConstraints.HORIZONTAL) { +			weightx = 1; +			weighty = 0; +		} else if (fill == GridBagConstraints.VERTICAL) { +			weightx = 0; +			weighty = 1; +		} else if (fill == GridBagConstraints.BOTH) { +			weightx = 1; +			weighty = 1; +		} + +		return constraints (x, width, fill, anchor, weightx, weighty); +	} + +	public GridBagConstraints constraints (int x, int width, int fill) { +		return constraints (x, width, fill, GridBagConstraints.WEST); +	} + +	public GridBagConstraints constraints(int x, int width) { +		return constraints(x, width, GridBagConstraints.NONE); +	} +  	void init() {  		AltosUIPreferences.register_ui_listener(this);  		AltosUIPreferences.register_position_listener(this); diff --git a/altosuilib/AltosUIFreqList.java b/altosuilib/AltosUIFreqList.java index 430069f5..9479087e 100644 --- a/altosuilib/AltosUIFreqList.java +++ b/altosuilib/AltosUIFreqList.java @@ -15,10 +15,10 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosUIFreqList extends JComboBox<AltosFrequency> { diff --git a/altosuilib/AltosUIGraph.java b/altosuilib/AltosUIGraph.java index d20aa54b..a11978d0 100644 --- a/altosuilib/AltosUIGraph.java +++ b/altosuilib/AltosUIGraph.java @@ -15,14 +15,14 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.io.*;  import java.util.ArrayList;  import java.awt.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  import org.jfree.ui.*;  import org.jfree.chart.*; diff --git a/altosuilib/AltosUIGrapher.java b/altosuilib/AltosUIGrapher.java index fcd3546f..0fe685ef 100644 --- a/altosuilib/AltosUIGrapher.java +++ b/altosuilib/AltosUIGrapher.java @@ -15,14 +15,14 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.io.*;  import java.util.ArrayList;  import java.awt.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  import org.jfree.ui.*;  import org.jfree.chart.*; diff --git a/altosuilib/AltosUIVersion.java.in b/altosuilib/AltosUIImage.java index beb62cbf..77743741 100644 --- a/altosuilib/AltosUIVersion.java.in +++ b/altosuilib/AltosUIImage.java @@ -1,5 +1,5 @@  /* - * Copyright © 2011 Keith Packard <keithp@keithp.com> + * Copyright © 2015 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 @@ -15,14 +15,24 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altoslib_8; -public class AltosUIVersion { -	public final static String version = "@VERSION@"; +import javax.swing.*; +import javax.imageio.ImageIO; +import java.awt.image.*; +import java.awt.*; +import java.io.*; +import java.net.*; -	public final static String google_maps_api_key = @GOOGLEKEY@; +public class AltosUIImage implements AltosImage { +	public Image	image; -	static boolean has_google_maps_api_key() { -		return google_maps_api_key != null && google_maps_api_key.length() > 1; +	/* Discard storage for image */ +	public void flush() { +		image.flush(); +	} + +	public AltosUIImage(Image image) { +		this.image = image;  	}  } diff --git a/altosuilib/AltosUIIndicator.java b/altosuilib/AltosUIIndicator.java index f2e77218..0a940d97 100644 --- a/altosuilib/AltosUIIndicator.java +++ b/altosuilib/AltosUIIndicator.java @@ -15,11 +15,11 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public abstract class AltosUIIndicator implements AltosFontListener, AltosUnitsListener {  	JLabel		label; diff --git a/altosuilib/AltosUILatLon.java b/altosuilib/AltosUILatLon.java deleted file mode 100644 index 72ff74d8..00000000 --- a/altosuilib/AltosUILatLon.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright © 2014 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.altosuilib_6; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.lang.Math; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_6.*; - -public class AltosUILatLon { -	public double	lat; -	public double	lon; - -	public boolean equals(AltosUILatLon other) { -		if (other == null) -			return false; -		return lat == other.lat && lon == other.lon; -	} - -	public AltosUILatLon(double lat, double lon) { -		this.lat = lat; -		this.lon = lon; -	} -} diff --git a/altosuilib/AltosUILib.java b/altosuilib/AltosUILib.java index 2fa6cbd6..2fc20317 100644 --- a/altosuilib/AltosUILib.java +++ b/altosuilib/AltosUILib.java @@ -15,12 +15,12 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import libaltosJNI.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosUILib extends AltosLib { diff --git a/altosuilib/AltosUIListener.java b/altosuilib/AltosUIListener.java index 9eec0b24..5b49e7da 100644 --- a/altosuilib/AltosUIListener.java +++ b/altosuilib/AltosUIListener.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  public interface AltosUIListener {  	public void ui_changed(String look_and_feel); diff --git a/altosuilib/AltosUIMap.java b/altosuilib/AltosUIMap.java deleted file mode 100644 index 5c6d5bdf..00000000 --- a/altosuilib/AltosUIMap.java +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns <aj@erisian.com.au> - * - * 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.altosuilib_6; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.lang.Math; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_6.*; - -public class AltosUIMap extends JComponent implements AltosFlightDisplay, AltosUIMapZoomListener { - -	static final int px_size = 512; - -	static final int maptype_hybrid = 0; -	static final int maptype_roadmap = 1; -	static final int maptype_satellite = 2; -	static final int maptype_terrain = 3; -	static final int maptype_default = maptype_hybrid; - -	static final String[] maptype_names = { -		"hybrid", -		"roadmap", -		"satellite", -		"terrain" -	}; - -	public static final String[] maptype_labels = { -		"Hybrid", -		"Roadmap", -		"Satellite", -		"Terrain" -	}; - -	public static final Color stateColors[] = { -		Color.WHITE,  // startup -		Color.WHITE,  // idle -		Color.WHITE,  // pad -		Color.RED,    // boost -		Color.PINK,   // fast -		Color.YELLOW, // coast -		Color.CYAN,   // drogue -		Color.BLUE,   // main -		Color.BLACK,  // landed -		Color.BLACK,  // invalid -		Color.CYAN,   // stateless -	}; - -	public void reset() { -		// nothing -	} - -	public void font_size_changed(int font_size) { -		view.set_font(); -	} - -	public void units_changed(boolean imperial_units) { -		view.set_units(); -	} - -	JLabel	zoom_label; - -	private void set_zoom_label() { -		zoom_label.setText(String.format("Zoom %d", view.zoom() - view.default_zoom)); -	} - -	public void zoom_changed(int zoom) { -		set_zoom_label(); -	} - -	public void set_zoom(int zoom) { -		view.set_zoom(zoom); -	} - -	public int get_zoom() { -		return view.zoom(); -	} - -	public void set_maptype(int type) { -		view.set_maptype(type); -		maptype_combo.setSelectedIndex(type); -	} - -	public void show(AltosState state, AltosListenerState listener_state) { -		view.show(state, listener_state); -	} - -	public void centre(double lat, double lon) { -		view.centre(lat, lon); -	} - -	public void centre(AltosState state) { -		if (!state.gps.locked && state.gps.nsat < 4) -			return; -		centre(state.gps.lat, state.gps.lon); -	} - -	public void add_mark(double lat, double lon, int state) { -		view.add_mark(lat, lon, state); -	} - -	public void clear_marks() { -		view.clear_marks(); -	} - -	AltosUIMapView	view; - -	private GridBagLayout layout = new GridBagLayout(); - -	JComboBox<String>	maptype_combo; - -	public void set_load_params(double lat, double lon, int radius, AltosUIMapTileListener listener) { -		view.set_load_params(lat, lon, radius, listener); -	} - -	public boolean all_fetched() { -		return view.all_fetched(); -	} - -	public static void prefetch_maps(double lat, double lon) { -	} - -	public String getName() { -		return "Map"; -	} - -	public AltosUIMap() { - -		view = new AltosUIMapView(); - -		view.setPreferredSize(new Dimension(500,500)); -		view.setVisible(true); -		view.setEnabled(true); -		view.add_zoom_listener(this); - -		GridBagLayout	my_layout = new GridBagLayout(); - -		setLayout(my_layout); - -		GridBagConstraints c = new GridBagConstraints(); -		c.anchor = GridBagConstraints.CENTER; -		c.fill = GridBagConstraints.BOTH; -		c.gridx = 0; -		c.gridy = 0; -		c.gridwidth = 1; -		c.gridheight = 10; -		c.weightx = 1; -		c.weighty = 1; -		add(view, c); - -		int	y = 0; - -		zoom_label = new JLabel("", JLabel.CENTER); -		set_zoom_label(); - -		c = new GridBagConstraints(); -		c.anchor = GridBagConstraints.CENTER; -		c.fill = GridBagConstraints.HORIZONTAL; -		c.gridx = 1; -		c.gridy = y++; -		c.weightx = 0; -		c.weighty = 0; -		add(zoom_label, c); - -		JButton zoom_reset = new JButton("0"); -		zoom_reset.addActionListener(new ActionListener() { -				public void actionPerformed(ActionEvent e) { -					set_zoom(view.default_zoom); -				} -			}); - -		c = new GridBagConstraints(); -		c.anchor = GridBagConstraints.CENTER; -		c.fill = GridBagConstraints.HORIZONTAL; -		c.gridx = 1; -		c.gridy = y++; -		c.weightx = 0; -		c.weighty = 0; -		add(zoom_reset, c); - -		JButton zoom_in = new JButton("+"); -		zoom_in.addActionListener(new ActionListener() { -				public void actionPerformed(ActionEvent e) { -					set_zoom(get_zoom() + 1); -				} -			}); - -		c = new GridBagConstraints(); -		c.anchor = GridBagConstraints.CENTER; -		c.fill = GridBagConstraints.HORIZONTAL; -		c.gridx = 1; -		c.gridy = y++; -		c.weightx = 0; -		c.weighty = 0; -		add(zoom_in, c); - -		JButton zoom_out = new JButton("-"); -		zoom_out.addActionListener(new ActionListener() { -				public void actionPerformed(ActionEvent e) { -					set_zoom(get_zoom() - 1); -				} -			}); -		c = new GridBagConstraints(); -		c.anchor = GridBagConstraints.CENTER; -		c.fill = GridBagConstraints.HORIZONTAL; -		c.gridx = 1; -		c.gridy = y++; -		c.weightx = 0; -		c.weighty = 0; -		add(zoom_out, c); - -		maptype_combo = new JComboBox<String>(maptype_labels); - -		maptype_combo.setEditable(false); -		maptype_combo.setMaximumRowCount(maptype_combo.getItemCount()); -		maptype_combo.addItemListener(new ItemListener() { -				public void itemStateChanged(ItemEvent e) { -					view.set_maptype(maptype_combo.getSelectedIndex()); -				} -			}); - -		c = new GridBagConstraints(); -		c.anchor = GridBagConstraints.CENTER; -		c.fill = GridBagConstraints.HORIZONTAL; -		c.gridx = 1; -		c.gridy = y++; -		c.weightx = 0; -		c.weighty = 0; -		add(maptype_combo, c); -	} -} diff --git a/altosuilib/AltosUIMapCache.java b/altosuilib/AltosUIMapCache.java deleted file mode 100644 index 73401e3c..00000000 --- a/altosuilib/AltosUIMapCache.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns <aj@erisian.com.au> - * - * 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.altosuilib_6; - -import javax.swing.*; -import javax.imageio.ImageIO; -import java.awt.image.*; -import java.awt.*; -import java.io.*; -import java.net.*; - -public class AltosUIMapCache implements AltosUIMapCacheListener { -	static final int	success = 0; -	static final int	loading = 1; -	static final int	failed = 2; -	static final int	bad_request = 3; -	static final int	forbidden = 4; - -	int			min_cache_size;		/* configured minimum cache size */ -	int			cache_size;		/* current cache size */ -	int			requested_cache_size;	/* cache size computed by application */ - -	private Object 		fetch_lock = new Object(); -	private Object 		cache_lock = new Object(); - -	AltosUIMapImage[]	images = new AltosUIMapImage[cache_size]; - -	long			used; - -	public void set_cache_size(int new_size) { - -		requested_cache_size = new_size; - -		if (new_size < min_cache_size) -			new_size = min_cache_size; - -		if (new_size == cache_size) -			return; - -		synchronized(cache_lock) { -			AltosUIMapImage[]	new_images = new AltosUIMapImage[new_size]; - -			for (int i = 0; i < cache_size; i++) { -				if (i < new_size) -					new_images[i] = images[i]; -				else if (images[i] != null) -					images[i].flush(); -			} -			images = new_images; -			cache_size = new_size; -		} -	} - -	public Image get(AltosUIMapTile tile, AltosUIMapStore store, int width, int height) { -		int		oldest = -1; -		long		age = used; - -		synchronized(cache_lock) { -			AltosUIMapImage	image = null; -			for (int i = 0; i < cache_size; i++) { -				image = images[i]; - -				if (image == null) { -					oldest = i; -					break; -				} -				if (store.equals(image.store)) { -					image.used = used++; -					return image.image; -				} -				if (image.used < age) { -					oldest = i; -					age = image.used; -				} -			} - -			try { -				image = new AltosUIMapImage(tile, store); -				image.used = used++; -				if (images[oldest] != null) -					images[oldest].flush(); - -				images[oldest] = image; - -				if (image.image == null) -					tile.set_status(loading); -				else -					tile.set_status(success); - -				return image.image; -			} catch (IOException e) { -				tile.set_status(failed); -				return null; -			} -		} -	} - -	public void map_cache_changed(int map_cache) { -		min_cache_size = map_cache; - -		set_cache_size(requested_cache_size); -	} - -	public void dispose() { -		AltosUIPreferences.unregister_map_cache_listener(this); - -		for (int i = 0; i < cache_size; i++) { -			AltosUIMapImage image = images[i]; - -			if (image != null) -			    image.flush(); -		} -	} - -	public AltosUIMapCache() { -		min_cache_size = AltosUIPreferences.map_cache(); - -		set_cache_size(0); - -		AltosUIPreferences.register_map_cache_listener(this); -	} -} diff --git a/altosuilib/AltosUIMapCacheListener.java b/altosuilib/AltosUIMapCacheListener.java deleted file mode 100644 index 1eec7b0a..00000000 --- a/altosuilib/AltosUIMapCacheListener.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © 2014 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.altosuilib_6; - -public interface AltosUIMapCacheListener { -	public void map_cache_changed(int map_cache); -} diff --git a/altosuilib/AltosUIMapImage.java b/altosuilib/AltosUIMapImage.java deleted file mode 100644 index 97220a40..00000000 --- a/altosuilib/AltosUIMapImage.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns <aj@erisian.com.au> - * - * 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.altosuilib_6; - -import javax.swing.*; -import javax.imageio.ImageIO; -import java.awt.image.*; -import java.awt.*; -import java.io.*; -import java.net.*; - -public class AltosUIMapImage implements AltosUIMapStoreListener { -	static final long google_maps_ratelimit_ms = 1200; -	// Google limits static map queries to 50 per minute per IP, so -	// each query should take at least 1.2 seconds. - -	static final int	success = 0; -	static final int	loading = 1; -	static final int	failed = 2; -	static final int	bad_request = 3; -	static final int	forbidden = 4; - -	static long		forbidden_time; -	static boolean		forbidden_set = false; -	static final long	forbidden_interval = 60l * 1000l * 1000l * 1000l; - -	AltosUIMapTile		tile;		/* Notify when image has been loaded */ -	Image			image; -	AltosUIMapStore		store; -	long			used; - -	class loader implements Runnable { -		public void run() { -			if (image != null) -				tile.notify_image(image); -			try { -				image = ImageIO.read(store.file); -			} catch (Exception ex) { -			} -			if (image == null) -				tile.set_status(failed); -			else -				tile.set_status(success); -			tile.notify_image(image); -		} -	} - -	private void load() { -		loader	l = new loader(); -		Thread	lt = new Thread(l); -		lt.start(); -	} - -	public void flush() { -		if (image != null) { -			image.flush(); -			image = null; -		} -	} - -	public boolean has_map() { -		return store.status() == AltosUIMapStore.success; -	} - -	public synchronized void notify_store(AltosUIMapStore store, int status) { -		switch (status) { -		case AltosUIMapStore.loading: -			break; -		case AltosUIMapStore.success: -			load(); -			break; -		default: -			tile.set_status(status); -			tile.notify_image(null); -		} -	} - -	public AltosUIMapImage(AltosUIMapTile tile, AltosUIMapStore store) throws IOException { -		this.tile = tile; -		this.image = null; -		this.store = store; -		this.used = 0; - -		int status = store.status(); -		switch (status) { -		case AltosUIMapStore.loading: -			store.add_listener(this); -			break; -		case AltosUIMapStore.success: -			load(); -			break; -		default: -			tile.set_status(status); -			tile.notify_image(null); -			break; -		} -	} -} diff --git a/altosuilib/AltosUIMapLine.java b/altosuilib/AltosUIMapLine.java deleted file mode 100644 index 2634f843..00000000 --- a/altosuilib/AltosUIMapLine.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright © 2014 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.altosuilib_6; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.lang.Math; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_6.*; - -public class AltosUIMapLine { -	AltosUILatLon	start, end; - -	private Font	font = null; -	static public int stroke_width = 6; - -	public void set_font(Font font) { -		this.font = font; -	} - -	private AltosUILatLon lat_lon(MouseEvent e, AltosUIMapTransform t) { -		return t.screen_lat_lon(e.getPoint()); -	} - -	public void dragged(MouseEvent e, AltosUIMapTransform t) { -		end = lat_lon(e, t); -	} - -	public void pressed(MouseEvent e, AltosUIMapTransform t) { -		start = lat_lon(e, t); -		end = null; -	} - -	private String line_dist() { -		String	format; -		AltosGreatCircle	g = new AltosGreatCircle(start.lat, start.lon, -								 end.lat, end.lon); -		double	distance = g.distance; - -		if (AltosConvert.imperial_units) { -			distance = AltosConvert.meters_to_feet(distance); -			if (distance < 10000) { -				format = "%4.0fft"; -			} else { -				distance /= 5280; -				if (distance < 10) -					format = "%5.3fmi"; -				else if (distance < 100) -					format = "%5.2fmi"; -				else if (distance < 1000) -					format = "%5.1fmi"; -				else -					format = "%5.0fmi"; -			} -		} else { -			if (distance < 10000) { -				format = "%4.0fm"; -			} else { -				distance /= 1000; -				if (distance < 100) -					format = "%5.2fkm"; -				else if (distance < 1000) -					format = "%5.1fkm"; -				else -					format = "%5.0fkm"; -			} -		} -		return String.format(format, distance); -	} - -	public void paint(Graphics2D g, AltosUIMapTransform t) { - -		if (start == null || end == null) -			return; - -		g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - -		Line2D.Double line = new Line2D.Double(t.screen(start), -						       t.screen(end)); - -		g.setColor(Color.WHITE); -		g.setStroke(new BasicStroke(stroke_width+4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); -		g.draw(line); - -		g.setColor(Color.BLUE); -		g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); -		g.draw(line); - -		String	message = line_dist(); -		Rectangle2D	bounds; -		bounds = font.getStringBounds(message, g.getFontRenderContext()); - -		float x = (float) line.x1; -		float y = (float) line.y1 + (float) bounds.getHeight() / 2.0f; - -		if (line.x1 < line.x2) { -			x -= (float) bounds.getWidth() + 2.0f; -		} else { -			x += 2.0f; -		} - -		g.setFont(font); -		g.setColor(Color.WHITE); -		for (int dy = -2; dy <= 2; dy += 2) -			for (int dx = -2; dx <= 2; dx += 2) -				g.drawString(message, x + dx, y + dy); -		g.setColor(Color.BLUE); -		g.drawString(message, x, y); -	} -} diff --git a/altosuilib/AltosUIMapMark.java b/altosuilib/AltosUIMapMark.java deleted file mode 100644 index b4b98efa..00000000 --- a/altosuilib/AltosUIMapMark.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright © 2014 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.altosuilib_6; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.lang.Math; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_6.*; - -public class AltosUIMapMark { - -	AltosUILatLon	lat_lon; -	int		state; - -	static public int stroke_width = 6; - -	public void paint(Graphics2D g, AltosUIMapTransform t) { - -		Point2D.Double pt = t.screen(lat_lon); - -		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, -				   RenderingHints.VALUE_ANTIALIAS_ON); -		g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); - -		if (0 <= state && state < AltosUIMap.stateColors.length) -			g.setColor(AltosUIMap.stateColors[state]); -		else -			g.setColor(AltosUIMap.stateColors[AltosLib.ao_flight_invalid]); - -		g.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10); -		g.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40); -		g.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); -	} - -	public AltosUIMapMark (double lat, double lon, int state) { -		lat_lon = new AltosUILatLon(lat, lon); -		this.state = state; -	} -} diff --git a/altosuilib/AltosUIMapNew.java b/altosuilib/AltosUIMapNew.java new file mode 100644 index 00000000..016a202b --- /dev/null +++ b/altosuilib/AltosUIMapNew.java @@ -0,0 +1,538 @@ +/* + * Copyright © 2010 Anthony Towns <aj@erisian.com.au> + * + * 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.altosuilib_8; + +import java.awt.*; +import java.awt.event.*; +import java.awt.image.*; +import javax.swing.*; +import java.io.*; +import java.lang.Math; +import java.awt.geom.*; +import java.util.*; +import java.util.concurrent.*; +import javax.imageio.*; +import org.altusmetrum.altoslib_8.*; + +public class AltosUIMapNew extends JComponent implements AltosFlightDisplay, AltosMapInterface { + +	AltosMap	map; +	Graphics2D	g; +	Font		tile_font; +	Font		line_font; + +	static Point2D.Double point2d(AltosPointDouble pt) { +		return new Point2D.Double(pt.x, pt.y); +	} + +	static final AltosPointDouble point_double(Point pt) { +		return new AltosPointDouble(pt.x, pt.y); +	} + +	class MapMark extends AltosMapMark { +		public void paint(AltosMapTransform t) { +			AltosPointDouble pt = t.screen(lat_lon); + +			g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, +					   RenderingHints.VALUE_ANTIALIAS_ON); +			g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); + +			if (0 <= state && state < AltosUIMapNew.stateColors.length) +				g.setColor(AltosUIMapNew.stateColors[state]); +			else +				g.setColor(AltosUIMapNew.stateColors[AltosLib.ao_flight_invalid]); + +			g.drawOval((int)pt.x-5, (int)pt.y-5, 10, 10); +			g.drawOval((int)pt.x-20, (int)pt.y-20, 40, 40); +			g.drawOval((int)pt.x-35, (int)pt.y-35, 70, 70); +		} + +		MapMark(double lat, double lon, int state) { +			super(lat, lon, state); +		} +	} + +	class MapView extends JComponent implements MouseMotionListener, MouseListener, ComponentListener, MouseWheelListener { + +		private VolatileImage create_back_buffer() { +			return getGraphicsConfiguration().createCompatibleVolatileImage(getWidth(), getHeight()); +		} + +		private void do_paint(Graphics my_g) { +			g = (Graphics2D) my_g; + +			map.paint(); +		} + +		public void paint(Graphics my_g) { +			VolatileImage	back_buffer = create_back_buffer(); + +			Graphics2D	top_g = (Graphics2D) my_g; + +			do { +				GraphicsConfiguration gc = getGraphicsConfiguration(); +				int code = back_buffer.validate(gc); +				if (code == VolatileImage.IMAGE_INCOMPATIBLE) +					back_buffer = create_back_buffer(); + +				Graphics g_back = back_buffer.getGraphics(); +				g_back.setClip(top_g.getClip()); +				do_paint(g_back); +				g_back.dispose(); + +				top_g.drawImage(back_buffer, 0, 0, this); +			} while (back_buffer.contentsLost()); +			back_buffer.flush(); +		} + +		public void repaint(AltosRectangle damage) { +			repaint(damage.x, damage.y, damage.width, damage.height); +		} + +		private boolean is_drag_event(MouseEvent e) { +			return e.getModifiers() == InputEvent.BUTTON1_MASK; +		} + +		/* MouseMotionListener methods */ + +		public void mouseDragged(MouseEvent e) { +			map.touch_continue(e.getPoint().x, e.getPoint().y, is_drag_event(e)); +		} + +		public void mouseMoved(MouseEvent e) { +		} + +		/* MouseListener methods */ +		public void mouseClicked(MouseEvent e) { +		} + +		public void mouseEntered(MouseEvent e) { +		} + +		public void mouseExited(MouseEvent e) { +		} + +		public void mousePressed(MouseEvent e) { +			map.touch_start(e.getPoint().x, e.getPoint().y, is_drag_event(e)); +		} + +		public void mouseReleased(MouseEvent e) { +		} + +		/* MouseWheelListener methods */ + +		public void mouseWheelMoved(MouseWheelEvent e) { +			int	zoom_change = e.getWheelRotation(); + +			map.set_zoom_centre(map.get_zoom() - zoom_change, new AltosPointInt(e.getPoint().x, e.getPoint().y)); +		} + +		/* ComponentListener methods */ + +		public void componentHidden(ComponentEvent e) { +		} + +		public void componentMoved(ComponentEvent e) { +		} + +		public void componentResized(ComponentEvent e) { +			map.set_transform(); +		} + +		public void componentShown(ComponentEvent e) { +			map.set_transform(); +		} + +		MapView() { +			addComponentListener(this); +			addMouseMotionListener(this); +			addMouseListener(this); +			addMouseWheelListener(this); +		} +	} + +	class MapLine extends AltosMapLine { + +		public void paint(AltosMapTransform t) { + +			if (start == null || end == null) +				return; + +			g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + +			Line2D.Double line = new Line2D.Double(point2d(t.screen(start)), +							       point2d(t.screen(end))); + +			g.setColor(Color.WHITE); +			g.setStroke(new BasicStroke(stroke_width+4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); +			g.draw(line); + +			g.setColor(Color.BLUE); +			g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); +			g.draw(line); + +			String	message = line_dist(); +			Rectangle2D	bounds; +			bounds = line_font.getStringBounds(message, g.getFontRenderContext()); + +			float x = (float) line.x1; +			float y = (float) line.y1 + (float) bounds.getHeight() / 2.0f; + +			if (line.x1 < line.x2) { +				x -= (float) bounds.getWidth() + 2.0f; +			} else { +				x += 2.0f; +			} + +			g.setFont(line_font); +			g.setColor(Color.WHITE); +			for (int dy = -2; dy <= 2; dy += 2) +				for (int dx = -2; dx <= 2; dx += 2) +					g.drawString(message, x + dx, y + dy); +			g.setColor(Color.BLUE); +			g.drawString(message, x, y); +		} + +		public MapLine() { +		} +	} + +	class MapPath extends AltosMapPath { +		public void paint(AltosMapTransform t) { +			Point2D.Double	prev = null; + +			g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, +					   RenderingHints.VALUE_ANTIALIAS_ON); +			g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); + +			for (AltosMapPathPoint point : points) { +				Point2D.Double	cur = point2d(t.screen(point.lat_lon)); +				if (prev != null) { +					Line2D.Double	line = new Line2D.Double (prev, cur); +					Rectangle	bounds = line.getBounds(); + +					if (g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height)) { +						if (0 <= point.state && point.state < AltosUIMapNew.stateColors.length) +							g.setColor(AltosUIMapNew.stateColors[point.state]); +						else +							g.setColor(AltosUIMapNew.stateColors[AltosLib.ao_flight_invalid]); + +						g.draw(line); +					} +				} +				prev = cur; +			} +		} +	} + +	class MapTile extends AltosMapTile { +		public MapTile(AltosMapTileListener listener, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) { +			super(listener, upper_left, center, zoom, maptype, px_size); +		} + +		public void paint(AltosMapTransform t) { + +			AltosPointDouble	point_double = t.screen(upper_left); +			Point			point = new Point((int) (point_double.x + 0.5), +								  (int) (point_double.y + 0.5)); + +			if (!g.hitClip(point.x, point.y, px_size, px_size)) +				return; + +			AltosImage altos_image = cache.get(this, store, px_size, px_size); + +			AltosUIImage	ui_image = (AltosUIImage) altos_image; + +			Image image = null; + +			if (ui_image != null) +				image = ui_image.image; + +			if (image != null) { +				g.drawImage(image, point.x, point.y, null); +			} else { +				g.setColor(Color.GRAY); +				g.fillRect(point.x, point.y, px_size, px_size); + +				if (t.has_location()) { +					String	message = null; +					switch (status) { +					case AltosMapTile.loading: +						message = "Loading..."; +						break; +					case AltosMapTile.bad_request: +						message = "Internal error"; +						break; +					case AltosMapTile.failed: +						message = "Network error, check connection"; +						break; +					case AltosMapTile.forbidden: +						message = "Too many requests, try later"; +						break; +					} +					if (message != null && tile_font != null) { +						g.setFont(tile_font); +						g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); +						Rectangle2D bounds = tile_font.getStringBounds(message, g.getFontRenderContext()); + +						float x = px_size / 2.0f; +						float y = px_size / 2.0f; +						x = x - (float) bounds.getWidth() / 2.0f; +						y = y + (float) bounds.getHeight() / 2.0f; +						g.setColor(Color.BLACK); +						g.drawString(message, (float) point_double.x + x, (float) point_double.y + y); +					} +				} +			} +		} +	} + +	public static final Color stateColors[] = { +		Color.WHITE,  // startup +		Color.WHITE,  // idle +		Color.WHITE,  // pad +		Color.RED,    // boost +		Color.PINK,   // fast +		Color.YELLOW, // coast +		Color.CYAN,   // drogue +		Color.BLUE,   // main +		Color.BLACK,  // landed +		Color.BLACK,  // invalid +		Color.CYAN,   // stateless +	}; + +	/* AltosMapInterface functions */ + +	public AltosMapPath new_path() { +		return new MapPath(); +	} + +	public AltosMapLine new_line() { +		return new MapLine(); +	} + +	public AltosImage load_image(File file) throws Exception { +		return new AltosUIImage(ImageIO.read(file)); +	} + +	public AltosMapMark new_mark(double lat, double lon, int state) { +		return new MapMark(lat, lon, state); +	} + +	public AltosMapTile new_tile(AltosMapTileListener listener, AltosLatLon upper_left, AltosLatLon center, int zoom, int maptype, int px_size) { +		return new MapTile(listener, upper_left, center, zoom, maptype, px_size); +	} + +	public int width() { +		return view.getWidth(); +	} + +	public int height() { +		return view.getHeight(); +	} + +	public void repaint() { +		view.repaint(); +	} + +	public void repaint(AltosRectangle damage) { +		view.repaint(damage); +	} + +	public void set_zoom_label(String label) { +		zoom_label.setText(label); +	} + +	public void select_object(AltosLatLon latlon) { +		debug("select at %f,%f\n", latlon.lat, latlon.lon); +	} + +	public void debug(String format, Object ... arguments) { +		System.out.printf(format, arguments); +	} + + +	/* AltosFlightDisplay interface */ + +	public void set_font() { +		tile_font = AltosUILib.value_font; +		line_font = AltosUILib.status_font; +	} + +	public void font_size_changed(int font_size) { +		set_font(); +		repaint(); +	} + +	public void units_changed(boolean imperial_units) { +		repaint(); +	} + +	JLabel	zoom_label; + +	public void set_maptype(int type) { +		map.set_maptype(type); +		maptype_combo.setSelectedIndex(type); +	} + +	/* AltosUIMapPreload functions */ + +	public void set_zoom(int zoom) { +		map.set_zoom(zoom); +	} + +	public void add_mark(double lat, double lon, int status) { +		map.add_mark(lat, lon, status); +	} + +	public void clear_marks() { +		map.clear_marks(); +	} + +	/* AltosFlightDisplay interface */ +	public void reset() { +		// nothing +	} + +	public void show(AltosState state, AltosListenerState listener_state) { +		map.show(state, listener_state); +	} + +	public String getName() { +		return "Map"; +	} + +	/* AltosGraphUI interface */ +	public void centre(AltosState state) { +		map.centre(state); +	} + +	/* internal layout bits */ +	private GridBagLayout layout = new GridBagLayout(); + +	JComboBox<String>	maptype_combo; + +	MapView	view; + +	public AltosUIMapNew() { + +		set_font(); + +		view = new MapView(); + +		view.setPreferredSize(new Dimension(500,500)); +		view.setVisible(true); +		view.setEnabled(true); + +		GridBagLayout	my_layout = new GridBagLayout(); + +		setLayout(my_layout); + +		GridBagConstraints c = new GridBagConstraints(); +		c.anchor = GridBagConstraints.CENTER; +		c.fill = GridBagConstraints.BOTH; +		c.gridx = 0; +		c.gridy = 0; +		c.gridwidth = 1; +		c.gridheight = 10; +		c.weightx = 1; +		c.weighty = 1; +		add(view, c); + +		int	y = 0; + +		zoom_label = new JLabel("", JLabel.CENTER); + +		c = new GridBagConstraints(); +		c.anchor = GridBagConstraints.CENTER; +		c.fill = GridBagConstraints.HORIZONTAL; +		c.gridx = 1; +		c.gridy = y++; +		c.weightx = 0; +		c.weighty = 0; +		add(zoom_label, c); + +		JButton zoom_reset = new JButton("0"); +		zoom_reset.addActionListener(new ActionListener() { +				public void actionPerformed(ActionEvent e) { +					map.set_zoom(map.default_zoom); +				} +			}); + +		c = new GridBagConstraints(); +		c.anchor = GridBagConstraints.CENTER; +		c.fill = GridBagConstraints.HORIZONTAL; +		c.gridx = 1; +		c.gridy = y++; +		c.weightx = 0; +		c.weighty = 0; +		add(zoom_reset, c); + +		JButton zoom_in = new JButton("+"); +		zoom_in.addActionListener(new ActionListener() { +				public void actionPerformed(ActionEvent e) { +					map.set_zoom(map.get_zoom() + 1); +				} +			}); + +		c = new GridBagConstraints(); +		c.anchor = GridBagConstraints.CENTER; +		c.fill = GridBagConstraints.HORIZONTAL; +		c.gridx = 1; +		c.gridy = y++; +		c.weightx = 0; +		c.weighty = 0; +		add(zoom_in, c); + +		JButton zoom_out = new JButton("-"); +		zoom_out.addActionListener(new ActionListener() { +				public void actionPerformed(ActionEvent e) { +					map.set_zoom(map.get_zoom() - 1); +				} +			}); +		c = new GridBagConstraints(); +		c.anchor = GridBagConstraints.CENTER; +		c.fill = GridBagConstraints.HORIZONTAL; +		c.gridx = 1; +		c.gridy = y++; +		c.weightx = 0; +		c.weighty = 0; +		add(zoom_out, c); + +		maptype_combo = new JComboBox<String>(map.maptype_labels); + +		maptype_combo.setEditable(false); +		maptype_combo.setMaximumRowCount(maptype_combo.getItemCount()); +		maptype_combo.addItemListener(new ItemListener() { +				public void itemStateChanged(ItemEvent e) { +					map.set_maptype(maptype_combo.getSelectedIndex()); +				} +			}); + +		c = new GridBagConstraints(); +		c.anchor = GridBagConstraints.CENTER; +		c.fill = GridBagConstraints.HORIZONTAL; +		c.gridx = 1; +		c.gridy = y++; +		c.weightx = 0; +		c.weighty = 0; +		add(maptype_combo, c); + +		map = new AltosMap(this); +	} +} diff --git a/altosuilib/AltosUIMapPath.java b/altosuilib/AltosUIMapPath.java deleted file mode 100644 index e77af580..00000000 --- a/altosuilib/AltosUIMapPath.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright © 2014 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.altosuilib_6; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.lang.Math; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_6.*; - -class PathPoint { -	AltosUILatLon	lat_lon; -	int		state; - -	public PathPoint(AltosUILatLon lat_lon, int state) { -		this.lat_lon = lat_lon; -		this.state = state; -	} - -	public boolean equals(PathPoint other) { -		if (other == null) -			return false; - -		return lat_lon.equals(other.lat_lon) && state == other.state; -	} -} - -public class AltosUIMapPath { - -	LinkedList<PathPoint>	points = new LinkedList<PathPoint>(); -	PathPoint		last_point = null; - -	static public int stroke_width = 6; - -	public void paint(Graphics2D g, AltosUIMapTransform t) { -		Point2D.Double	prev = null; - -		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, -				   RenderingHints.VALUE_ANTIALIAS_ON); -		g.setStroke(new BasicStroke(stroke_width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); - -		for (PathPoint point : points) { -			Point2D.Double	cur = t.screen(point.lat_lon); -			if (prev != null) { -				Line2D.Double	line = new Line2D.Double (prev, cur); -				Rectangle	bounds = line.getBounds(); - -				if (g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height)) { -					if (0 <= point.state && point.state < AltosUIMap.stateColors.length) -						g.setColor(AltosUIMap.stateColors[point.state]); -					else -						g.setColor(AltosUIMap.stateColors[AltosLib.ao_flight_invalid]); - -					g.draw(line); -				} -			} -			prev = cur; -		} -	} - -	public AltosUIMapRectangle add(double lat, double lon, int state) { -		PathPoint		point = new PathPoint(new AltosUILatLon (lat, lon), state); -		AltosUIMapRectangle	rect = null; - -		if (!point.equals(last_point)) { -			if (last_point != null) -				rect = new AltosUIMapRectangle(last_point.lat_lon, point.lat_lon); -			points.add (point); -			last_point = point; -		} -		return rect; -	} - -	public void clear () { -		points = new LinkedList<PathPoint>(); -	} -} diff --git a/altosuilib/AltosUIMapPreload.java b/altosuilib/AltosUIMapPreloadNew.java index e82b6c60..2d4d45b2 100644 --- a/altosuilib/AltosUIMapPreload.java +++ b/altosuilib/AltosUIMapPreloadNew.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*; @@ -26,7 +26,7 @@ import java.text.*;  import java.lang.Math;  import java.net.URL;  import java.net.URLConnection; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  class AltosUIMapPos extends Box {  	AltosUIFrame	owner; @@ -53,33 +53,33 @@ class AltosUIMapPos extends Box {  		hemi.setSelectedIndex(h);  	} -	public double get_value() throws NumberFormatException { +	public double get_value() throws ParseException {  		int	h = hemi.getSelectedIndex();  		String	d_t = deg.getText();  		String	m_t = min.getText();  		double 	d, m, v;  		try { -			d = Double.parseDouble(d_t); -		} catch (NumberFormatException ne) { +			d = AltosParse.parse_double_locale(d_t); +		} catch (ParseException pe) {  			JOptionPane.showMessageDialog(owner,  						      String.format("Invalid degrees \"%s\"",  								    d_t),  						      "Invalid number",  						      JOptionPane.ERROR_MESSAGE); -			throw ne; +			throw pe;  		}  		try {  			if (m_t.equals(""))  				m = 0;  			else -				m = Double.parseDouble(m_t); -		} catch (NumberFormatException ne) { +				m = AltosParse.parse_double_locale(m_t); +		} catch (ParseException pe) {  			JOptionPane.showMessageDialog(owner,  						      String.format("Invalid minutes \"%s\"",  								    m_t),  						      "Invalid number",  						      JOptionPane.ERROR_MESSAGE); -			throw ne; +			throw pe;  		}  		v = d + m/60.0;  		if (h == 1) @@ -118,250 +118,87 @@ class AltosUIMapPos extends Box {  	}  } -class AltosUISite { -	String	name; -	double	latitude; -	double	longitude; - -	public String toString() { -		return name; -	} - -	public AltosUISite(String in_name, double in_latitude, double in_longitude) { -		name = in_name; -		latitude = in_latitude; -		longitude = in_longitude; -	} - -	public AltosUISite(String line) throws ParseException { -		String[]	elements = line.split(":"); - -		if (elements.length < 3) -			throw new ParseException(String.format("Invalid site line %s", line), 0); - -		name = elements[0]; - -		try { -			latitude = Double.parseDouble(elements[1]); -			longitude = Double.parseDouble(elements[2]); -		} catch (NumberFormatException ne) { -			throw new ParseException(String.format("Invalid site line %s", line), 0); -		} -	} -} - -class AltosUISites extends Thread { -	AltosUIMapPreload	preload; -	URL			url; -	LinkedList<AltosUISite>	sites; - -	void notify_complete() { -		SwingUtilities.invokeLater(new Runnable() { -				public void run() { -					preload.set_sites(); -				} -			}); -	} - -	void add(AltosUISite site) { -		sites.add(site); -	} - -	void add(String line) { -		try { -			add(new AltosUISite(line)); -		} catch (ParseException pe) { -		} -	} - -	public void run() { -		try { -			URLConnection uc = url.openConnection(); -			//int length = uc.getContentLength(); - -			InputStreamReader in_stream = new InputStreamReader(uc.getInputStream(), AltosLib.unicode_set); -			BufferedReader in = new BufferedReader(in_stream); - -			for (;;) { -				String line = in.readLine(); -				if (line == null) -					break; -				add(line); -			} -		} catch (IOException e) { -		} finally { -			notify_complete(); -		} -	} - -	public AltosUISites(AltosUIMapPreload in_preload) { -		sites = new LinkedList<AltosUISite>(); -		preload = in_preload; -		try { -			url = new URL(AltosLib.launch_sites_url); -		} catch (java.net.MalformedURLException e) { -			notify_complete(); -		} -		start(); -	} -} - -public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, ItemListener, AltosUIMapTileListener { +public class AltosUIMapPreloadNew extends AltosUIFrame implements ActionListener, ItemListener, AltosLaunchSiteListener, AltosMapLoaderListener  {  	AltosUIFrame	owner; -	AltosUIMap	map; -	AltosUIMapCache	cache = new AltosUIMapCache(); +	AltosUIMapNew	map;  	AltosUIMapPos	lat;  	AltosUIMapPos	lon;  	JProgressBar	pbar; -	int		pbar_max; -	int		pbar_cur; -	AltosUISites	sites; +	AltosMapLoader	loader; +  	JLabel		site_list_label; -	JComboBox<AltosUISite>	site_list; +	JComboBox<AltosLaunchSite>	site_list;  	JToggleButton	load_button;  	boolean		loading;  	JButton		close_button; -	JCheckBox[]	maptypes = new JCheckBox[AltosUIMap.maptype_terrain - AltosUIMap.maptype_hybrid + 1]; +	JCheckBox[]	maptypes = new JCheckBox[AltosMap.maptype_terrain - AltosMap.maptype_hybrid + 1];  	JComboBox<Integer>	min_zoom;  	JComboBox<Integer>	max_zoom; -	JComboBox<Integer>	radius; +	JComboBox<Double>	radius;  	Integer[]		zooms = { -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6 }; -	Integer[]		radii = { 1, 2, 3, 4, 5 }; -	static final String[]	lat_hemi_names = { "N", "S" }; -	static final String[]	lon_hemi_names = { "E", "W" }; +	Double[]	radius_mi = { 1.0, 2.0, 5.0, 10.0, 20.0 }; +	Double		radius_def_mi = 5.0; +	Double[]	radius_km = { 2.0, 5.0, 10.0, 20.0, 30.0 }; +	Double		radius_def_km = 10.0; -	class updatePbar implements Runnable { -		String		s; -		public updatePbar(String in_s) { -			s = in_s; -		} - -		public void run() { -			int 	n = ++pbar_cur; - -			pbar.setMaximum(pbar_max); -			pbar.setValue(n); -			pbar.setString(s); -		} -	} +	static final String[]	lat_hemi_names = { "N", "S" }; +	static final String[]	lon_hemi_names = { "E", "W" };  	double	latitude, longitude; -	int	min_z; -	int	max_z; -	int	cur_z; -	int	all_types; -	int	cur_type; -	int	r; - -	int	tiles_per_layer; -	int	tiles_loaded; -	int	layers_total; -	int	layers_loaded; - - -	private void do_load() { -		tiles_loaded = 0; -		map.set_zoom(cur_z + AltosUIMapView.default_zoom); -		map.set_maptype(cur_type); -		map.set_load_params(latitude, longitude, r, this); -	} -	private int next_type(int start) { -		int next_type; -		for (next_type = start; -		     next_type <= AltosUIMap.maptype_terrain && (all_types & (1 << next_type)) == 0; -		     next_type++) -			; -		return next_type; +	/* AltosMapLoaderListener interfaces */ +	public void loader_start(final int max) { +		SwingUtilities.invokeLater(new Runnable() { +				public void run() { +					pbar.setMaximum(max); +					pbar.setValue(0); +					pbar.setString(""); +					map.clear_marks(); +					map.add_mark(latitude, longitude, AltosLib.ao_flight_boost); +				} +			});  	} -	private void next_load() { -		int next_type = next_type(cur_type + 1); - -		if (next_type > AltosUIMap.maptype_terrain) { -			if (cur_z == max_z) { -				return; -			} else { -				cur_z++; -			} -			next_type = next_type(0); -		} -		cur_type = next_type; -		do_load(); +	public void loader_notify(final int cur, final int max, final String name) { +		SwingUtilities.invokeLater(new Runnable() { +				public void run() { +					pbar.setValue(cur); +					pbar.setString(name); +				} +			});  	} -	private void start_load() { -		cur_z = min_z; -		int ntype = 0; -		all_types = 0; -		for (int t = AltosUIMap.maptype_hybrid; t <= AltosUIMap.maptype_terrain; t++) -			if (maptypes[t].isSelected()) { -				all_types |= (1 << t); -				ntype++; -			} -		if (ntype == 0) { -			all_types |= (1 << AltosUIMap.maptype_hybrid); -			ntype = 1; -		} - -		cur_type = next_type(0); -		tiles_per_layer = (r * 2 + 1) * (r * 2 + 1); -		layers_total = (max_z - min_z + 1) * ntype; -		layers_loaded = 0; -		pbar_max = layers_total * tiles_per_layer; -		pbar_cur = 0; - -		map.clear_marks(); -		map.add_mark(latitude,longitude, AltosLib.ao_flight_boost); -		do_load(); +	public void loader_done(int max) { +		SwingUtilities.invokeLater(new Runnable() { +				public void run() { +					pbar.setValue(0); +					pbar.setString(""); +					load_button.setSelected(false); +					loading = false; +				} +			});  	} -	/* AltosUIMapTileListener methods */ - -	public synchronized void notify_tile(AltosUIMapTile tile, int status) { -		if (status == AltosUIMapStore.loading) -			return; - -		SwingUtilities.invokeLater(new updatePbar(tile.store.file.toString())); -		++tiles_loaded; -		if (tiles_loaded == tiles_per_layer) { -			++layers_loaded; -			if (layers_loaded == layers_total) { -				SwingUtilities.invokeLater(new Runnable() { -						public void run() { -							pbar.setValue(0); -							pbar.setString(""); -							load_button.setSelected(false); -							loading = false; -						} -					}); -			} else { -				SwingUtilities.invokeLater(new Runnable() { -						public void run() { -							next_load(); -						} -					}); -			} -		} +	public void debug(String format, Object ... arguments) { +		System.out.printf(format, arguments);  	} -	public AltosUIMapCache cache() { return cache; } -	public void set_sites() { -		int	i = 1; -		for (AltosUISite site : sites.sites) { -			site_list.insertItemAt(site, i); -			i++; -		} +	private int all_types() { +		int all_types = 0; +		for (int t = AltosMap.maptype_hybrid; t <= AltosMap.maptype_terrain; t++) +			if (maptypes[t].isSelected()) +				all_types |= (1 << t); +		return all_types;  	}  	public void itemStateChanged(ItemEvent e) { @@ -369,8 +206,8 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I  		if (state == ItemEvent.SELECTED) {  			Object	o = e.getItem(); -			if (o instanceof AltosUISite) { -				AltosUISite	site = (AltosUISite) o; +			if (o instanceof AltosLaunchSite) { +				AltosLaunchSite	site = (AltosLaunchSite) o;  				lat.set_value(site.latitude);  				lon.set_value(site.longitude);  			} @@ -388,21 +225,39 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I  				try {  					latitude = lat.get_value();  					longitude = lon.get_value(); -					min_z = (Integer) min_zoom.getSelectedItem(); -					max_z = (Integer) max_zoom.getSelectedItem(); +					int min_z = (Integer) min_zoom.getSelectedItem(); +					int max_z = (Integer) max_zoom.getSelectedItem();  					if (max_z < min_z)  						max_z = min_z; -					r = (Integer) radius.getSelectedItem(); +					Double r = (Double) radius.getSelectedItem(); + +					if (AltosPreferences.imperial_units()) +						r = AltosConvert.distance.inverse(r); +					else +						r = r * 1000;  					loading = true; -				} catch (NumberFormatException ne) { + +					loader.load(latitude, longitude, min_z, max_z, r, all_types()); +				} catch (ParseException pe) {  					load_button.setSelected(false);  				} -				start_load();  			}  		}  	} -	public AltosUIMapPreload(AltosUIFrame in_owner) { +	public void notify_launch_sites(final java.util.List<AltosLaunchSite> sites) { +		SwingUtilities.invokeLater(new Runnable() { +				public void run() { +					int	i = 1; +					for (AltosLaunchSite site : sites) { +						site_list.insertItemAt(site, i); +						i++; +					} +				} +			}); +	} + +	public AltosUIMapPreloadNew(AltosUIFrame in_owner) {  		owner = in_owner;  		Container		pane = getContentPane(); @@ -413,7 +268,9 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I  		pane.setLayout(new GridBagLayout()); -		map = new AltosUIMap(); +		map = new AltosUIMapNew(); + +		loader = new AltosMapLoader(map.map, this);  		c.fill = GridBagConstraints.BOTH;  		c.anchor = GridBagConstraints.CENTER; @@ -461,10 +318,10 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I  		pane.add(site_list_label, c); -		site_list = new JComboBox<AltosUISite>(new AltosUISite[] { new AltosUISite("Site List", 0, 0) }); +		site_list = new JComboBox<AltosLaunchSite>(new AltosLaunchSite[] { new AltosLaunchSite("Site List", 0, 0) });  		site_list.addItemListener(this); -		sites = new AltosUISites(this); +		new AltosLaunchSites(this);  		c.fill = GridBagConstraints.HORIZONTAL;  		c.anchor = GridBagConstraints.CENTER; @@ -555,9 +412,9 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I  		c.gridwidth = 1; -		for (int type = AltosUIMap.maptype_hybrid; type <= AltosUIMap.maptype_terrain; type++) { -			maptypes[type] = new JCheckBox(AltosUIMap.maptype_labels[type], -						       type == AltosUIMap.maptype_hybrid); +		for (int type = AltosMap.maptype_hybrid; type <= AltosMap.maptype_terrain; type++) { +			maptypes[type] = new JCheckBox(AltosMap.maptype_labels[type], +						       type == AltosMap.maptype_hybrid);  			c.gridx = 2 + (type >> 1);  			c.fill = GridBagConstraints.HORIZONTAL;  			c.gridy = (type & 1) + 3; @@ -588,13 +445,21 @@ public class AltosUIMapPreload extends AltosUIFrame implements ActionListener, I  		c.gridy = 3;  		pane.add(max_zoom, c); -		JLabel radius_label = new JLabel("Tile Radius"); +		JLabel radius_label = new JLabel(String.format("Map Radius (%s)", +							       AltosPreferences.imperial_units() ? "miles" : "km"));  		c.gridx = 4;  		c.gridy = 4;  		pane.add(radius_label, c); -		radius = new JComboBox<Integer>(radii); -		radius.setSelectedItem(radii[4]); +		Double[]	radii; +		Double		radius_default; + +		if (AltosPreferences.imperial_units()) +			radii = radius_mi; +		else +			radii = radius_km; +		radius = new JComboBox<Double>(radii); +		radius.setSelectedItem(radii[2]);  		radius.setEditable(true);  		c.gridx = 5;  		c.gridy = 4; diff --git a/altosuilib/AltosUIMapRectangle.java b/altosuilib/AltosUIMapRectangle.java deleted file mode 100644 index dc0e4cc1..00000000 --- a/altosuilib/AltosUIMapRectangle.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © 2014 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.altosuilib_6; - -public class AltosUIMapRectangle { -	AltosUILatLon	ul, lr; - -	public AltosUIMapRectangle(AltosUILatLon a, AltosUILatLon b) { -		double	ul_lat, ul_lon; -		double	lr_lat, lr_lon; - -		if (a.lat > b.lat) { -			ul_lat = a.lat; -			lr_lat = b.lat; -		} else { -			ul_lat = b.lat; -			lr_lat = a.lat; -		} -		if (a.lon < b.lon) { -			ul_lon = a.lon; -			lr_lon = b.lon; -		} else { -			ul_lon = b.lon; -			lr_lon = a.lon; -		} - -		ul = new AltosUILatLon(ul_lat, ul_lon); -		lr = new AltosUILatLon(lr_lat, lr_lon); -	} -} diff --git a/altosuilib/AltosUIMapStore.java b/altosuilib/AltosUIMapStore.java deleted file mode 100644 index 70bb6fed..00000000 --- a/altosuilib/AltosUIMapStore.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright © 2014 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.altosuilib_6; - -import java.io.*; -import java.net.*; -import java.util.*; - -public class AltosUIMapStore { -	String					url; -	File					file; -	LinkedList<AltosUIMapStoreListener>	listeners = new LinkedList<AltosUIMapStoreListener>(); - -	static final int			success = 0; -	static final int			loading = 1; -	static final int			failed = 2; -	static final int			bad_request = 3; -	static final int			forbidden = 4; - -	int					status; - -	public int status() { -		return status; -	} - -	public synchronized void add_listener(AltosUIMapStoreListener listener) { -		if (!listeners.contains(listener)) -			listeners.add(listener); -	} - -	public synchronized void remove_listener(AltosUIMapStoreListener listener) { -		listeners.remove(listener); -	} - -	private synchronized void notify_listeners(int status) { -		this.status = status; -		for (AltosUIMapStoreListener listener : listeners) -			listener.notify_store(this, status); -	} - -	static Object	forbidden_lock = new Object(); -	static long	forbidden_time; -	static boolean	forbidden_set; - -	private int fetch_url() { -		URL u; - -		try { -			u = new URL(url); -		} catch (java.net.MalformedURLException e) { -			return bad_request; -		} - -		byte[] data; -		URLConnection uc = null; -		try { -			uc = u.openConnection(); -			String type = uc.getContentType(); -			int contentLength = uc.getContentLength(); -			if (uc instanceof HttpURLConnection) { -				int response = ((HttpURLConnection) uc).getResponseCode(); -				switch (response) { -				case HttpURLConnection.HTTP_FORBIDDEN: -				case HttpURLConnection.HTTP_PAYMENT_REQUIRED: -				case HttpURLConnection.HTTP_UNAUTHORIZED: -					synchronized (forbidden_lock) { -						forbidden_time = System.nanoTime(); -						forbidden_set = true; -						return forbidden; -					} -				} -			} -			InputStream in = new BufferedInputStream(uc.getInputStream()); -			int bytesRead = 0; -			int offset = 0; -			data = new byte[contentLength]; -			while (offset < contentLength) { -				bytesRead = in.read(data, offset, data.length - offset); -				if (bytesRead == -1) -					break; -				offset += bytesRead; -			} -			in.close(); - -			if (offset != contentLength) -				return failed; - -		} catch (IOException e) { -			return failed; -		} - -		try { -			FileOutputStream out = new FileOutputStream(file); -			out.write(data); -			out.flush(); -			out.close(); -		} catch (FileNotFoundException e) { -			return bad_request; -		} catch (IOException e) { -			if (file.exists()) -				file.delete(); -			return bad_request; -		} -		return success; -	} - -	static Object	fetch_lock = new Object(); - -	static final long	forbidden_interval = 60l * 1000l * 1000l * 1000l; -	static final long 	google_maps_ratelimit_ms = 1200; - -	class loader implements Runnable { - -		public void run() { -			if (file.exists()) { -				notify_listeners(success); -				return; -			} - -			synchronized(forbidden_lock) { -				if (forbidden_set && (System.nanoTime() - forbidden_time) < forbidden_interval) { -					notify_listeners(forbidden); -					return; -				} -			} - -			int new_status; - -			if (!AltosUIVersion.has_google_maps_api_key()) { -				synchronized (fetch_lock) { -					long startTime = System.nanoTime(); -					new_status = fetch_url(); -					if (new_status == success) { -						long duration_ms = (System.nanoTime() - startTime) / 1000000; -						if (duration_ms < google_maps_ratelimit_ms) { -							try { -								Thread.sleep(google_maps_ratelimit_ms - duration_ms); -							} catch (InterruptedException e) { -								Thread.currentThread().interrupt(); -							} -						} -					} -				} -			} else { -				new_status = fetch_url(); -			} -			notify_listeners(new_status); -		} -	} - -	private void load() { -		loader	l = new loader(); -		Thread	lt = new Thread(l); -		lt.start(); -	} - -	private AltosUIMapStore (String url, File file) { -		this.url = url; -		this.file = file; - -		if (file.exists()) -			status = success; -		else { -			status = loading; -			load(); -		} -	} - -	public boolean equals(AltosUIMapStore other) { -		return url.equals(other.url); -	} - -	static HashMap<String,AltosUIMapStore> stores = new HashMap<String,AltosUIMapStore>(); - -	public static AltosUIMapStore get(String url, File file) { -		AltosUIMapStore	store; -		synchronized(stores) { -			if (stores.containsKey(url)) { -				store = stores.get(url); -			} else { -				store = new AltosUIMapStore(url, file); -				stores.put(url, store); -			} -		} -		return store; -	} - -} diff --git a/altosuilib/AltosUIMapStoreListener.java b/altosuilib/AltosUIMapStoreListener.java deleted file mode 100644 index ccda8983..00000000 --- a/altosuilib/AltosUIMapStoreListener.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © 2014 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.altosuilib_6; - -public interface AltosUIMapStoreListener { -	abstract void notify_store(AltosUIMapStore store, int status); -} diff --git a/altosuilib/AltosUIMapTile.java b/altosuilib/AltosUIMapTile.java deleted file mode 100644 index afd1bbc6..00000000 --- a/altosuilib/AltosUIMapTile.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright © 2010 Anthony Towns <aj@erisian.com.au> - * - * 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.altosuilib_6; - -import java.awt.*; -import java.awt.image.*; -import javax.swing.*; -import javax.imageio.*; -import java.awt.geom.*; -import java.io.*; -import java.util.*; -import java.awt.RenderingHints.*; -import org.altusmetrum.altoslib_6.*; - -public class AltosUIMapTile { -	AltosUIMapTileListener	listener; -	AltosUILatLon	upper_left, center; -	int		px_size; -	int		zoom; -	int		maptype; -	AltosUIMapStore	store; -	AltosUIMapCache	cache; -	int		status; - -	private File map_file() { -		double lat = center.lat; -		double lon = center.lon; -		char chlat = lat < 0 ? 'S' : 'N'; -		char chlon = lon < 0 ? 'W' : 'E'; - -		if (lat < 0) lat = -lat; -		if (lon < 0) lon = -lon; -		String maptype_string = String.format("%s-", AltosUIMap.maptype_names[maptype]); -		String format_string; -		if (maptype == AltosUIMap.maptype_hybrid || maptype == AltosUIMap.maptype_satellite || maptype == AltosUIMap.maptype_terrain) -			format_string = "jpg"; -		else -			format_string = "png"; -		return new File(AltosUIPreferences.mapdir(), -				String.format("map-%c%.6f,%c%.6f-%s%d.%s", -					      chlat, lat, chlon, lon, maptype_string, zoom, format_string)); -	} - -	private String map_url() { -		String format_string; -		if (maptype == AltosUIMap.maptype_hybrid || maptype == AltosUIMap.maptype_satellite || maptype == AltosUIMap.maptype_terrain) -			format_string = "jpg"; -		else -			format_string = "png32"; - -		if (AltosUIVersion.has_google_maps_api_key()) -			return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=%s&format=%s&key=%s", -					     center.lat, center.lon, zoom, px_size, px_size, AltosUIMap.maptype_names[maptype], format_string, AltosUIVersion.google_maps_api_key); -		else -			return String.format("http://maps.google.com/maps/api/staticmap?center=%.6f,%.6f&zoom=%d&size=%dx%d&sensor=false&maptype=%s&format=%s", -					     center.lat, center.lon, zoom, px_size, px_size, AltosUIMap.maptype_names[maptype], format_string); -	} -	private Font	font = null; - -	public void set_font(Font font) { -		this.font = font; -	} - -	int	painting_serial; -	int	painted_serial; - -	Image	image; - -	public void paint_graphics(Graphics2D g2d, AltosUIMapTransform t, int serial) { -		if (serial < painted_serial) -			return; - -		Point2D.Double	point_double = t.screen(upper_left); -		Point		point = new Point((int) (point_double.x + 0.5), -						  (int) (point_double.y + 0.5)); - -		painted_serial = serial; - -		if (!g2d.hitClip(point.x, point.y, px_size, px_size)) -			return; - -		if (image != null) { -			g2d.drawImage(image, point.x, point.y, null); -			image = null; -		} else { -			g2d.setColor(Color.GRAY); -			g2d.fillRect(point.x, point.y, px_size, px_size); - -			if (t.has_location()) { -				String	message = null; -				switch (status) { -				case AltosUIMapCache.loading: -					message = "Loading..."; -					break; -				case AltosUIMapCache.bad_request: -					message = "Internal error"; -					break; -				case AltosUIMapCache.failed: -					message = "Network error, check connection"; -					break; -				case AltosUIMapCache.forbidden: -					message = "Too many requests, try later"; -					break; -				} -				if (message != null && font != null) { -					g2d.setFont(font); -					g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); -					Rectangle2D bounds = font.getStringBounds(message, g2d.getFontRenderContext()); - -					float x = px_size / 2.0f; -					float y = px_size / 2.0f; -					x = x - (float) bounds.getWidth() / 2.0f; -					y = y + (float) bounds.getHeight() / 2.0f; -					g2d.setColor(Color.BLACK); -					g2d.drawString(message, (float) point_double.x + x, (float) point_double.y + y); -				} -			} -		} -	} - -	public void set_status(int status) { -		this.status = status; -		listener.notify_tile(this, status); -	} - -	public void notify_image(Image image) { -		listener.notify_tile(this, status); -	} - -	public void paint(Graphics g, AltosUIMapTransform t) { -		Graphics2D		g2d = (Graphics2D) g; -		boolean			queued = false; - -		Point2D.Double	point = t.screen(upper_left); - -		if (!g.hitClip((int) (point.x + 0.5), (int) (point.y + 0.5), px_size, px_size)) -			return; - -		++painting_serial; - -		if (image == null && t.has_location()) -			image = cache.get(this, store, px_size, px_size); - -		paint_graphics(g2d, t, painting_serial); -	} - -	public int store_status() { -		return store.status(); -	} - -	public void add_store_listener(AltosUIMapStoreListener listener) { -		store.add_listener(listener); -	} - -	public void remove_store_listener(AltosUIMapStoreListener listener) { -		store.remove_listener(listener); -	} - -	public AltosUIMapTile(AltosUIMapTileListener listener, AltosUILatLon upper_left, AltosUILatLon center, int zoom, int maptype, int px_size, Font font) { -		this.listener = listener; -		this.upper_left = upper_left; -		cache = listener.cache(); - -		while (center.lon < -180.0) -			center.lon += 360.0; -		while (center.lon > 180.0) -			center.lon -= 360.0; - -		this.center = center; -		this.zoom = zoom; -		this.maptype = maptype; -		this.px_size = px_size; -		this.font = font; -		status = AltosUIMapCache.loading; -		store = AltosUIMapStore.get(map_url(), map_file()); -	} -} diff --git a/altosuilib/AltosUIMapTileListener.java b/altosuilib/AltosUIMapTileListener.java deleted file mode 100644 index dace5b76..00000000 --- a/altosuilib/AltosUIMapTileListener.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright © 2014 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.altosuilib_6; - -public interface AltosUIMapTileListener { -	abstract public void notify_tile(AltosUIMapTile tile, int status); - -	abstract public AltosUIMapCache cache(); -} diff --git a/altosuilib/AltosUIMapTransform.java b/altosuilib/AltosUIMapTransform.java deleted file mode 100644 index 25497403..00000000 --- a/altosuilib/AltosUIMapTransform.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright © 2014 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.altosuilib_6; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.io.*; -import java.lang.Math; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_6.*; - -public class AltosUIMapTransform { - -	double	scale_x, scale_y; - -	double	offset_x, offset_y; - -	public AltosUILatLon lat_lon (Point2D.Double point) { -		double lat, lon; -		double rads; - -		lon = point.x/scale_x; -		rads = 2 * Math.atan(Math.exp(-point.y/scale_y)); -		lat = Math.toDegrees(rads - Math.PI/2); - -		return new AltosUILatLon(lat,lon); -	} - -	public Point2D.Double screen_point(Point screen) { -		return new Point2D.Double(screen.x + offset_x, screen.y + offset_y); -	} - -	public AltosUILatLon screen_lat_lon(Point screen) { -		return lat_lon(screen_point(screen)); -	} - -	public Point2D.Double point(AltosUILatLon lat_lon) { -		double x, y; -		double e; - -		x = lat_lon.lon * scale_x; - -		e = Math.sin(Math.toRadians(lat_lon.lat)); -		e = Math.max(e,-(1-1.0E-15)); -		e = Math.min(e,  1-1.0E-15 ); - -		y = 0.5*Math.log((1+e)/(1-e))*-scale_y; - -		return new Point2D.Double(x, y); -	} - -	public Point2D.Double screen(Point2D.Double point) { -		return new Point2D.Double(point.x - offset_x, point.y - offset_y); -	} - -	public Point screen(Point point) { -		return new Point((int) (point.x - offset_x + 0.5), -				 (int) (point.y - offset_y + 0.5)); -	} - -	public Rectangle screen(AltosUIMapRectangle map_rect) { -		Point2D.Double	ul = screen(map_rect.ul); -		Point2D.Double	lr = screen(map_rect.lr); - -		return new Rectangle((int) ul.x, (int) ul.y, (int) (lr.x - ul.x), (int) (lr.y - ul.y)); -	} - -	public Point2D.Double screen(AltosUILatLon lat_lon) { -		return screen(point(lat_lon)); -	} - -	private boolean has_location; - -	public boolean has_location() { -		return has_location; -	} - -	public AltosUIMapTransform(int width, int height, int zoom, AltosUILatLon centre_lat_lon) { -		scale_x = 256/360.0 * Math.pow(2, zoom); -		scale_y = 256/(2.0*Math.PI) * Math.pow(2, zoom); - -		Point2D.Double centre_pt = point(centre_lat_lon); - -		has_location = (centre_lat_lon.lat != 0 || centre_lat_lon.lon != 0); -		offset_x = centre_pt.x - width / 2.0; -		offset_y = centre_pt.y - height / 2.0; -	} -} diff --git a/altosuilib/AltosUIMapView.java b/altosuilib/AltosUIMapView.java deleted file mode 100644 index c8632b99..00000000 --- a/altosuilib/AltosUIMapView.java +++ /dev/null @@ -1,472 +0,0 @@ -/* - * Copyright © 2014 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.altosuilib_6; - -import java.awt.*; -import java.awt.event.*; -import java.awt.image.*; -import javax.swing.*; -import java.io.*; -import java.lang.*; -import java.awt.geom.*; -import java.util.*; -import java.util.concurrent.*; -import org.altusmetrum.altoslib_6.*; - -public class AltosUIMapView extends Component implements MouseMotionListener, MouseListener, MouseWheelListener, ComponentListener, AltosUIMapTileListener, AltosUIMapStoreListener { - -	AltosUIMapPath	path = new AltosUIMapPath(); - -	AltosUIMapLine	line = new AltosUIMapLine(); - -	AltosUIMapCache	cache = new AltosUIMapCache(); - -	LinkedList<AltosUIMapMark> marks = new LinkedList<AltosUIMapMark>(); - -	LinkedList<AltosUIMapZoomListener> zoom_listeners = new LinkedList<AltosUIMapZoomListener>(); - -	boolean		have_boost = false; -	boolean		have_landed = false; - -	ConcurrentHashMap<Point,AltosUIMapTile> tiles = new ConcurrentHashMap<Point,AltosUIMapTile>(); - -	static final int default_zoom = 15; -	static final int min_zoom = 3; -	static final int max_zoom = 21; -	static final int px_size = 512; - -	int		load_radius; -	AltosUILatLon	load_centre = null; -	AltosUIMapTileListener	load_listener; - -	int 		zoom = default_zoom; -	int		maptype = AltosUIMap.maptype_default; - -	long		user_input_time; - -	/* Milliseconds to wait after user action before auto-scrolling -	 */ -	static final long auto_scroll_delay = 20 * 1000; - -	AltosUIMapTransform	transform; -	AltosUILatLon		centre; - -	public void set_font() { -		line.set_font(AltosUILib.status_font); -		for (AltosUIMapTile tile : tiles.values()) -			tile.set_font(AltosUILib.value_font); -		repaint(); -	} - -	public void set_units() { -		repaint(); -	} - -	private boolean is_drag_event(MouseEvent e) { -		return e.getModifiers() == InputEvent.BUTTON1_MASK; -	} - -	Point	drag_start; - -	private void drag(MouseEvent e) { -		if (drag_start == null) -			return; - -		int dx = e.getPoint().x - drag_start.x; -		int dy = e.getPoint().y - drag_start.y; - -		AltosUILatLon	new_centre = transform.screen_lat_lon(new Point(getWidth() / 2 - dx, getHeight() / 2 - dy)); -		centre (new_centre.lat, new_centre.lon); -		drag_start = e.getPoint(); -	} - -	private void drag_start(MouseEvent e) { -		drag_start = e.getPoint(); -	} - -	private void notice_user_input() { -		user_input_time = System.currentTimeMillis(); -	} - -	private boolean recent_user_input() { -		return (System.currentTimeMillis() - user_input_time) < auto_scroll_delay; -	} - -	/* MouseMotionListener methods */ - -	public void mouseDragged(MouseEvent e) { -		notice_user_input(); -		if (is_drag_event(e)) -			drag(e); -		else { -			line.dragged(e, transform); -			repaint(); -		} -	} - -	public void mouseMoved(MouseEvent e) { -	} - -	/* MouseListener methods */ -	public void mouseClicked(MouseEvent e) { -	} - -	public void mouseEntered(MouseEvent e) { -	} - -	public void mouseExited(MouseEvent e) { -	} - -	public void mousePressed(MouseEvent e) { -		notice_user_input(); -		if (is_drag_event(e)) -			drag_start(e); -		else { -			line.pressed(e, transform); -			repaint(); -		} -	} - -	public void mouseReleased(MouseEvent e) { -	} - -	/* MouseWheelListener methods */ - -	public void mouseWheelMoved(MouseWheelEvent e) { -		int	zoom_change = e.getWheelRotation(); - -		notice_user_input(); -		AltosUILatLon	mouse_lat_lon = transform.screen_lat_lon(e.getPoint()); -		set_zoom(zoom() - zoom_change); - -		Point2D.Double	new_mouse = transform.screen(mouse_lat_lon); - -		int	dx = getWidth()/2 - e.getPoint().x; -		int	dy = getHeight()/2 - e.getPoint().y; - -		AltosUILatLon	new_centre = transform.screen_lat_lon(new Point((int) new_mouse.x + dx, (int) new_mouse.y + dy)); - -		centre(new_centre.lat, new_centre.lon); -	} - -	/* ComponentListener methods */ - -	public void componentHidden(ComponentEvent e) { -	} - -	public void componentMoved(ComponentEvent e) { -	} - -	public void componentResized(ComponentEvent e) { -		set_transform(); -	} - -	public void componentShown(ComponentEvent e) { -		set_transform(); -	} - -	public void repaint(Rectangle r, int pad) { -		repaint(r.x - pad, r.y - pad, r.width + pad*2, r.height + pad*2); -	} - -	public void repaint(AltosUIMapRectangle rect, int pad) { -		repaint (transform.screen(rect), pad); -	} - -	private boolean far_from_centre(AltosUILatLon lat_lon) { - -		if (centre == null || transform == null) -			return true; - -		Point2D.Double	screen = transform.screen(lat_lon); - -		int		width = getWidth(); -		int		dx = Math.abs ((int) screen.x - width/2); - -		if (dx > width / 4) -			return true; - -		int		height = getHeight(); -		int		dy = Math.abs ((int) screen.y - height/2); - -		if (dy > height / 4) -			return true; - -		return false; -	} - -	public void show(AltosState state, AltosListenerState listener_state) { - -		/* If insufficient gps data, nothing to update -		 */ -		AltosGPS	gps = state.gps; - -		if (gps == null) -			return; - -		if (!gps.locked && gps.nsat < 4) -			return; - -		AltosUIMapRectangle	damage = path.add(gps.lat, gps.lon, state.state); - -		switch (state.state) { -		case AltosLib.ao_flight_boost: -			if (!have_boost) { -				add_mark(gps.lat, gps.lon, state.state); -				have_boost = true; -			} -			break; -		case AltosLib.ao_flight_landed: -			if (!have_landed) { -				add_mark(gps.lat, gps.lon, state.state); -				have_landed = true; -			} -			break; -		} - -		if (damage != null) -			repaint(damage, AltosUIMapPath.stroke_width); -		maybe_centre(gps.lat, gps.lon); -	} - -	private void set_transform() { -		Rectangle	bounds = getBounds(); - -		transform = new AltosUIMapTransform(bounds.width, bounds.height, zoom, centre); -		repaint(); -	} - -	public boolean set_zoom(int zoom) { -		if (min_zoom <= zoom && zoom <= max_zoom && zoom != this.zoom) { -			this.zoom = zoom; -			tiles.clear(); -			set_transform(); - -			for (AltosUIMapZoomListener listener : zoom_listeners) -				listener.zoom_changed(this.zoom); - -			return true; -		} -		return false; -	} - -	public void add_zoom_listener(AltosUIMapZoomListener listener) { -		if (!zoom_listeners.contains(listener)) -			zoom_listeners.add(listener); -	} - -	public void remove_zoom_listener(AltosUIMapZoomListener listener) { -		zoom_listeners.remove(listener); -	} - -	public void set_load_params(double lat, double lon, int radius, AltosUIMapTileListener listener) { -		load_centre = new AltosUILatLon(lat, lon); -		load_radius = radius; -		load_listener = listener; -		centre(lat, lon); -		make_tiles(); -		for (AltosUIMapTile tile : tiles.values()) { -			tile.add_store_listener(this); -			if (tile.store_status() != AltosUIMapStore.loading) -				listener.notify_tile(tile, tile.store_status()); -		} -		repaint(); -	} - -	public boolean all_fetched() { -		for (AltosUIMapTile tile : tiles.values()) { -			if (tile.store_status() == AltosUIMapStore.loading) -				return false; -		} -		return true; -	} - -	public boolean set_maptype(int maptype) { -		if (maptype != this.maptype) { -			this.maptype = maptype; -			tiles.clear(); -			repaint(); -			return true; -		} -		return false; -	} - -	public int get_maptype() { -		return maptype; -	} - -	public int zoom() { -		return zoom; -	} - -	public void centre(AltosUILatLon lat_lon) { -		centre = lat_lon; -		set_transform(); -	} - -	public void centre(double lat, double lon) { -		centre(new AltosUILatLon(lat, lon)); -	} - -	public void maybe_centre(double lat, double lon) { -		AltosUILatLon	lat_lon = new AltosUILatLon(lat, lon); -		if (centre == null || (!recent_user_input() && far_from_centre(lat_lon))) -			centre(lat_lon); -	} - -	private VolatileImage create_back_buffer() { -		return getGraphicsConfiguration().createCompatibleVolatileImage(getWidth(), getHeight()); -	} - -	private Point floor(Point2D.Double point) { -		return new Point ((int) Math.floor(point.x / px_size) * px_size, -				  (int) Math.floor(point.y / px_size) * px_size); -	} - -	private Point ceil(Point2D.Double point) { -		return new Point ((int) Math.ceil(point.x / px_size) * px_size, -				  (int) Math.ceil(point.y / px_size) * px_size); -	} - -	private void make_tiles() { -		Point	upper_left; -		Point	lower_right; - -		if (load_centre != null) { -			Point centre = floor(transform.point(load_centre)); - -			upper_left = new Point(centre.x - load_radius * px_size, -					       centre.y - load_radius * px_size); -			lower_right = new Point(centre.x + load_radius * px_size, -					       centre.y + load_radius * px_size); -		} else { -			upper_left = floor(transform.screen_point(new Point(0, 0))); -			lower_right = floor(transform.screen_point(new Point(getWidth(), getHeight()))); -		} -		LinkedList<Point> to_remove = new LinkedList<Point>(); - -		for (Point point : tiles.keySet()) { -			if (point.x < upper_left.x || lower_right.x < point.x || -			    point.y < upper_left.y || lower_right.y < point.y) { -				to_remove.add(point); -			} -		} - -		for (Point point : to_remove) -			tiles.remove(point); - -		cache.set_cache_size((getWidth() / px_size + 2) * (getHeight() / px_size + 2)); -		for (int y = upper_left.y; y <= lower_right.y; y += px_size) { -			for (int x = upper_left.x; x <= lower_right.x; x += px_size) { -				Point point = new Point(x, y); - -				if (!tiles.containsKey(point)) { -					AltosUILatLon	ul = transform.lat_lon(new Point2D.Double(x, y)); -					AltosUILatLon	center = transform.lat_lon(new Point2D.Double(x + px_size/2, y + px_size/2)); -					AltosUIMapTile tile = new AltosUIMapTile(this, ul, center, zoom, maptype, -										 px_size, AltosUILib.value_font); -					tiles.put(point, tile); -				} -			} -		} -	} - -	/* AltosUIMapTileListener methods */ -	public synchronized void notify_tile(AltosUIMapTile tile, int status) { -		for (Point point : tiles.keySet()) { -			if (tile == tiles.get(point)) { -				Point	screen = transform.screen(point); -				repaint(screen.x, screen.y, px_size, px_size); -			} -		} -	} - -	public AltosUIMapCache cache() { return cache; } - -	/* AltosUIMapStoreListener methods */ -	public synchronized void notify_store(AltosUIMapStore store, int status) { -		if (load_listener != null) { -			for (AltosUIMapTile tile : tiles.values()) -				if (store.equals(tile.store)) -					load_listener.notify_tile(tile, status); -		} -	} - -	private void do_paint(Graphics g) { -		Graphics2D	g2d = (Graphics2D) g; - -		make_tiles(); - -		for (AltosUIMapTile tile : tiles.values()) -			tile.paint(g2d, transform); - -		synchronized(marks) { -			for (AltosUIMapMark mark : marks) -				mark.paint(g2d, transform); -		} - -		path.paint(g2d, transform); - -		line.paint(g2d, transform); -	} - -	public void paint(Graphics g) { -		VolatileImage	back_buffer = create_back_buffer(); -		do { -			GraphicsConfiguration gc = getGraphicsConfiguration(); -			int code = back_buffer.validate(gc); -			if (code == VolatileImage.IMAGE_INCOMPATIBLE) -				back_buffer = create_back_buffer(); - -			Graphics g_back = back_buffer.getGraphics(); -			g_back.setClip(g.getClip()); -			do_paint(g_back); -			g_back.dispose(); - -			g.drawImage(back_buffer, 0, 0, this); -		} while (back_buffer.contentsLost()); -		back_buffer.flush(); -	} - -	public void update(Graphics g) { -		paint(g); -	} - -	public void add_mark(double lat, double lon, int state) { -		synchronized(marks) { -			marks.add(new AltosUIMapMark(lat, lon, state)); -		} -		repaint(); -	} - -	public void clear_marks() { -		synchronized(marks) { -			marks.clear(); -		} -	} - -	public AltosUIMapView() { -		centre(0, 0); - -		addComponentListener(this); -		addMouseMotionListener(this); -		addMouseListener(this); -		addMouseWheelListener(this); -		set_font(); -	} -} diff --git a/altosuilib/AltosUIMapZoomListener.java b/altosuilib/AltosUIMapZoomListener.java deleted file mode 100644 index 9f74baca..00000000 --- a/altosuilib/AltosUIMapZoomListener.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright © 2014 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.altosuilib_6; - -public interface AltosUIMapZoomListener { -	abstract public void zoom_changed(int zoom); -} diff --git a/altosuilib/AltosUIMarker.java b/altosuilib/AltosUIMarker.java index 843ee939..ec5aae78 100644 --- a/altosuilib/AltosUIMarker.java +++ b/altosuilib/AltosUIMarker.java @@ -15,14 +15,14 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.io.*;  import java.util.ArrayList;  import java.awt.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  import org.jfree.ui.*;  import org.jfree.chart.*; diff --git a/altosuilib/AltosUIPreferences.java b/altosuilib/AltosUIPreferences.java index 9760494c..5602dc17 100644 --- a/altosuilib/AltosUIPreferences.java +++ b/altosuilib/AltosUIPreferences.java @@ -15,13 +15,13 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.io.*;  import java.util.*;  import java.awt.Component;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosUIPreferences extends AltosPreferences { @@ -55,10 +55,6 @@ public class AltosUIPreferences extends AltosPreferences {  	public static int position = AltosUILib.position_top_left; -	static LinkedList<AltosUIMapCacheListener> map_cache_listeners; - -	public static int map_cache = 9; -  	public static void init() {  		AltosPreferences.init(new AltosUIPreferencesBackend()); @@ -75,9 +71,6 @@ public class AltosUIPreferences extends AltosPreferences {  		position = backend.getInt(positionPreference, AltosUILib.position_top_left);  		position_listeners = new LinkedList<AltosPositionListener>(); - -		map_cache = backend.getInt(mapCachePreference, 9); -		map_cache_listeners = new LinkedList<AltosUIMapCacheListener>();  	}  	static { init(); } @@ -225,32 +218,4 @@ public class AltosUIPreferences extends AltosPreferences {  			return position;  		}  	} - -	public static void register_map_cache_listener(AltosUIMapCacheListener l) { -		synchronized(backend) { -			map_cache_listeners.add(l); -		} -	} - -	public static void unregister_map_cache_listener(AltosUIMapCacheListener l) { -		synchronized (backend) { -			map_cache_listeners.remove(l); -		} -	} - -	public static void set_map_cache(int new_map_cache) { -		synchronized(backend) { -			map_cache = new_map_cache; -			backend.putInt(mapCachePreference, map_cache); -			flush_preferences(); -			for (AltosUIMapCacheListener l: map_cache_listeners) -				l.map_cache_changed(map_cache); -		} -	} - -	public static int map_cache() { -		synchronized(backend) { -			return map_cache; -		} -	}  } diff --git a/altosuilib/AltosUIPreferencesBackend.java b/altosuilib/AltosUIPreferencesBackend.java index 91fe42ec..ebdc8b77 100644 --- a/altosuilib/AltosUIPreferencesBackend.java +++ b/altosuilib/AltosUIPreferencesBackend.java @@ -15,11 +15,11 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.io.File;  import java.util.prefs.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  import javax.swing.filechooser.FileSystemView;  public class AltosUIPreferencesBackend implements AltosPreferencesBackend { diff --git a/altosuilib/AltosUIRateList.java b/altosuilib/AltosUIRateList.java index 0c783a89..a8898808 100644 --- a/altosuilib/AltosUIRateList.java +++ b/altosuilib/AltosUIRateList.java @@ -15,10 +15,10 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosUIRateList extends JComboBox<String> { diff --git a/altosuilib/AltosUISeries.java b/altosuilib/AltosUISeries.java index 4cd5ccd1..d4421ac7 100644 --- a/altosuilib/AltosUISeries.java +++ b/altosuilib/AltosUISeries.java @@ -15,14 +15,14 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.io.*;  import java.util.ArrayList;  import java.awt.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  import org.jfree.ui.*;  import org.jfree.chart.*; diff --git a/altosuilib/AltosUITelemetryList.java b/altosuilib/AltosUITelemetryList.java index 77eef567..edbc7fd6 100644 --- a/altosuilib/AltosUITelemetryList.java +++ b/altosuilib/AltosUITelemetryList.java @@ -15,11 +15,11 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.util.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public class AltosUITelemetryList extends JComboBox<String> { diff --git a/altosuilib/AltosUIUnitsIndicator.java b/altosuilib/AltosUIUnitsIndicator.java index f86e274f..b58cd1cc 100644 --- a/altosuilib/AltosUIUnitsIndicator.java +++ b/altosuilib/AltosUIUnitsIndicator.java @@ -15,11 +15,11 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public abstract class AltosUIUnitsIndicator extends AltosUIIndicator { @@ -36,6 +36,10 @@ public abstract class AltosUIUnitsIndicator extends AltosUIIndicator {  		return hide(value(state, i));  	} +	public boolean hide(AltosState state, AltosListenerState listener_state, int i) { +		return hide(state, i); +	} +  	public double value (AltosState state, AltosListenerState listener_state, int i) {  		return value(state, i);  	} @@ -77,7 +81,7 @@ public abstract class AltosUIUnitsIndicator extends AltosUIIndicator {  				v[i] = value(state, listener_state, i);  			else  				v[i] = AltosLib.MISSING; -			if (hide(state, i)) +			if (hide(state, listener_state, i))  				hide = true;  		} diff --git a/altosuilib/AltosUIVoltageIndicator.java b/altosuilib/AltosUIVoltageIndicator.java index 44ad2ea2..12649730 100644 --- a/altosuilib/AltosUIVoltageIndicator.java +++ b/altosuilib/AltosUIVoltageIndicator.java @@ -15,11 +15,11 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import javax.swing.*; -import org.altusmetrum.altoslib_6.*; +import org.altusmetrum.altoslib_8.*;  public abstract class AltosUIVoltageIndicator extends AltosUIUnitsIndicator { diff --git a/altosuilib/AltosUSBDevice.java b/altosuilib/AltosUSBDevice.java index e940493f..74306523 100644 --- a/altosuilib/AltosUSBDevice.java +++ b/altosuilib/AltosUSBDevice.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.util.*;  import libaltosJNI.*; diff --git a/altosuilib/AltosVoice.java b/altosuilib/AltosVoice.java index 867f6619..71a05a23 100644 --- a/altosuilib/AltosVoice.java +++ b/altosuilib/AltosVoice.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import com.sun.speech.freetts.Voice;  import com.sun.speech.freetts.VoiceManager; diff --git a/altosuilib/GrabNDrag.java b/altosuilib/GrabNDrag.java index 5d9ce2d9..919289c7 100644 --- a/altosuilib/GrabNDrag.java +++ b/altosuilib/GrabNDrag.java @@ -15,7 +15,7 @@   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.   */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.awt.*;  import java.awt.event.*; diff --git a/altosuilib/Makefile.am b/altosuilib/Makefile.am index d51da91d..a00e4a12 100644 --- a/altosuilib/Makefile.am +++ b/altosuilib/Makefile.am @@ -12,8 +12,6 @@ altosuilib_JAVA = \  	GrabNDrag.java \  	AltosDevice.java \  	AltosDeviceDialog.java \ -	AltosFlightDisplay.java \ -	AltosFontListener.java \  	AltosPositionListener.java \  	AltosUIConfigure.java \  	AltosUIAxis.java \ @@ -31,7 +29,6 @@ altosuilib_JAVA = \  	AltosUIPreferencesBackend.java \  	AltosUIPreferences.java \  	AltosUISeries.java \ -	AltosUIVersion.java \  	AltosUSBDevice.java \  	AltosVoice.java \  	AltosDisplayThread.java \ @@ -60,23 +57,8 @@ altosuilib_JAVA = \  	AltosBTDeviceIterator.java \  	AltosBTManage.java \  	AltosBTKnown.java \ -	AltosUIMap.java \ -	AltosUIMapView.java \ -	AltosUIMapLine.java \ -	AltosUIMapMark.java \ -	AltosUIMapPath.java \ -	AltosUIMapTile.java \ -	AltosUIMapCache.java \ -	AltosUIMapCacheListener.java \ -	AltosUIMapImage.java \ -	AltosUIMapTransform.java \ -	AltosUIMapRectangle.java \ -	AltosUIMapZoomListener.java \ -	AltosUIMapTileListener.java \ -	AltosUIMapPreload.java \ -	AltosUIMapStore.java \ -	AltosUIMapStoreListener.java \ -	AltosUILatLon.java \ +	AltosUIMapNew.java \ +	AltosUIMapPreloadNew.java \  	AltosUIFlightTab.java \  	AltosUIIndicator.java \  	AltosUIUnitsIndicator.java \ @@ -84,6 +66,7 @@ altosuilib_JAVA = \  	AltosUIFreqList.java \  	AltosUITelemetryList.java \  	AltosUIRateList.java \ +	AltosUIImage.java \  	OSXAdapter.java  JAR=altosuilib_$(ALTOSUILIB_VERSION).jar diff --git a/altosuilib/OSXAdapter.java b/altosuilib/OSXAdapter.java index 28b00ce1..5155b0fe 100755 --- a/altosuilib/OSXAdapter.java +++ b/altosuilib/OSXAdapter.java @@ -55,7 +55,7 @@ Copyright © 2003-2007 Apple, Inc., All Rights Reserved  */ -package org.altusmetrum.altosuilib_6; +package org.altusmetrum.altosuilib_8;  import java.lang.reflect.*;  import java.util.HashMap;  | 
