Search in sources :

Example 26 with Element

use of com.codename1.xml.Element in project CodenameOne by codenameone.

the class CSSEngine method setVisibleRecursive.

/**
 * Usually we don't have to set visibility in a recursive manner, i.e. suffices to set a top level container as invisible and all its contents are invisible.
 * However, in CSS it is possible that a top level element has visibility:hidden and some child of his has visibility:visible, and then what we do
 * is use the setVisibleParents to make sure all containers containing this child are visible.
 * But since other child components still need to be invsibile - we make sure that all are invisible with this method.
 *
 * @param cmp The component to set visibility on
 * @param visible true to set visible and enabled, false otherwise
 */
private void setVisibleRecursive(Component cmp, boolean visible) {
    cmp.setEnabled(visible);
    cmp.setVisible(visible);
    if (cmp instanceof Container) {
        Container cont = (Container) cmp;
        for (int i = 0; i < cont.getComponentCount(); i++) {
            setVisibleRecursive(cont.getComponentAt(i), visible);
        }
    }
}
Also used : Container(com.codename1.ui.Container)

Example 27 with Element

use of com.codename1.xml.Element in project CodenameOne by codenameone.

the class CSSEngine method setWrapRecursive.

/**
 * Sets this element and all children to have wrapped text.
 * In cases where text is already wrapped no change will be made.
 * This will work only in FIXED_WIDTH mode (Checked before called)
 * Technically all this logic can be found in HTMLComponent.showText, 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
 * @param htmlC The HTMLComponent
 */
private void setWrapRecursive(HTMLElement element, HTMLComponent htmlC) {
    if (element.isTextElement()) {
        String text = element.getText();
        final Vector ui = element.getUi();
        if ((text != null) && (ui != null) && (ui.size() == 1)) {
            // If it's already wrapped, no need to process
            final Vector words = htmlC.getWords(text, Component.LEFT, false);
            final Label label = (Label) ui.elementAt(0);
            setWrapText(label, words, element, htmlC);
        }
    }
    for (int i = 0; i < element.getNumChildren(); i++) {
        setWrapRecursive((HTMLElement) element.getChildAt(i), htmlC);
    }
}
Also used : Label(com.codename1.ui.Label) Vector(java.util.Vector)

Example 28 with Element

use of com.codename1.xml.Element 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 29 with Element

use of com.codename1.xml.Element in project CodenameOne by codenameone.

the class CSSEngine method createBorder.

/**
 *  Returns a border for a specific side of the component
 *
 * @param styleAttributes The style attributes element containing the border directives
 * @param ui The component we want to set the border on
 * @param location One of Component.TOP/BOTTOM/LEFT/RIGHT
 * @return
 */
Border createBorder(CSSElement styleAttributes, Component ui, int location, int styles, int type) {
    int borderStyle = styleAttributes.getAttrVal(BORDER_OUTLINE_PROPERTIES[type][STYLE] + location);
    if ((borderStyle == -1) || (borderStyle == BORDER_STYLE_NONE)) {
        return null;
    }
    int borderColor = styleAttributes.getAttrVal(BORDER_OUTLINE_PROPERTIES[type][COLOR] + location);
    int borderWidth = styleAttributes.getAttrLengthVal(BORDER_OUTLINE_PROPERTIES[type][WIDTH] + location, ui, 0);
    if (borderWidth == -1) {
        // Default value
        borderWidth = CSSElement.BORDER_DEFAULT_WIDTH;
    }
    if (type == OUTLINE) {
        // all
        location = -1;
    }
    if ((styles & STYLE_SELECTED) != 0) {
        incPadding(ui.getSelectedStyle(), location, borderWidth);
    }
    if ((styles & STYLE_UNSELECTED) != 0) {
        incPadding(ui.getUnselectedStyle(), location, borderWidth);
    }
    if ((styles & STYLE_PRESSED) != 0) {
        incPadding(((HTMLLink) ui).getPressedStyle(), location, borderWidth);
    }
    Border border = null;
    if ((borderColor == -1) && (borderStyle >= BORDER_STYLE_GROOVE)) {
        borderColor = DEFAULT_3D_BORDER_COLOR;
    }
    switch(borderStyle) {
        case BORDER_STYLE_SOLID:
            if (borderColor == -1) {
                border = Border.createLineBorder(borderWidth);
            } else {
                border = Border.createLineBorder(borderWidth, borderColor);
            }
            break;
        case BORDER_STYLE_DOUBLE:
            if (borderColor == -1) {
                border = Border.createDoubleBorder(borderWidth);
            } else {
                border = Border.createDoubleBorder(borderWidth, borderColor);
            }
            break;
        case BORDER_STYLE_GROOVE:
            border = Border.createGrooveBorder(borderWidth, borderColor);
            break;
        case BORDER_STYLE_RIDGE:
            border = Border.createRidgeBorder(borderWidth, borderColor);
            break;
        case BORDER_STYLE_INSET:
            border = Border.createInsetBorder(borderWidth, borderColor);
            break;
        case BORDER_STYLE_OUTSET:
            border = Border.createOutsetBorder(borderWidth, borderColor);
            break;
        case BORDER_STYLE_DOTTED:
            if (borderColor == -1) {
                border = Border.createDottedBorder(borderWidth);
            } else {
                border = Border.createDottedBorder(borderWidth, borderColor);
            }
            break;
        case BORDER_STYLE_DASHED:
            if (borderColor == -1) {
                border = Border.createDashedBorder(borderWidth);
            } else {
                border = Border.createDashedBorder(borderWidth, borderColor);
            }
            break;
    }
    return border;
}
Also used : Border(com.codename1.ui.plaf.Border)

Example 30 with Element

use of com.codename1.xml.Element 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)

Aggregations

Container (com.codename1.ui.Container)9 Label (com.codename1.ui.Label)9 Vector (java.util.Vector)9 Component (com.codename1.ui.Component)8 Button (com.codename1.ui.Button)5 Style (com.codename1.ui.plaf.Style)5 RadioButton (com.codename1.ui.RadioButton)4 TextArea (com.codename1.ui.TextArea)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 BoxLayout (com.codename1.ui.layouts.BoxLayout)4 Border (com.codename1.ui.plaf.Border)4 Dimension (com.codename1.ui.geom.Dimension)3 EditableResources (com.codename1.ui.util.EditableResources)3 Hashtable (java.util.Hashtable)3 TextField (com.codename1.ui.TextField)2 Rectangle (com.codename1.ui.geom.Rectangle)2 CharArrayReader (com.codename1.io.CharArrayReader)1 NetworkEvent (com.codename1.io.NetworkEvent)1 CheckBox (com.codename1.ui.CheckBox)1 Command (com.codename1.ui.Command)1