Java Code Examples for cz.vutbr.web.css.Declaration#setProperty()

The following examples show how to use cz.vutbr.web.css.Declaration#setProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BoxFactory.java    From CSSBox with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates the style definition for an anonymous box. It contains only the class name set to "Xanonymous"
 * and the display: property set according to the parametres.
 * @param display <code>display:</code> property value of the resulting style.
 * @return Resulting style definition
 */
public NodeData createAnonymousStyle(String display)
{
    NodeData ret = CSSFactory.createNodeData();
    
    Declaration cls = CSSFactory.getRuleFactory().createDeclaration();
    cls.unlock();
    cls.setProperty("class");
    cls.add(CSSFactory.getTermFactory().createString("Xanonymous"));
    ret.push(cls);
    
    Declaration disp = CSSFactory.getRuleFactory().createDeclaration();
    disp.unlock();
    disp.setProperty("display");
    disp.add(CSSFactory.getTermFactory().createIdent(display));
    ret.push(disp);
    
    return ret;
}
 
Example 2
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unused")
private boolean processGrid(Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
    // <'grid-template'> 
    // | <'grid-template-rows'> / [ auto-flow && dense? ] <'grid-auto-columns'>?
    // | [ auto-flow && dense? ] <'grid-auto-rows'>? / <'grid-template-columns'>
    Declaration templateDecl = rf.createDeclaration(d);
    templateDecl.setProperty("grid-template");
    if (processGridTemplate(templateDecl, properties, values)) {
        return true;
    }

    boolean beforeSlash = true;
    boolean autoFlowBeforeSlash = false;
    Declaration autoFlowDecl = (Declaration) rf.createDeclaration().unlock();
    autoFlowDecl.setProperty("grid-auto-flow");
    Declaration templateRowsDecl = (Declaration) rf.createDeclaration().unlock();
    templateRowsDecl.setProperty("grid-template-rows");
    Declaration autoRowsDecl = (Declaration) rf.createDeclaration().unlock();
    autoRowsDecl.setProperty("grid-auto-rows");
    Declaration templateColumnsDecl = (Declaration) rf.createDeclaration().unlock();
    templateColumnsDecl.setProperty("grid-template-columns");
    Declaration autoColumnsDecl = (Declaration) rf.createDeclaration().unlock();
    autoColumnsDecl.setProperty("grid-auto-columns");

    for (int i = 0; i < d.size(); i++) {
        Term<?> t = d.get(i);
        if (t.getOperator() == Term.Operator.SLASH) {
            beforeSlash = false;
        }

        if (t instanceof TermIdent) {
            CSSProperty property = Decoder.genericPropertyRaw(Grid.class, null, (TermIdent) t);
            if (Grid.AUTO_FLOW.equals(property)) {
                if (beforeSlash) {
                    autoFlowDecl.add(tf.createIdent("row"));
                } else {
                    autoFlowDecl.add(tf.createIdent("column"));
                }
                autoFlowBeforeSlash = beforeSlash;
                continue;
            } else {
                property = Decoder.genericPropertyRaw(GridAutoFlow.class, null, (TermIdent) t);
                if (GridAutoFlow.DENSE.equals(property)) {
                    autoFlowDecl.add(t);
                    continue;
                }
            }
        }

        if (autoFlowDecl.isEmpty()) {
            if (beforeSlash) {
                templateRowsDecl.add(t);
            }
        } else {
            if (beforeSlash) {
                autoRowsDecl.add(t);
            } else if (autoFlowBeforeSlash) {
                templateColumnsDecl.add(t);
            } else {
                autoColumnsDecl.add(t);
            }
        }
    }
    processGridAutoRows(autoRowsDecl, properties, values);
    processGridAutoColumns(autoColumnsDecl, properties, values);

    return processGridAutoFlow(autoFlowDecl, properties, values)
            && (processGridTemplateRows(templateRowsDecl, properties, values)
            || processGridTemplateColumns(templateColumnsDecl, properties, values));
}
 
Example 3
Source File: DeclarationTransformerImpl.java    From jStyleParser with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean processPropertiesInList(String[] propertyList, Declaration d, Map<String, CSSProperty> properties, Map<String, Term<?>> values) {
    Declaration subDeclaration = (Declaration) rf.createDeclaration().unlock();
    TermList[] termLists = new TermList[propertyList.length];
    for (int i = 0; i < termLists.length; i++) termLists[i] = tf.createList();
    boolean[] propertySet = new boolean[propertyList.length];
    Arrays.fill(propertySet, false);

    for (int i = 0; i < d.size(); i++) {
        Term<?> t = d.get(i);
        subDeclaration.add(t);
        if (t.getOperator() == Operator.COMMA) {
            Arrays.fill(propertySet, false);
        }
        for (int propertyIndex = 0; propertyIndex <= propertyList.length; propertyIndex++) {
            if (propertyIndex == propertyList.length) {
                return false;
            }
            if (propertySet[propertyIndex]) {
                continue;
            }
            subDeclaration.setProperty(propertyList[propertyIndex]);
            if (parseDeclaration(subDeclaration, properties, values)) {
                propertySet[propertyIndex] = true;
                t.setOperator(termLists[propertyIndex].isEmpty() ? null : Operator.COMMA);
                termLists[propertyIndex].add(t);
                break;
            }
        }
        subDeclaration.clear();
    }

    for (int propertyIndex = 0; propertyIndex < propertyList.length; propertyIndex++) {
        subDeclaration.setProperty(propertyList[propertyIndex]);
        subDeclaration.addAll(termLists[propertyIndex]);
        if (!subDeclaration.isEmpty() && !parseDeclaration(subDeclaration, properties, values)) {
            return false;
        }
        subDeclaration.clear();
    }
    return true;
}
 
Example 4
Source File: DeclarationsUtil.java    From jStyleParser with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Simple declaration of rule. Other functions are wrappers
 * @param property Property name
 * @param terms Terms of declaration
 * @param important !IMPORTANT flag
 * @return Created declaration
 */
public static Declaration createDeclaration(String property, boolean important, List<Term<?>> terms) {

	Declaration dec = (Declaration) rf.createDeclaration().replaceAll(terms);
	
	dec.setProperty(property);
	dec.setImportant(important);
	
	return dec;
	
}