]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/Field.java
Version 4, January 2008
[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         public static final Field[] ALL_AVAILABLE_FIELDS = {
25                         LATITUDE, LONGITUDE, ALTITUDE, TIMESTAMP, WAYPT_NAME, WAYPT_TYPE, NEW_SEGMENT,
26                         new Field("fieldname.custom", FieldType.NONE)
27         };
28
29         /**
30          * Private constructor
31          * @param inLabelKey Key for label texts
32          * @param inType type of field
33          */
34         private Field(String inLabelKey, FieldType inType)
35         {
36                 _labelKey = inLabelKey;
37                 _customLabel = null;
38                 _type = inType;
39                 _builtin = true;
40         }
41
42
43         /**
44          * Public constructor for custom fields
45          * @param inLabel label to use for display
46          */
47         public Field(String inLabel)
48         {
49                 _labelKey = null;
50                 _customLabel = inLabel;
51                 _type = FieldType.NONE;
52         }
53
54         /**
55          * @return the name of the field
56          */
57         public String getName()
58         {
59                 if (_labelKey != null)
60                         return I18nManager.getText(_labelKey);
61                 return _customLabel;
62         }
63
64         /**
65          * Change the name of the (non built-in) field
66          * @param inName new name
67          */
68         public void setName(String inName)
69         {
70                 if (!isBuiltIn()) _customLabel = inName;
71         }
72
73         /**
74          * @return true if this is a built-in field
75          */
76         public boolean isBuiltIn()
77         {
78                 return _builtin;
79         }
80
81         /**
82          * @return field type
83          */
84         public FieldType getType()
85         {
86                 return _type;
87         }
88
89         /**
90          * Checks if the two fields are equal
91          * @param inOther other Field object
92          * @return true if Fields identical
93          */
94         public boolean equals(Field inOther)
95         {
96                 return (isBuiltIn() == inOther.isBuiltIn() && getName().equals(inOther.getName()));
97         }
98 }