use of com.codename1.ui.html.HTMLElement in project CodenameOne by codenameone.
the class CSSEngine method setWrapText.
/**
* Replaces an unwrapped text with a wrapped version, while copying the style of the original text.
*
* @param label The current label that contains the unwrapped text
* @param words A vector containing one word of the text (without white spaces) in each element
* @param element The text element
*/
private void setWrapText(Label label, Vector words, HTMLElement element, HTMLComponent htmlC) {
Style selectedStyle = label.getSelectedStyle();
Style unselectedStyle = label.getUnselectedStyle();
Vector ui = new Vector();
label.setText((String) words.elementAt(0) + ' ');
HTMLLink link = null;
if (label instanceof HTMLLink) {
link = (HTMLLink) label;
}
ui.addElement(label);
for (int i = 1; i < words.size(); i++) {
Label word = null;
if (link != null) {
word = new HTMLLink((String) words.elementAt(i) + ' ', link.link, htmlC, link, link.linkVisited);
} else {
word = new Label((String) words.elementAt(i) + ' ');
}
word.setSelectedStyle(selectedStyle);
word.setUnselectedStyle(unselectedStyle);
label.getParent().addComponent(word);
ui.addElement(word);
}
element.setAssociatedComponents(ui);
label.getParent().revalidate();
}
use of com.codename1.ui.html.HTMLElement in project CodenameOne by codenameone.
the class CSSEngine method setNowrapRecursive.
/**
* Sets this element and all children to have unwrapped text.
* In cases where text is already unwrapped no change will be made.
* This will work only in FIXED_WIDTH mode (Checked before called)
* Technically a lot of this logic can be found in HTMLComponent, but since we don't want to get into
* the context of this element (i.e. what was the indentation, alignment etc.), we use this algorithm.
*
* @param element The element to apply text wrapping on
*/
private void setNowrapRecursive(final HTMLElement element) {
// if (element.getId()==HTMLElement.TAG_TEXT) {
if (element.isTextElement()) {
// String text=element.getAttributeById(HTMLElement.ATTR_TITLE);
String text = element.getText();
final Vector ui = element.getUi();
if ((text != null) && (ui != null) && (ui.size() > 1)) {
// If it's just one word or already no-wrapped, no need to process
String word = "";
String newText = "";
for (int c = 0; c < text.length(); c++) {
char ch = text.charAt(c);
if ((ch == ' ') || (ch == 10) || (ch == 13) || (ch == '\t') || (ch == '\n')) {
if (!word.equals("")) {
newText += word + " ";
word = "";
}
} else {
word += ch;
}
}
if (!word.equals("")) {
newText += word + " ";
}
final Label label = (Label) ui.elementAt(0);
setNowrapText(label, ui, newText, element);
}
}
for (int i = 0; i < element.getNumChildren(); i++) {
setNowrapRecursive((HTMLElement) element.getChildAt(i));
}
// If children elements' UI was changed, we need to recalc the UI of the parent
element.recalcUi();
}
use of com.codename1.ui.html.HTMLElement in project CodenameOne by codenameone.
the class CSSEngine method applyStyle.
/**
* Applies the given style attributes to the HTML DOM entry
*
* @param element The element to apply the style to
* @param selector The selector containing the style directives
* @param htmlC The HTMLComponent
*/
private void applyStyle(HTMLElement element, CSSElement selector, HTMLComponent htmlC) {
if ((element.getUi() != null) && (element.getUi().size() > 0)) {
if (!HTMLComponent.PROCESS_HTML_MP1_ONLY) {
String reset = selector.getAttributeById(CSSElement.CSS_COUNTER_RESET);
if (reset != null) {
htmlC.incCounter(reset, true);
}
String inc = selector.getAttributeById(CSSElement.CSS_COUNTER_INCREMENT);
if (inc != null) {
htmlC.incCounter(inc, false);
}
if ((selector.getSelectorPseudoClass() & (CSSElement.PC_BEFORE | CSSElement.PC_AFTER)) != 0) {
handleContentProperty(element, selector, htmlC);
return;
}
}
for (int iter = 0; iter < element.getUi().size(); iter++) {
Object o = element.getUi().elementAt(iter);
if (o != null && o instanceof Component) {
final Component cmp = (Component) o;
applyStyleToUIElement(cmp, selector, element, htmlC);
}
}
}
}
Aggregations