1 package tim.prune.data;
3 import tim.prune.I18nManager;
6 * Class to represent a field of a data point
11 private String _labelKey = null;
12 private String _customLabel = null;
13 private FieldType _type = null;
14 private boolean _builtin = false;
16 public static final Field LATITUDE = new Field("fieldname.latitude", FieldType.COORD);
17 public static final Field LONGITUDE = new Field("fieldname.longitude", FieldType.COORD);
18 public static final Field ALTITUDE = new Field("fieldname.altitude", FieldType.INT);
19 public static final Field TIMESTAMP = new Field("fieldname.timestamp", FieldType.TIME);
20 public static final Field WAYPT_NAME = new Field("fieldname.waypointname", FieldType.NONE);
21 public static final Field WAYPT_TYPE = new Field("fieldname.waypointtype", FieldType.NONE);
22 public static final Field NEW_SEGMENT = new Field("fieldname.newsegment", FieldType.BOOL);
24 // TODO: Field for photo filename, ability to load (from text) and save (to text)
26 private static final Field[] ALL_AVAILABLE_FIELDS = {
27 LATITUDE, LONGITUDE, ALTITUDE, TIMESTAMP, WAYPT_NAME, WAYPT_TYPE, NEW_SEGMENT,
28 new Field("fieldname.custom", FieldType.NONE)
33 * @param inLabelKey Key for label texts
34 * @param inType type of field
36 private Field(String inLabelKey, FieldType inType)
38 _labelKey = inLabelKey;
46 * Public constructor for custom fields
47 * @param inLabel label to use for display
49 public Field(String inLabel)
52 _customLabel = inLabel;
53 _type = FieldType.NONE;
57 * @return the name of the field
59 public String getName()
61 if (_labelKey != null)
62 return I18nManager.getText(_labelKey);
67 * Change the name of the (non built-in) field
68 * @param inName new name
70 public void setName(String inName)
72 if (!isBuiltIn()) _customLabel = inName;
76 * @return true if this is a built-in field
78 public boolean isBuiltIn()
86 public FieldType getType()
92 * Checks if the two fields are equal
93 * @param inOther other Field object
94 * @return true if Fields identical
96 public boolean equals(Field inOther)
98 return (isBuiltIn() == inOther.isBuiltIn() && getName().equals(inOther.getName()));
102 * Get the field for the given field name
103 * @param inFieldName name of field to look for
104 * @return Field if found, or null otherwise
106 public static Field getField(String inFieldName)
108 for (int i=0; i<ALL_AVAILABLE_FIELDS.length; i++) {
109 Field field = ALL_AVAILABLE_FIELDS[i];
110 if (field.getName().equals(inFieldName)) {
119 * @return array of field names
121 public static String[] getFieldNames()
123 String[] names = new String[ALL_AVAILABLE_FIELDS.length];
124 for (int i=0; i<ALL_AVAILABLE_FIELDS.length; i++) {
125 names[i] = ALL_AVAILABLE_FIELDS[i].getName();