1 package tim.prune.data;
3 import tim.prune.I18nManager;
6 * Class to represent a field of a data point
10 private String _labelKey = null;
11 private String _customLabel = null;
12 private boolean _builtin = false;
14 public static final Field LATITUDE = new Field("fieldname.latitude", true);
15 public static final Field LONGITUDE = new Field("fieldname.longitude", true);
16 public static final Field ALTITUDE = new Field("fieldname.altitude", true);
17 public static final Field TIMESTAMP = new Field("fieldname.timestamp", true);
18 public static final Field WAYPT_NAME = new Field("fieldname.waypointname", true);
19 public static final Field WAYPT_TYPE = new Field("fieldname.waypointtype", true);
20 public static final Field NEW_SEGMENT = new Field("fieldname.newsegment", true);
22 // TODO: Field for photo filename, ability to load (from text) and save (to text)
24 private static final Field[] ALL_AVAILABLE_FIELDS = {
25 LATITUDE, LONGITUDE, ALTITUDE, TIMESTAMP, WAYPT_NAME, WAYPT_TYPE, NEW_SEGMENT,
26 new Field(I18nManager.getText("fieldname.custom"))
31 * @param inLabelKey Key for label texts
32 * @param inBuiltin true for built-in types, false for custom
34 private Field(String inLabelKey, boolean inBuiltin)
37 _labelKey = inLabelKey;
42 _customLabel = inLabelKey;
49 * Public constructor for custom fields
50 * @param inLabel label to use for display
52 public Field(String inLabel)
58 * @return the name of the field
60 public String getName()
62 if (_labelKey != null)
63 return I18nManager.getText(_labelKey);
68 * Change the name of the (non built-in) field
69 * @param inName new name
71 public void setName(String inName)
73 if (!isBuiltIn()) _customLabel = inName;
77 * @return true if this is a built-in field
79 public boolean isBuiltIn()
85 * Checks if the two fields are equal
86 * @param inOther other Field object
87 * @return true if Fields identical
89 public boolean equals(Field inOther)
91 return (isBuiltIn() == inOther.isBuiltIn() && getName().equals(inOther.getName()));
95 * Get the field for the given field name
96 * @param inFieldName name of field to look for
97 * @return Field if found, or null otherwise
99 public static Field getField(String inFieldName)
101 for (int i=0; i<ALL_AVAILABLE_FIELDS.length; i++)
103 Field field = ALL_AVAILABLE_FIELDS[i];
104 if (field.getName().equals(inFieldName)) {
113 * @return array of field names
115 public static String[] getFieldNames()
117 String[] names = new String[ALL_AVAILABLE_FIELDS.length];
118 for (int i=0; i<ALL_AVAILABLE_FIELDS.length; i++) {
119 names[i] = ALL_AVAILABLE_FIELDS[i].getName();