use of com.codename1.ui.layouts.GridLayout in project CodenameOne by codenameone.
the class DefaultCrashReporter method exception.
/**
* {@inheritDoc}
*/
public void exception(Throwable t) {
Preferences.set("$CN1_pendingCrash", true);
if (promptUser) {
Dialog error = new Dialog("Error");
error.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
TextArea txt = new TextArea(errorText);
txt.setEditable(false);
txt.setUIID("DialogBody");
error.addComponent(txt);
CheckBox cb = new CheckBox(checkboxText);
cb.setUIID("DialogBody");
error.addComponent(cb);
Container grid = new Container(new GridLayout(1, 2));
error.addComponent(grid);
Command ok = new Command(sendButtonText);
Command dont = new Command(dontSendButtonText);
Button send = new Button(ok);
Button dontSend = new Button(dont);
grid.addComponent(send);
grid.addComponent(dontSend);
Command result = error.showPacked(BorderLayout.CENTER, true);
if (result == dont) {
if (cb.isSelected()) {
Preferences.set("$CN1_crashBlocked", true);
}
Preferences.set("$CN1_pendingCrash", false);
return;
} else {
if (cb.isSelected()) {
Preferences.set("$CN1_prompt", false);
}
}
}
Log.sendLog();
Preferences.set("$CN1_pendingCrash", false);
}
use of com.codename1.ui.layouts.GridLayout in project CodenameOne by codenameone.
the class Tabs method setTabsLayout.
private void setTabsLayout(int tabPlacement) {
if (tabPlacement == TOP || tabPlacement == BOTTOM) {
if (tabsFillRows) {
FlowLayout f = new FlowLayout();
f.setFillRows(true);
tabsContainer.setLayout(f);
} else {
if (tabsGridLayout) {
tabsContainer.setLayout(new GridLayout(1, Math.max(1, getTabCount())));
} else {
tabsContainer.setLayout(new BoxLayout(BoxLayout.X_AXIS));
}
}
tabsContainer.setScrollableX(true);
tabsContainer.setScrollableY(false);
} else {
// LEFT Or RIGHT
if (tabsGridLayout) {
tabsContainer.setLayout(new GridLayout(Math.max(1, getTabCount()), 1));
} else {
tabsContainer.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
}
tabsContainer.setScrollableX(false);
tabsContainer.setScrollableY(true);
}
}
use of com.codename1.ui.layouts.GridLayout in project CodenameOne by codenameone.
the class MenuBar method initMenuBar.
/**
* Initialize the MenuBar
*
* @param parent the associated Form
*/
protected void initMenuBar(Form parent) {
this.parent = parent;
selectMenuItem = createMenuSelectCommand();
cancelMenuItem = createMenuCancelCommand();
UIManager manager = parent.getUIManager();
LookAndFeel lf = manager.getLookAndFeel();
// don't minimize the app if it's a Dialog
minimizeOnBack = manager.isThemeConstant("minimizeOnBackBool", true) && !(parent instanceof Dialog);
hideEmptyCommands = manager.isThemeConstant("hideEmptyCommandsBool", false);
menuStyle = manager.getComponentStyle("Menu");
setUIID("SoftButton");
menuCommand = new Command(manager.localize("menu", "Menu"), lf.getMenuIcons()[2]);
// use the slide transition by default
if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
transitionIn = lf.getDefaultMenuTransitionIn();
transitionOut = lf.getDefaultMenuTransitionOut();
} else {
transitionIn = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 300, true);
transitionOut = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 300, true);
}
menuCellRenderer = lf.getMenuRenderer();
int softkeyCount = Display.getInstance().getImplementation().getSoftkeyCount();
thirdSoftButton = Display.getInstance().isThirdSoftButton();
int commandBehavior = getCommandBehavior();
if (softkeyCount > 1 && commandBehavior < Display.COMMAND_BEHAVIOR_BUTTON_BAR) {
if (thirdSoftButton) {
setLayout(new GridLayout(1, 3));
soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
main = soft[0];
left = soft[1];
right = soft[2];
if (parent.isRTL()) {
right.setUIID("SoftButtonLeft");
left.setUIID("SoftButtonRight");
addComponent(right);
addComponent(main);
addComponent(left);
} else {
addComponent(left);
addComponent(main);
addComponent(right);
}
if (isReverseSoftButtons()) {
Button b = soft[1];
soft[1] = soft[2];
soft[2] = b;
}
} else {
setLayout(new GridLayout(1, 2));
soft = new Button[] { createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
main = soft[0];
left = soft[0];
right = soft[1];
if (parent.isRTL()) {
right.setUIID("SoftButtonLeft");
left.setUIID("SoftButtonRight");
addComponent(right);
addComponent(left);
} else {
addComponent(left);
addComponent(right);
}
if (isReverseSoftButtons()) {
Button b = soft[0];
soft[0] = soft[1];
soft[1] = b;
}
}
// It doesn't make sense for softbuttons to have ... at the end
for (int iter = 0; iter < soft.length; iter++) {
soft[iter].setEndsWith3Points(false);
}
} else {
// special case for touch screens we still want the 3 softbutton areas...
if (thirdSoftButton) {
setLayout(new GridLayout(1, 3));
soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
main = soft[0];
left = soft[1];
right = soft[2];
addComponent(left);
addComponent(main);
addComponent(right);
if (isReverseSoftButtons()) {
Button b = soft[1];
soft[1] = soft[2];
soft[2] = b;
}
} else {
soft = new Button[] { createSoftButton("SoftButtonCenter") };
}
}
softCommand = new Command[soft.length];
}
use of com.codename1.ui.layouts.GridLayout in project CodenameOne by codenameone.
the class MenuBar method createCommandComponent.
/**
* Creates the component containing the commands within the given vector
* used for showing the menu dialog, this method calls the createCommandList
* method by default however it allows more elaborate menu creation.
*
* @param commands list of command objects
* @return Component that will result in the parent menu dialog recieving a command event
*/
protected Component createCommandComponent(Vector commands) {
UIManager manager = parent.getUIManager();
// Create a touch based menu interface
if (manager.getLookAndFeel().isTouchMenus()) {
Container menu = new Container();
menu.setScrollableY(true);
for (int iter = 0; iter < commands.size(); iter++) {
Command c = (Command) commands.elementAt(iter);
menu.addComponent(createTouchCommandButton(c));
}
if (!manager.isThemeConstant("touchCommandFlowBool", false)) {
int cols = calculateTouchCommandGridColumns(menu);
if (cols > getCommandCount()) {
cols = getCommandCount();
}
int rows = Math.max(1, getCommandCount() / cols + (getCommandCount() % cols != 0 ? 1 : 0));
if (rows > 1) {
// try to prevent too many columns concentraiting within a single row
int remainingColumns = (rows * cols) % getCommandCount();
int newCols = cols;
int newRows = rows;
while (remainingColumns != 0 && remainingColumns > 1 && newCols >= 2) {
newCols--;
newRows = Math.max(1, getCommandCount() / newCols + (getCommandCount() % newCols != 0 ? 1 : 0));
if (newRows != rows) {
break;
}
remainingColumns = (newRows * newCols) % getCommandCount();
}
if (newRows == rows) {
cols = newCols;
rows = newRows;
}
}
GridLayout g = new GridLayout(rows, cols);
g.setFillLastRow(manager.isThemeConstant("touchCommandFillBool", true));
menu.setLayout(g);
} else {
((FlowLayout) menu.getLayout()).setFillRows(true);
}
menu.setPreferredW(Display.getInstance().getDisplayWidth());
return menu;
}
return createCommandList(commands);
}
use of com.codename1.ui.layouts.GridLayout 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();
}
Aggregations