diff --git a/src/main/java/org/hvdw/jexiftoolgui/editpane/EditGPSdata.java b/src/main/java/org/hvdw/jexiftoolgui/editpane/EditGPSdata.java index dc94d84d..7445e650 100644 --- a/src/main/java/org/hvdw/jexiftoolgui/editpane/EditGPSdata.java +++ b/src/main/java/org/hvdw/jexiftoolgui/editpane/EditGPSdata.java @@ -13,7 +13,10 @@ import javax.swing.text.NumberFormatter; import java.io.File; import java.io.IOException; +import java.math.BigDecimal; +import java.text.DecimalFormat; import java.text.NumberFormat; +import java.text.ParseException; import java.util.*; import static org.hvdw.jexiftoolgui.Utils.in_Range; @@ -296,4 +299,31 @@ private String checkValue (String value, String int_or_double, int maxvalue) { return checked_value; } + /** + * Convert a decimal coordiante back to deg-min-sec for the deg-min-sec textfields + * @param coordinate + * @return + */ + public static String[] decDegToDegMinSec(String coordinate) { + String deg; + double decdegrees = 0.0; + double decminutes = 0.0; + double decseconds = 0.0; + + //int intDeg = Integer.parseInt(coordinate); + decdegrees = Double.parseDouble(coordinate); + int intDeg = (int) decdegrees; + decminutes = (decdegrees - intDeg) * 60; + int intMin = (int) decminutes; + decseconds = (decminutes - intMin) * 60; + //logger.info("decdegrees {} intDeg {} decminutes {} intMin {} decseconds {}", String.valueOf(decdegrees), String.valueOf(intDeg), String.valueOf(decminutes), String.valueOf(intMin), String.valueOf(decseconds)); + + NumberFormat numsecs = NumberFormat.getInstance(new Locale("en", "US" )); + numsecs.setMaximumFractionDigits(2); + String strSeconds = numsecs.format(decseconds); + //logger.info("strSeconds {}", strSeconds); + String[] dmscoordinate = { String.valueOf(intDeg), String.valueOf(intMin), strSeconds}; + + return dmscoordinate; + } } diff --git a/src/main/java/org/hvdw/jexiftoolgui/mainScreen.java b/src/main/java/org/hvdw/jexiftoolgui/mainScreen.java index 577536d2..302e0463 100644 --- a/src/main/java/org/hvdw/jexiftoolgui/mainScreen.java +++ b/src/main/java/org/hvdw/jexiftoolgui/mainScreen.java @@ -2924,6 +2924,26 @@ public void actionPerformed(ActionEvent actionEvent) { gpsCitytextField.setText(place.get("isolated_dwelling")); } } + // Now do the dec-min-sec fields + String[] dmsLat = EGPSd.decDegToDegMinSec(place.get("geoLatitude")); + CalcLatDegtextField.setText(dmsLat[0]); + CalcLatMintextField.setText(dmsLat[1]); + CalcLatSectextField.setText(dmsLat[2]); + if (place.get("geoLatitude").startsWith("-")) { + // Negative means South + CalcSouthRadioButton.setSelected(true); + } else { + CalcNorthRadioButton.setSelected(true); + } + String[] dmsLon = EGPSd.decDegToDegMinSec(place.get("geoLongitude")); + CalcLonDegtextField.setText(dmsLon[0]); + CalcLonMintextField.setText(dmsLon[1]); + CalcLonSectextField.setText(dmsLon[2]); + if (place.get("geoLongitude").startsWith("-")) { + CalcWestRadioButton.setSelected(true); + } else { + CalcEastradioButton.setSelected(true); + } } });