use of com.codename1.rad.models.Property in project CodeRAD by shannah.
the class ViewPropertyParameter method createBindingParam.
public static <V> ViewPropertyParameter<V> createBindingParam(ViewProperty<V> property, Tag... tags) {
ViewPropertyParameter<V> out = new ViewPropertyParameter<V>();
out.tags = new Tags(tags);
out.property = property;
return out;
}
use of com.codename1.rad.models.Property in project CodeRAD by shannah.
the class PropertySelector method addPropertyChangeListener.
/**
* Adds a change listener on property.
* @param l The listener to add.
*/
public void addPropertyChangeListener(ActionListener<PropertyChangeEvent> l) {
if (root != null) {
Property prop = property;
if (prop == null && tags != null) {
prop = root.getEntity().findProperty(tags);
}
if (prop != null) {
root.getEntity().addPropertyChangeListener(prop, pcl());
}
} else {
Entity leafEntity = getLeafEntity();
Property leafProperty = getLeafProperty();
if (leafEntity != null && leafProperty != null) {
leafEntity.getEntity().addPropertyChangeListener(leafProperty, pcl());
}
parent.addVetoablePropertyChangeListener(vpcl());
parent.addListChangeListener(listChangeListener());
}
if (listeners == null) {
listeners = new EventDispatcher();
}
listeners.addListener(l);
}
use of com.codename1.rad.models.Property in project CodenameOne by codenameone.
the class CSSEngine method getQuote.
// /////////////////
// Methods relevant to CSS2 only (not WCSS)
// /////////////////
/**
* Returns a quote label with the proper client property
*
* @param open true if this is an opening quote, false otherwise
* @return The quote label
*/
private Label getQuote(boolean open) {
Label quoteLabel = new Label("\"");
// 0 is open quote, 1 is closed quote (both stand for primary quotes - see HTMLComponent.addQuote)
quoteLabel.putClientProperty(HTMLComponent.CLIENT_PROPERTY_QUOTE, new Integer(open ? 0 : 1));
return quoteLabel;
}
use of com.codename1.rad.models.Property in project CodenameOne by codenameone.
the class CSSEngine method evalContentExpression.
/**
* Evaluates a CSS content property expression and returns the matching label component
*
* @param htmlC The HTMLComponent
* @param exp The expression to evaluate
* @param element The element this content property
* @param selector The CSS selector that includes the content property (mainly for error messages)
* @return A label representing the evaluated expression or null if not found
*/
private Label evalContentExpression(HTMLComponent htmlC, String exp, HTMLElement element, CSSElement selector) {
if (exp.length() != 0) {
if (exp.startsWith("counter(")) {
exp = exp.substring(8);
int index = exp.indexOf(")");
if (index != -1) {
return new Label("" + htmlC.getCounterValue(exp.substring(0, index)));
}
} else if (exp.startsWith("attr(")) {
exp = exp.substring(5);
int index = exp.indexOf(")");
if (index != -1) {
String attr = exp.substring(0, index);
String attrValue = element.getAttribute(attr);
return new Label(attrValue == null ? "" : attrValue);
}
} else if (exp.equals("open-quote")) {
return getQuote(true);
} else if (exp.equals("close-quote")) {
return getQuote(false);
} else if (exp.startsWith("url(")) {
String url = getCSSUrl(exp);
Label imgLabel = new Label();
if (htmlC.showImages) {
if (htmlC.getDocumentInfo() != null) {
htmlC.getThreadQueue().add(imgLabel, htmlC.convertURL(url));
} else {
if (DocumentInfo.isAbsoluteURL(url)) {
htmlC.getThreadQueue().add(imgLabel, url);
} else {
if (htmlC.getHTMLCallback() != null) {
htmlC.getHTMLCallback().parsingError(HTMLCallback.ERROR_NO_BASE_URL, selector.getTagName(), selector.getAttributeName(new Integer(CSSElement.CSS_CONTENT)), url, "Ignoring image file referred in a CSS file/segment (" + url + "), since page was set by setBody/setHTML/setDOM so there's no way to access relative URLs");
}
}
}
}
return imgLabel;
}
}
return null;
}
use of com.codename1.rad.models.Property in project CodenameOne by codenameone.
the class CSSEngine method handleContentProperty.
/**
* Handles a CSS content property
*
* @param element The element this content property
* @param selector The CSS selector that includes the content property
* @param htmlC The HTMLComponent
*/
private void handleContentProperty(HTMLElement element, CSSElement selector, HTMLComponent htmlC) {
boolean after = ((selector.getSelectorPseudoClass() & CSSElement.PC_AFTER) != 0);
String content = selector.getAttributeById(CSSElement.CSS_CONTENT);
if (content != null) {
// if there's no content, we don't add anything
Component cmp = after ? (Component) element.getUi().lastElement() : (Component) element.getUi().firstElement();
Component styleCmp = cmp;
Container parent = null;
int pos = 0;
if (cmp instanceof Container) {
parent = ((Container) cmp);
while ((parent.getComponentCount() > 0) && (parent.getComponentAt(after ? parent.getComponentCount() - 1 : 0) instanceof Container)) {
// find the actual content
parent = (Container) parent.getComponentAt(after ? parent.getComponentCount() - 1 : 0);
}
if (parent.getComponentCount() > 0) {
pos = after ? parent.getComponentCount() - 1 : 0;
styleCmp = parent.getComponentAt(pos);
}
} else {
parent = cmp.getParent();
pos = cmp.getParent().getComponentIndex(cmp);
}
if (after) {
pos++;
}
int initPos = pos;
String str = "";
// to make sure the last expression is evaluated, note that this will not print an extra space in any case, since it is out of the quotes if any
content = content + " ";
boolean segment = false;
for (int i = 0; i < content.length(); i++) {
char c = content.charAt(i);
Label lbl = null;
if (c == '"') {
segment = !segment;
if ((!segment) && (str.length() > 0)) {
lbl = new Label(str);
str = "";
}
} else if (CSSParser.isWhiteSpace(c)) {
if (segment) {
str += c;
lbl = new Label(str);
} else if (str.length() > 0) {
lbl = evalContentExpression(htmlC, str, element, selector);
if (lbl == null) {
// if we didn't find a match we search for the following expressions which are used to remove added content
int removeQuoteType = -1;
boolean removeAll = false;
if ((str.equals("none")) || (str.equals("normal"))) {
// normal/none means remove all content
removeAll = true;
} else if (str.equals("no-open-quote")) {
// 0 is the quote type for open quote, 1 for closed one
removeQuoteType = 0;
} else if (str.equals("no-close-quote")) {
removeQuoteType = 1;
}
if ((removeAll) || (removeQuoteType != -1)) {
Vector v = element.getUi();
if (v != null) {
Vector toRemove = new Vector();
for (Enumeration e = v.elements(); e.hasMoreElements(); ) {
Component ui = (Component) e.nextElement();
String conStr = (String) ui.getClientProperty(CLIENT_PROPERTY_CSS_CONTENT);
if ((conStr != null) && (((after) && (conStr.equals("a"))) || ((!after) && (conStr.equals("b"))))) {
boolean remove = true;
if (removeQuoteType != -1) {
Object obj = ui.getClientProperty(HTMLComponent.CLIENT_PROPERTY_QUOTE);
if (obj != null) {
int quoteType = ((Integer) obj).intValue();
remove = (quoteType == removeQuoteType);
} else {
remove = false;
}
}
if (remove) {
parent.removeComponent(ui);
toRemove.addElement(ui);
}
}
}
for (Enumeration e = toRemove.elements(); e.hasMoreElements(); ) {
v.removeElement(e.nextElement());
}
}
// stop processing after removal clauses such as none/normal
return;
}
}
}
str = "";
} else {
str += c;
}
if (lbl != null) {
if (after) {
element.addAssociatedComponent(lbl);
} else {
element.addAssociatedComponentAt(pos - initPos, lbl);
}
lbl.setUnselectedStyle(new Style(styleCmp.getUnselectedStyle()));
lbl.putClientProperty(CLIENT_PROPERTY_CSS_CONTENT, after ? "a" : "b");
if (parent.getComponentCount() == 0) {
parent.addComponent(lbl);
} else {
parent.addComponent(pos, lbl);
}
pos++;
applyStyleToUIElement(lbl, selector, element, htmlC);
}
}
}
}
Aggregations