- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Thu, 05 Mar 2009 18:00:23 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/org/w3c/css/values In directory hutz:/tmp/cvs-serv8471 Modified Files: RGBA.java Log Message: fixed RGBA to match RGB Index: RGBA.java =================================================================== RCS file: /sources/public/2002/css-validator/org/w3c/css/values/RGBA.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- RGBA.java 14 Sep 2005 15:15:33 -0000 1.4 +++ RGBA.java 5 Mar 2009 18:00:21 -0000 1.5 @@ -15,10 +15,8 @@ public class RGBA { String output = null; - Object r; - Object g; - Object b; - Object a; + int r,g,b; + float fr,fg,fb,a; boolean percent = false; @@ -36,6 +34,52 @@ this.percent = percent; } + public final void setRed(int r) { + this.r = r; + } + public final void setRed(float fr) { + this.fr = fr; + } + + public final void setGreen(int g) { + this.g = g; + } + public final void setGreen(float gr) { + this.fg = fg; + } + + public final void setBlue(int b) { + this.b = b; + } + public final void setBlue(float fb) { + this.fb = fb; + } + + public final void setAlpha(float a) { + this.a = a; + } + + public boolean equals(RGBA other) { + if (other != null) { + if (percent) { + if (other.percent) { + return ((fr == other.fr) && + (fg == other.fg) && + (fb == other.fb) && + (a == other.a)); + } + } else { + if (!other.percent) { + return ((r == other.r) && + (g == other.g) && + (b == other.b) && + (a == other.a)); + } + } + } + return false; + } + /** * Create a new RGBA */ @@ -45,23 +89,44 @@ /** * Create a new RGBA with default values */ - public RGBA(Object r, Object g, Object b, Object a) { + public RGBA(int r, int g, int b, float a) { this.r = r; this.g = g; this.b = b; this.a = a; + this.percent = false; } /** + * Create a new RGBA with default values + */ + public RGBA(float r, float g, float b, float a) { + this.fr = r; + this.fg = g; + this.fb = b; + this.a = a; + this.percent = true; + } + + + /** * Returns a string representation of the object. */ public String toString() { if (output == null) { - String unit = (isPercent()) ? "%" : ""; - return "rgba(" + r + unit + ", " + g + unit + ", " + b + unit + - ", " + a + unit + ")"; - } else { - return output; - } + StringBuilder sb = new StringBuilder("rgba("); + if (isPercent()) { + sb.append(fr).append("%, "); + sb.append(fg).append("%, "); + sb.append(fb).append("%, "); + } else { + sb.append(r).append(", "); + sb.append(g).append(", "); + sb.append(b).append(", "); + } + sb.append(a).append(')'); + output = sb.toString(); + } + return output; } }
Received on Thursday, 5 March 2009 18:00:33 UTC