]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/data/Field.java
Version 20.1, December 2020
[GpsPrune.git] / src / 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 COMMENT = new Field("fieldname.comment", true);
22         public static final Field NEW_SEGMENT = new Field("fieldname.newsegment", true);
23
24         public static final Field SPEED          = new Field("fieldname.speed", true);
25         public static final Field VERTICAL_SPEED = new Field("fieldname.verticalspeed", true);
26         public static final Field MEDIA_FILENAME = new Field("fieldname.mediafilename", true);
27
28         // TODO: Ability to load media (from text) and save (to text)
29
30         /** List of all the available fields */
31         private static final Field[] ALL_AVAILABLE_FIELDS = {
32                 LATITUDE, LONGITUDE, ALTITUDE, TIMESTAMP, WAYPT_NAME, WAYPT_TYPE, DESCRIPTION, NEW_SEGMENT,
33                 SPEED, VERTICAL_SPEED,
34                 new Field(I18nManager.getText("fieldname.custom"))
35         };
36
37         /**
38          * Private constructor
39          * @param inLabelKey Key for label texts
40          * @param inBuiltin true for built-in types, false for custom
41          */
42         private Field(String inLabelKey, boolean inBuiltin)
43         {
44                 if (inBuiltin) {
45                         _labelKey = inLabelKey;
46                         _customLabel = null;
47                 }
48                 else {
49                         _labelKey = null;
50                         _customLabel = inLabelKey;
51                 }
52                 _builtin = inBuiltin;
53         }
54
55
56         /**
57          * Public constructor for custom fields
58          * @param inLabel label to use for display
59          */
60         public Field(String inLabel)
61         {
62                 this(inLabel, false);
63         }
64
65         /**
66          * @return the name of the field
67          */
68         public String getName()
69         {
70                 if (_labelKey != null) {
71                         return I18nManager.getText(_labelKey);
72                 }
73                 return _customLabel;
74         }
75
76         /**
77          * Change the name of the (non built-in) field
78          * @param inName new name
79          */
80         public void setName(String inName)
81         {
82                 if (!isBuiltIn()) _customLabel = inName;
83         }
84
85         /**
86          * @return true if this is a built-in field
87          */
88         public boolean isBuiltIn()
89         {
90                 return _builtin;
91         }
92
93         /**
94          * Checks if the two fields are equal
95          * @param inOther other Field object
96          * @return true if Fields identical
97          */
98         public boolean equals(Field inOther)
99         {
100                 return (isBuiltIn() == inOther.isBuiltIn() && getName().equals(inOther.getName()));
101         }
102
103         /**
104          * Get the field for the given field name
105          * @param inFieldName name of field to look for
106          * @return Field if found, or null otherwise
107          */
108         public static Field getField(String inFieldName)
109         {
110                 for (int i=0; i<ALL_AVAILABLE_FIELDS.length; i++)
111                 {
112                         Field field = ALL_AVAILABLE_FIELDS[i];
113                         if (field.getName().equals(inFieldName)) {
114                                 return field;
115                         }
116                 }
117                 // not found
118                 return null;
119         }
120
121         /**
122          * @return array of field names
123          */
124         public static String[] getFieldNames()
125         {
126                 String[] names = new String[ALL_AVAILABLE_FIELDS.length];
127                 for (int i=0; i<ALL_AVAILABLE_FIELDS.length; i++) {
128                         names[i] = ALL_AVAILABLE_FIELDS[i].getName();
129                 }
130                 return names;
131         }
132 }