Search in sources :

Example 76 with Label

use of com.codename1.ui.Label in project CodenameOne by codenameone.

the class Label method shouldTickerStart.

/**
 * Returns true if a ticker should be started since there is no room to show
 * the text in the label.
 *
 * @return true if a ticker should start running
 */
public boolean shouldTickerStart() {
    if (!tickerEnabled) {
        return false;
    }
    Style style = getStyle();
    int txtW = style.getFont().stringWidth(getText());
    int textSpaceW = getAvaliableSpaceForText();
    return txtW > textSpaceW && textSpaceW > 0;
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 77 with Label

use of com.codename1.ui.Label 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 78 with Label

use of com.codename1.ui.Label 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 79 with Label

use of com.codename1.ui.Label 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 80 with Label

use of com.codename1.ui.Label in project CodenameOne by codenameone.

the class TextArea method calcPreferredSize.

/**
 * {@inheritDoc}
 */
protected Dimension calcPreferredSize() {
    if (shouldShowHint()) {
        Label l = getHintLabelImpl();
        if (l != null) {
            Dimension d1 = getUIManager().getLookAndFeel().getTextAreaSize(this, true);
            Dimension d2 = l.getPreferredSize();
            return new Dimension(Math.max(d1.getWidth(), d2.getWidth()), Math.max(d1.getHeight(), d2.getHeight()));
        }
    }
    return getUIManager().getLookAndFeel().getTextAreaSize(this, true);
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Aggregations

Label (com.codename1.ui.Label)41 BorderLayout (com.codename1.ui.layouts.BorderLayout)22 Container (com.codename1.ui.Container)21 Component (com.codename1.ui.Component)16 Form (com.codename1.ui.Form)15 Button (com.codename1.ui.Button)14 TextArea (com.codename1.ui.TextArea)14 Style (com.codename1.ui.plaf.Style)13 ActionListener (com.codename1.ui.events.ActionListener)12 ActionEvent (com.codename1.ui.events.ActionEvent)11 Image (com.codename1.ui.Image)10 Dimension (com.codename1.ui.geom.Dimension)10 Vector (java.util.Vector)10 BoxLayout (com.codename1.ui.layouts.BoxLayout)9 EncodedImage (com.codename1.ui.EncodedImage)8 RadioButton (com.codename1.ui.RadioButton)7 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)6 Hashtable (java.util.Hashtable)6 Paint (com.codename1.charts.compat.Paint)5 Font (com.codename1.ui.Font)5