Search in sources :

Example 11 with Label

use of com.vaadin.v7.ui.Label 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;
}
Also used : Label(com.codename1.ui.Label)

Example 12 with Label

use of com.vaadin.v7.ui.Label 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);
            }
        }
    }
}
Also used : Container(com.codename1.ui.Container) Enumeration(java.util.Enumeration) Label(com.codename1.ui.Label) Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component) Vector(java.util.Vector)

Example 13 with Label

use of com.vaadin.v7.ui.Label in project CodenameOne by codenameone.

the class MorphTransition method initTransition.

/**
 * {@inheritDoc}
 */
public final void initTransition() {
    animationMotion = Motion.createEaseInOutMotion(0, 255, duration);
    animationMotion.start();
    Container s = (Container) getSource();
    Container d = (Container) getDestination();
    Iterator<String> keyIterator = fromTo.keySet().iterator();
    int size = fromTo.size();
    fromToComponents = new CC[size];
    Form destForm = d.getComponentForm();
    destForm.forceRevalidate();
    Form sourceForm = s.getComponentForm();
    for (int iter = 0; iter < size; iter++) {
        String k = keyIterator.next();
        String v = fromTo.get(k);
        Component sourceCmp = findByName(s, k);
        Component destCmp = findByName(d, v);
        if (sourceCmp == null || destCmp == null) {
            continue;
        }
        CC cc = new CC(sourceCmp, destCmp, sourceForm, destForm);
        fromToComponents[iter] = cc;
        cc.placeholderDest = new Label();
        cc.placeholderDest.setVisible(false);
        Container destParent = cc.dest.getParent();
        cc.placeholderDest.setX(cc.dest.getX());
        cc.placeholderDest.setY(cc.dest.getY() - destForm.getContentPane().getY());
        cc.placeholderDest.setWidth(cc.dest.getWidth());
        cc.placeholderDest.setHeight(cc.dest.getHeight());
        cc.placeholderDest.setPreferredSize(new Dimension(cc.dest.getWidth(), cc.dest.getHeight()));
        destParent.replace(cc.dest, cc.placeholderDest, null);
        destForm.getLayeredPane().addComponent(cc.dest);
        cc.placeholderSrc = new Label();
        cc.placeholderSrc.setVisible(false);
        cc.placeholderSrc.setX(cc.source.getX());
        cc.placeholderSrc.setY(cc.source.getY() - sourceForm.getContentPane().getY());
        cc.placeholderSrc.setWidth(cc.source.getWidth());
        cc.placeholderSrc.setHeight(cc.source.getHeight());
        cc.placeholderSrc.setPreferredSize(new Dimension(cc.source.getWidth(), cc.source.getHeight()));
        cc.originalContainer = cc.source.getParent();
        cc.originalConstraint = cc.originalContainer.getLayout().getComponentConstraint(cc.source);
        cc.originalOffset = cc.originalContainer.getComponentIndex(cc.source);
        cc.originalContainer.replace(cc.source, cc.placeholderSrc, null);
        cc.originalContainer.getComponentForm().getLayeredPane().addComponent(cc.source);
    }
}
Also used : Container(com.codename1.ui.Container) Form(com.codename1.ui.Form) Label(com.codename1.ui.Label) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Example 14 with Label

use of com.vaadin.v7.ui.Label in project CodenameOne by codenameone.

the class AutoCapitalizationTest method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.add(new Label("Hi World"));
    TextField myTextField = new TextField();
    myTextField.setSingleLineTextArea(false);
    myTextField.setConstraint(TextArea.INITIAL_CAPS_SENTENCE);
    myTextField.setGrowLimit(-1);
    myTextField.setMaxSize(1600);
    myTextField.setHint("Type Something...");
    hi.add(myTextField);
    hi.show();
}
Also used : Form(com.codename1.ui.Form) Label(com.codename1.ui.Label) TextField(com.codename1.ui.TextField)

Example 15 with Label

use of com.vaadin.v7.ui.Label in project CodenameOne by codenameone.

the class FingerprintScannerSample method start.

public void start() {
    if (current != null) {
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    TextField keyName = new TextField();
    TextField keyValue = new TextField();
    Button addItem = new Button("Add Item");
    Button getItem = new Button("Get Item");
    Button deleteItem = new Button("Delete Item");
    Button checkAvailable = new Button("Check Available");
    checkAvailable.addActionListener(evt -> {
        Container cnt = BoxLayout.encloseY(new Label("TouchID: " + Fingerprint.isTouchIDAvailable()), new Label("FaceID: " + Fingerprint.isFaceIDAvailable()));
        Dialog.show("Capabilities", cnt, new Command("OK"));
    });
    addItem.addActionListener(evt -> {
        if (!Fingerprint.isAvailable()) {
            ToastBar.showErrorMessage("Fingerprint not avaiable on this platform");
            return;
        }
        Fingerprint.addPassword("Adding secure item to keystore", keyName.getText(), keyValue.getText()).onResult((res, err) -> {
            if (err != null) {
                if (AsyncResource.isCancelled(err)) {
                    Log.p("addPassword request was cancelled");
                    return;
                }
                Log.e(err);
                ToastBar.showErrorMessage(err.getMessage());
            } else {
                ToastBar.showInfoMessage("Result: " + res);
            }
        });
    });
    getItem.addActionListener(evt -> {
        Fingerprint.getPassword("Getting secure item", keyName.getText()).onResult((res, err) -> {
            if (err != null) {
                if (AsyncResource.isCancelled(err)) {
                    Log.p("getPassword request was cancelled");
                    return;
                }
                Log.e(err);
                if (err instanceof KeyRevokedException) {
                    ToastBar.showErrorMessage("Your key has been invalidated, likely due to adding new fingerprints");
                } else {
                    ToastBar.showErrorMessage(err.getMessage());
                }
            } else {
                keyValue.setText(res);
                hi.revalidateWithAnimationSafety();
            }
        });
    });
    deleteItem.addActionListener(evt -> {
        Fingerprint.deletePassword("Getting secure item", keyName.getText()).onResult((res, err) -> {
            if (err != null) {
                if (AsyncResource.isCancelled(err)) {
                    Log.p("deletePassword request was cancelled");
                }
                Log.e(err);
                ToastBar.showErrorMessage(err.getMessage());
            } else {
                keyValue.setText("");
                hi.revalidateWithAnimationSafety();
            }
        });
    });
    Button checkHardware = new Button("Check Hardware");
    checkHardware.addActionListener(evt -> {
        Fingerprint.isAvailable();
        Dialog.show("Hardware", CN.getProperty("Fingerprint.types", "None"), "OK", null);
    });
    hi.addAll(checkHardware, new Label("Key:"), keyName, new Label("Value: "), keyValue, addItem, getItem, deleteItem, checkAvailable);
    hi.show();
}
Also used : Container(com.codename1.ui.Container) KeyRevokedException(com.codename1.fingerprint.KeyRevokedException) Form(com.codename1.ui.Form) Button(com.codename1.ui.Button) Command(com.codename1.ui.Command) Label(com.codename1.ui.Label) TextField(com.codename1.ui.TextField)

Aggregations

Label (com.codename1.ui.Label)129 Form (com.codename1.ui.Form)85 Label (com.vaadin.ui.Label)56 Container (com.codename1.ui.Container)45 Button (com.codename1.ui.Button)41 Label (com.vaadin.v7.ui.Label)40 TextField (com.vaadin.v7.ui.TextField)32 BorderLayout (com.codename1.ui.layouts.BorderLayout)31 Button (com.vaadin.ui.Button)31 ComboBox (com.vaadin.v7.ui.ComboBox)31 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)31 Captions (de.symeda.sormas.api.i18n.Captions)29 Strings (de.symeda.sormas.api.i18n.Strings)28 VerticalLayout (com.vaadin.ui.VerticalLayout)26 FacadeProvider (de.symeda.sormas.api.FacadeProvider)26 HorizontalLayout (com.vaadin.ui.HorizontalLayout)24 Window (com.vaadin.ui.Window)24 CssStyles (de.symeda.sormas.ui.utils.CssStyles)24 ValoTheme (com.vaadin.ui.themes.ValoTheme)21 List (java.util.List)21