All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cz.vutbr.web.css.TermNumeric Maven / Gradle / Ivy

Go to download

jStyleParser is a CSS parser written in Java. It has its own application interface that is designed to allow an efficient CSS processing in Java and mapping the values to the Java data types. It parses CSS 2.1 style sheets into structures that can be efficiently assigned to DOM elements. It is intended be the primary CSS parser for the CSSBox library. While handling errors, it is user agent conforming according to the CSS specification.

There is a newer version: 4.0.0
Show newest version
package cz.vutbr.web.css;

/**
 * Holds value of numeric type. This could be integer or float
 * according to <T>.
 * @author kapy
 *
 * @param  Type of value stored in term
 */
public interface TermNumeric extends Term {
	
	/**
	 * These are available units in CSS
	 * @author kapy
	 *
	 */
	public enum Unit {
	    none(""),
    	em("em"),
    	ex("ex"),
    	ch("ch"),
    	rem("rem"),
    	vw("vw"),
    	vh("vh"),
    	vmin("vmin"),
    	vmax("vmax"),
    	cm("cm"),
    	mm("mm"),
    	q("q"),
        in("in"),
    	pt("pt"),
    	pc("pc"),
        px("px"),
    	deg("deg"),
    	rad("rad"),
    	grad("grad"),
        turn("turn"),
    	ms("ms"),
    	s("s"),
    	hz("hz"),
    	khz("khz"),
    	dpi("dpi"),
    	dpcm("dpcm"),
    	dppx("dppx");
    
    	private String value;
    	
    	private Unit(String value) { 
    		this.value = value;
    	}
    	public String value() { return value; }
    	
    	public boolean isAngle() {
    		return this==deg || this==rad || this==grad || this==turn;
    	}
    	
    	public boolean isLength() {
            switch (this) {
                case pt:
                case in:
                case cm:
                case mm:
                case q:
                case pc:
                case px:
                case em:
                case ex:
                case ch:
                case rem:
                case vw:
                case vh:
                case vmin:
                case vmax:
                    return true;
                default:
                    return false;
            }
    	}
    	
    	public boolean isTime() {
    		return this==s || this==ms;    
    	}
    	
    	public boolean isFrequency() {
    		return this==hz || this==khz;
    	}
    	
    	public boolean isResolution() {
    	    return this==dpi || this==dpcm || this==dppx;
    	}
    }
	
	/**
	 * Returns unit of type or null if not defined
	 * for numeric types that does not allow units
	 * @return Unit or null
	 */
	public Unit getUnit();
	
	/**
	 * Sets unit
	 * @param unit Unit value
	 * @return Modified object to allow chaining
	 */
    public TermNumeric setUnit(Unit unit);

    /**
     * Sets the value to zero.
     * @return Modified object to allow chaining
     */
    public TermNumeric setZero();
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy