+ return null;
+ }
+
+ /**
+ * Return the value associated to the given id as a {@link Character}.
+ *
+ * @param id
+ * the id of the value to get
+ * @param def
+ * the default value when it is not present in the config file or
+ * if it is not a char value
+ *
+ * @return the associated value
+ */
+ public char getCharacter(E id, char def) {
+ String s = getString(id).trim();
+ if (s.length() > 0) {
+ return s.charAt(0);
+ }
+
+ return def;
+ }
+
+ /**
+ * Return the value associated to the given id as a {@link Color}.
+ *
+ * @param id
+ * the id of the value to get
+ *
+ * @return the associated value
+ */
+ public Color getColor(E id) {
+ Color color = null;
+
+ String bg = getString(id).trim();
+ if (bg.startsWith("#") && (bg.length() == 7 || bg.length() == 9)) {
+ try {
+ int r = Integer.parseInt(bg.substring(1, 3), 16);
+ int g = Integer.parseInt(bg.substring(3, 5), 16);
+ int b = Integer.parseInt(bg.substring(5, 7), 16);
+ int a = 255;
+ if (bg.length() == 9) {
+ a = Integer.parseInt(bg.substring(7, 9), 16);
+ }
+ color = new Color(r, g, b, a);
+ } catch (NumberFormatException e) {
+ color = null; // no changes
+ }
+ }
+
+ // Try by name if still not found
+ if (color == null) {
+ try {
+ Field field = Color.class.getField(bg);
+ color = (Color) field.get(null);
+ } catch (Exception e) {
+ }
+ }
+ //
+
+ return color;
+ }
+
+ /**
+ * Set the value associated to the given id as a {@link Color}.
+ *
+ * @param id
+ * the id of the value to set
+ * @param color
+ * the new color
+ */
+ public void setColor(E id, Color color) {
+ // Check for named colours first
+ try {
+ Field[] fields = Color.class.getFields();
+ for (Field field : fields) {
+ if (field.equals(color)) {
+ setString(id, field.getName());
+ return;
+ }
+ }
+ } catch (Exception e) {
+ }
+ //
+
+ String r = Integer.toString(color.getRed(), 16);
+ String g = Integer.toString(color.getGreen(), 16);
+ String b = Integer.toString(color.getBlue(), 16);
+ String a = "";
+ if (color.getAlpha() < 255) {
+ a = Integer.toString(color.getAlpha(), 16);
+ }
+
+ setString(id, "#" + r + g + b + a);
+ }
+
+ /**
+ * Create/update the .properties file.
+ * <p>
+ * Will use the most likely candidate as base if the file does not already
+ * exists and this resource is translatable (for instance, "en_US" will use
+ * "en" as a base if the resource is a translation file).
+ * <p>
+ * Will update the files in {@link Bundles#getDirectory()}; it <b>MUST</b>
+ * be set.
+ *
+ * @throws IOException
+ * in case of IO errors
+ */
+ public void updateFile() throws IOException {
+ updateFile(Bundles.getDirectory());