diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-11-13 00:29:48 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-11-13 00:29:48 +0000 |
commit | 2a2b91f336fe4f6c2a314db2bc4cdffff6cf5a61 (patch) | |
tree | 21df1df36e4070dbe32198f06ea33964e82a998b /gnu/javax/swing/text/html/css/Length.java | |
parent | 237bdd93058f891ae4567cf4e051c5831bd4646b (diff) | |
download | classpath-2a2b91f336fe4f6c2a314db2bc4cdffff6cf5a61.tar.gz |
2006-11-13 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD-->generics from 2006/11/04-2006/11/12.
Diffstat (limited to 'gnu/javax/swing/text/html/css/Length.java')
-rw-r--r-- | gnu/javax/swing/text/html/css/Length.java | 64 |
1 files changed, 56 insertions, 8 deletions
diff --git a/gnu/javax/swing/text/html/css/Length.java b/gnu/javax/swing/text/html/css/Length.java index 7091fbae7..339e2a2e0 100644 --- a/gnu/javax/swing/text/html/css/Length.java +++ b/gnu/javax/swing/text/html/css/Length.java @@ -54,7 +54,12 @@ public class Length /** * The converted value. */ - private float floatValue; + protected float floatValue; + + /** + * Indicates when the value is a percentage value. + */ + private boolean isPercentage; /** * Creates a new length converter instance. @@ -65,16 +70,31 @@ public class Length { value = val; int i = value.indexOf("px"); - floatValue = 0.0F; - if (i != -1) + int percent = value.indexOf("%"); + try { - String sub = value.substring(0, i); - floatValue = Float.parseFloat(sub); + floatValue = 0.0F; + if (i != -1) + { + String sub = value.substring(0, i); + floatValue = Float.parseFloat(sub); + } + else if (percent != -1) + { + isPercentage = true; + String sub = value.substring(0, percent); + floatValue = Float.parseFloat(sub) / 100; + } + else + { + // TODO: Implement other length options. + floatValue = Float.parseFloat(value); + } } - else + catch (NumberFormatException ex) { - // TODO: Implement other length options. - floatValue = Float.parseFloat(value); + // Don't let such small problems interrupt CSS parsing. + System.err.println("couldn't parse: " + val); } } @@ -87,4 +107,32 @@ public class Length { return floatValue; } + + /** + * Returns the absolute span for the case when this length value is + * a relative value. + * + * @param available the target span + * + * @return the absolute span + */ + public float getValue(float available) + { + float span = floatValue; + if (isPercentage) + span *= available; + return span; + } + + /** + * Returns <code>true</code> when the length value is a percentage + * value, <code>false</code> otherwise. + * + * @return <code>true</code> when the length value is a percentage + * value, <code>false</code> otherwise + */ + public boolean isPercentage() + { + return isPercentage; + } } |