summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Antoni Buj i Gelonch <robert.buj@gmail.com>2014-10-16 10:47:34 +0200
committerNoel Grandin <noelgrandin@gmail.com>2014-10-16 10:25:58 +0000
commit96e3718e5ae4e74084f537ae64a2999eb93fa8fb (patch)
tree06b972a83f47990f5fdc59a3af33e3eff73f8b7a
parentbbd5a304112c57ac1b1357c93ba7bd8ed8973cfa (diff)
xmerge: use String.format
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html#format(java.lang.String, java.lang.Object...) Change-Id: I98b7fca9dee870c9a1d0f9842cbb009a13537967 Reviewed-on: https://gerrit.libreoffice.org/11995 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r--xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java26
-rw-r--r--xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/CellStyle.java26
2 files changed, 14 insertions, 38 deletions
diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java
index 0d61b1a60cc7..20ccd6e7d51e 100644
--- a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java
+++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/TextStyle.java
@@ -151,19 +151,18 @@ public class TextStyle extends Style implements Cloneable {
* @return The {@code Color} associated the value.
*/
private Color parseColorString(String value) {
- // Assume color value is of form #rrggbb
- String r = value.substring(1, 3);
- String g = value.substring(3, 5);
- String b = value.substring(5, 7);
int red = 0;
int green = 0;
int blue = 0;
try {
- red = Integer.parseInt(r, 16);
- green = Integer.parseInt(g, 16);
- blue = Integer.parseInt(b, 16);
+ // Assume color value is of form #rrggbb
+ red = Integer.parseInt(value.substring(1, 3), 16);
+ green = Integer.parseInt(value.substring(3, 5), 16);
+ blue = Integer.parseInt(value.substring(5, 7), 16);
} catch (NumberFormatException e) {
Debug.log(Debug.ERROR, "Problem parsing a color string", e);
+ } catch (IndexOutOfBoundsException e) {
+ Debug.log(Debug.ERROR, "Problem parsing a color string", e);
}
return new Color(red, green, blue);
}
@@ -545,18 +544,7 @@ public class TextStyle extends Style implements Cloneable {
* @return The {@code Color} value in the form <i>{@literal #rrggbb}</i>.
*/
private String buildColorString(Color c) {
- int v[] = new int[3];
- v[0] = c.getRed();
- v[1] = c.getGreen();
- v[2] = c.getBlue();
- String colorString = "#";
- for (int i = 0; i <= 2; i++) {
- String xx = Integer.toHexString(v[i]);
- if (xx.length() < 2)
- xx = "0" + xx;
- colorString += xx;
- }
- return colorString;
+ return String.format("#%06X", c.getRGB() & 0x00FFFFFF);
}
private static String[] ignored = {
diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/CellStyle.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/CellStyle.java
index 644d91eacc3f..1628f199ef69 100644
--- a/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/CellStyle.java
+++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/converter/xml/sxc/CellStyle.java
@@ -118,19 +118,18 @@ public class CellStyle extends Style implements Cloneable {
* @return The {@code Color} associated the value.
*/
private Color parseColorString(String value) {
- // Assume color value is of form #rrggbb
- String r = value.substring(1, 3);
- String g = value.substring(3, 5);
- String b = value.substring(5, 7);
int red = 0;
int green = 0;
int blue = 0;
try {
- red = Integer.parseInt(r, 16);
- green = Integer.parseInt(g, 16);
- blue = Integer.parseInt(b, 16);
+ // Assume color value is of form #rrggbb
+ red = Integer.parseInt(value.substring(1, 3), 16);
+ green = Integer.parseInt(value.substring(3, 5), 16);
+ blue = Integer.parseInt(value.substring(5, 7), 16);
} catch (NumberFormatException e) {
Debug.log(Debug.ERROR, "Problem parsing a color string", e);
+ } catch (IndexOutOfBoundsException e) {
+ Debug.log(Debug.ERROR, "Problem parsing a color string", e);
}
return new Color(red, green, blue, 0);
}
@@ -438,18 +437,7 @@ public class CellStyle extends Style implements Cloneable {
* @return The {@code Color} value in the form <i>{@literal #rrggbb}</i>.
*/
private String buildColorString(Color c) {
- int v[] = new int[3];
- v[0] = c.getRed();
- v[1] = c.getGreen();
- v[2] = c.getBlue();
- String colorString = "#";
- for (int i = 0; i <= 2; i++) {
- String xx = Integer.toHexString(v[i]);
- if (xx.length() < 2)
- xx = "0" + xx;
- colorString += xx;
- }
- return colorString;
+ return String.format("#%06X", c.getRGB() & 0x00FFFFFF);
}
private static String[] ignored = {