1- /*
2- * Copyright (c) 2001 World Wide Web Consortium,
3- * (Massachusetts Institute of Technology, Institut National de
4- * Recherche en Informatique et en Automatique, Keio University). All
5- * Rights Reserved. This program is distributed under the W3C's Software
6- * Intellectual Property License. This program is distributed in the
7- * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
8- * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9- * PURPOSE.
10- * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
11- *
12- * $Id$
13- */
1+ //
2+ // Rewritten in 2018: Yves Lafon <ylafon@w3.org>
3+ //
4+ // (c) COPYRIGHT MIT, ERCIM, Keio University, Beihang University 2001-2018.
5+ // Please first read the full copyright statement in file COPYRIGHT.html
6+ //
147package org .w3c .css .values ;
158
169import org .w3c .css .util .ApplContext ;
@@ -56,13 +49,12 @@ public final void setRed(ApplContext ac, CssValue val)
5649 nb .setIntValue (0 );
5750 nv = nb ;
5851 }
59- if (val .getRawType () == CssTypes .CSS_NUMBER ) {
60- float p = ((CssNumber ) val ).getValue ();
52+ if (val .getRawType () == CssTypes .CSS_PERCENTAGE ) {
53+ float p = ((CssPercentage ) val ).floatValue ();
6154 if (p > 100. ) {
6255 ac .getFrame ().addWarning ("out-of-range" , Util .displayFloat (p ));
63- CssNumber nb = new CssNumber ();
64- nb .setIntValue (100 );
65- nv = nb ;
56+ CssPercentage np = new CssPercentage (100 );
57+ nv = np ;
6658 }
6759 }
6860 }
@@ -101,13 +93,12 @@ public final void setGreen(ApplContext ac, CssValue val)
10193 nb .setIntValue (0 );
10294 nv = nb ;
10395 }
104- if (val .getRawType () == CssTypes .CSS_NUMBER ) {
105- float p = ((CssNumber ) val ).getValue ();
96+ if (val .getRawType () == CssTypes .CSS_PERCENTAGE ) {
97+ float p = ((CssPercentage ) val ).floatValue ();
10698 if (p > 100. ) {
10799 ac .getFrame ().addWarning ("out-of-range" , Util .displayFloat (p ));
108- CssNumber nb = new CssNumber ();
109- nb .setIntValue (100 );
110- nv = nb ;
100+ CssPercentage np = new CssPercentage (100 );
101+ nv = np ;
111102 }
112103 }
113104 }
@@ -147,13 +138,12 @@ public final void setBlue(ApplContext ac, CssValue val)
147138 nb .setIntValue (0 );
148139 nv = nb ;
149140 }
150- if (val .getRawType () == CssTypes .CSS_NUMBER ) {
151- float p = ((CssNumber ) val ).getValue ();
141+ if (val .getRawType () == CssTypes .CSS_PERCENTAGE ) {
142+ float p = ((CssPercentage ) val ).floatValue ();
152143 if (p > 100. ) {
153144 ac .getFrame ().addWarning ("out-of-range" , Util .displayFloat (p ));
154- CssNumber nb = new CssNumber ();
155- nb .setIntValue (100 );
156- nv = nb ;
145+ CssPercentage np = new CssPercentage (100 );
146+ nv = np ;
157147 }
158148 }
159149 }
@@ -175,7 +165,6 @@ public final void setPercent(boolean percent) {
175165 this .percent = percent ;
176166 }
177167
178-
179168 /**
180169 * Create a new RGB
181170 */
@@ -218,15 +207,9 @@ protected void setRepresentationString(String s) {
218207 public String toString () {
219208 if (output == null ) {
220209 StringBuilder sb = new StringBuilder (functionname ).append ('(' );
221- if (isPercent ()) {
222- sb .append (vr ).append ("%, " );
223- sb .append (vg ).append ("%, " );
224- sb .append (vb ).append ("%)" );
225- } else {
226- sb .append (vr ).append (", " );
227- sb .append (vg ).append (", " );
228- sb .append (vb ).append (')' );
229- }
210+ sb .append (vr ).append (", " );
211+ sb .append (vg ).append (", " );
212+ sb .append (vb ).append (')' );
230213 output = sb .toString ();
231214 }
232215 return output ;
0 commit comments