Search in sources :

Example 36 with TextArea

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

the class BooleanContainer method editNextTextArea.

/**
 * 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) {
                    TextArea text = (TextArea) next;
                    text.requestFocus();
                    Display.getInstance().editString(next, text.getMaxSize(), text.getConstraint(), text.getText(), 0);
                }
            }
        }
    };
    Display.getInstance().callSerially(task);
}
Also used : TextArea(com.codename1.ui.TextArea) Component(com.codename1.ui.Component)

Example 37 with TextArea

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

the class IOSImplementation method updateNativeTextEditorFrame.

private static void updateNativeTextEditorFrame() {
    if (instance.currentEditing != null) {
        TextArea cmp = instance.currentEditing;
        final Style stl = cmp.getStyle();
        final boolean rtl = UIManager.getInstance().getLookAndFeel().isRTL();
        instance.doNotHideTextEditorSemaphore++;
        try {
            instance.currentEditing.requestFocus();
        } finally {
            instance.doNotHideTextEditorSemaphore--;
        }
        int x = cmp.getAbsoluteX() + cmp.getScrollX();
        int y = cmp.getAbsoluteY() + cmp.getScrollY();
        int w = cmp.getWidth();
        int h = cmp.getHeight();
        int pt = stl.getPaddingTop();
        int pb = stl.getPaddingBottom();
        int pl = stl.getPaddingLeft(rtl);
        int pr = stl.getPaddingRight(rtl);
        /*
            if(cmp.isSingleLineTextArea()) {
                switch(cmp.getVerticalAlignment()) {
                    case TextArea.CENTER:
                        if(h > cmp.getPreferredH()) {
                            y += (h / 2 - cmp.getPreferredH() / 2);
                        }
                        break;
                    case TextArea.BOTTOM:
                        if(h > cmp.getPreferredH()) {
                            y += (h - cmp.getPreferredH());
                        }
                        break;
                }
            }
            */
        int maxH = Display.getInstance().getDisplayHeight() - nativeInstance.getVKBHeight();
        if (h > maxH) {
            // For text areas, we don't want the keyboard to cover part of the
            // typing region.  So we will try to size the component to
            // to only go up to the top edge of the keyboard
            // that should allow the OS to enable scrolling properly.... at least
            // in theory.
            h = maxH;
        }
        nativeInstance.resizeNativeTextView(x, y, w, h, pt, pr, pb, pl);
    }
}
Also used : TextArea(com.codename1.ui.TextArea) Style(com.codename1.ui.plaf.Style)

Example 38 with TextArea

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

the class IOSImplementation method editString.

public void editString(final Component cmp, final int maxSize, final int constraint, final String text, final int i) {
    // The very first time we try to edit a string, let's determine if the
    // system default is to do async editing.  If the system default
    // is not yet set, we set it here, and it will be used as the default from now on
    // We do this because the nativeInstance.isAsyncEditMode() value changes
    // to reflect the currently edited field so it isn't a good way to keep a
    // system default.
    pendingEditingText = false;
    String defaultAsyncEditingSetting = Display.getInstance().getProperty("ios.VKBAlwaysOpen", null);
    if (defaultAsyncEditingSetting == null) {
        defaultAsyncEditingSetting = nativeInstance.isAsyncEditMode() ? "true" : "false";
        Display.getInstance().setProperty("ios.VKBAlwaysOpen", defaultAsyncEditingSetting);
    }
    boolean asyncEdit = "true".equals(defaultAsyncEditingSetting) ? true : false;
    try {
        if (currentEditing != cmp && currentEditing != null && currentEditing instanceof TextArea) {
            Display.getInstance().onEditingComplete(currentEditing, ((TextArea) currentEditing).getText());
            currentEditing = null;
            callHideTextEditor();
            if (nativeInstance.isAsyncEditMode()) {
                nativeInstance.setNativeEditingComponentVisible(false);
            }
            synchronized (EDITING_LOCK) {
                EDITING_LOCK.notify();
            }
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    pendingEditingText = true;
                    Display.getInstance().editString(cmp, maxSize, constraint, text, i);
                }
            });
            return;
        }
        if (cmp.isFocusable() && !cmp.hasFocus()) {
            doNotHideTextEditorSemaphore++;
            try {
                cmp.requestFocus();
            } finally {
                doNotHideTextEditorSemaphore--;
            }
            // of our upcoming field.
            if (isAsyncEditMode()) {
                // flush the EDT so the focus will work...
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        pendingEditingText = true;
                        Display.getInstance().editString(cmp, maxSize, constraint, text, i);
                    }
                });
                return;
            }
        }
        // Check if the form has any setting for asyncEditing that should override
        // the application defaults.
        Form parentForm = cmp.getComponentForm();
        if (parentForm == null) {
            // Log.p("Attempt to edit text area that is not on a form.  This is not supported");
            return;
        }
        if (parentForm.getClientProperty("asyncEditing") != null) {
            Object async = parentForm.getClientProperty("asyncEditing");
            if (async instanceof Boolean) {
                asyncEdit = ((Boolean) async).booleanValue();
            // Log.p("Form overriding asyncEdit due to asyncEditing client property: "+asyncEdit);
            }
        }
        if (parentForm.getClientProperty("ios.asyncEditing") != null) {
            Object async = parentForm.getClientProperty("ios.asyncEditing");
            if (async instanceof Boolean) {
                asyncEdit = ((Boolean) async).booleanValue();
            // Log.p("Form overriding asyncEdit due to ios.asyncEditing client property: "+asyncEdit);
            }
        }
        // editing - and should instead revert to legacy editing mode.
        if (asyncEdit && !parentForm.isFormBottomPaddingEditingMode()) {
            Container p = cmp.getParent();
            // A crude estimate of how far the component needs to be able to scroll to make
            // async editing viable.  We start with half-way down the screen.
            int keyboardClippingThresholdY = Display.getInstance().getDisplayWidth() / 2;
            while (p != null) {
                if (Accessor.scrollableYFlag(p) && p.getAbsoluteY() < keyboardClippingThresholdY) {
                    break;
                }
                p = p.getParent();
            }
            // no scrollabel parent automatically configure the text field for legacy mode
            // nativeInstance.setAsyncEditMode(p != null);
            asyncEdit = p != null;
        // Log.p("Overriding asyncEdit due to form scrollability: "+asyncEdit);
        } else if (parentForm.isFormBottomPaddingEditingMode()) {
            // If form uses bottom padding mode, then we will always
            // use async edit (unless the field explicitly overrides it).
            asyncEdit = true;
        // Log.p("Overriding asyncEdit due to form bottom padding edit mode: "+asyncEdit);
        }
        // then this will override all other settings.
        if (cmp.getClientProperty("asyncEditing") != null) {
            Object async = cmp.getClientProperty("asyncEditing");
            if (async instanceof Boolean) {
                asyncEdit = ((Boolean) async).booleanValue();
            // Log.p("Overriding asyncEdit due to field asyncEditing client property: "+asyncEdit);
            }
        }
        if (cmp.getClientProperty("ios.asyncEditing") != null) {
            Object async = cmp.getClientProperty("ios.asyncEditing");
            if (async instanceof Boolean) {
                asyncEdit = ((Boolean) async).booleanValue();
            // Log.p("Overriding asyncEdit due to field ios.asyncEditing client property: "+asyncEdit);
            }
        }
        // Finally we set the async edit mode for this field.
        // System.out.println("Async edit mode is "+asyncEdit);
        nativeInstance.setAsyncEditMode(asyncEdit);
        textEditorHidden = false;
        currentEditing = (TextArea) cmp;
        // register the edited TextArea to support moving to the next field
        TextEditUtil.setCurrentEditComponent(cmp);
        final NativeFont fnt = f(cmp.getStyle().getFont().getNativeFont());
        boolean forceSlideUpTmp = false;
        final Form current = Display.getInstance().getCurrent();
        if (current instanceof Dialog && !isTablet()) {
            // special case, if we are editing a small dialog we want to move it
            // so the bottom of the dialog shows within the screen. This is
            // described in issue 505
            Dialog dlg = (Dialog) current;
            Component c = dlg.getDialogComponent();
            if (c.getHeight() < Display.getInstance().getDisplayHeight() / 2 && c.getAbsoluteY() + c.getHeight() > Display.getInstance().getDisplayHeight() / 2) {
                forceSlideUpTmp = true;
            }
        }
        final boolean forceSlideUp = forceSlideUpTmp;
        cmp.repaint();
        // give the repaint one cycle to "do its magic...
        final Style stl = currentEditing.getStyle();
        final boolean rtl = UIManager.getInstance().getLookAndFeel().isRTL();
        Display.getInstance().callSerially(new Runnable() {

            @Override
            public void run() {
                int x = cmp.getAbsoluteX() + cmp.getScrollX();
                int y = cmp.getAbsoluteY() + cmp.getScrollY();
                int w = cmp.getWidth();
                int h = cmp.getHeight();
                int pt = stl.getPaddingTop();
                int pb = stl.getPaddingBottom();
                int pl = stl.getPaddingLeft(rtl);
                int pr = stl.getPaddingRight(rtl);
                /*
                    if(currentEditing != null && currentEditing.isSingleLineTextArea()) {
                        switch(currentEditing.getVerticalAlignment()) {
                            case TextArea.CENTER:
                                if(h > cmp.getPreferredH()) {
                                    y += (h / 2 - cmp.getPreferredH() / 2);
                                }
                                break;
                            case TextArea.BOTTOM:
                                if(h > cmp.getPreferredH()) {
                                    y += (h - cmp.getPreferredH());
                                }
                                break;
                        }
                    }
                    */
                String hint = null;
                if (currentEditing != null && currentEditing.getUIManager().isThemeConstant("nativeHintBool", true) && currentEditing.getHint() != null) {
                    hint = currentEditing.getHint();
                }
                if (isAsyncEditMode()) {
                    // request focus triggers a scroll which flicks the textEditorHidden flag
                    doNotHideTextEditorSemaphore++;
                    try {
                        cmp.requestFocus();
                    } finally {
                        doNotHideTextEditorSemaphore--;
                    }
                    textEditorHidden = false;
                }
                boolean showToolbar = cmp.getClientProperty("iosHideToolbar") == null;
                if (showToolbar && Display.getInstance().getProperty("iosHideToolbar", "false").equalsIgnoreCase("true")) {
                    showToolbar = false;
                }
                if (currentEditing != null) {
                    nativeInstance.editStringAt(x, y, w, h, fnt.peer, currentEditing.isSingleLineTextArea(), currentEditing.getRows(), maxSize, constraint, text, forceSlideUp, // peer,
                    stl.getFgColor(), // peer,
                    0, pt, pb, pl, pr, hint, showToolbar, Boolean.TRUE.equals(cmp.getClientProperty("blockCopyPaste")), currentEditing.getStyle().getAlignment(), currentEditing.getVerticalAlignment());
                }
            }
        });
        if (isAsyncEditMode()) {
            return;
        }
        editNext = false;
        Display.getInstance().invokeAndBlock(new Runnable() {

            @Override
            public void run() {
                synchronized (EDITING_LOCK) {
                    while (instance.currentEditing == cmp) {
                        try {
                            EDITING_LOCK.wait(20);
                        } catch (InterruptedException ex) {
                        }
                    }
                }
            }
        });
        if (cmp instanceof TextArea && !((TextArea) cmp).isSingleLineTextArea()) {
            Form form = cmp.getComponentForm();
            if (form != null) {
                form.revalidate();
            }
        }
        if (editNext) {
            editNext = false;
            TextEditUtil.editNextTextArea();
        }
    } finally {
    }
}
Also used : TextArea(com.codename1.ui.TextArea) Form(com.codename1.ui.Form) Container(com.codename1.ui.Container) Dialog(com.codename1.ui.Dialog) Style(com.codename1.ui.plaf.Style) BrowserComponent(com.codename1.ui.BrowserComponent) Component(com.codename1.ui.Component) PeerComponent(com.codename1.ui.PeerComponent)

Example 39 with TextArea

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

the class Log method showLog.

/**
 * 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();
    }
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) TextArea(com.codename1.ui.TextArea) Form(com.codename1.ui.Form) Command(com.codename1.ui.Command) ActionEvent(com.codename1.ui.events.ActionEvent) IOException(java.io.IOException)

Example 40 with TextArea

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

the class HTMLComponent method setInputFormat.

/**
 * Sets input format validation for a TextArea or TextField
 * This is called from the CSSEngine, and since it is done after the TextArea has been added it is a bit more complicated
 *
 * @param inputField The TextArea to place the input format validation on
 * @param inputFormat The string representing the input format
 * @return The same TextArea or a new instance representing the element
 */
TextArea setInputFormat(final TextArea inputField, String inputFormat) {
    TextArea returnInputField = inputField;
    if (SUPPORT_INPUT_FORMAT) {
        HTMLForm form = (HTMLForm) textfieldsToForms.get(inputField);
        if (form != null) {
            HTMLInputFormat format = HTMLInputFormat.getInputFormat(inputFormat);
            if (format != null) {
                form.setInputFormat(inputField, format);
                final TextArea newInputField = format.applyConstraints(inputField);
                returnInputField = newInputField;
                // Replace operation must be done on the EDT if the form is visible
                if (Display.getInstance().getCurrent() != inputField.getComponentForm()) {
                    // ((inputField.getComponentForm()==null) ||
                    // Applying the constraints may return a new instance that has to be replaced in the form
                    inputField.getParent().replace(inputField, newInputField, null);
                } else {
                    Display.getInstance().callSerially(new Runnable() {

                        public void run() {
                            // Applying the constraints may return a new instance that has to be replaced in the form
                            inputField.getParent().replace(inputField, newInputField, null);
                        }
                    });
                }
                if (firstFocusable == inputField) {
                    firstFocusable = newInputField;
                }
            }
        }
    }
    return returnInputField;
}
Also used : TextArea(com.codename1.ui.TextArea)

Aggregations

TextArea (com.codename1.ui.TextArea)46 Component (com.codename1.ui.Component)22 Label (com.codename1.ui.Label)11 Button (com.codename1.ui.Button)10 Container (com.codename1.ui.Container)10 Form (com.codename1.ui.Form)10 RadioButton (com.codename1.ui.RadioButton)8 PeerComponent (com.codename1.ui.PeerComponent)6 TextField (com.codename1.ui.TextField)6 BorderLayout (com.codename1.ui.layouts.BorderLayout)6 Font (com.codename1.ui.Font)5 BoxLayout (com.codename1.ui.layouts.BoxLayout)5 CheckBox (com.codename1.ui.CheckBox)4 Dialog (com.codename1.ui.Dialog)4 List (com.codename1.ui.List)4 Hashtable (java.util.Hashtable)4 Paint (android.graphics.Paint)3 Command (com.codename1.ui.Command)3 Slider (com.codename1.ui.Slider)3 ActionEvent (com.codename1.ui.events.ActionEvent)3