use of com.codename1.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.codename1.ui.CheckBox in project CodenameOne by codenameone.
the class DefaultLookAndFeel method updateCheckBoxConstants.
private void updateCheckBoxConstants(UIManager m, boolean focus, String append) {
Image checkSel = m.getThemeImageConstant("checkBoxChecked" + append + "Image");
if (checkSel != null) {
Image checkUnsel = m.getThemeImageConstant("checkBoxUnchecked" + append + "Image");
if (checkUnsel != null) {
Image disUnsel = m.getThemeImageConstant("checkBoxUncheckDis" + append + "Image");
Image disSel = m.getThemeImageConstant("checkBoxCheckDis" + append + "Image");
if (disSel == null) {
disSel = checkSel;
}
if (disUnsel == null) {
disUnsel = checkUnsel;
}
if (focus) {
setCheckBoxFocusImages(checkSel, checkUnsel, disSel, disUnsel);
} else {
setCheckBoxImages(checkSel, checkUnsel, disSel, disUnsel);
}
}
if (checkUnsel != null) {
if (focus) {
setCheckBoxFocusImages(checkSel, checkUnsel, checkSel, checkUnsel);
} else {
setCheckBoxImages(checkSel, checkUnsel);
}
}
} else {
if (!Font.isTrueTypeFileSupported()) {
return;
}
UIManager uim = UIManager.getInstance();
Style unsel = uim.createStyle("CheckBox.", "", false);
Style sel = uim.createStyle("CheckBox.", "sel#", true);
Style dis = uim.createStyle("CheckBox.", "dis#", false);
FontImage checkedDis = FontImage.createMaterial(FontImage.MATERIAL_CHECK_BOX, dis);
FontImage uncheckedDis = FontImage.createMaterial(FontImage.MATERIAL_CHECK_BOX_OUTLINE_BLANK, sel);
if (focus) {
FontImage checkedSelected = FontImage.createMaterial(FontImage.MATERIAL_CHECK_BOX, sel);
FontImage uncheckedSelected = FontImage.createMaterial(FontImage.MATERIAL_CHECK_BOX_OUTLINE_BLANK, sel);
setCheckBoxFocusImages(checkedSelected, uncheckedSelected, checkedDis, uncheckedDis);
} else {
FontImage checkedUnselected = FontImage.createMaterial(FontImage.MATERIAL_CHECK_BOX, unsel);
FontImage uncheckedUnselected = FontImage.createMaterial(FontImage.MATERIAL_CHECK_BOX_OUTLINE_BLANK, unsel);
setCheckBoxImages(checkedUnselected, uncheckedUnselected, checkedDis, uncheckedDis);
}
}
}
use of com.codename1.ui.CheckBox in project CodenameOne by codenameone.
the class DefaultLookAndFeel method getCheckBoxPreferredSize.
/**
* {@inheritDoc}
*/
public Dimension getCheckBoxPreferredSize(Button cb) {
if (cb.isToggle()) {
return getButtonPreferredSize(cb);
}
threeImageCache[0] = cb.getMaskedIcon();
threeImageCache[1] = cb.getRolloverIcon();
threeImageCache[2] = cb.getPressedIcon();
if (chkBoxImages != null) {
return getPreferredSize(cb, threeImageCache, chkBoxImages[0]);
}
Dimension d = getPreferredSize(cb, threeImageCache, null);
// checkbox square needs to be the height and width of the font height even
// when no text is in the check box this is a good indication of phone DPI
int checkBoxSquareSize = cb.getStyle().getFont().getHeight();
// allow for checkboxes without a string within them
d.setHeight(Math.max(checkBoxSquareSize, d.getHeight()));
d.setWidth(d.getWidth() + checkBoxSquareSize + cb.getGap());
return d;
}
use of com.codename1.ui.CheckBox in project CodenameOne by codenameone.
the class DefaultLookAndFeel method getPreferredSize.
/**
* {@inheritDoc}
*/
private Dimension getPreferredSize(Label l, Image[] icons, Image stateImage) {
int prefW = 0;
int prefH = 0;
Style style = l.getStyle();
int gap = l.getGap();
int ilen = icons.length;
for (int i = 0; i < ilen; i++) {
Image icon = icons[i];
if (icon != null) {
prefW = Math.max(prefW, icon.getWidth());
prefH = Math.max(prefH, icon.getHeight());
}
}
String text = l.getText();
Font font = style.getFont();
if (font == null) {
System.out.println("Missing font for " + l);
font = Font.getDefaultFont();
}
if (text != null && text.length() > 0) {
// add the text size
switch(l.getTextPosition()) {
case Label.LEFT:
case Label.RIGHT:
prefW += font.stringWidth(text);
prefH = Math.max(prefH, font.getHeight());
break;
case Label.BOTTOM:
case Label.TOP:
prefW = Math.max(prefW, font.stringWidth(text));
prefH += font.getHeight();
break;
}
}
// add the state image(relevant for CheckBox\RadioButton)
if (stateImage != null) {
prefW += (stateImage.getWidth() + gap);
prefH = Math.max(prefH, stateImage.getHeight());
}
if (icons[0] != null && text != null && text.length() > 0) {
switch(l.getTextPosition()) {
case Label.LEFT:
case Label.RIGHT:
prefW += gap;
break;
case Label.BOTTOM:
case Label.TOP:
prefH += gap;
break;
}
}
if (l.isShowEvenIfBlank()) {
prefH += style.getVerticalPadding();
prefW += style.getHorizontalPadding();
} else {
if (prefH != 0) {
prefH += style.getVerticalPadding();
}
if (prefW != 0) {
prefW += style.getHorizontalPadding();
}
}
if (style.getBorder() != null) {
prefW = Math.max(style.getBorder().getMinimumWidth(), prefW);
prefH = Math.max(style.getBorder().getMinimumHeight(), prefH);
}
if (isBackgroundImageDetermineSize() && style.getBgImage() != null) {
prefW = Math.max(style.getBgImage().getWidth(), prefW);
prefH = Math.max(style.getBgImage().getHeight(), prefH);
}
return new Dimension(prefW, prefH);
}
use of com.codename1.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"));
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();
}
Aggregations