use of com.codename1.ui.TextField 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);
}
use of com.codename1.ui.TextField 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;
}
use of com.codename1.ui.TextField in project CodenameOne by codenameone.
the class CodenameOneInputConnection method setComposingText.
@Override
public boolean setComposingText(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();
StringBuilder sb = new StringBuilder(textFieldText);
sb.replace(sb.length() - composingText.length(), sb.length(), text.toString());
int cursorPosition = t.getCursorPosition();
composingText = text.toString();
t.setText(sb.toString());
t.setCursorPosition(cursorPosition + text.length());
updateExtractedText();
return true;
}
}
return false;
}
use of com.codename1.ui.TextField in project CodenameOne by codenameone.
the class CodenameOneInputConnection method getEditable.
public Editable getEditable() {
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();
edit.clear();
edit.append(textFieldText);
return edit;
}
}
return super.getEditable();
}
use of com.codename1.ui.TextField in project CodenameOne by codenameone.
the class CodenameOneInputConnection method getTextBeforeCursor.
@Override
public CharSequence getTextBeforeCursor(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();
int start;
if (position > 0) {
start = txt.subSequence(0, position).toString().lastIndexOf(" ");
if (start > 0) {
return txt.subSequence(start, position);
} else {
return txt.subSequence(0, position);
}
}
}
}
return "";
}
Aggregations