Search in sources :

Example 1 with Toolbar

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);
    }
}
Also used : Form(com.codename1.ui.Form) SideMenuBar(com.codename1.ui.SideMenuBar) Toolbar(com.codename1.ui.Toolbar)

Example 2 with Toolbar

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.");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 3 with Toolbar

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);
}
Also used : Util(com.codename1.io.Util) BoxLayout(com.codename1.ui.layouts.BoxLayout) ActionEvent(com.codename1.ui.events.ActionEvent) NetworkManager(com.codename1.io.NetworkManager) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) NetworkEvent(com.codename1.io.NetworkEvent) ComponentSelector.$(com.codename1.ui.ComponentSelector.$) ConnectionRequest(com.codename1.io.ConnectionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) AbstractTest(com.codename1.testing.AbstractTest) TestUtils(com.codename1.testing.TestUtils) SimpleDateFormat(com.codename1.l10n.SimpleDateFormat) Cookie(com.codename1.io.Cookie) FileSystemStorage(com.codename1.io.FileSystemStorage) IOException(java.io.IOException) ActionListener(com.codename1.ui.events.ActionListener) JSONParser(com.codename1.io.JSONParser) Log(com.codename1.io.Log) BorderLayout(com.codename1.ui.layouts.BorderLayout) InputStreamReader(java.io.InputStreamReader) Style(com.codename1.ui.plaf.Style) Coord(com.codename1.maps.Coord) ToastBar(com.codename1.components.ToastBar) InteractionDialog(com.codename1.components.InteractionDialog) InteractionDialog(com.codename1.components.InteractionDialog) ActionEvent(com.codename1.ui.events.ActionEvent) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Example 4 with Toolbar

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();
}
Also used : Slider(com.codename1.ui.Slider) Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label) RadioButton(com.codename1.ui.RadioButton) Container(com.codename1.ui.Container) ActionListener(com.codename1.ui.events.ActionListener) BorderLayout(com.codename1.ui.layouts.BorderLayout) RadioButton(com.codename1.ui.RadioButton) Button(com.codename1.ui.Button) MultiButton(com.codename1.components.MultiButton) CheckBox(com.codename1.ui.CheckBox) TextField(com.codename1.ui.TextField) MultiButton(com.codename1.components.MultiButton) Toolbar(com.codename1.ui.Toolbar)

Example 5 with Toolbar

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 &amp; 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;
}
Also used : Form(com.codename1.ui.Form) Command(com.codename1.ui.Command) ArrayList(java.util.ArrayList) Toolbar(com.codename1.ui.Toolbar)

Aggregations

Form (com.codename1.ui.Form)3 Toolbar (com.codename1.ui.Toolbar)3 ActionEvent (com.codename1.ui.events.ActionEvent)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 ActionListener (com.codename1.ui.events.ActionListener)2 BoxLayout (com.codename1.ui.layouts.BoxLayout)2 InteractionDialog (com.codename1.components.InteractionDialog)1 MultiButton (com.codename1.components.MultiButton)1 ToastBar (com.codename1.components.ToastBar)1 ConnectionRequest (com.codename1.io.ConnectionRequest)1 Cookie (com.codename1.io.Cookie)1 FileSystemStorage (com.codename1.io.FileSystemStorage)1 JSONParser (com.codename1.io.JSONParser)1 Log (com.codename1.io.Log)1 NetworkEvent (com.codename1.io.NetworkEvent)1 NetworkManager (com.codename1.io.NetworkManager)1 Util (com.codename1.io.Util)1 SimpleDateFormat (com.codename1.l10n.SimpleDateFormat)1 Coord (com.codename1.maps.Coord)1 AbstractTest (com.codename1.testing.AbstractTest)1