e727e3389d2c35ff4c33a4d283310451fda164a3
[fw/altos] / altoslib / AltosMapLine.java
1 /*
2  * Copyright © 2014 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.altoslib_7;
19
20 import java.io.*;
21 import java.lang.Math;
22 import java.util.*;
23 import java.util.concurrent.*;
24
25 public abstract class AltosMapLine implements AltosFontListener {
26         public AltosLatLon      start, end;
27
28         static public int stroke_width = 6;
29
30         public abstract void font_size_changed(int font_size);
31
32         public abstract void paint(AltosMapTransform t);
33
34         private AltosLatLon lat_lon(AltosPointInt pt, AltosMapTransform t) {
35                 return t.screen_lat_lon(pt);
36         }
37
38         public void dragged(AltosPointInt pt, AltosMapTransform t) {
39                 end = lat_lon(pt, t);
40         }
41
42         public void pressed(AltosPointInt pt, AltosMapTransform t) {
43                 start = lat_lon(pt, t);
44                 end = null;
45         }
46
47         public String line_dist() {
48                 String  format;
49                 AltosGreatCircle        g = new AltosGreatCircle(start.lat, start.lon,
50                                                                  end.lat, end.lon);
51                 double  distance = g.distance;
52
53                 if (AltosConvert.imperial_units) {
54                         distance = AltosConvert.meters_to_feet(distance);
55                         if (distance < 10000) {
56                                 format = "%4.0fft";
57                         } else {
58                                 distance /= 5280;
59                                 if (distance < 10)
60                                         format = "%5.3fmi";
61                                 else if (distance < 100)
62                                         format = "%5.2fmi";
63                                 else if (distance < 1000)
64                                         format = "%5.1fmi";
65                                 else
66                                         format = "%5.0fmi";
67                         }
68                 } else {
69                         if (distance < 10000) {
70                                 format = "%4.0fm";
71                         } else {
72                                 distance /= 1000;
73                                 if (distance < 100)
74                                         format = "%5.2fkm";
75                                 else if (distance < 1000)
76                                         format = "%5.1fkm";
77                                 else
78                                         format = "%5.0fkm";
79                         }
80                 }
81                 return String.format(format, distance);
82         }
83 }