1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
package tim.prune.data;
import tim.prune.I18nManager;
/**
* Class to represent a field of a data point.
* File type-specific fields are represented by subclasses
*/
public class Field
{
private final String _labelKey;
private final FileType _fileType;
public static final Field LATITUDE = new Field("latitude");
public static final Field LONGITUDE = new Field("longitude");
public static final Field ALTITUDE = new Field("altitude");
public static final Field TIMESTAMP = new Field("timestamp");
public static final Field WAYPT_NAME = new Field("waypointname");
public static final Field WAYPT_TYPE = new Field("waypointtype");
public static final Field DESCRIPTION = new Field("description");
public static final Field COMMENT = new Field("comment");
public static final Field SYMBOL = new Field("symbol");
public static final Field NEW_SEGMENT = new Field("newsegment");
public static final Field SPEED = new Field("speed");
public static final Field VERTICAL_SPEED = new Field("verticalspeed");
public static final Field GRADIENT = new Field("gradient");
public static final Field PHOTO = new Field("photo");
public static final Field AUDIO = new Field("audio");
/** List of all the available built-in fields */
private static final Field[] ALL_AVAILABLE_FIELDS = {
LATITUDE, LONGITUDE, ALTITUDE, TIMESTAMP, WAYPT_NAME, WAYPT_TYPE, DESCRIPTION, NEW_SEGMENT,
SPEED, VERTICAL_SPEED
};
/**
* Private constructor
* @param inLabelKey Key for label texts
*/
private Field(String inLabelKey)
{
_labelKey = "fieldname." + inLabelKey;
_fileType = null;
}
/**
* Constructor for subtypes
* @param inFileType file type for which this field is valid
*/
protected Field(FileType inFileType)
{
_labelKey = null;
_fileType = inFileType;
}
/**
* @return the name of the field
*/
public String getName() {
return I18nManager.getText(_labelKey);
}
public void setName(String inName) {
// ignored, only used for custom fields
}
/** @return true if this field is specific to the given file type */
public boolean isSpecificToFileType(FileType inFileType) {
return _fileType == inFileType;
}
/** @return true if this field can be saved as the given file type */
public boolean matchesFileType(FileType inFileType) {
return _fileType == null || _fileType == inFileType;
}
/**
* Checks if the two fields are equal
* @param inOther other Field object
* @return true if Fields identical
*/
public boolean equals(Object inOther)
{
return inOther != null
&& getClass().equals(inOther.getClass())
&& getName().equals(((Field) inOther).getName());
}
/** @return true if this is a built-in field, not a custom field or extension */
public final boolean isBuiltIn() {
return getClass() == Field.class;
}
/**
* 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 (Field field : ALL_AVAILABLE_FIELDS)
{
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;
}
}
|