X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Ffunction%2Fdistance%2FDistanceTableModel.java;h=2c1d83d1337b56af1a8ab1fbad0a3cc938b3d5a2;hb=a6197ddcaac11c0b943183da7d46169742d024af;hp=8adbf6915150a4f5e9875ef394def5d756596dce;hpb=54b9d8bc8f0025ccf97a67d9dd217ef1f9cf082f;p=GpsPrune.git diff --git a/tim/prune/function/distance/DistanceTableModel.java b/tim/prune/function/distance/DistanceTableModel.java index 8adbf69..2c1d83d 100644 --- a/tim/prune/function/distance/DistanceTableModel.java +++ b/tim/prune/function/distance/DistanceTableModel.java @@ -1,9 +1,10 @@ package tim.prune.function.distance; -import tim.prune.Config; import tim.prune.I18nManager; +import tim.prune.config.Config; import tim.prune.data.DataPoint; import tim.prune.data.Distance; +import tim.prune.data.Unit; /** * Class to hold the table model for the distances table @@ -12,14 +13,12 @@ public class DistanceTableModel extends GenericTableModel { /** Distances */ private double[] _distances = null; - /** Metric distances? */ - private boolean _useMetric = true; - /** Previous value of metric flag (to spot changes) */ - private boolean _prevUseMetric = false; /** Column heading */ private static final String _toColLabel = I18nManager.getText("dialog.distances.column.to"); /** Column heading (depends on metric/imperial settings) */ private String _distanceLabel = null; + /** Previous distance units */ + private Unit _previousDistUnit = null; /** * @return column count @@ -68,9 +67,13 @@ public class DistanceTableModel extends GenericTableModel */ public void recalculate(int inIndex) { - // Use metric or not? - _useMetric = Config.getUseMetricUnits(); - _distanceLabel = getDistanceLabel(_useMetric); + // Which units to use? + Unit distUnit = Config.getUnitSet().getDistanceUnit(); + _distanceLabel = I18nManager.getText("fieldname.distance") + " (" + + I18nManager.getText(distUnit.getShortnameKey()) + ")"; + final boolean distUnitsChanged = (distUnit != _previousDistUnit); + _previousDistUnit = distUnit; + // Initialize array of distances int numRows = getRowCount(); if (_distances == null || _distances.length != numRows) { @@ -83,26 +86,15 @@ public class DistanceTableModel extends GenericTableModel } else { double rads = DataPoint.calculateRadiansBetween(fromPoint, _pointList.get(i)); - _distances[i] = Distance.convertRadiansToDistance(rads, _useMetric?Distance.Units.KILOMETRES:Distance.Units.MILES); + _distances[i] = Distance.convertRadiansToDistance(rads); } } - // Let table know that it has to refresh data (and maybe refresh column headings too) - if (_useMetric == _prevUseMetric) { - fireTableDataChanged(); + // Let table know that it has to refresh data, and maybe the whole table too + if (distUnitsChanged) { + fireTableStructureChanged(); } else { - fireTableStructureChanged(); + fireTableDataChanged(); } - _prevUseMetric = _useMetric; - } - - /** - * @param inMetric true to use metric distances - * @return distance label for column heading - */ - private static String getDistanceLabel(boolean inMetric) - { - return I18nManager.getText("fieldname.distance") + " (" + - I18nManager.getText(inMetric?"units.kilometres.short" : "units.miles.short") + ")"; } }