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);
}
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;
}
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);
}
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 "";
}
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;
}
Aggregations