org.w3c.css.properties.css1.CssVerticalAlignTV Maven / Gradle / Ivy
//
// $Id: CssVerticalAlignTV.java,v 1.4 2010-01-05 13:49:46 ylafon Exp $
// From Philippe Le Hegaret ([email protected])
//
// (c) COPYRIGHT MIT and INRIA, 1997.
// Please first read the full copyright statement in file COPYRIGHT.html
package org.w3c.css.properties.css1;
import org.w3c.css.parser.CssStyle;
import org.w3c.css.properties.css.CssProperty;
import org.w3c.css.util.ApplContext;
import org.w3c.css.util.InvalidParamException;
import org.w3c.css.values.CssExpression;
import org.w3c.css.values.CssIdent;
import org.w3c.css.values.CssPercentage;
import org.w3c.css.values.CssValue;
/**
*
* 'vertical-align'
*
*
* Value: baseline | sub | super | top | text-top | middle | bottom
* | text-bottom | <percentage>
* Initial: baseline
* Applies to: inline elements
* Inherited: no
* Percentage values: refer to the 'line-height' of the element
* itself
*
* The property affects the vertical positioning of the element. One set of
* keywords is relative to the parent element:
*
* -
* 'baseline'
*
-
* align the baseline of the element (or the bottom, if the element doesn't
* have a baseline) with the baseline of the parent
*
-
* 'middle'
*
-
* align the vertical midpoint of the element (typically an image) with the
* baseline plus half the x-height of the parent
*
-
* 'sub'
*
-
* subscript the element
*
-
* 'super'
*
-
* superscript the element
*
-
* 'text-top'
*
-
* align the top of the element with the top of the parent element's font
*
-
* 'text-bottom'
*
-
* align the bottom of the element with the bottom of the parent element's font
*
*
* Another set of properties are relative to the formatted line that the element
* is a part of:
*
* -
* 'top'
*
-
* align the top of the element with the tallest element on the line
*
-
* 'bottom'
*
-
* align the bottom of the element with the lowest element on the line
*
*
* Using the 'top' and 'bottom' alignment, unsolvable situations can occur where
* element dependencies form a loop.
*
* Percentage values refer to the value of the 'line-height' property of the
* element itself. They raise the baseline of the element (or the bottom, if
* it has no baseline) the specified amount above the baseline of the parent.
* Negative values are possible. E.g., a value of '-100%' will lower the element
* so that the baseline of the element ends up where the baseline of the next
* line should have been. This allows precise control over the vertical position
* of elements (such as images that are used in place of letters) that don't
* have a baseline.
*
* It is expected that a future version of CSS will allow <length&t;
* as a value on this property.
*
* @version $Revision: 1.4 $
*/
public class CssVerticalAlignTV extends CssProperty
implements CssTextPropertiesConstants {
Object value;
private static int[] hash_values;
/**
* Create a new CssVerticalAlignTV
*/
public CssVerticalAlignTV() {
value = VERTICALALIGNTV[0];
}
/**
* Create a new CssVerticalAlignTV
*
* @param expression The expression for this property
* @exception InvalidParamException Values are incorrect
*/
public CssVerticalAlignTV(ApplContext ac, CssExpression expression,
boolean check) throws InvalidParamException {
if(check && expression.getCount() > 1) {
throw new InvalidParamException("unrecognize", ac);
}
CssValue val = expression.getValue();
int hash = val.hashCode();
setByUser();
if (val instanceof CssIdent) {
for (int i = 0; i < VERTICALALIGNTV.length; i++)
if (hash_values[i] == hash) {
value = VERTICALALIGNTV[i];
expression.next();
return;
}
throw new InvalidParamException("value",
val.toString(), getPropertyName(), ac);
} else if (val instanceof CssPercentage) {
value = val;
expression.next();
} else {
throw new InvalidParamException("value",
val.toString(), getPropertyName(), ac);
}
}
public CssVerticalAlignTV(ApplContext ac, CssExpression expression)
throws InvalidParamException {
this(ac, expression, false);
}
/**
* Returns the value of this property
*/
public Object get() {
return value;
}
/**
* Returns the name of this property
*/
public String getPropertyName() {
return "vertical-align";
}
/**
* Returns a string representation of the object.
*/
public String toString() {
return value.toString();
}
/**
* Add this property to the CssStyle.
*
* @param style The CssStyle
*/
public void addToStyle(ApplContext ac, CssStyle style) {
Css1Style style0 = (Css1Style) style;
if (style0.cssVerticalAlignTV != null)
style0.addRedefinitionWarning(ac, this);
style0.cssVerticalAlignTV = this;
}
/**
* Get this property in the style.
*
* @param style The style where the property is
* @param resolve if true, resolve the style to find this property
*/
public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) {
if (resolve) {
return ((Css1Style) style).getVerticalAlignTV();
} else {
return ((Css1Style) style).cssVerticalAlignTV;
}
}
/**
* Compares two properties for equality.
*
* @param value The other property.
*/
public boolean equals(CssProperty property) {
return (property instanceof CssVerticalAlignTV && value.equals(((CssVerticalAlignTV) property).value));
}
/**
* Is the value of this property is a default value.
* It is used by all macro for the function print
*/
public boolean isDefault() {
return value.equals(VERTICALALIGNTV[0]);
}
static {
hash_values = new int[VERTICALALIGNTV.length];
for (int i=0; i