use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class MenuBar method updateTitleCommandPlacement.
private void updateTitleCommandPlacement() {
int commandBehavior = getCommandBehavior();
Container t = getTitleAreaContainer();
BorderLayout titleLayout = (BorderLayout) t.getLayout();
if (getParent() == null) {
installMenuBar();
} else {
if (getParent() == getTitleAreaContainer() && commandBehavior != Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT && commandBehavior != Display.COMMAND_BEHAVIOR_ICS) {
getParent().removeComponent(this);
installMenuBar();
}
}
if (!(parent instanceof Dialog)) {
if ((commandBehavior == Display.COMMAND_BEHAVIOR_ICS || commandBehavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION || commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK) && parent.getTitle() != null && parent.getTitle().length() > 0) {
synchronizeCommandsWithButtonsInBackbutton();
return;
} else {
if (commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT || commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK) {
if (getParent() != null) {
if (getParent() == getTitleAreaContainer()) {
return;
}
getParent().removeComponent(this);
}
// getTitleAreaContainer().addComponent(BorderLayout.EAST, findRightTitleContainer());
return;
}
}
}
if (t.getComponentCount() - componentCountOffset(t) > 1) {
if (Display.COMMAND_BEHAVIOR_ICS == getCommandBehavior()) {
titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
} else {
titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
}
Component l = getTitleComponent();
if (l.getParent() != null) {
l.getParent().removeComponent(l);
}
t.removeAll();
t.addComponent(BorderLayout.CENTER, l);
initTitleBarStatus();
}
}
use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class MenuBar method actionPerformed.
/**
* Invoked when a softbutton is pressed
*/
public void actionPerformed(ActionEvent evt) {
if (evt.isConsumed()) {
return;
}
Object src = evt.getSource();
if (commandList == null) {
Button source = (Button) src;
for (int iter = 0; iter < soft.length; iter++) {
if (source == soft[iter]) {
if (softCommand[iter] == menuCommand) {
showMenu();
return;
}
if (softCommand[iter] != null) {
ActionEvent e = new ActionEvent(softCommand[iter], ActionEvent.Type.Command);
softCommand[iter].actionPerformed(e);
if (!e.isConsumed()) {
parent.actionCommandImpl(softCommand[iter]);
}
}
return;
}
}
} else {
// the list for the menu sent the event
if (src instanceof Button) {
for (int iter = 0; iter < soft.length; iter++) {
if (src == soft[iter]) {
Container parent = commandList.getParent();
while (parent != null) {
if (parent instanceof Dialog) {
((Dialog) parent).actionCommand(softCommand[iter]);
return;
}
parent = parent.getParent();
}
}
}
}
Command c = getComponentSelectedCommand(commandList);
if (!c.isEnabled()) {
return;
}
Container p = commandList.getParent();
while (p != null) {
if (p instanceof Dialog) {
((Dialog) p).actionCommand(c);
return;
}
p = p.getParent();
}
}
}
use of com.codename1.ui.Container in project CodenameOne by codenameone.
the class MenuBar method adaptTitleLayoutBackCommandStructure.
void adaptTitleLayoutBackCommandStructure() {
Container t = getTitleAreaContainer();
if (t.getComponentCount() - componentCountOffset(t) == 3) {
return;
}
BorderLayout titleLayout = (BorderLayout) t.getLayout();
if (Display.COMMAND_BEHAVIOR_ICS == getCommandBehavior()) {
titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
getTitleComponent().getUnselectedStyle().setAlignment(Component.LEFT, true);
} else {
titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
}
t.removeAll();
t.addComponent(BorderLayout.CENTER, getTitleComponent());
Container leftContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
Container rightContainer = new Container(new BoxLayout(BoxLayout.X_AXIS));
t.addComponent(BorderLayout.EAST, rightContainer);
t.addComponent(BorderLayout.WEST, leftContainer);
initTitleBarStatus();
}
use of com.codename1.ui.Container 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.Container in project CodenameOne by codenameone.
the class TestComponent method testNestedScrollingLabels.
private void testNestedScrollingLabels() {
int w = Display.getInstance().getDisplayWidth();
int h = Display.getInstance().getDisplayHeight();
Form f = new Form("Scrolling Labels");
Toolbar tb = new Toolbar();
f.setToolbar(tb);
final Form backForm = Display.getInstance().getCurrent();
tb.addCommandToSideMenu(new Command("Back") {
@Override
public void actionPerformed(ActionEvent e) {
if (backForm != null) {
backForm.showBack();
}
}
});
f.setTitle("Scrolling Labels");
Container cnt = new Container(BoxLayout.y());
cnt.setScrollableY(true);
for (String l : new String[] { "Red", "Green", "Blue", "Orange", "Indigo" }) {
for (int i = 0; i < 20; i++) {
cnt.add(l + i);
}
}
f.setLayout(new BorderLayout());
f.add(BorderLayout.CENTER, LayeredLayout.encloseIn(new Button("Press me"), BorderLayout.center(BorderLayout.center(cnt))));
f.show();
TestUtils.waitForFormTitle("Scrolling Labels", 2000);
Component res = f.getComponentAt(w / 2, h / 2);
assertTrue(res == cnt || res.getParent() == cnt, "getComponentAt(x,y) should return scrollable container on top of button when in layered pane.");
}
Aggregations