X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;ds=sidebyside;f=tim%2Fprune%2Ffunction%2Fdistance%2FDistanceTableModel.java;fp=tim%2Fprune%2Ffunction%2Fdistance%2FDistanceTableModel.java;h=8adbf6915150a4f5e9875ef394def5d756596dce;hb=54b9d8bc8f0025ccf97a67d9dd217ef1f9cf082f;hp=0000000000000000000000000000000000000000;hpb=52bf9e8686c916be37a26a0b75340393d4478b05;p=GpsPrune.git diff --git a/tim/prune/function/distance/DistanceTableModel.java b/tim/prune/function/distance/DistanceTableModel.java new file mode 100644 index 0000000..8adbf69 --- /dev/null +++ b/tim/prune/function/distance/DistanceTableModel.java @@ -0,0 +1,108 @@ +package tim.prune.function.distance; + +import tim.prune.Config; +import tim.prune.I18nManager; +import tim.prune.data.DataPoint; +import tim.prune.data.Distance; + +/** + * Class to hold the table model for the distances table + */ +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; + + /** + * @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) + { + // Use metric or not? + _useMetric = Config.getUseMetricUnits(); + _distanceLabel = getDistanceLabel(_useMetric); + // 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