X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fresources%2FBundle.java;h=ca61f6d8e509c2616f307f3d2076a1475575d2ad;hp=2039d578e3c581a98efabad7369dbd0c879ed626;hb=009196a48ec0820288dac580f661c8884e1c1108;hpb=80383c142f85a7850d0fbea418689608fdccac05 diff --git a/src/be/nikiroo/utils/resources/Bundle.java b/src/be/nikiroo/utils/resources/Bundle.java index 2039d57..ca61f6d 100644 --- a/src/be/nikiroo/utils/resources/Bundle.java +++ b/src/be/nikiroo/utils/resources/Bundle.java @@ -1,5 +1,6 @@ package be.nikiroo.utils.resources; +import java.awt.Color; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; @@ -178,6 +179,31 @@ public class Bundle> { return ' '; } + /** + * Return the value associated to the given id as a {@link Color}. + * + * @param 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) { + try { + color = new Color(Integer.parseInt(bg.substring(1, 3), 16), + Integer.parseInt(bg.substring(3, 5), 16), + Integer.parseInt(bg.substring(5, 7), 16)); + } catch (NumberFormatException e) { + color = null; // no changes + } + } + + return color; + } + /** * Create/update the .properties file. *

@@ -374,7 +400,7 @@ public class Bundle> { value = ""; } - String[] lines = value.replaceAll("\t", "\\t").split("\n"); + String[] lines = value.replaceAll("\t", "\\\\\\t").split("\n"); for (int i = 0; i < lines.length; i++) { writer.write(lines[i]); if (i < lines.length - 1) {