use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class MultiButton 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 OnOffSwitch method initialize.
private void initialize() {
iosMode = UIManager.getInstance().isThemeConstant("onOffIOSModeBool", false);
removeAll();
setFocusable(true);
if (iosMode) {
button = null;
switchMaskImage = UIManager.getInstance().getThemeImageConstant("switchMaskImage");
switchOnImage = UIManager.getInstance().getThemeImageConstant("switchOnImage");
switchOffImage = UIManager.getInstance().getThemeImageConstant("switchOffImage");
noTextMode = UIManager.getInstance().isThemeConstant("noTextModeBool", false);
} else {
setLayout(new BoxLayout(BoxLayout.Y_AXIS));
button = new CheckBox(on);
button.setToggle(true);
button.setUIID("Button");
button.setEndsWith3Points(false);
button.getUnselectedStyle().setFont(getUnselectedStyle().getFont());
button.getSelectedStyle().setFont(getSelectedStyle().getFont());
button.getPressedStyle().setFont(getSelectedStyle().getFont());
Dimension d = button.getPreferredSize();
button.setText(off);
int pw = button.getPreferredW();
d.setWidth(Math.max(pw, d.getWidth()));
// prevents the button from growing/shrinking as its states flip
button.setPreferredSize(d);
buttonWidth = button.getPreferredW();
button.setFocusable(false);
updateButton();
addComponent(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
flip();
}
});
}
}
use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class LiveDemo method start.
public void start() {
Form previewForm = new Form("Preview Theme");
Toolbar tb = new Toolbar();
previewForm.setToolbar(tb);
tb.setTitle("Preview Theme");
tb.addMaterialCommandToSideMenu("Side Command", FontImage.MATERIAL_HELP, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ToastBar.showErrorMessage("Unmapped....");
}
});
tb.addMaterialCommandToOverflowMenu("Overflow Command", FontImage.MATERIAL_HELP, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ToastBar.showErrorMessage("Unmapped....");
}
});
tb.addMaterialCommandToRightBar("", FontImage.MATERIAL_HELP, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ToastBar.showErrorMessage("Unmapped....");
}
});
previewForm.setLayout(new BorderLayout());
Container first = new Container(new BoxLayout(BoxLayout.Y_AXIS));
first.addComponent(new Label("This is a Label"));
first.addComponent(new Button("This is a Button"));
MultiButton mb = new MultiButton("This is a MultiButton");
mb.setTextLine2("Second line of text");
FontImage.setMaterialIcon(mb, FontImage.MATERIAL_HELP);
first.addComponent(mb);
TextField txt = new TextField();
txt.setHint("This is a TextField");
first.addComponent(txt);
first.addComponent(new CheckBox("This is a CheckBox"));
first.addComponent(FlowLayout.encloseIn(new Label("This is a switch "), new Switch()));
RadioButton rb1 = new RadioButton("This is a Radio Button 1");
rb1.setGroup("group");
first.addComponent(rb1);
RadioButton rb2 = new RadioButton("This is a Radio Button 2");
rb2.setGroup("group");
first.addComponent(rb2);
final Slider s = new Slider();
s.setText("50%");
s.setProgress(50);
s.setEditable(true);
s.setRenderPercentageOnTop(true);
first.addComponent(s);
Button b1 = new Button("Show a Dialog");
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
Dialog.show("Dialog Title", "Dialog Body", "Ok", "Cancel");
}
});
first.addComponent(b1);
previewForm.add(BorderLayout.CENTER, first);
previewForm.show();
}
use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class InterFormContainerSample method start.
public void start() {
Button sharedButton = new Button("Shared Button");
InterFormContainer cnt = new InterFormContainer(sharedButton);
InterFormContainer cnt2 = new InterFormContainer(sharedButton);
Toolbar.setGlobalToolbar(true);
Form hi = new Form("Transitions", new BorderLayout());
Container c = new Container(BoxLayout.y());
hi.add(BorderLayout.CENTER, c);
hi.add(BorderLayout.SOUTH, cnt);
Style bg = hi.getContentPane().getUnselectedStyle();
bg.setBgTransparency(255);
bg.setBgColor(0xff0000);
Button showTransition = new Button("Show");
Picker pick = new Picker();
pick.setStrings("Slide", "SlideFade", "Cover", "Uncover", "Fade", "Flip");
pick.setSelectedString("Slide");
TextField duration = new TextField("10000", "Duration", 6, TextArea.NUMERIC);
CheckBox horizontal = CheckBox.createToggle("Horizontal");
pick.addActionListener((e) -> {
String s = pick.getSelectedString().toLowerCase();
horizontal.setEnabled(s.equals("slide") || s.indexOf("cover") > -1);
});
horizontal.setSelected(true);
c.add(showTransition).add(pick).add(duration).add(horizontal);
Form dest = new Form("Destination", new BorderLayout());
sharedButton.addActionListener(e -> {
if (sharedButton.getComponentForm() == hi) {
dest.show();
} else {
hi.showBack();
}
});
dest.add(BorderLayout.SOUTH, cnt2);
bg = dest.getContentPane().getUnselectedStyle();
bg.setBgTransparency(255);
bg.setBgColor(0xff);
dest.setBackCommand(dest.getToolbar().addCommandToLeftBar("Back", null, (e) -> hi.showBack()));
showTransition.addActionListener((e) -> {
int h = CommonTransitions.SLIDE_HORIZONTAL;
if (!horizontal.isSelected()) {
h = CommonTransitions.SLIDE_VERTICAL;
}
switch(pick.getSelectedString()) {
case "Slide":
hi.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000)));
dest.setTransitionOutAnimator(CommonTransitions.createSlide(h, true, duration.getAsInt(3000)));
break;
case "SlideFade":
hi.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000)));
dest.setTransitionOutAnimator(CommonTransitions.createSlideFadeTitle(true, duration.getAsInt(3000)));
break;
case "Cover":
hi.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000)));
dest.setTransitionOutAnimator(CommonTransitions.createCover(h, true, duration.getAsInt(3000)));
break;
case "Uncover":
hi.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000)));
dest.setTransitionOutAnimator(CommonTransitions.createUncover(h, true, duration.getAsInt(3000)));
break;
case "Fade":
hi.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000)));
dest.setTransitionOutAnimator(CommonTransitions.createFade(duration.getAsInt(3000)));
break;
case "Flip":
hi.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000)));
dest.setTransitionOutAnimator(new FlipTransition(-1, duration.getAsInt(3000)));
break;
}
dest.show();
});
hi.show();
}
use of com.vaadin.v7.ui.CheckBox in project CodenameOne by codenameone.
the class JavascriptCapturePhotoSample method start.
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Hi World", BoxLayout.y());
CheckBox useUserMedia = new CheckBox("Use UserMedia APIs for Photo Capture");
useUserMedia.addActionListener(e -> {
Display.getInstance().setProperty("javascript.useGetUserMedia", useUserMedia.isSelected() ? "true" : "false");
});
TextField width = new TextField();
width.setHint("width");
TextField height = new TextField();
height.setHint("height");
Button capture = new Button("Capture");
Label imagePlaceholder = new Label();
capture.addActionListener(e -> {
int w = -1;
int h = -1;
try {
w = Integer.parseInt(width.getText());
} catch (Throwable t) {
}
try {
h = Integer.parseInt(height.getText());
} catch (Throwable t) {
}
String path = Capture.capturePhoto(w, h);
if (path != null) {
try {
Image img = Image.createImage(path);
imagePlaceholder.setIcon(img);
hi.revalidate();
} catch (Exception ex) {
Log.e(ex);
}
}
});
hi.add(new Label("Photo Capture Demo"));
hi.add(useUserMedia);
hi.add(GridLayout.encloseIn(2, width, height));
hi.add(capture);
hi.add(imagePlaceholder);
hi.show();
}
Aggregations