Java Code Examples for com.codename1.ui.Form#setName()

The following examples show how to use com.codename1.ui.Form#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestComponent.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * https://github.com/codenameone/CodenameOne/issues/2255
 */
public void testOverflowMenuNPE() {
    log("Testing testOverflowMenuNPE");
    Form hi = new Form();
    hi.setName("testOverflowMenuNPE");
    hi.getToolbar().addCommandToOverflowMenu("Test", FontImage.createMaterial(FontImage.MATERIAL_3D_ROTATION, new Style()), new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent evt) {
                   ToastBar.showMessage("menu", FontImage.MATERIAL_3D_ROTATION);
                   hi.revalidate();
                }
            });
    hi.show();

    TestUtils.waitForFormName("testOverflowMenuNPE", 2000);
    hi.getToolbar().closeSideMenu();

}
 
Example 2
Source File: SpanLabelLayeredLayoutPreferredSizeTest3000.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void testBorderLayout() {
    Button showPopUp = new Button("Show PopUp in Border Layout");
    Form f = new Form(BoxLayout.y());
    f.setName("testBorderLayout");
    f.add(showPopUp);

    showPopUp.addActionListener((e) -> {

        SpanLabel messageSpanLabel = new SpanLabel("Tap the following button to open the gallery. You should be able to select multiple images and videos. Tap the following button to open the gallery. You should be able to select multiple images and videos.");
        messageSpanLabel.setName("messageSpanLabel");
        Container centerContainerOuter = new Container(new BorderLayout(CENTER_BEHAVIOR_CENTER));
        centerContainerOuter.add(CENTER, messageSpanLabel);

        Container layeredPane = getCurrentForm().getLayeredPane();
        layeredPane.setLayout(new LayeredLayout());        
        layeredPane.add(centerContainerOuter);
        layeredPane.setVisible(true);

        getCurrentForm().revalidate();     
    });
    showPopUp.setName("showBorderLayout");
    f.show();
    waitForFormName("testBorderLayout");
    clickButtonByName("showBorderLayout");
    SpanLabel spanLabel = (SpanLabel)findByName("messageSpanLabel");
    Label l = new Label("Tap the following");
    
    assertTrue(spanLabel.getHeight() > l.getPreferredH() * 2, "Span Label height is too small.  Should be at least a few lines.");
    
    
}
 
Example 3
Source File: TestComponent.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
private void testBrowserComponent2267() {
    Form hi = new Form();
    String formName = "testBrowserComponent2267";
    hi.setName(formName);
    hi.setLayout(new BorderLayout());

    BrowserComponent browserComponent = new BrowserComponent();
    hi.add(BorderLayout.CENTER, browserComponent);

    final Throwable[] ex = new Throwable[1];
    final boolean[] complete = new boolean[1];
    Button loadButton = new Button("setUrl");
    String buttonName = "setUrl";
    loadButton.setName(buttonName);
    loadButton.addActionListener((ev) -> {
            ActionListener errorHandler = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    e.consume();
                    ex[0] = (Throwable)e.getSource();
                    complete[0] = true;
                    Display.getInstance().removeEdtErrorHandler(this);
                }
            };
            try {


                Display.getInstance().addEdtErrorHandler(errorHandler);
                browserComponent.addWebEventListener("onLoad", e-> {
                    Display.getInstance().removeEdtErrorHandler(errorHandler);
                    complete[0] = true;
                });
                browserComponent.setURL("https://www.google.es");
            } catch (Throwable t) {
                ex[0] = t;
                complete[0] = true;
                Display.getInstance().removeEdtErrorHandler(errorHandler);
            } finally {
                //complete[0] = true;
            }
    });
    hi.add(BorderLayout.SOUTH, loadButton);
    hi.show();
    log("About to wait for form "+formName);
    TestUtils.waitForFormName(formName, 4000);
    log("Finished waiting for form "+formName);
    TestUtils.clickButtonByName(buttonName);
    log("Waiting for browserComponent to load https://www.google.es");
    while (!complete[0]) {
        Display.getInstance().invokeAndBlock(()->{
            Util.sleep(50);
        });
    }
    log("Finished waiting for browserComponent to load https://www.google.es");
    String message = null;
    if (ex[0] != null) {
        message = ex[0].getMessage();
    }
    TestUtils.assertBool(ex[0] == null, "We received an exception setting the browserComponent URL: "+message);
}
 
Example 4
Source File: TestComponent.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
boolean runOwnerTests() throws Exception {
    log("Running ownerTests");
    Container cnt = new Container();
    Button b2 = new Button();
    assertTrue(!cnt.isOwnedBy(b2), "cnt is not owned by b2");
    assertTrue(!b2.isOwnedBy(cnt), "b2 is not owned by cn1");
    cnt.add(b2);
    assertTrue(!b2.isOwnedBy(cnt), "button should not be owned by cn1 even though it is a child");
    b2.setOwner(cnt);
    assertTrue(b2.isOwnedBy(cnt), "Button should be owned by container");
    b2.setOwner(null);
    assertTrue(!b2.isOwnedBy(cnt), "Button should no longer be owned by container");

    Container c2 = new Container();
    c2.setOwner(cnt);
    assertTrue(c2.isOwnedBy(cnt), "c2 should be owned by cnt");
    b2.remove();
    c2.add(b2);
    assertTrue(b2.isOwnedBy(cnt), "b2 should be owned by cnt because its parent is owned by cnt");
    b2.remove();
    assertTrue(!b2.isOwnedBy(cnt), "b2 should no longer be owned by cnt");

    b2.setOwner(c2);
    assertTrue(b2.isOwnedBy(cnt), "b2 should be owned by cnt because of the owner hierarchy through c2");

    Form f1 = new Form("Test Form", BoxLayout.y());
    f1.setName("TestForm");
    f1.show();
    waitForFormName("TestForm");
    //waitFor(2000);
    Button b3 = new Button("B3");
    Button b4 = new Button("B4");
    f1.add(b3).add(b4);
    f1.revalidate();
    //System.out.println(c(b3));
    //System.out.println(b3.contains(c(b3).getX(), c(b3).getY()));
    //System.out.println("Absx="+b3.getAbsoluteX()+", absy="+b3.getAbsoluteY()+", w="+b3.getWidth()+", h="+b3.getHeight());
    assertTrue(b3.contains(c(b3).getX(), c(b3).getY()));
    assertTrue(!b3.contains(c(b4).getX(), c(b4).getY()));
    assertTrue(b3.containsOrOwns(c(b3).getX(), c(b3).getY()));
    assertTrue(!b3.containsOrOwns(c(b4).getX(), c(b4).getY()));
    
    b4.setOwner(b3);
    assertTrue(b3.containsOrOwns(c(b4).getX(), c(b4).getY()));
    
    Container c4 = new Container(BoxLayout.x());
    Button b5 = new Button("B5");
    c4.add(b5);
    f1.add(c4);
    f1.revalidate();
    assertTrue(!b3.containsOrOwns(c(b5).getX(), c(b5).getY()));
    c4.setOwner(b3);
    //System.out.println("Component: "+f1.getComponentAt(c(b5).getX(), c(b5).getY()));
    assertTrue(b3.containsOrOwns(c(b5).getX(), c(b5).getY()));
    Container c5 = new Container();
    b3.remove();
    c5.add(b3);
    f1.add(c5);
    f1.revalidate();
    assertTrue(c5.containsOrOwns(c(b5).getX(), c(b5).getY()));
    
    

return true;
}