com.codename1.ui.TextArea Java Examples

The following examples show how to use com.codename1.ui.TextArea. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextEditUtil.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Opens onscreenkeyboard for the next textfield. The method works in EDT if
 * needed.
 */
public static void editNextTextArea() {
    Runnable task = new Runnable() {

        public void run() {
            
            Component next = getNextEditComponent();
            if (next != null) {
                if (!(next instanceof TextArea)) {
                    IOSImplementation.foldKeyboard();
                }
                next.requestFocus();
                next.startEditingAsync();
            } else {
                IOSImplementation.foldKeyboard();
            }
        }
    };
    Display.getInstance().callSerially(task);
}
 
Example #2
Source File: InPlaceEditView.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
static void scrollActiveTextfieldToVisible() {
    if (isEditing() && sInstance != null) {
        Runnable r = new Runnable() {

            @Override
            public void run() {
                if (sInstance != null && sInstance.mEditText != null && sInstance.mEditText.mTextArea != null) {
                    TextArea ta = sInstance.mEditText.mTextArea;
                    if (isScrollableParent(ta)) {
                        ta.scrollRectToVisible(0, 0, ta.getWidth(), ta.getHeight(), ta);
                        ta.getComponentForm().getAnimationManager().flushAnimation(new Runnable() {

                            @Override
                            public void run() {
                                reLayoutEdit();
                            }
                            
                        });
                    }
                }
            }
            
        };
    }
}
 
Example #3
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @inheritDoc
 */
public void editString(Component cmp, int maxSize, int constraint, String text, int keyCode) {
    UIManager m = UIManager.getInstance();
    CONFIRM_COMMAND = new Command(m.localize("ok", "OK"), Command.OK, 1);
    CANCEL_COMMAND = new Command(m.localize("cancel", "Cancel"), Command.CANCEL, 2);
    if(mid.getAppProperty("forceBackCommand") != null) {
        canvas.addCommand(MIDP_BACK_COMMAND);
    }
    currentTextBox = new TextBox("", "", maxSize, TextArea.ANY);
    currentTextBox.setCommandListener((CommandListener)canvas);
    currentTextBox.addCommand(CONFIRM_COMMAND);
    currentTextBox.addCommand(CANCEL_COMMAND);
    currentTextComponent = cmp;
    currentTextBox.setMaxSize(maxSize);
    currentTextBox.setString(text);
    currentTextBox.setConstraints(constraint);
    display.setCurrent(currentTextBox);
    ((C)canvas).setDone(false);
    Display.getInstance().invokeAndBlock(((C)canvas));
}
 
Example #4
Source File: InPlaceEditView.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
TextAreaData(TextArea ta) {

            absoluteX = ta.getAbsoluteX();
            absoluteY = ta.getAbsoluteY();
            scrollX = ta.getScrollX();
            scrollY = ta.getScrollY();
            Style s = ta.getStyle();
            paddingTop = s.getPaddingTop();
            paddingLeft = s.getPaddingLeft(ta.isRTL());
            paddingRight = s.getPaddingRight(ta.isRTL());
            paddingBottom = s.getPaddingBottom();
            isTextField = (ta instanceof TextField);
            verticalAlignment = ta.getVerticalAlignment();
            height = ta.getHeight();
            width = ta.getWidth();
            fontHeight = s.getFont().getHeight();
            textArea = ta;
            isRTL = ta.isRTL();
            nextDown = textArea.getComponentForm().getNextComponent(textArea);
            isSingleLineTextArea = textArea.isSingleLineTextArea();
            hint = ta.getHint();
            nativeHintBool = textArea.getUIManager().isThemeConstant("nativeHintBool", false);
            nativeFont = s.getFont().getNativeFont();
            fgColor = s.getFgColor();
            maxSize = ta.getMaxSize();
        }
 
Example #5
Source File: Validator.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the value of the given component, this can be overriden to add support for custom built components
 * 
 * @param cmp the component
 * @return  the object value
 */
protected Object getComponentValue(Component cmp) {
    if(cmp instanceof InputComponent) {
        cmp = ((InputComponent)cmp).getEditor();
    }
    if(cmp instanceof TextArea) {
        return ((TextArea)cmp).getText();
    }
    if(cmp instanceof Picker) {
        return ((Picker)cmp).getValue();
    }
    if(cmp instanceof RadioButton || cmp instanceof CheckBox) {
        if(((Button)cmp).isSelected()) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
    if(cmp instanceof Label) {
        return ((Label)cmp).getText();
    }
    if(cmp instanceof List) {
        return ((List)cmp).getSelectedItem();
    }
    return null;
}
 
Example #6
Source File: AndroidKeyboard.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void showKeyboard(boolean show) {
//        manager.restartInput(myView);
//        if (keyboardShowing != show) {
//            manager.toggleSoftInputFromWindow(myView.getWindowToken(), 0, 0);
//            this.keyboardShowing = show;
//        }
        System.out.println("showKeyboard " + show);
        Form current = Display.getInstance().getCurrent();
        if(current != null){
            Component cmp = current.getFocused();
            if(cmp != null && cmp instanceof TextArea){
                TextArea txt = (TextArea)cmp;
                if(show){
                    Display.getInstance().editString(txt, txt.getMaxSize(), txt.getConstraint(), txt.getText(), 0);
                }
            }
        }else{
            InPlaceEditView.endEdit();
        }
//        if(!show){
//            impl.saveTextEditingState();
//        }
    }
 
Example #7
Source File: RSSReader.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
private Container createRendererContainer() {
    Container entries = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    entries.setUIID("RSSEntry");
    Label title = new Label();
    title.setName("title");
    title.setUIID("RSSTitle");
    entries.addComponent(title);
    TextArea description = new TextArea(2, 30);
    description.setGrowByContent(false);
    description.setName("details");
    description.setUIID("RSSDescription");
    description.setScrollVisible(false);
    entries.addComponent(description);
    if(iconPlaceholder != null) {
        Container wrap = new Container(new BorderLayout());
        wrap.addComponent(BorderLayout.CENTER, entries);
        Label icon = new Label();
        icon.setIcon(iconPlaceholder);
        icon.setUIID("RSSIcon");
        icon.setName("icon");
        wrap.addComponent(BorderLayout.WEST, icon);
        entries = wrap;
    }
    return entries;
}
 
Example #8
Source File: UiBinding.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Binds the given property to the component using default adapters
 * @param prop the property
 * @param cmp the component
 * @return a binding object that allows us to toggle auto commit mode, commit/rollback and unbind
 */
public Binding bind(final PropertyBase prop, final Component cmp) {
    ObjectConverter cnv = getPropertyConverter(prop);
    if(cmp instanceof TextArea) {
        return bind(prop, cmp, new TextAreaAdapter(cnv));
    }
    if(cmp instanceof TextComponent) {
        return bind(prop, cmp, new TextComponentAdapter(cnv));
    }
    if(cmp instanceof CheckBox) {
        return bind(prop, cmp, new CheckBoxRadioSelectionAdapter(cnv));
    }
    if(cmp instanceof RadioButton) {
        return bind(prop, cmp, new CheckBoxRadioSelectionAdapter(cnv));
    }
    if(cmp instanceof Picker) {
        return bind(prop, cmp, new PickerAdapter(cnv, ((Picker)cmp).getType()));
    }
    throw new RuntimeException("Unsupported binding type: " + cmp.getClass().getName());
}
 
Example #9
Source File: Flickr.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
public static Form createMainForm() {
    Form main = new Form("Flickr tags");
    main.setLayout(new BorderLayout());
    Toolbar bar = new Toolbar();
    main.setToolBar(bar);
    addCommandsToToolbar(bar);

    TextArea desc = new TextArea();
    desc.setText("This is a Flickr tags demo, the demo uses the Toolbar to arrange the Form Commands.\n\n"
            + "Select \"Cats\" to view the latest photos that were tagged as \"Cats\".\n\n"
            + "Select \"Dogs\" to view the latest photos that were tagged as \"Dogs\".\n\n"
            + "Select \"Search\" to enter your own tags for search.");
    desc.setEditable(false);

    main.addComponent(BorderLayout.CENTER, desc);
    return main;
}
 
Example #10
Source File: GenericListCellRenderer.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
private void findComponentsOfInterest(Component cmp, ArrayList dest) {
    if(cmp instanceof Container) {
        Container c = (Container)cmp;
        int count = c.getComponentCount();
        for(int iter = 0 ; iter < count ; iter++) {
            findComponentsOfInterest(c.getComponentAt(iter), dest);
        }
        return;
    }
    // performance optimization for fixed images in lists
    if(cmp.getName() != null) {
        if(cmp instanceof Label) {
            Label l = (Label)cmp;
            if(l.getName().toLowerCase().endsWith("fixed") && l.getIcon() != null) {
                l.getIcon().lock();
            }
            dest.add(cmp);
            return;
        }
        if(cmp instanceof TextArea) {
            dest.add(cmp);
            return;
        }
    }
}
 
Example #11
Source File: TextFieldCaretColorTest2780.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.add(new Label("Hi World"));
    TextField tf1 = new TextField();
    TextField tf2 = new TextField();
    TextArea ta1 = new TextArea();
    TextArea ta2 = new TextArea();
    ta1.setRows(5);
    ta2.setRows(5);
    
    $(tf2, ta2).selectAllStyles()
            .setBgColor(0x0000ff)
            .setFgColor(0xffffff)
            .setBgTransparency(0xff)
            .setBackgroundType(Style.BACKGROUND_NONE);
    
    hi.addAll(tf1, tf2, ta1, ta2);
    hi.show();
}
 
Example #12
Source File: HTMLForm.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Adds an input field to the form, note that unlike adding to a Codename One form here the components are added logically only to query them for their value on submit.
 * 
 * @param key The input field's name/id
 * @param input The field itself (either the component or the value for a hidden field)
 * @param defaultValue The default value of the field (or null if none)
 */
void addInput(String key,Object input,String defaultValue) {
    if (defaultValue!=null) { // Default values are added even before the key is checked, since even if the input component is unnamed, the form still needs to be able to reset it
        defaultValues.put(input,defaultValue);
    }

    if (key==null) {
        return; //no id
    }
    comps.put(key,input);
    if ((htmlC.getHTMLCallback()!=null) && (input instanceof TextArea)) {
        String autoVal=htmlC.getHTMLCallback().getAutoComplete(htmlC, action, key);
        if (autoVal!=null) {
            ((TextArea)input).setText(autoVal);
        }
    }
}
 
Example #13
Source File: TestUtils.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Finds a component with the given name, works even with UI's that weren't created with the GUI builder
 * @param text the text of the label/button
 * @return the component with the given label text within the tree
 */
private static TextArea findTextAreaText(Container root, String text) {
    int count = root.getComponentCount();
    for(int iter = 0 ; iter < count ; iter++) {
        Component c = root.getComponentAt(iter);
        if(c instanceof TextArea) {
            String n = ((TextArea)c).getText();
            if(n != null && n.equals(text)) {
                return (TextArea)c;
            }
            continue;
        }
        if(c instanceof Container) {
            TextArea l = findTextAreaText((Container)c, text);
            if(l != null) {
                return l;
            }
        }
    }
    return null;
}
 
Example #14
Source File: Log.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Places a form with the log as a TextArea on the screen, this method can
 * be attached to appear at a given time or using a fixed global key. Using
 * this method might cause a problem with further log output
 * @deprecated this method is an outdated method that's no longer supported
 */
public static void showLog() {
    try {
        String text = getLogContent();
        TextArea area = new TextArea(text, 5, 20);
        Form f = new Form("Log");
        f.setScrollable(false);
        final Form current = Display.getInstance().getCurrent();
        Command back = new Command("Back") {
            public void actionPerformed(ActionEvent ev) {
                current.show();
            }
        };
        f.addCommand(back);
        f.setBackCommand(back);
        f.setLayout(new BorderLayout());
        f.addComponent(BorderLayout.CENTER, area);
        f.show();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
Example #15
Source File: SpanButton.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor accepting default text
 */
public SpanButton(String txt) {
    setUIID("Button");
    setLayout(new BorderLayout());
    text = new TextArea(getUIManager().localize(txt, txt));
    text.setColumns(100);
    text.setUIID("Button");
    text.setGrowByContent(true);
    text.setEditable(false);
    text.setFocusable(false);
    text.setActAsLabel(true);
    setFocusable(true);
    removeBackground(text.getUnselectedStyle());
    removeBackground(text.getSelectedStyle());
    removeBackground(text.getPressedStyle());
    removeBackground(text.getDisabledStyle());
    actualButton = new Button();
    actualButton.setUIID("icon");
    addComponent(BorderLayout.WEST, actualButton);
    Container center = BoxLayout.encloseYCenter(text);
    center.getStyle().setMargin(0, 0, 0, 0);
    center.getStyle().setPadding(0, 0, 0, 0);
    addComponent(BorderLayout.CENTER, center);
    setLeadComponent(actualButton);
    updateGap();
}
 
Example #16
Source File: ClearableTextField.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Wraps the given text field with a UI that will allow us to clear it
 * @param tf the text field
 * @param iconSize size in millimeters for the clear icon, -1 for default size
 * @return a Container that should be added to the UI instead of the actual text field
 */
public static ClearableTextField wrap(final TextArea tf, float iconSize) {
    ClearableTextField cf = new ClearableTextField();
    Button b = new Button("", tf.getUIID());
    if(iconSize > 0) {
        FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR, iconSize);
    } else {
        FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR);
    }
    removeCmpBackground(tf);
    removeCmpBackground(b);
    cf.setUIID(tf.getUIID());
    cf.add(BorderLayout.CENTER, tf);
    cf.add(BorderLayout.EAST, b);
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            tf.stopEditing();
            tf.setText("");
            tf.startEditingAsync();
        }
    });
    return cf;        
}
 
Example #17
Source File: TestUtils.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Asserts that we have a TextArea with the a text starting with the given text and with the given name
     * @param name the name of the TextArea
     * @param text the prefix to search for in the TextArea
     */
    public static void assertTextAreaStartingWith(String name, String text) {
        if(verbose) {
            log("assertTextAreaStartingWith(" + name + ", " + text + ")");
        }
        TextArea l = (TextArea)findByName(name);
        assertBool(l != null, "Null area " + text);
        assertBool(l.getText().startsWith(text), "assertTextArea: \"" + l.getText() + "\" is not starting with: \"" + text + "\"");
}
 
Example #18
Source File: InstantUI.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The text field constraint for the property. notice that some constraints 
 * are implicit unless set manually e.g. numeric for numbers or password for fields with password 
 * in the name
 * @param p the property
 * @return the constraint matching this property
 */
public int getTextFieldConstraint(PropertyBase p) {
    Integer v = (Integer)p.getClientProperty("cn1$tconstraint");
    if(v != null) {
        return v;
    }
    
    Class t = p.getGenericType();
    if(t != null) {
        if(t == Integer.class || t == Long.class || t == Short.class || t == Byte.class) {
            return TextArea.NUMERIC;
        }
        if(t == Double.class || t == Float.class) {
            return TextArea.DECIMAL;
        }
    }
    String n = p.getName().toLowerCase();
    if(n.indexOf("password") > -1) {
        return TextArea.PASSWORD;
    }
    if(n.indexOf("url") > -1 || n.indexOf("website") > -1 || n.indexOf("blog") > -1) {
        return TextArea.URL;
    }
    if(n.indexOf("email") > -1) {
        return TextArea.EMAILADDR;
    }
    if(n.indexOf("phone") > -1 || n.indexOf("mobile") > -1) {
        return TextArea.PHONENUMBER;
    }
    return TextArea.ANY;
}
 
Example #19
Source File: InPlaceEditView.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prepare an int-to-int map that maps Codename One input-types to
 * Android input types
 */
private void initInputTypeMap() {
    mInputTypeMap.append(TextArea.ANY, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    mInputTypeMap.append(TextArea.DECIMAL, InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
    mInputTypeMap.append(TextArea.EMAILADDR, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    mInputTypeMap.append(TextArea.INITIAL_CAPS_SENTENCE, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    mInputTypeMap.append(TextArea.INITIAL_CAPS_WORD, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    mInputTypeMap.append(TextArea.UPPERCASE, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
    mInputTypeMap.append(TextArea.NON_PREDICTIVE, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
    mInputTypeMap.append(TextArea.NUMERIC, InputType.TYPE_CLASS_NUMBER);
    mInputTypeMap.append(TextArea.PASSWORD, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    mInputTypeMap.append(TextArea.PHONENUMBER, InputType.TYPE_CLASS_PHONE);
    mInputTypeMap.append(TextArea.URL, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    
}
 
Example #20
Source File: HTMLEventsListener.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Registeres the specified component/element duo to listen to all available events
 *
 * @param cmp The actual component
 * @param element The element representing the component
 */
void registerComponent(final Component cmp,final HTMLElement element) {
    comps.put(cmp, element);
    cmp.addFocusListener(this);
    if (cmp instanceof Button) { // catches Button, CheckBox, RadioButton
        ((Button)cmp).addActionListener(this);
    } else if (cmp instanceof List) { // catches ComboBox
        final List list = (List)cmp;
        list.addActionListener(this);
        SelectionListener sl = new SelectionListener() { // We create a listener and not listen ourself since the listener's method does not pass the event origin, so we need to make one listener per component
            public void selectionChanged(int oldSelected, int newSelected) {
                if (htmlC.getHTMLCallback()!=null) {
                    htmlC.getHTMLCallback().selectionChanged(oldSelected, newSelected, htmlC, list, element);
                }
            }
        };
        list.addSelectionListener(sl);
        listeners.put(cmp, sl);

    } else if (cmp instanceof TextArea) {
        ((TextArea)cmp).addActionListener(this);
        if (cmp instanceof TextField) {
            final TextField tf = (TextField)cmp;
            DataChangedListener dcl = new DataChangedListener() { // We create a listener and not listen ourself since the listener's method does not pass the event origin, so we need to make one listener per component
                public void dataChanged(int type, int index) {
                    element.setAttributeById(HTMLElement.ATTR_VALUE, tf.getText());
                    if (htmlC.getHTMLCallback()!=null) {
                        htmlC.getHTMLCallback().dataChanged(type, index, htmlC, tf, element);
                    }
                }
            };
            tf.addDataChangedListener(dcl);
            listeners.put(cmp, dcl);
        }
    }
}
 
Example #21
Source File: PickerUnresponsiveTest3051.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi110 = new Form("Welcome", new BorderLayout());
    TextField textField1 = new TextField("TextField1", "", 20,  TextArea.ANY);

    TextField textField2 = new TextField("TextField2", "", 20,  TextArea.ANY);
    hi110.add(BorderLayout.NORTH, textField1);
    hi110.add(BorderLayout.CENTER, textField2);
    hi110.add(BorderLayout.SOUTH, new Picker());
    hi110.show();
}
 
Example #22
Source File: JavascriptScrollingTest.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
protected void onTest() {
	Dialog dlg = new Dialog("Test");
	dlg.setLayout(new BorderLayout());
	TextArea taMsg = new TextArea();
	dlg.add(BorderLayout.CENTER, taMsg);
	Button btnOk = new Button("Ok");
	btnOk.addActionListener(e -> dlg.dispose());
	dlg.add(BorderLayout.SOUTH, btnOk);
	taMsg.setText("This is a test Message");
	taMsg.setGrowLimit(-1);
	taMsg.getAllStyles().setAlignment(TextArea.LEFT);
	dlg.show();

}
 
Example #23
Source File: InPlaceEditView.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private int makeNonPredictive(int codenameOneInputType, int inputType) {
    if (isNonPredictive(codenameOneInputType)) {
        inputType = inputType | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
        if (!hasConstraint(codenameOneInputType, TextArea.PASSWORD)) {
            inputType = inputType | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
        }
    }
    return inputType;
}
 
Example #24
Source File: HTMLComponent.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets an input-required restriction on the given input field
 * 
 * @param inputField The TextArea to place the input required restriction on
 * @param inputRequired true if input is required (i.e. emptyok=false), false if input is not required (i.e. emptyok=true)
 */
void setInputRequired(TextArea inputField,boolean inputRequired) {
    if (SUPPORT_INPUT_FORMAT) {
        HTMLForm form=(HTMLForm)textfieldsToForms.get(inputField);
        if (form!=null) {
            if (inputRequired) { // Note that input-required is the reverse from emptyok...
                form.setEmptyOK(inputField, false);
            } else {
                form.setEmptyOK(inputField, true);
            }
        }
    }
}
 
Example #25
Source File: TestUtils.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the text for the given component
 * @param name the name of the component
 * @param text the text to set
 */
public static void setText(String name, String text) {
    if(verbose) {
        log("setText(" + name + ", " + text + ")");
    }
    Component c = findByName(name);
    if(c instanceof Label) {
        ((Label)c).setText(text);
        return;
    }
    ((TextArea)c).setText(text);
    Display.getInstance().onEditingComplete(c, text);

}
 
Example #26
Source File: TestUtils.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the text for the given component
 * @param path the path to the component
 * @param text the text to set
 */
public static void setText(int[] path, String text) {
    if(verbose) {
        log("setText(" + toString(path) + ", " + text + ")");
    }
    Component c = getComponentByPath(path);
    if(c instanceof Label) {
        ((Label)c).setText(text);
        return;
    }
    ((TextArea)c).setText(text);
}
 
Example #27
Source File: AndroidTextFieldTests2905.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void start() {
    if(current != null){
        current.show();
        return;
    }
    Form hi = new Form("Hi World", BoxLayout.y());
    hi.add(new TextField("", "Type here (TextArea.ANY)", 80, TextArea.ANY));
    hi.add(new TextField("", "Type here (TextArea.SENSITIVE)", 80, TextArea.SENSITIVE));
    hi.add(new TextField("", "Type here (TextArea.NON_PREDICTIVE)", 80, TextArea.NON_PREDICTIVE));
    hi.add(new TextField("", "Type here (TextArea.UPPERCASE)", 80, TextArea.UPPERCASE));
    hi.show();
}
 
Example #28
Source File: TestUtils.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Asserts that we have a TextArea with the given text and the given name
     * @param name the name of the TextArea
     * @param text the text of the TextArea
     */
    public static void assertTextArea(String name, String text) {
        if(verbose) {
            log("assertTextArea(" + name + ", " + text + ")");
        }
        TextArea l = (TextArea)findByName(name);
        assertBool(l != null, "Null area " + text);
        assertBool(l.getText().equals(text), "assertTextArea: " + l.getText() + " != " + text);
}
 
Example #29
Source File: TestUtils.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Asserts that we have a TextArea with the a text contains the given text and with the given name
     * @param name the name of the TextArea
     * @param text the sequence to search for in the TextArea
     */
    public static void assertTextAreaContaining(String name, String text) {
        if(verbose) {
            log("assertTextAreaContaining(" + name + ", " + text + ")");
        }
        TextArea l = (TextArea)findByName(name);
        assertBool(l != null, "Null area " + text);
        assertBool(l.getText().indexOf(text) > -1, "assertTextArea: \"" + l.getText() + "\" is not containing: \"" + text + "\"");
}
 
Example #30
Source File: DefaultLookAndFeel.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Similar to getText() but works properly with password fields
 */
protected String getTextFieldString(TextArea ta) {
    String txt = ta.getText();
    String text;
    if(ta.isSingleLineTextArea()){
        text = txt;
    }else{
        text = (String) ta.getTextAt(ta.getCursorY());
        if(ta.getCursorPosition() + text.length() < txt.length()){
            char c = txt.charAt(ta.getCursorPosition() + text.length());
            if(c == '\n'){
                text += "\n";
            }else if(c == ' '){
                text += " ";            
            }
        }
    }
    
    String displayText = "";
    if ((ta.getConstraint() & TextArea.PASSWORD) != 0) {
        // show the last character in a password field
        if (ta.isPendingCommit()) {
            if (text.length() > 0) {
                int tlen = text.length();
                for (int j = 0; j < tlen - 1; j++) {
                    displayText += passwordChar;
                }
                displayText += text.charAt(text.length() - 1);
            }
        } else {
            for (int j = 0; j < text.length(); j++) {
                displayText += passwordChar;
            }
        }
    } else {
        displayText = text;
    }
    return displayText;
}