]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/Field.java
Version 8, September 2009
[GpsPrune.git] / tim / prune / data / Field.java
1 package tim.prune.data;
2
3 import tim.prune.I18nManager;
4
5 /**
6  * Class to represent a field of a data point
7  * including its type
8  */
9 public class Field
10 {
11         private String _labelKey = null;
12         private String _customLabel = null;
13         private FieldType _type = null;
14         private boolean _builtin = false;
15
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);
23
24         // TODO: Field for photo filename, ability to load (from text) and save (to text)
25
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)
29         };
30
31         /**
32          * Private constructor
33          * @param inLabelKey Key for label texts
34          * @param inType type of field
35          */
36         private Field(String inLabelKey, FieldType inType)
37         {
38                 _labelKey = inLabelKey;
39                 _customLabel = null;
40                 _type = inType;
41                 _builtin = true;
42         }
43
44
45         /**
46          * Public constructor for custom fields
47          * @param inLabel label to use for display
48          */
49         public Field(String inLabel)
50         {
51                 _labelKey = null;
52                 _customLabel = inLabel;
53                 _type = FieldType.NONE;
54         }
55
56         /**
57          * @return the name of the field
58          */
59         public String getName()
60         {
61                 if (_labelKey != null)
62                         return I18nManager.getText(_labelKey);
63                 return _customLabel;
64         }
65
66         /**
67          * Change the name of the (non built-in) field
68          * @param inName new name
69          */
70         public void setName(String inName)
71         {
72                 if (!isBuiltIn()) _customLabel = inName;
73         }
74
75         /**
76          * @return true if this is a built-in field
77          */
78         public boolean isBuiltIn()
79         {
80                 return _builtin;
81         }
82
83         /**
84          * @return field type
85          */
86         public FieldType getType()
87         {
88                 return _type;
89         }
90
91         /**
92          * Checks if the two fields are equal
93          * @param inOther other Field object
94          * @return true if Fields identical
95          */
96         public boolean equals(Field inOther)
97         {
98                 return (isBuiltIn() == inOther.isBuiltIn() && getName().equals(inOther.getName()));
99         }
100
101         /**
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
105          */
106         public static Field getField(String inFieldName)
107         {
108                 for (int i=0; i<ALL_AVAILABLE_FIELDS.length; i++) {
109                         Field field = ALL_AVAILABLE_FIELDS[i];
110                         if (field.getName().equals(inFieldName)) {
111                                 return field;
112                         }
113                 }
114                 // not found
115                 return null;
116         }
117
118         /**
119          * @return array of field names
120          */
121         public static String[] getFieldNames()
122         {
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();
126                 }
127                 return names;
128         }
129 }