3 import tim.prune.data.Coordinate;
6 * Functions for display of coordinates in gui
8 public abstract class CoordDisplay
12 * Construct an appropriate coordinate label using the selected format
13 * @param inCoordinate coordinate
14 * @param inFormat selected display format
15 * @return language-sensitive string
17 public static String makeCoordinateLabel(Coordinate inCoordinate, int inFormat)
19 String coord = inCoordinate.output(inFormat);
20 // Fix broken degree signs (due to unicode mangling)
21 final char brokenDeg = 65533;
22 if (coord.indexOf(brokenDeg) >= 0)
24 coord = coord.replaceAll(String.valueOf(brokenDeg), "\u00B0");
26 return restrictDP(coord);
31 * Restrict the given coordinate to a limited number of decimal places for display
32 * @param inCoord coordinate string
33 * @return chopped string
35 private static String restrictDP(String inCoord)
37 final int DECIMAL_PLACES = 7;
38 if (inCoord == null) return "";
39 String result = inCoord;
40 final int dotPos = Math.max(inCoord.lastIndexOf('.'), inCoord.lastIndexOf(','));
43 final int chopPos = dotPos + DECIMAL_PLACES;
44 if (chopPos < (inCoord.length()-1))
46 result = inCoord.substring(0, chopPos);
47 // Maybe there's an exponential in there too which needs to be appended
48 int expPos = inCoord.toUpperCase().indexOf("E", chopPos);
49 if (expPos > 0 && expPos < (inCoord.length()-1))
51 result += inCoord.substring(expPos);