use of com.codename1.ui.Toolbar in project CodenameOne by codenameone.
the class TestUtils method showSidemenu.
/**
* Shows the sidemenu UI
*/
public static void showSidemenu() {
Form f = Display.getInstance().getCurrent();
Toolbar tb = f.getToolbar();
if (tb != null) {
tb.openSideMenu();
} else {
((SideMenuBar) f.getMenuBar()).openMenu(null);
}
}
use of com.codename1.ui.Toolbar 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.");
}
use of com.codename1.ui.Toolbar in project CodenameOne by codenameone.
the class TestComponent method getComponentAt_int_int_browsercomponent.
private void getComponentAt_int_int_browsercomponent() {
int w = Display.getInstance().getDisplayWidth();
int h = Display.getInstance().getDisplayHeight();
Form mapDemo = new Form("Maps", new LayeredLayout());
Toolbar.setOnTopSideMenu(true);
Toolbar tb = new Toolbar();
mapDemo.setToolbar(tb);
mapDemo.setTitle("Maps");
tb.addCommandToSideMenu(new Command("Test") {
@Override
public void actionPerformed(ActionEvent e) {
// testNestedScrollingLabels();
}
});
BrowserComponent mc = new BrowserComponent();
mapDemo.add(mc);
mapDemo.show();
TestUtils.waitForFormTitle("Maps", 2000);
Component middleComponent = mapDemo.getComponentAt(w / 2, h / 2);
assertTrue(mc == middleComponent || mc.contains(middleComponent), "Wrong component found in middle. Expected " + mc + " but found " + middleComponent);
tb.openSideMenu();
// wait for side menu to open
TestUtils.waitFor(500);
Component res = null;
res = tb.getComponentAt(10, h / 2);
// System.out.println("tb size = "+tb.getAbsoluteX()+", "+tb.getAbsoluteY()+", "+tb.getWidth()+", "+tb.getHeight());
// System.out.println("mb size = "+tb.getMenuBar().getAbsoluteX()+", "+tb.getMenuBar().getAbsoluteY()+", "+tb.getMenuBar().getWidth()+", "+tb.getMenuBar().getHeight());
// System.out.println("res is "+res);
res = mapDemo.getComponentAt(10, h / 2);
// Let's find the interaction dialog on the form
Component interactionDialog = $("*", mapDemo).filter(c -> {
return c instanceof InteractionDialog;
}).asComponent();
assertTrue(((InteractionDialog) interactionDialog).contains(res), "Toolbar is open so getComponentAt() should return something on the toolbar. But received " + res + ". Toolbar is " + tb);
}
use of com.codename1.ui.Toolbar in project CodenameOne by codenameone.
the class LiveDemo method start.
public void start() {
Form previewForm = new Form("Preview Theme");
Toolbar tb = new Toolbar();
previewForm.setToolbar(tb);
tb.setTitle("Preview Theme");
tb.addMaterialCommandToSideMenu("Side Command", FontImage.MATERIAL_HELP, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ToastBar.showErrorMessage("Unmapped....");
}
});
tb.addMaterialCommandToOverflowMenu("Overflow Command", FontImage.MATERIAL_HELP, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ToastBar.showErrorMessage("Unmapped....");
}
});
tb.addMaterialCommandToRightBar("", FontImage.MATERIAL_HELP, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ToastBar.showErrorMessage("Unmapped....");
}
});
previewForm.setLayout(new BorderLayout());
Container first = new Container(new BoxLayout(BoxLayout.Y_AXIS));
first.addComponent(new Label("This is a Label"));
first.addComponent(new Button("This is a Button"));
MultiButton mb = new MultiButton("This is a MultiButton");
mb.setTextLine2("Second line of text");
FontImage.setMaterialIcon(mb, FontImage.MATERIAL_HELP);
first.addComponent(mb);
TextField txt = new TextField();
txt.setHint("This is a TextField");
first.addComponent(txt);
first.addComponent(new CheckBox("This is a CheckBox"));
RadioButton rb1 = new RadioButton("This is a Radio Button 1");
rb1.setGroup("group");
first.addComponent(rb1);
RadioButton rb2 = new RadioButton("This is a Radio Button 2");
rb2.setGroup("group");
first.addComponent(rb2);
final Slider s = new Slider();
s.setText("50%");
s.setProgress(50);
s.setEditable(true);
s.setRenderPercentageOnTop(true);
first.addComponent(s);
Button b1 = new Button("Show a Dialog");
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
Dialog.show("Dialog Title", "Dialog Body", "Ok", "Cancel");
}
});
first.addComponent(b1);
previewForm.add(BorderLayout.CENTER, first);
previewForm.show();
}
use of com.codename1.ui.Toolbar in project CodenameOne by codenameone.
the class TestUtils method getToolbarCommands.
/**
* Returns all the command objects from the toolbar in the order of left, right, overflow & sidemenu
* @return the set of commands
*/
public static Command[] getToolbarCommands() {
Form f = Display.getInstance().getCurrent();
Toolbar tb = f.getToolbar();
ArrayList<Command> result = new ArrayList<Command>();
addAllCommands(tb.getLeftBarCommands(), result);
addAllCommands(tb.getRightBarCommands(), result);
addAllCommands(tb.getOverflowCommands(), result);
addAllCommands(tb.getSideMenuCommands(), result);
Command[] carr = new Command[result.size()];
result.toArray(carr);
return carr;
}
Aggregations