use of org.w3c.css.sac.ElementSelector in project CodenameOne by codenameone.
the class CSSTheme method getElementForSelector.
Element getElementForSelector(String media, Selector sel) {
switch(sel.getSelectorType()) {
case Selector.SAC_ANY_NODE_SELECTOR:
return anyNodeStyle;
case Selector.SAC_ELEMENT_NODE_SELECTOR:
{
ElementSelector esel = (ElementSelector) sel;
if (media != null && !media.isEmpty()) {
return getElementByName(media + "-" + esel.getLocalName());
} else {
return getElementByName(esel.getLocalName());
}
}
case Selector.SAC_CONDITIONAL_SELECTOR:
{
ConditionalSelector csel = (ConditionalSelector) sel;
SimpleSelector simple = csel.getSimpleSelector();
switch(simple.getSelectorType()) {
case Selector.SAC_ANY_NODE_SELECTOR:
{
Element parent = anyNodeStyle;
switch(csel.getCondition().getConditionType()) {
case Condition.SAC_CLASS_CONDITION:
AttributeCondition clsCond = (AttributeCondition) csel.getCondition();
switch(clsCond.getLocalName()) {
case "selected":
return parent.getSelected();
case "unselected":
return parent.getUnselected();
case "pressed":
return parent.getPressed();
case "disabled":
return parent.getDisabled();
default:
throw new RuntimeException("Unsupported style class " + clsCond.getLocalName());
}
default:
throw new RuntimeException("Unsupported CSS condition type " + csel.getCondition().getConditionType());
}
}
case Selector.SAC_ELEMENT_NODE_SELECTOR:
{
ElementSelector esel = (ElementSelector) simple;
Element parent = getElementForSelector(media, esel);
switch(csel.getCondition().getConditionType()) {
case Condition.SAC_CLASS_CONDITION:
AttributeCondition clsCond = (AttributeCondition) csel.getCondition();
switch(clsCond.getValue()) {
case "selected":
return parent.getSelected();
case "unselected":
return parent.getUnselected();
case "pressed":
return parent.getPressed();
case "disabled":
return parent.getDisabled();
default:
throw new RuntimeException("Unsupported style class " + clsCond.getValue());
}
default:
throw new CSSException("Unsupported CSS condition type " + csel.getCondition().getConditionType() + " for " + csel.getSimpleSelector());
}
}
default:
throw new RuntimeException("Unsupported selector type " + simple.getSelectorType());
}
}
default:
throw new RuntimeException("Unsupported selector type " + sel.getSelectorType());
}
}
use of org.w3c.css.sac.ElementSelector in project eclipse.platform.ui by eclipse-platform.
the class MockDocumentHandler method endSelector.
public void endSelector(SelectorList selectors) throws CSSException {
int length = selectors.getLength();
System.out.println("[MockDocumentHandler#endSelector], selectors=" + selectors + ", length=" + length);
for (int i = 0; i < length; i++) {
Selector selector = selectors.item(i);
if (selector instanceof ElementSelector) {
// Element selector
ElementSelector elementSelector = (ElementSelector) selector;
System.out.println("\tElementSelector=> localName=" + elementSelector.getLocalName());
} else if (selector instanceof ConditionalSelector) {
ConditionalSelector conditionalSelector = (ConditionalSelector) selector;
System.out.println("\tConditionalSelector");
Condition condition = conditionalSelector.getCondition();
if (condition instanceof AttributeCondition) {
AttributeCondition attributeCondition = (AttributeCondition) condition;
System.out.println("\t\tCondition (type=AttributeCondition)=> localName=" + attributeCondition.getLocalName() + ", value=" + attributeCondition.getValue());
} else {
System.out.println("\t\tCondition=>" + condition);
}
} else
System.out.println(selector);
}
}
Aggregations