use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class GenericListCellRenderer method setComponentValue.
/**
* Initializes the given component with the given value
*
* @param cmp one of the components that is or is a part of the renderer
* @param value the value to install into the component
*/
private void setComponentValue(Component cmp, Object value, Component parent, Component rootRenderer) {
// process so renderer selected/unselected styles are applied
if (cmp.getName().toLowerCase().endsWith("fixed")) {
return;
}
if (cmp instanceof Label) {
if (value instanceof Image) {
Image i = (Image) value;
if (i.isAnimation()) {
if (pendingAnimations == null) {
pendingAnimations = new ArrayList<Image>();
}
if (!pendingAnimations.contains(i)) {
pendingAnimations.add(i);
if (parentList == null) {
parentList = parent;
}
if (parentList != null) {
Form f = parentList.getComponentForm();
if (f != null) {
f.registerAnimated(mon);
waitingForRegisterAnimation = false;
} else {
waitingForRegisterAnimation = true;
}
}
} else {
if (waitingForRegisterAnimation) {
if (parentList != null) {
Form f = parentList.getComponentForm();
if (f != null) {
f.registerAnimated(mon);
waitingForRegisterAnimation = false;
}
}
}
}
}
Image oldImage = ((Label) cmp).getIcon();
((Label) cmp).setIcon(i);
((Label) cmp).setText("");
if (oldImage == null || oldImage.getWidth() != i.getWidth() || oldImage.getHeight() != i.getHeight()) {
((Container) rootRenderer).revalidate();
}
return;
} else {
((Label) cmp).setIcon(null);
}
if (cmp instanceof CheckBox) {
((CheckBox) cmp).setSelected(isSelectedValue(value));
return;
}
if (cmp instanceof RadioButton) {
((RadioButton) cmp).setSelected(isSelectedValue(value));
return;
}
if (cmp instanceof Slider) {
((Slider) cmp).setProgress(((Integer) value).intValue());
return;
}
Label l = (Label) cmp;
if (value == null) {
l.setText("");
} else {
if (value instanceof Label) {
l.setText(((Label) value).getText());
l.setIcon(((Label) value).getIcon());
} else {
l.setText(value.toString());
}
}
if (firstCharacterRTL) {
String t = l.getText();
if (t.length() > 0) {
l.setRTL(Display.getInstance().isRTL(t.charAt(0)));
}
}
return;
}
if (cmp instanceof TextArea) {
if (value == null) {
((TextArea) cmp).setText("");
} else {
((TextArea) cmp).setText(value.toString());
}
}
}
use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class SpanMultiButton method setCheckBox.
/**
* Turns the multi-button into a checkbox multi-button
*
* @param b true for a checkbox multi-button
*/
public void setCheckBox(boolean b) {
if (b != isCheckBox()) {
Container par = emblem.getParent();
Button old = emblem;
if (b) {
emblem = new CheckBox();
} else {
emblem = new Button();
}
emblem.setUIID(old.getUIID());
emblem.setName(old.getName());
java.util.List actionListeners = (java.util.List) old.getListeners();
if (actionListeners != null) {
for (int iter = 0; iter < actionListeners.size(); iter++) {
emblem.addActionListener((ActionListener) actionListeners.get(iter));
}
}
if (old.getCommand() != null) {
Image img = old.getIcon();
emblem.setCommand(old.getCommand());
emblem.setText("");
emblem.setIcon(img);
} else {
emblem.setText(old.getText());
if (old.getIcon() != null) {
emblem.setIcon(old.getIcon());
}
}
par.replace(old, emblem, null);
setLeadComponent(emblem);
}
}
use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class DefaultCrashReporter method exception.
/**
* {@inheritDoc}
*/
public void exception(Throwable t) {
Preferences.set("$CN1_pendingCrash", true);
if (promptUser) {
Dialog error = new Dialog("Error");
error.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
TextArea txt = new TextArea(errorText);
txt.setEditable(false);
txt.setUIID("DialogBody");
error.addComponent(txt);
CheckBox cb = new CheckBox(checkboxText);
cb.setUIID("DialogBody");
error.addComponent(cb);
Container grid = new Container(new GridLayout(1, 2));
error.addComponent(grid);
Command ok = new Command(sendButtonText);
Command dont = new Command(dontSendButtonText);
Button send = new Button(ok);
Button dontSend = new Button(dont);
grid.addComponent(send);
grid.addComponent(dontSend);
Command result = error.showPacked(BorderLayout.CENTER, true);
if (result == dont) {
if (cb.isSelected()) {
Preferences.set("$CN1_crashBlocked", true);
}
Preferences.set("$CN1_pendingCrash", false);
return;
} else {
if (cb.isSelected()) {
Preferences.set("$CN1_prompt", false);
}
}
}
Log.sendLog();
Preferences.set("$CN1_pendingCrash", false);
}
use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class HTMLComponent method handleInput.
/**
* Handles the INPUT tag
*
* @param element The input element
* @param align The current aligment
*/
private void handleInput(HTMLElement element, int align) {
String type = element.getAttributeById(HTMLElement.ATTR_TYPE);
if (type == null) {
return;
}
int typeID = INPUT_TYPES.indexOf(type.toLowerCase());
if (typeID == -1) {
if (htmlCallback != null) {
if (!htmlCallback.parsingError(HTMLCallback.ERROR_ATTIBUTE_VALUE_INVALID, element.getTagName(), element.getAttributeName(new Integer(HTMLElement.ATTR_TYPE)), type, "Unsupported input type '" + type + "'. Supported types: text, password, checkbox, radio, submit, reset, hidden, image")) {
cancel();
}
}
return;
}
String name = element.getAttributeById(HTMLElement.ATTR_NAME);
String id = element.getAttributeById(HTMLElement.ATTR_ID);
String value = element.getAttributeById(HTMLElement.ATTR_VALUE);
if (value == null) {
value = "";
}
Component cmp = null;
switch(typeID) {
case INPUT_CHECKBOX:
CheckBox cb = new CheckBox();
if (element.getAttributeById(HTMLElement.ATTR_CHECKED) != null) {
cb.setSelected(true);
}
cmp = cb;
if (curForm != null) {
curForm.addCheckBox(name, cb, value);
}
break;
case INPUT_HIDDEN:
if (curForm != null) {
curForm.addInput(name, value, null);
}
break;
case INPUT_EMAIL:
case INPUT_TEXT:
case INPUT_PASSWORD:
TextField tf = new TextField(value);
tf.setLeftAndRightEditingTrigger(false);
if (typeID == INPUT_PASSWORD) {
tf.setConstraint(TextField.PASSWORD);
}
if (typeID == INPUT_EMAIL) {
tf.setConstraint(TextField.EMAILADDR);
}
if (SUPPORT_INPUT_FORMAT) {
HTMLInputFormat inputFormat = HTMLInputFormat.getInputFormat(element.getAttributeById(HTMLElement.ATTR_FORMAT));
if (inputFormat != null) {
tf = (TextField) inputFormat.applyConstraints(tf);
if (curForm != null) {
curForm.setInputFormat(tf, inputFormat);
}
}
String emptyOk = element.getAttributeById(HTMLElement.ATTR_EMPTYOK);
if ((emptyOk != null) && (curForm != null)) {
if (emptyOk.equalsIgnoreCase("true")) {
curForm.setEmptyOK(tf, true);
} else if (emptyOk.equalsIgnoreCase("false")) {
curForm.setEmptyOK(tf, false);
}
}
}
int size = getInt(element.getAttributeById(HTMLElement.ATTR_SIZE));
int maxlen = getInt(element.getAttributeById(HTMLElement.ATTR_MAXLENGTH));
if (size == 0) {
size = DEFAULT_TEXTFIELD_SIZE;
}
if (maxlen != 0) {
tf.setMaxSize(maxlen);
if (size > maxlen) {
size = maxlen;
}
}
tf.setPreferredW(tf.getStyle().getFont().stringWidth("W") * size);
tf.getSelectedStyle().setFont(font.getFont());
tf.getUnselectedStyle().setFont(font.getFont());
if ((!PROCESS_HTML_MP1_ONLY) && (element.getAttributeById(HTMLElement.ATTR_READONLY) != null)) {
tf.setEditable(false);
}
cmp = tf;
if (curForm != null) {
curForm.addInput(name, cmp, value);
textfieldsToForms.put(tf, curForm);
}
break;
case INPUT_RADIO:
RadioButton rb = new RadioButton(" ");
if (element.getAttributeById(HTMLElement.ATTR_CHECKED) != null) {
rb.setSelected(true);
}
cmp = rb;
if (curForm != null) {
curForm.addRadioButton(name, rb, value);
}
break;
case INPUT_RESET:
Command resetCmd = null;
if (curForm != null) {
resetCmd = curForm.createResetCommand(value);
}
if (resetCmd == null) {
// dummy command - no form so it won't do anything
resetCmd = new Command(getUIManager().localize("html.reset", HTMLForm.DEFAULT_RESET_TEXT));
}
Button resetButton = new Button(resetCmd);
cmp = resetButton;
break;
case INPUT_BUTTON:
case INPUT_SUBMIT:
Command submitCmd = null;
if (curForm != null) {
submitCmd = curForm.createSubmitCommand(name, value);
}
if (submitCmd == null) {
// dummy command - no form so it won't do anything
submitCmd = new Command(value.equals("") ? value = getUIManager().localize("html.submit", HTMLForm.DEFAULT_SUBMIT_TEXT) : value);
}
Button submitButton = new Button(submitCmd);
cmp = submitButton;
break;
case // Image submit is not officially supported in XHTML-MP 1.0 but was added anyway, but pixel data submission is not supported (i.e. name.x=xx&name.y=yy)
INPUT_IMAGE:
submitCmd = null;
if (curForm != null) {
submitCmd = curForm.createSubmitCommand(name, value);
}
handleImage(element, align, submitCmd);
break;
}
if (cmp != null) {
if ((!PROCESS_HTML_MP1_ONLY) && (element.getAttributeById(HTMLElement.ATTR_DISABLED) != null)) {
cmp.setEnabled(false);
}
String aKey = element.getAttributeById(HTMLElement.ATTR_ACCESSKEY);
if ((aKey != null) && (aKey.length() == 1)) {
// accessKeys.put(new Integer(aKey.charAt(0)), cmp);
addAccessKey(aKey.charAt(0), cmp, false);
}
if (eventsListener != null) {
eventsListener.registerComponent(cmp, element);
}
// Even if CSS is off, we need to associate it for HTMLElement.getCurentValue
element.setAssociatedComponents(cmp);
if ((curForm != null) && (curForm.action == null)) {
// Form that submits to a forbidden link
cmp.setEnabled(false);
} else if (firstFocusable == null) {
firstFocusable = cmp;
}
if (id != null) {
inputFields.put(id, cmp);
}
}
addCmp(cmp, align);
}
use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class TabIteratorSample2775 method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Hi World", BoxLayout.y());
hi.add(new TextField("Text 1"));
Picker p1 = new Picker();
p1.setType(Display.PICKER_TYPE_STRINGS);
p1.setStrings("Red", "Green", "Blue", "Orange");
hi.add(p1);
hi.add(new TextField("Text 2"));
CheckBox enableTabsCheckBox = new CheckBox("Enable Tabbing");
enableTabsCheckBox.setSelected(true);
enableTabsCheckBox.addActionListener(e -> {
$("*", hi).each(c -> {
c.setPreferredTabIndex(enableTabsCheckBox.isSelected() ? 0 : -1);
});
});
hi.add(enableTabsCheckBox);
hi.show();
}
Aggregations