X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fgui%2FCoordDisplay.java;fp=src%2Ftim%2Fprune%2Fgui%2FCoordDisplay.java;h=45a749a68e30e2caa6dbcfc54e4ac047cdc47e46;hp=0000000000000000000000000000000000000000;hb=8b20e3e027058cdf6ff52993ee5576193d08667a;hpb=2302358503c38817e19f6e529f6c9e530aac0e86 diff --git a/src/tim/prune/gui/CoordDisplay.java b/src/tim/prune/gui/CoordDisplay.java new file mode 100644 index 0000000..45a749a --- /dev/null +++ b/src/tim/prune/gui/CoordDisplay.java @@ -0,0 +1,58 @@ +package tim.prune.gui; + +import tim.prune.data.Coordinate; + +/** + * Functions for display of coordinates in gui + */ +public abstract class CoordDisplay +{ + + /** + * Construct an appropriate coordinate label using the selected format + * @param inCoordinate coordinate + * @param inFormat selected display format + * @return language-sensitive string + */ + public static String makeCoordinateLabel(Coordinate inCoordinate, int inFormat) + { + String coord = inCoordinate.output(inFormat); + // Fix broken degree signs (due to unicode mangling) + final char brokenDeg = 65533; + if (coord.indexOf(brokenDeg) >= 0) + { + coord = coord.replaceAll(String.valueOf(brokenDeg), "\u00B0"); + } + return restrictDP(coord); + } + + + /** + * Restrict the given coordinate to a limited number of decimal places for display + * @param inCoord coordinate string + * @return chopped string + */ + private static String restrictDP(String inCoord) + { + final int DECIMAL_PLACES = 7; + if (inCoord == null) return ""; + String result = inCoord; + final int dotPos = Math.max(inCoord.lastIndexOf('.'), inCoord.lastIndexOf(',')); + if (dotPos >= 0) + { + final int chopPos = dotPos + DECIMAL_PLACES; + if (chopPos < (inCoord.length()-1)) + { + result = inCoord.substring(0, chopPos); + // Maybe there's an exponential in there too which needs to be appended + int expPos = inCoord.toUpperCase().indexOf("E", chopPos); + if (expPos > 0 && expPos < (inCoord.length()-1)) + { + result += inCoord.substring(expPos); + } + } + } + return result; + } + +}