use of com.codename1.ui.Button 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.Button in project CodenameOne by codenameone.
the class Progress method actionCommand.
/**
* {@inheritDoc}
*/
protected void actionCommand(Command cmd) {
if (Display.getInstance().isTouchScreenDevice() || getSoftButtonCount() < 2) {
for (int iter = 0; iter < getComponentCount(); iter++) {
Component c = getComponentAt(iter);
if (c instanceof Button) {
c.setEnabled(false);
}
}
} else {
removeAllCommands();
}
// cancel was pressed
request.kill();
dispose();
}
use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class FloatingActionButton method bindFabToContainer.
/**
* This is a utility method to bind the FAB to a given Container, it will return a new container to add or will
* use the layered pane if the container is a content pane.
*
* @param cnt the Container to add the FAB to
* @param orientation one of Component.RIGHT/LEFT/CENTER
* @param valign one of Component.TOP/BOTTOM/CENTER
*
* @return a new Container that contains the cnt and the FAB on top or null in the case of a content pane
*/
public Container bindFabToContainer(Component cnt, int orientation, int valign) {
FlowLayout flow = new FlowLayout(orientation);
flow.setValign(valign);
Form f = cnt.getComponentForm();
if (f != null && (f.getContentPane() == cnt || f == cnt)) {
// special case for content pane installs the button directly on the content pane
Container layers = f.getLayeredPane(getClass(), true);
layers.setLayout(flow);
layers.add(this);
return null;
}
Container conUpper = new Container(flow);
conUpper.add(this);
return LayeredLayout.encloseIn(cnt, conUpper);
}
use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class ClearableTextField method wrap.
/**
* Wraps the given text field with a UI that will allow us to clear it
* @param tf the text field
* @param iconSize size in millimeters for the clear icon, -1 for default size
* @return a Container that should be added to the UI instead of the actual text field
*/
public static ClearableTextField wrap(final TextArea tf, float iconSize) {
ClearableTextField cf = new ClearableTextField();
Button b = new Button("", tf.getUIID());
if (iconSize > 0) {
FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR, iconSize);
} else {
FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR);
}
removeCmpBackground(tf);
removeCmpBackground(b);
cf.setUIID(tf.getUIID());
cf.add(BorderLayout.CENTER, tf);
cf.add(BorderLayout.EAST, b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
tf.stopEditing();
tf.setText("");
tf.startEditingAsync();
}
});
return cf;
}
use of com.codename1.ui.Button 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;
}
Aggregations