1 package tim.prune.function.distance;
3 import tim.prune.I18nManager;
4 import tim.prune.config.Config;
5 import tim.prune.data.DataPoint;
6 import tim.prune.data.Distance;
7 import tim.prune.data.Unit;
10 * Class to hold the table model for the distances table
12 public class DistanceTableModel extends GenericTableModel
15 private double[] _distances = null;
17 private static final String _toColLabel = I18nManager.getText("dialog.distances.column.to");
18 /** Column heading (depends on metric/imperial settings) */
19 private String _distanceLabel = null;
22 * @return column count
24 public int getColumnCount()
30 * @param inRowIndex row index
31 * @param inColumnIndex column index
34 public Object getValueAt(int inRowIndex, int inColumnIndex)
36 if (inColumnIndex == 0) {return getPointName(inRowIndex);}
37 if (_distances == null) {return 0.0;}
38 return new Double(_distances[inRowIndex]);
42 * @param inColumnIndex column index
45 public String getColumnName(int inColumnIndex)
47 if (inColumnIndex == 0) {return _toColLabel;}
48 return _distanceLabel;
52 * Get the column class (required for sorting)
53 * @param inColumnIndex column index
54 * @return Class of specified column
56 public Class<?> getColumnClass(int inColumnIndex)
58 if (inColumnIndex == 0) return String.class;
63 * Recalculate the distances
64 * @param inIndex index of selected 'from' point
66 public void recalculate(int inIndex)
68 // Which units to use?
69 Unit distUnit = Config.getUnitSet().getDistanceUnit();
70 _distanceLabel = I18nManager.getText("fieldname.distance") + " (" +
71 I18nManager.getText(distUnit.getShortnameKey()) + ")";
72 // Initialize array of distances
73 int numRows = getRowCount();
74 if (_distances == null || _distances.length != numRows) {
75 _distances = new double[numRows];
77 DataPoint fromPoint = _pointList.get(inIndex);
78 for (int i=0; i<numRows; i++) {
83 double rads = DataPoint.calculateRadiansBetween(fromPoint, _pointList.get(i));
84 _distances[i] = Distance.convertRadiansToDistance(rads);
87 // Let table know that it has to refresh data (and might as well refresh column headings too)
88 fireTableStructureChanged();