]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/data/Field.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / data / Field.java
index 5f28fc578c3c39debbac07fc4944a1615ed5e72d..d020a7ebdd5789e080e1323dd2459a8796c851cc 100644 (file)
@@ -4,39 +4,50 @@ import tim.prune.I18nManager;
 
 /**
  * Class to represent a field of a data point
- * including its type
  */
 public class Field
 {
        private String _labelKey = null;
        private String _customLabel = null;
-       private FieldType _type = null;
        private boolean _builtin = false;
 
-       public static final Field LATITUDE = new Field("fieldname.latitude", FieldType.COORD);
-       public static final Field LONGITUDE = new Field("fieldname.longitude", FieldType.COORD);
-       public static final Field ALTITUDE = new Field("fieldname.altitude", FieldType.INT);
-       public static final Field TIMESTAMP = new Field("fieldname.timestamp", FieldType.TIME);
-       public static final Field WAYPT_NAME = new Field("fieldname.waypointname", FieldType.NONE);
-       public static final Field WAYPT_TYPE = new Field("fieldname.waypointtype", FieldType.NONE);
-       public static final Field NEW_SEGMENT = new Field("fieldname.newsegment", FieldType.BOOL);
+       public static final Field LATITUDE = new Field("fieldname.latitude", true);
+       public static final Field LONGITUDE = new Field("fieldname.longitude", true);
+       public static final Field ALTITUDE = new Field("fieldname.altitude", true);
+       public static final Field TIMESTAMP = new Field("fieldname.timestamp", true);
+       public static final Field WAYPT_NAME = new Field("fieldname.waypointname", true);
+       public static final Field WAYPT_TYPE = new Field("fieldname.waypointtype", true);
+       public static final Field DESCRIPTION = new Field("fieldname.description", true);
+       public static final Field NEW_SEGMENT = new Field("fieldname.newsegment", true);
 
-       public static final Field[] ALL_AVAILABLE_FIELDS = {
-                       LATITUDE, LONGITUDE, ALTITUDE, TIMESTAMP, WAYPT_NAME, WAYPT_TYPE, NEW_SEGMENT,
-                       new Field("fieldname.custom", FieldType.NONE)
+       public static final Field SPEED          = new Field("fieldname.speed", true);
+       public static final Field VERTICAL_SPEED = new Field("fieldname.verticalspeed", true);
+
+       // TODO: Field for photo filename, ability to load (from text) and save (to text)
+
+       /** List of all the available fields */
+       private static final Field[] ALL_AVAILABLE_FIELDS = {
+               LATITUDE, LONGITUDE, ALTITUDE, TIMESTAMP, WAYPT_NAME, WAYPT_TYPE, DESCRIPTION, NEW_SEGMENT,
+               SPEED, VERTICAL_SPEED,
+               new Field(I18nManager.getText("fieldname.custom"))
        };
 
        /**
         * Private constructor
         * @param inLabelKey Key for label texts
-        * @param inType type of field
+        * @param inBuiltin true for built-in types, false for custom
         */
-       private Field(String inLabelKey, FieldType inType)
+       private Field(String inLabelKey, boolean inBuiltin)
        {
-               _labelKey = inLabelKey;
-               _customLabel = null;
-               _type = inType;
-               _builtin = true;
+               if (inBuiltin) {
+                       _labelKey = inLabelKey;
+                       _customLabel = null;
+               }
+               else {
+                       _labelKey = null;
+                       _customLabel = inLabelKey;
+               }
+               _builtin = inBuiltin;
        }
 
 
@@ -46,9 +57,7 @@ public class Field
         */
        public Field(String inLabel)
        {
-               _labelKey = null;
-               _customLabel = inLabel;
-               _type = FieldType.NONE;
+               this(inLabel, false);
        }
 
        /**
@@ -78,14 +87,6 @@ public class Field
                return _builtin;
        }
 
-       /**
-        * @return field type
-        */
-       public FieldType getType()
-       {
-               return _type;
-       }
-
        /**
         * Checks if the two fields are equal
         * @param inOther other Field object
@@ -95,4 +96,34 @@ public class Field
        {
                return (isBuiltIn() == inOther.isBuiltIn() && getName().equals(inOther.getName()));
        }
+
+       /**
+        * Get the field for the given field name
+        * @param inFieldName name of field to look for
+        * @return Field if found, or null otherwise
+        */
+       public static Field getField(String inFieldName)
+       {
+               for (int i=0; i<ALL_AVAILABLE_FIELDS.length; i++)
+               {
+                       Field field = ALL_AVAILABLE_FIELDS[i];
+                       if (field.getName().equals(inFieldName)) {
+                               return field;
+                       }
+               }
+               // not found
+               return null;
+       }
+
+       /**
+        * @return array of field names
+        */
+       public static String[] getFieldNames()
+       {
+               String[] names = new String[ALL_AVAILABLE_FIELDS.length];
+               for (int i=0; i<ALL_AVAILABLE_FIELDS.length; i++) {
+                       names[i] = ALL_AVAILABLE_FIELDS[i].getName();
+               }
+               return names;
+       }
 }