1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
package tim.prune.data;
import tim.prune.I18nManager;
/**
* Class to represent a field of a data point
*/
public class Field
{
private String _labelKey = null;
private String _customLabel = null;
private boolean _builtin = false;
public static final Field LATITUDE = new Field("fieldname.latitude", true);
public static final Field LONGITUDE = new Field("fieldname.longitude", true);
public static final Field ALTITUDE = new Field("fieldname.altitude", true);
public static final Field TIMESTAMP = new Field("fieldname.timestamp", true);
public static final Field WAYPT_NAME = new Field("fieldname.waypointname", true);
public static final Field WAYPT_TYPE = new Field("fieldname.waypointtype", true);
public static final Field DESCRIPTION = new Field("fieldname.description", true);
public static final Field NEW_SEGMENT = new Field("fieldname.newsegment", true);
public static final Field SPEED = new Field("fieldname.speed", true);
public static final Field VERTICAL_SPEED = new Field("fieldname.verticalspeed", true);
public static final Field MEDIA_FILENAME = new Field("fieldname.mediafilename", true);
// TODO: Ability to load media (from text) and save (to text)
/** List of all the available fields */
private static final Field[] ALL_AVAILABLE_FIELDS = {
LATITUDE, LONGITUDE, ALTITUDE, TIMESTAMP, WAYPT_NAME, WAYPT_TYPE, DESCRIPTION, NEW_SEGMENT,
SPEED, VERTICAL_SPEED,
new Field(I18nManager.getText("fieldname.custom"))
};
/**
* Private constructor
* @param inLabelKey Key for label texts
* @param inBuiltin true for built-in types, false for custom
*/
private Field(String inLabelKey, boolean inBuiltin)
{
if (inBuiltin) {
_labelKey = inLabelKey;
_customLabel = null;
}
else {
_labelKey = null;
_customLabel = inLabelKey;
}
_builtin = inBuiltin;
}
/**
* Public constructor for custom fields
* @param inLabel label to use for display
*/
public Field(String inLabel)
{
this(inLabel, false);
}
/**
* @return the name of the field
*/
public String getName()
{
if (_labelKey != null)
return I18nManager.getText(_labelKey);
return _customLabel;
}
/**
* Change the name of the (non built-in) field
* @param inName new name
*/
public void setName(String inName)
{
if (!isBuiltIn()) _customLabel = inName;
}
/**
* @return true if this is a built-in field
*/
public boolean isBuiltIn()
{
return _builtin;
}
/**
* Checks if the two fields are equal
* @param inOther other Field object
* @return true if Fields identical
*/
public boolean equals(Field inOther)
{
return (isBuiltIn() == inOther.isBuiltIn() && getName().equals(inOther.getName()));
}
/**
* Get the field for the given field name
* @param inFieldName name of field to look for
* @return Field if found, or null otherwise
*/
public static Field getField(String inFieldName)
{
for (int i=0; i<ALL_AVAILABLE_FIELDS.length; i++)
{
Field field = ALL_AVAILABLE_FIELDS[i];
if (field.getName().equals(inFieldName)) {
return field;
}
}
// not found
return null;
}
/**
* @return array of field names
*/
public static String[] getFieldNames()
{
String[] names = new String[ALL_AVAILABLE_FIELDS.length];
for (int i=0; i<ALL_AVAILABLE_FIELDS.length; i++) {
names[i] = ALL_AVAILABLE_FIELDS[i].getName();
}
return names;
}
}
|