Search in sources :

Example 16 with HTMLElement

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();
}
Also used : Label(com.codename1.ui.Label) Style(com.codename1.ui.plaf.Style) Vector(java.util.Vector)

Example 17 with HTMLElement

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();
}
Also used : Label(com.codename1.ui.Label) Vector(java.util.Vector)

Example 18 with HTMLElement

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);
            }
        }
    }
}
Also used : Component(com.codename1.ui.Component)

Aggregations

Label (com.codename1.ui.Label)9 Vector (java.util.Vector)9 Component (com.codename1.ui.Component)8 Container (com.codename1.ui.Container)7 Button (com.codename1.ui.Button)4 RadioButton (com.codename1.ui.RadioButton)4 TextArea (com.codename1.ui.TextArea)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 BoxLayout (com.codename1.ui.layouts.BoxLayout)3 TextField (com.codename1.ui.TextField)2 Border (com.codename1.ui.plaf.Border)2 Style (com.codename1.ui.plaf.Style)2 Hashtable (java.util.Hashtable)2 CheckBox (com.codename1.ui.CheckBox)1 Command (com.codename1.ui.Command)1 List (com.codename1.ui.List)1 DataChangedListener (com.codename1.ui.events.DataChangedListener)1 SelectionListener (com.codename1.ui.events.SelectionListener)1 Dimension (com.codename1.ui.geom.Dimension)1 Rectangle (com.codename1.ui.geom.Rectangle)1