Search in sources :

Example 6 with Filter

use of com.codename1.ui.ComponentSelector.Filter in project CodenameOne by codenameone.

the class ConnectionRequest method initConnection.

/**
 * Invoked to initialize HTTP headers, cookies etc.
 *
 * @param connection the connection object
 */
protected void initConnection(Object connection) {
    timeSinceLastUpdate = System.currentTimeMillis();
    CodenameOneImplementation impl = Util.getImplementation();
    impl.setPostRequest(connection, isPost());
    if (readTimeout > 0) {
        impl.setReadTimeout(connection, readTimeout);
    }
    if (insecure) {
        impl.setInsecure(connection, insecure);
    }
    impl.setConnectionId(connection, id);
    if (getUserAgent() != null) {
        impl.setHeader(connection, "User-Agent", getUserAgent());
    }
    if (getContentType() != null) {
        // UWP will automatically filter out the Content-Type header from GET requests
        // Historically, CN1 has always included this header even though it has no meaning
        // for GET requests.  it would be be better if CN1 did not include this header
        // with GET requests, but for backward compatibility, I'll leave it on as
        // the default, and add a property to turn it off.
        // -- SJH Sept. 15, 2016
        boolean shouldAddContentType = contentTypeSetExplicitly || Display.getInstance().getProperty("ConnectionRequest.excludeContentTypeFromGetRequests", "true").equals("false");
        if (isPost() || (getHttpMethod() != null && !"get".equals(getHttpMethod().toLowerCase()))) {
            shouldAddContentType = true;
        }
        if (shouldAddContentType) {
            impl.setHeader(connection, "Content-Type", getContentType());
        }
    }
    if (chunkedStreamingLen > -1) {
        impl.setChunkedStreamingMode(connection, chunkedStreamingLen);
    }
    if (!post && (cacheMode == CachingMode.MANUAL || cacheMode == CachingMode.SMART || cacheMode == CachingMode.OFFLINE_FIRST)) {
        String msince = Preferences.get("cn1MSince" + createRequestURL(), null);
        if (msince != null) {
            impl.setHeader(connection, "If-Modified-Since", msince);
        } else {
            String etag = Preferences.get("cn1Etag" + createRequestURL(), null);
            if (etag != null) {
                impl.setHeader(connection, "If-None-Match", etag);
            }
        }
    }
    if (userHeaders != null) {
        Enumeration e = userHeaders.keys();
        while (e.hasMoreElements()) {
            String k = (String) e.nextElement();
            String value = (String) userHeaders.get(k);
            impl.setHeader(connection, k, value);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) CodenameOneImplementation(com.codename1.impl.CodenameOneImplementation)

Example 7 with Filter

use of com.codename1.ui.ComponentSelector.Filter in project CodenameOne by codenameone.

the class ComponentSelector method parents.

/**
 * Creates new set of components consisting of all of the ancestors of components in this set which
 * match the provided selector.
 * @param selector The selector to filter the ancestors.
 * @return New set with ancestors of elements in current set.
 */
public ComponentSelector parents(String selector) {
    ComponentSelector matcher = new ComponentSelector(selector, new Label());
    LinkedHashSet<Component> matches = new LinkedHashSet<Component>();
    for (Component c : this) {
        Component parent = c.getParent();
        while (parent != null) {
            if (matcher.match(parent)) {
                matches.add(parent);
            }
            parent = parent.getParent();
        }
    }
    return matcher.addAll(matches, true);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SpanLabel(com.codename1.components.SpanLabel)

Example 8 with Filter

use of com.codename1.ui.ComponentSelector.Filter in project CodenameOne by codenameone.

the class ComponentSelector method parent.

/**
 * Creates a new set of components consisting of all of the parents of components in this set.
 * Only parent components matching the provided selector will be included in the set.
 * @param selector Selector to filter the parent components.
 * @return New set with parents of elements in current set.
 */
public ComponentSelector parent(String selector) {
    ComponentSelector matcher = new ComponentSelector(selector, new Label());
    LinkedHashSet<Component> matches = new LinkedHashSet<Component>();
    for (Component c : this) {
        Component parent = c.getParent();
        if (parent != null && matcher.match(parent)) {
            matches.add(parent);
        }
    }
    return matcher.addAll(matches, true);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SpanLabel(com.codename1.components.SpanLabel)

Example 9 with Filter

use of com.codename1.ui.ComponentSelector.Filter in project CodenameOne by codenameone.

the class AutoCompleteTextField method addPopup.

private void addPopup() {
    final Form f = getComponentForm();
    popup.removeAll();
    popup.setVisible(false);
    popup.setEnabled(false);
    filter(getText());
    final com.codename1.ui.List l = new com.codename1.ui.List(getSuggestionModel());
    if (getMinimumElementsShownInPopup() > 0) {
        l.setMinElementHeight(getMinimumElementsShownInPopup());
    }
    l.setScrollToSelected(false);
    l.setItemGap(0);
    for (ActionListener al : listeners) {
        l.addActionListener(al);
    }
    if (completionRenderer == null) {
        ((DefaultListCellRenderer<String>) l.getRenderer()).setShowNumbers(false);
    } else {
        l.setRenderer(completionRenderer);
    }
    l.setUIID("AutoCompleteList");
    l.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            pickedText = (String) l.getSelectedItem();
            setParentText(pickedText);
            fireActionEvent();
            // relaunch text editing if we are still editing
            if (Display.getInstance().isTextEditing(AutoCompleteTextField.this)) {
                Display.getInstance().editString(AutoCompleteTextField.this, getMaxSize(), getConstraint(), (String) l.getSelectedItem());
            }
            popup.setVisible(false);
            popup.setEnabled(false);
            f.repaint();
        }
    });
    byte[] units = popup.getStyle().getMarginUnit();
    if (units != null) {
        units[Component.LEFT] = Style.UNIT_TYPE_PIXELS;
        units[Component.TOP] = Style.UNIT_TYPE_PIXELS;
        popup.getAllStyles().setMarginUnit(units);
    }
    popup.getAllStyles().setMargin(LEFT, Math.max(0, getAbsoluteX()));
    int popupHeight = calcPopuupHeight(l);
    popup.setPreferredW(getWidth());
    popup.setHeight(popupHeight);
    popup.setWidth(getWidth());
    popup.addComponent(l);
    popup.layoutContainer();
    // block the reflow of this popup, which can cause painting problems
    dontCalcSize = true;
    if (f != null) {
        if (popup.getParent() == null) {
            Container lay = f.getLayeredPane(AutoCompleteTextField.this.getClass(), true);
            lay.setLayout(new LayeredLayout());
            Container wrapper = new Container();
            wrapper.add(popup);
            lay.addComponent(wrapper);
        }
        f.revalidate();
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) ActionListener(com.codename1.ui.events.ActionListener) ArrayList(java.util.ArrayList) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Example 10 with Filter

use of com.codename1.ui.ComponentSelector.Filter in project CodenameOne by codenameone.

the class AutoCompleteTextField method addPopup.

private void addPopup(boolean updateFilter) {
    final Form f = getComponentForm();
    popup.removeAll();
    popup.setVisible(false);
    popup.setEnabled(false);
    if (updateFilter) {
        filter(getText());
    }
    final com.codename1.ui.List l = new com.codename1.ui.List(getSuggestionModel());
    if (getMinimumElementsShownInPopup() > 0) {
        l.setMinElementHeight(getMinimumElementsShownInPopup());
    }
    l.setScrollToSelected(false);
    l.setItemGap(0);
    for (ActionListener al : listeners) {
        l.addActionListener(al);
    }
    if (completionRenderer == null) {
        ((DefaultListCellRenderer<String>) l.getRenderer()).setShowNumbers(false);
    } else {
        l.setRenderer(completionRenderer);
    }
    l.setUIID("AutoCompleteList");
    l.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (shouldShowPopup()) {
                pickedText = (String) l.getSelectedItem();
                setParentText(pickedText);
                fireActionEvent();
                // relaunch text editing if we are still editing
                if (Display.getInstance().isTextEditing(AutoCompleteTextField.this)) {
                    Display.getInstance().editString(AutoCompleteTextField.this, getMaxSize(), getConstraint(), (String) l.getSelectedItem());
                }
                popup.setVisible(false);
                popup.setEnabled(false);
                f.revalidate();
            }
        }
    });
    byte[] units = popup.getStyle().getMarginUnit();
    if (units != null) {
        units[Component.LEFT] = Style.UNIT_TYPE_PIXELS;
        units[Component.TOP] = Style.UNIT_TYPE_PIXELS;
        popup.getAllStyles().setMarginUnit(units);
    }
    int leftMargin = isRTL() ? Math.max(0, f.getWidth() - getAbsoluteX() - getWidth()) : Math.max(0, getAbsoluteX());
    popup.getAllStyles().setMargin(LEFT, leftMargin);
    int popupHeight = calcPopupHeight(l);
    popup.setPreferredW(getWidth());
    popup.setHeight(popupHeight);
    popup.setWidth(getWidth());
    popup.addComponent(l);
    popup.layoutContainer();
    // block the reflow of this popup, which can cause painting problems
    dontCalcSize = true;
    if (f != null) {
        if (popup.getParent() == null) {
            Container lay = f.getLayeredPane(AutoCompleteTextField.this.getClass(), true);
            lay.setLayout(new LayeredLayout());
            Container wrapper = new Container();
            wrapper.add(popup);
            lay.addComponent(wrapper);
        }
        f.revalidate();
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) ActionListener(com.codename1.ui.events.ActionListener) ArrayList(java.util.ArrayList) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Aggregations

SpanLabel (com.codename1.components.SpanLabel)4 java.util (java.util)4 RAD (com.codename1.rad.annotations.RAD)3 ActionEvent (com.codename1.ui.events.ActionEvent)3 ActionListener (com.codename1.ui.events.ActionListener)3 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 RADDoc (com.codename1.rad.annotations.RADDoc)2 AutoCompleteTextField (com.codename1.ui.AutoCompleteTextField)2 Form (com.codename1.ui.Form)2 Point (com.codename1.ui.geom.Point)2 BoxLayout (com.codename1.ui.layouts.BoxLayout)2 DefaultListModel (com.codename1.ui.list.DefaultListModel)2 FilenameFilter (java.io.FilenameFilter)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2