Search in sources :

Example 1 with TextField

use of com.codename1.ui.TextField in project charts by vaadin.

the class TListUi method loadTestClasses.

private void loadTestClasses(TListUi aThis) {
    if (testClassess != null) {
        return;
    }
    testClassess = new IndexedContainer();
    testClassess.addContainerProperty("name", String.class, "");
    testClassess.addContainerProperty("description", String.class, "");
    testClassess.addContainerProperty("package", String.class, "");
    listTestClasses(testClassess, "area");
    listTestClasses(testClassess, "columnandbar");
    listTestClasses(testClassess, "combinations");
    listTestClasses(testClassess, "container");
    listTestClasses(testClassess, "dynamic");
    listTestClasses(testClassess, "lineandscatter");
    listTestClasses(testClassess, "other");
    listTestClasses(testClassess, "pie");
    listTestClasses(testClassess, "themes");
    listTestClasses(testClassess, "librarydata");
    listTestClasses(testClassess, "timeline");
    listTestClasses(testClassess, "threed");
    listTestClasses(testClassess, "declarative");
    listTestClasses(testClassess, "dataprovider");
    Table table = new Table("Test cases", testClassess);
    table.addGeneratedColumn("name", new Table.ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            String name = (String) source.getItem(itemId).getItemProperty(columnId).getValue();
            String pack = (String) source.getItem(itemId).getItemProperty("package").getValue();
            Link link = new Link();
            link.setResource(new ExternalResource("/" + (pack != null ? pack + "/" : "") + name));
            link.setCaption(name);
            link.setTargetName("_new");
            return link;
        }
    });
    table.addGeneratedColumn("description", new Table.ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            String description = (String) source.getItem(itemId).getItemProperty(columnId).getValue();
            return new Label(description);
        }
    });
    table.setSizeFull();
    table.setColumnExpandRatio("description", 1);
    VerticalLayout verticalLayout = new VerticalLayout();
    TextField filter = new TextField();
    filter.addTextChangeListener(new TextChangeListener() {

        @Override
        public void textChange(TextChangeEvent event) {
            String text = event.getText();
            testClassess.removeAllContainerFilters();
            testClassess.addContainerFilter("name", text, true, false);
        }
    });
    verticalLayout.addComponent(filter);
    filter.focus();
    verticalLayout.addComponent(table);
    setContent(verticalLayout);
}
Also used : Table(com.vaadin.v7.ui.Table) IndexedContainer(com.vaadin.v7.data.util.IndexedContainer) Label(com.vaadin.ui.Label) ExternalResource(com.vaadin.server.ExternalResource) TextChangeEvent(com.vaadin.v7.event.FieldEvents.TextChangeEvent) VerticalLayout(com.vaadin.ui.VerticalLayout) TextField(com.vaadin.v7.ui.TextField) TextChangeListener(com.vaadin.v7.event.FieldEvents.TextChangeListener) Link(com.vaadin.ui.Link)

Example 2 with TextField

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

the class InstantUI method createEditUI.

/**
 * Creates editing UI for the given business object
 * @param bo the business object
 * @param autoCommit true if the bindings used should be auto-committed
 * @return a UI container that can be used to edit the business object
 */
public Container createEditUI(PropertyBusinessObject bo, boolean autoCommit) {
    Container cnt;
    if (Display.getInstance().isTablet()) {
        TableLayout tl = new TableLayout(1, 2);
        tl.setGrowHorizontally(true);
        cnt = new Container(tl);
    } else {
        cnt = new Container(BoxLayout.y());
    }
    UiBinding uib = new UiBinding();
    ArrayList<UiBinding.Binding> allBindings = new ArrayList<UiBinding.Binding>();
    for (PropertyBase b : bo.getPropertyIndex()) {
        if (isExcludedProperty(b)) {
            continue;
        }
        Class cls = (Class) b.getClientProperty("cn1$cmpCls");
        if (cls != null) {
            try {
                Component cmp = (Component) cls.newInstance();
                cmp.setName(b.getName());
                cnt.add(b.getLabel()).add(cmp);
                allBindings.add(uib.bind(b, cmp));
            } catch (Exception err) {
                Log.e(err);
                throw new RuntimeException("Custom property instant UI failed for " + b.getName() + " " + err);
            }
            continue;
        }
        String[] multiLabels = (String[]) b.getClientProperty("cn1$multiChceLbl");
        if (multiLabels != null) {
            // multi choice component
            final Object[] multiValues = (Object[]) b.getClientProperty("cn1$multiChceVal");
            if (multiLabels.length < 5) {
                // toggle buttons
                ButtonGroup bg = new ButtonGroup();
                RadioButton[] rbs = new RadioButton[multiLabels.length];
                cnt.add(b.getLabel());
                Container radioBox = new Container(new GridLayout(multiLabels.length));
                for (int iter = 0; iter < multiLabels.length; iter++) {
                    rbs[iter] = RadioButton.createToggle(multiLabels[iter], bg);
                    radioBox.add(rbs[iter]);
                }
                cnt.add(radioBox);
                allBindings.add(uib.bindGroup(b, multiValues, rbs));
            } else {
                Picker stringPicker = new Picker();
                stringPicker.setStrings(multiLabels);
                Map<Object, Object> m1 = new HashMap<Object, Object>();
                Map<Object, Object> m2 = new HashMap<Object, Object>();
                for (int iter = 0; iter < multiLabels.length; iter++) {
                    m1.put(multiLabels[iter], multiValues[iter]);
                    m2.put(multiValues[iter], multiLabels[iter]);
                }
                cnt.add(b.getLabel()).add(stringPicker);
                allBindings.add(uib.bind(b, stringPicker, new UiBinding.PickerAdapter<Object>(new UiBinding.MappingConverter(m1), new UiBinding.MappingConverter(m2))));
            }
            continue;
        }
        Class t = b.getGenericType();
        if (t != null) {
            if (t == Boolean.class) {
                CheckBox cb = new CheckBox();
                uib.bind(b, cb);
                cnt.add(b.getLabel()).add(cb);
                continue;
            }
            if (t == Date.class) {
                Picker dp = new Picker();
                dp.setType(Display.PICKER_TYPE_DATE);
                uib.bind(b, dp);
                cnt.add(b.getLabel()).add(dp);
                continue;
            }
        }
        TextField tf = new TextField();
        tf.setConstraint(getTextFieldConstraint(b));
        uib.bind(b, tf);
        cnt.add(b.getLabel()).add(tf);
    }
    cnt.putClientProperty("cn1$iui-binding", uib.createGroupBinding(allBindings));
    return cnt;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Container(com.codename1.ui.Container) GridLayout(com.codename1.ui.layouts.GridLayout) Picker(com.codename1.ui.spinner.Picker) TextField(com.codename1.ui.TextField) Component(com.codename1.ui.Component) TableLayout(com.codename1.ui.table.TableLayout) RadioButton(com.codename1.ui.RadioButton) ButtonGroup(com.codename1.ui.ButtonGroup) CheckBox(com.codename1.ui.CheckBox)

Example 3 with TextField

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

the class CodenameOneInputConnection method commitText.

@Override
public boolean commitText(CharSequence text, int newCursorPosition) {
    if (Display.isInitialized() && Display.getInstance().getCurrent() != null) {
        Component txtCmp = Display.getInstance().getCurrent().getFocused();
        if (txtCmp != null && txtCmp instanceof TextField) {
            TextField t = (TextField) txtCmp;
            String textFieldText = t.getText();
            int cursorPosition = t.getCursorPosition();
            StringBuilder sb = new StringBuilder(textFieldText);
            if (text.equals("\n")) {
            // System.out.println("hello backslash");
            }
            if (composingText.length() > 0) {
                if (text.equals(" ")) {
                    return commitText(composingText + " ", newCursorPosition);
                }
                sb.replace(sb.length() - composingText.length(), sb.length(), text.toString());
                composingText = "";
            } else {
                sb.insert(cursorPosition, text);
            }
            t.setText(sb.toString());
            t.setCursorPosition(cursorPosition + text.length());
            updateExtractedText();
        }
    }
    return super.commitText(text, newCursorPosition);
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) TextField(com.codename1.ui.TextField) Component(com.codename1.ui.Component)

Example 4 with TextField

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

the class CodenameOneInputConnection method getTextAfterCursor.

@Override
public CharSequence getTextAfterCursor(int length, int flags) {
    if (Display.isInitialized() && Display.getInstance().getCurrent() != null) {
        Component txtCmp = Display.getInstance().getCurrent().getFocused();
        if (txtCmp != null && txtCmp instanceof TextField) {
            String txt = ((TextField) txtCmp).getText();
            int position = ((TextField) txtCmp).getCursorPosition();
            if (position > -1 && position < txt.length()) {
                return txt.subSequence(position, txt.length() - 1);
            }
        }
    }
    return "";
}
Also used : TextField(com.codename1.ui.TextField) Component(com.codename1.ui.Component)

Example 5 with TextField

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

the class CodenameOneInputConnection method extractTextInternal.

boolean extractTextInternal(ExtractedTextRequest request, ExtractedText outText) {
    Component txtCmp = Display.getInstance().getCurrent().getFocused();
    if (txtCmp != null && txtCmp instanceof TextField) {
        String txt = ((TextField) txtCmp).getText();
        int partialStartOffset = -1;
        int partialEndOffset = -1;
        final CharSequence content = txt;
        if (content != null) {
            final int N = content.length();
            outText.partialStartOffset = outText.partialEndOffset = -1;
            partialStartOffset = 0;
            partialEndOffset = N;
            if ((request.flags & InputConnection.GET_TEXT_WITH_STYLES) != 0) {
                outText.text = content.subSequence(partialStartOffset, partialEndOffset);
            } else {
                outText.text = TextUtils.substring(content, partialStartOffset, partialEndOffset);
            }
            outText.flags = 0;
            outText.flags |= ExtractedText.FLAG_SINGLE_LINE;
            outText.startOffset = 0;
            outText.selectionStart = Selection.getSelectionStart(content);
            outText.selectionEnd = Selection.getSelectionEnd(content);
            return true;
        }
    }
    return false;
}
Also used : TextField(com.codename1.ui.TextField) Component(com.codename1.ui.Component)

Aggregations

TextField (com.codename1.ui.TextField)19 Component (com.codename1.ui.Component)16 TextArea (com.codename1.ui.TextArea)10 Button (com.codename1.ui.Button)8 Container (com.codename1.ui.Container)6 Label (com.codename1.ui.Label)6 RadioButton (com.codename1.ui.RadioButton)6 Form (com.codename1.ui.Form)5 ActionListener (com.codename1.ui.events.ActionListener)5 BorderLayout (com.codename1.ui.layouts.BorderLayout)5 CheckBox (com.codename1.ui.CheckBox)4 ActionEvent (com.codename1.ui.events.ActionEvent)4 BoxLayout (com.codename1.ui.layouts.BoxLayout)4 FlowLayout (com.codename1.ui.layouts.FlowLayout)3 Paint (android.graphics.Paint)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 List (com.codename1.ui.List)2 Slider (com.codename1.ui.Slider)2 SelectionListener (com.codename1.ui.events.SelectionListener)2 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)2