package tim.prune.data;
+import tim.prune.Config;
+
/**
* Class to represent a single data point in the series
* including all its fields
private Photo _photo = null;
private String _waypointName = null;
private boolean _startOfSegment = false;
+ private boolean _markedForDeletion = false;
/**
* @param inFieldList list of fields
* @param inAltFormat altitude format
*/
- public DataPoint(String[] inValueArray, FieldList inFieldList, int inAltFormat)
+ public DataPoint(String[] inValueArray, FieldList inFieldList, Altitude.Format inAltFormat)
{
// save data
_fieldValues = inValueArray;
// save list of fields
_fieldList = inFieldList;
// parse fields into objects
- parseFields(inAltFormat);
+ parseFields(null, inAltFormat);
}
/**
* Parse the string values into objects eg Coordinates
+ * @param inField field which has changed, or null for all
* @param inAltFormat altitude format
*/
- private void parseFields(int inAltFormat)
+ private void parseFields(Field inField, Altitude.Format inAltFormat)
{
- _latitude = new Latitude(getFieldValue(Field.LATITUDE));
- _longitude = new Longitude(getFieldValue(Field.LONGITUDE));
- _altitude = new Altitude(getFieldValue(Field.ALTITUDE), inAltFormat);
- _timestamp = new Timestamp(getFieldValue(Field.TIMESTAMP));
- _waypointName = getFieldValue(Field.WAYPT_NAME);
- String segmentStr = getFieldValue(Field.NEW_SEGMENT);
- if (segmentStr != null) {segmentStr = segmentStr.trim();}
- _startOfSegment = (segmentStr != null && (segmentStr.equals("1") || segmentStr.toUpperCase().equals("Y")));
+ if (inField == null || inField == Field.LATITUDE) {
+ _latitude = new Latitude(getFieldValue(Field.LATITUDE));
+ }
+ if (inField == null || inField == Field.LONGITUDE) {
+ _longitude = new Longitude(getFieldValue(Field.LONGITUDE));
+ }
+ if (inField == null || inField == Field.ALTITUDE) {
+ _altitude = new Altitude(getFieldValue(Field.ALTITUDE), inAltFormat);
+ }
+ if (inField == null || inField == Field.TIMESTAMP) {
+ _timestamp = new Timestamp(getFieldValue(Field.TIMESTAMP));
+ }
+ if (inField == null || inField == Field.WAYPT_NAME) {
+ _waypointName = getFieldValue(Field.WAYPT_NAME);
+ }
+ if (inField == null || inField == Field.NEW_SEGMENT) {
+ String segmentStr = getFieldValue(Field.NEW_SEGMENT);
+ if (segmentStr != null) {segmentStr = segmentStr.trim();}
+ _startOfSegment = (segmentStr != null && (segmentStr.equals("1") || segmentStr.toUpperCase().equals("Y")));
+ }
}
}
else {
_altitude = inAltitude;
- _fieldValues[2] = "" + inAltitude.getValue(Altitude.FORMAT_METRES); // units are ignored
+ _fieldValues[2] = "" + inAltitude.getValue(Altitude.Format.METRES); // units are ignored
}
_timestamp = new Timestamp(null);
}
// Set field value in array
_fieldValues[fieldIndex] = inValue;
// Change Coordinate, Altitude, Name or Timestamp fields after edit
- if (_altitude != null)
- {
- parseFields(_altitude.getFormat());
+ if (_altitude != null && _altitude.getFormat() != Altitude.Format.NO_FORMAT) {
+ // Altitude already present so reuse format
+ parseFields(inField, _altitude.getFormat());
}
- else
- {
- // use default altitude format of metres
- parseFields(Altitude.FORMAT_METRES);
+ else {
+ // use default altitude format from config
+ parseFields(inField, Config.getUseMetricUnits()?Altitude.Format.METRES:Altitude.Format.FEET);
}
}
setFieldValue(Field.NEW_SEGMENT, inFlag?"1":null);
}
+ /**
+ * Mark the point for deletion
+ * @param inFlag true to delete, false to keep
+ */
+ public void setMarkedForDeletion(boolean inFlag) {
+ _markedForDeletion = inFlag;
+ }
+
/** @return latitude */
public Coordinate getLatitude()
{
return _startOfSegment;
}
+ /** @return true if point marked for deletion */
+ public boolean getDeleteFlag()
+ {
+ return _markedForDeletion;
+ }
+
/**
* @return true if point has a waypoint name
*/
}
- /**
- * Restore the contents from another point
- * @param inOther point containing contents to copy
- * @return true if successful
- */
- public boolean restoreContents(DataPoint inOther)
- {
- if (inOther != null)
- {
- // Copy string values across
- _fieldValues = inOther._fieldValues;
- if (_altitude != null)
- {
- parseFields(_altitude.getFormat());
- }
- else
- {
- // use default altitude format of metres
- parseFields(Altitude.FORMAT_METRES);
- }
- return true;
- }
- return false;
- }
-
-
/**
* Get string for debug
* @see java.lang.Object#toString()