X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2Fdistance%2FDistanceTableModel.java;fp=src%2Ftim%2Fprune%2Ffunction%2Fdistance%2FDistanceTableModel.java;h=2c1d83d1337b56af1a8ab1fbad0a3cc938b3d5a2;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/function/distance/DistanceTableModel.java b/src/tim/prune/function/distance/DistanceTableModel.java new file mode 100644 index 0000000..2c1d83d --- /dev/null +++ b/src/tim/prune/function/distance/DistanceTableModel.java @@ -0,0 +1,100 @@ +package tim.prune.function.distance; + +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 + */ +public class DistanceTableModel extends GenericTableModel +{ + /** Distances */ + private double[] _distances = null; + /** 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 + */ + public int getColumnCount() + { + return 2; + } + + /** + * @param inRowIndex row index + * @param inColumnIndex column index + * @return cell value + */ + public Object getValueAt(int inRowIndex, int inColumnIndex) + { + if (inColumnIndex == 0) {return getPointName(inRowIndex);} + if (_distances == null) {return 0.0;} + return new Double(_distances[inRowIndex]); + } + + /** + * @param inColumnIndex column index + * @return column name + */ + public String getColumnName(int inColumnIndex) + { + if (inColumnIndex == 0) {return _toColLabel;} + return _distanceLabel; + } + + /** + * Get the column class (required for sorting) + * @param inColumnIndex column index + * @return Class of specified column + */ + public Class getColumnClass(int inColumnIndex) + { + if (inColumnIndex == 0) return String.class; + return Double.class; + } + + /** + * Recalculate the distances + * @param inIndex index of selected 'from' point + */ + public void recalculate(int inIndex) + { + // 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) { + _distances = new double[numRows]; + } + DataPoint fromPoint = _pointList.get(inIndex); + for (int i=0; i