use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class MenuBar method removeCommand.
/**
* Removes a Command from the MenuBar
*
* @param cmd Command to remove
*/
protected void removeCommand(Command cmd) {
int behavior = getCommandBehavior();
if (behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR || behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK || behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT || behavior == Display.COMMAND_BEHAVIOR_ICS) {
int i = commands.indexOf(cmd);
if (i > -1) {
commands.removeElementAt(i);
Button b = findCommandComponent(cmd);
if (b != null && b.getParent() != null) {
b.getParent().removeComponent(b);
}
if (getCommandCount() > 0) {
setLayout(new GridLayout(1, getCommandCount()));
}
}
return;
}
commands.removeElement(cmd);
updateCommands();
}
use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class MenuBar method updateGridCommands.
private void updateGridCommands(int startOffset) {
int cmdCount = getCommandCount() - startOffset;
if (cmdCount <= 0 || getCommandBehavior() == Display.COMMAND_BEHAVIOR_ICS) {
return;
}
setLayout(new GridLayout(1, cmdCount));
while (cmdCount < getComponentCount()) {
removeComponent(getComponentAt(getComponentCount() - 1));
}
int off = startOffset;
while (getComponentCount() < cmdCount) {
Button btn = new Button(getCommand(off));
btn.setUIID("TouchCommand");
off++;
addComponent(btn);
}
for (int iter = 0; iter < cmdCount; iter++) {
Button btn = (Button) getComponentAt(iter);
if (btn.getCommand() != getCommand(iter + startOffset)) {
btn.setCommand(getCommand(iter + startOffset));
}
}
}
use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class TextField method createSymbolTable.
/**
* Creates a symbol table container used by the showSymbolDialog method.
* This method is designed for subclases to override and customize.
*
* @return container for the symbol table.
*/
protected Container createSymbolTable() {
char[] symbolArray = getSymbolTable();
Container symbols = new Container(new GridLayout(symbolArray.length / 5, 5));
int slen = symbolArray.length;
for (int iter = 0; iter < slen; iter++) {
Button button = new Button(new Command("" + symbolArray[iter]));
button.setUIID("VKBButton");
button.setAlignment(CENTER);
symbols.addComponent(button);
}
return symbols;
}
use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class Toolbar method addComponentToSideMenu.
/**
* Adds a Component to the side navigation menu. The Component is added to
* the navigation menu and the command gets the events once the Component is
* being pressed.
*
* @param cmp c Component to be added to the menu
* @param cmd a Command to handle the events
*/
public void addComponentToSideMenu(Component cmp, Command cmd) {
checkIfInitialized();
if (permanentSideMenu) {
constructPermanentSideMenu();
Container cnt = new Container(new BorderLayout());
cnt.addComponent(BorderLayout.CENTER, cmp);
Button btn = new Button(cmd);
btn.setParent(cnt);
cnt.setLeadComponent(btn);
addComponentToSideMenu(permanentSideMenuContainer, cnt);
} else {
if (onTopSideMenu) {
constructOnTopSideMenu();
Container cnt = new Container(new BorderLayout());
cnt.addComponent(BorderLayout.CENTER, cmp);
Button btn = new Button(cmd);
btn.setParent(cnt);
cnt.setLeadComponent(btn);
addComponentToSideMenu(permanentSideMenuContainer, cnt);
} else {
cmd.putClientProperty(SideMenuBar.COMMAND_SIDE_COMPONENT, cmp);
cmd.putClientProperty(SideMenuBar.COMMAND_ACTIONABLE, Boolean.TRUE);
sideMenu.addCommand(cmd);
sideMenu.installMenuBar();
}
}
}
use of com.codename1.ui.Button in project CodenameOne by codenameone.
the class FontImage method setMaterialIcon.
/**
* <p>Applies a material design icon (one of the MATERIAL_* icon constants) to the given label using the
* styling of the label. Notice that when the argument is a button the pressed/selected & disabled states
* will be set appropriately.</p>
* <script src="https://gist.github.com/codenameone/8cf6f70188959524474b.js"></script>
*
* @param l a label or subclass (e.g. Button etc.)
* @param icon one of the MATERIAL_* icons
* @param size the size of the icon in millimeters
*/
public static void setMaterialIcon(Label l, char icon, float size) {
if (Font.isTrueTypeFileSupported()) {
Style s = new Style(l.getUnselectedStyle());
s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
l.setIcon(FontImage.create("" + icon, s));
if (l instanceof Button) {
Button b = (Button) l;
Style sel = b.getSelectedStyle();
Style pre = b.getPressedStyle();
Style dis = b.getDisabledStyle();
if (sel.getFgColor() != s.getFgColor() || (sel.getBgColor() != s.getBgColor()) || (sel.getBgTransparency() != s.getBgTransparency())) {
sel = new Style(sel);
sel.setFont(getMaterialDesignFont().derive(rightSize(sel, size), Font.STYLE_PLAIN));
b.setRolloverIcon(FontImage.create("" + icon, sel));
}
if (pre.getFgColor() != s.getFgColor() || (pre.getBgColor() != s.getBgColor()) || (pre.getBgTransparency() != s.getBgTransparency())) {
pre = new Style(pre);
pre.setFont(getMaterialDesignFont().derive(rightSize(pre, size), Font.STYLE_PLAIN));
b.setPressedIcon(FontImage.create("" + icon, pre));
b.setRolloverPressedIcon(FontImage.create("" + icon, pre));
}
if (dis.getFgColor() != s.getFgColor() || (dis.getBgColor() != s.getBgColor()) || (dis.getBgTransparency() != s.getBgTransparency())) {
dis = new Style(dis);
dis.setFont(getMaterialDesignFont().derive(rightSize(dis, size), Font.STYLE_PLAIN));
b.setDisabledIcon(FontImage.create("" + icon, dis));
}
}
}
}
Aggregations