]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/Field.java
7b9d77925c1f39fbd4a1d842d63539245fe93b5b
[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  */
8 public class Field
9 {
10         private String _labelKey = null;
11         private String _customLabel = null;
12         private boolean _builtin = false;
13
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 DESCRIPTION = new Field("fieldname.description", true);
21         public static final Field NEW_SEGMENT = new Field("fieldname.newsegment", true);
22
23         public static final Field SPEED          = new Field("fieldname.speed", true);
24         public static final Field VERTICAL_SPEED = new Field("fieldname.verticalspeed", true);
25         public static final Field MEDIA_FILENAME = new Field("fieldname.mediafilename", true);
26
27         // TODO: Ability to load media (from text) and save (to text)
28
29         /** List of all the available fields */
30         private static final Field[] ALL_AVAILABLE_FIELDS = {
31                 LATITUDE, LONGITUDE, ALTITUDE, TIMESTAMP, WAYPT_NAME, WAYPT_TYPE, DESCRIPTION, NEW_SEGMENT,
32                 SPEED, VERTICAL_SPEED,
33                 new Field(I18nManager.getText("fieldname.custom"))
34         };
35
36         /**
37          * Private constructor
38          * @param inLabelKey Key for label texts
39          * @param inBuiltin true for built-in types, false for custom
40          */
41         private Field(String inLabelKey, boolean inBuiltin)
42         {
43                 if (inBuiltin) {
44                         _labelKey = inLabelKey;
45                         _customLabel = null;
46                 }
47                 else {
48                         _labelKey = null;
49                         _customLabel = inLabelKey;
50                 }
51                 _builtin = inBuiltin;
52         }
53
54
55         /**
56          * Public constructor for custom fields
57          * @param inLabel label to use for display
58          */
59         public Field(String inLabel)
60         {
61                 this(inLabel, false);
62         }
63
64         /**
65          * @return the name of the field
66          */
67         public String getName()
68         {
69                 if (_labelKey != null)
70                         return I18nManager.getText(_labelKey);
71                 return _customLabel;
72         }
73
74         /**
75          * Change the name of the (non built-in) field
76          * @param inName new name
77          */
78         public void setName(String inName)
79         {
80                 if (!isBuiltIn()) _customLabel = inName;
81         }
82
83         /**
84          * @return true if this is a built-in field
85          */
86         public boolean isBuiltIn()
87         {
88                 return _builtin;
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                 {
110                         Field field = ALL_AVAILABLE_FIELDS[i];
111                         if (field.getName().equals(inFieldName)) {
112                                 return field;
113                         }
114                 }
115                 // not found
116                 return null;
117         }
118
119         /**
120          * @return array of field names
121          */
122         public static String[] getFieldNames()
123         {
124                 String[] names = new String[ALL_AVAILABLE_FIELDS.length];
125                 for (int i=0; i<ALL_AVAILABLE_FIELDS.length; i++) {
126                         names[i] = ALL_AVAILABLE_FIELDS[i].getName();
127                 }
128                 return names;
129         }
130 }