use of com.codename1.ui.Command in project CodenameOne by codenameone.
the class MenuBar method calculateTouchCommandGridColumns.
/**
* Calculates the amount of columns to give to the touch commands within the
* grid
*
* @param grid container that will be arranged in the grid containing the
* components
* @return an integer representing the touch command grid size
*/
protected int calculateTouchCommandGridColumns(Container grid) {
int count = grid.getComponentCount();
int maxWidth = 10;
for (int iter = 0; iter < count; iter++) {
Component c = grid.getComponentAt(iter);
Style s = c.getUnselectedStyle();
// bidi doesn't matter since this is just a summary of width
maxWidth = Math.max(maxWidth, c.getPreferredW() + s.getHorizontalMargins());
}
return Math.max(2, Display.getInstance().getDisplayWidth() / maxWidth);
}
use of com.codename1.ui.Command in project CodenameOne by codenameone.
the class MenuBar method addCommand.
/**
* Add a Command to the MenuBar
*
* @param cmd Command to Add
* @param index determines the order of the added commands
*/
protected void addCommand(Command cmd, int index) {
if (getCommandCount() == 0 && parent != null) {
installMenuBar();
}
// with the select command
if (commands.contains(cmd)) {
return;
}
commands.insertElementAt(cmd, index);
if (!(parent instanceof Dialog)) {
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 || behavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION) {
if (behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK && cmd == parent.getBackCommand()) {
return;
}
if (behavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION) {
return;
}
if ((behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK || behavior == Display.COMMAND_BEHAVIOR_ICS) && parent.getTitle() != null && parent.getTitle().length() > 0) {
synchronizeCommandsWithButtonsInBackbutton();
return;
}
if (parent.getBackCommand() != cmd) {
if (behavior != Display.COMMAND_BEHAVIOR_ICS) {
setLayout(new GridLayout(1, getComponentCount() + 1));
addComponent(Math.min(getComponentCount(), index), createTouchCommandButton(cmd));
revalidate();
}
} else {
commands.removeElement(cmd);
}
return;
}
}
updateCommands();
}
use of com.codename1.ui.Command 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.Command 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.Command in project CodenameOne by codenameone.
the class Toolbar method showOverflowMenu.
/*
* A Overflow Menu is implemented as a dialog, this method allows you to
* override the dialog display in order to customize the dialog menu in
* various ways
*
* @param menu a dialog containing Overflow Menu options that can be
* customized
* @return the command selected by the user in the dialog
*/
protected Command showOverflowMenu(Dialog menu) {
Form parent = sideMenu.getParentForm();
int height;
int marginLeft;
int marginRight = 0;
Container dialogContentPane = menu.getDialogComponent();
marginLeft = parent.getWidth() - (dialogContentPane.getPreferredW() + menu.getStyle().getHorizontalPadding());
marginLeft = Math.max(0, marginLeft);
if (parent.getSoftButtonCount() > 1) {
height = parent.getHeight() - parent.getSoftButton(0).getParent().getPreferredH() - dialogContentPane.getPreferredH();
} else {
height = parent.getHeight() - dialogContentPane.getPreferredH();
}
height = Math.max(0, height);
int th = getHeight();
Transition transitionIn;
Transition transitionOut;
UIManager manager = parent.getUIManager();
LookAndFeel lf = manager.getLookAndFeel();
if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
transitionIn = lf.getDefaultMenuTransitionIn();
if (transitionIn instanceof BubbleTransition) {
((BubbleTransition) transitionIn).setComponentName("OverflowButton");
}
transitionOut = lf.getDefaultMenuTransitionOut();
} else {
transitionIn = CommonTransitions.createEmpty();
transitionOut = CommonTransitions.createEmpty();
}
menu.setTransitionInAnimator(transitionIn);
menu.setTransitionOutAnimator(transitionOut);
if (isRTL()) {
marginRight = marginLeft;
marginLeft = 0;
}
int tint = parent.getTintColor();
parent.setTintColor(0x00FFFFFF);
parent.tint = false;
boolean showBelowTitle = manager.isThemeConstant("showMenuBelowTitleBool", true);
int topPadding = 0;
Component statusBar = ((BorderLayout) getLayout()).getNorth();
if (statusBar != null) {
topPadding = statusBar.getAbsoluteY() + statusBar.getHeight();
}
if (showBelowTitle) {
topPadding = th;
}
Command r = menu.show(topPadding, Math.max(topPadding, height - topPadding), marginLeft, marginRight, true);
parent.setTintColor(tint);
return r;
}
Aggregations