Search in sources :

Example 41 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class SpanLabelTests2980 method runTest.

@Override
public boolean runTest() throws Exception {
    if (layout == null) {
        Layout[] layouts = new Layout[] { new FlowLayout(), BoxLayout.x(), BoxLayout.y() };
        for (Layout l : layouts) {
            layout = l;
            runTest();
        }
        return true;
    }
    System.out.println("Laying out SpanLabel with layout " + layout);
    Label label = new Label("Tap the following");
    Container cnt = new Container(layout) {

        @Override
        protected Dimension calcPreferredSize() {
            return new Dimension(label.getPreferredW(), CN.convertToPixels(1000));
        }

        @Override
        public int getWidth() {
            return label.getPreferredW();
        }

        @Override
        public int getHeight() {
            return CN.convertToPixels(1000);
        }
    };
    cnt.setScrollableX(false);
    cnt.setScrollableY(false);
    cnt.setWidth(label.getPreferredW());
    cnt.setHeight(CN.convertToPixels(1000));
    SpanLabel sl = new SpanLabel("Tap the following button to open the gallery. You should be able to select multiple images and videos.");
    sl.setName("TheSpanLabel");
    cnt.add(sl);
    cnt.add(new Button("Click Me"));
    cnt.setShouldCalcPreferredSize(true);
    cnt.layoutContainer();
    assertTrue(sl.getHeight() > label.getPreferredH() * 2, "Span Label height is too low for layout " + layout + ": was " + sl.getHeight() + " but should be at least " + (label.getPreferredH() * 2));
    SpanButton sb = new SpanButton("Tap the following button to open the gallery. You should be able to select multiple images and videos.");
    sb.setName("TheSpanButton");
    cnt.removeAll();
    cnt.add(sb);
    cnt.add(new Button("Click Me"));
    cnt.setShouldCalcPreferredSize(true);
    cnt.layoutContainer();
    assertTrue(sb.getHeight() > label.getPreferredH() * 2, "Span button height is too low for layout " + layout + ": was " + sb.getHeight() + " but should be at least " + (label.getPreferredH() * 2));
    testBorderLayout();
    return true;
}
Also used : FlowLayout(com.codename1.ui.layouts.FlowLayout) Layout(com.codename1.ui.layouts.Layout) BoxLayout(com.codename1.ui.layouts.BoxLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) SpanButton(com.codename1.components.SpanButton) SpanLabel(com.codename1.components.SpanLabel) SpanButton(com.codename1.components.SpanButton) Dimension(com.codename1.ui.geom.Dimension) SpanLabel(com.codename1.components.SpanLabel)

Example 42 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class SpanLabelTests2980 method testBorderLayout.

private void testBorderLayout() {
    System.out.println("Testing SpanLabel preferred size in BorderLayout.  https://github.com/codenameone/CodenameOne/issues/3000");
    // Button showPopUp = new Button("Show PopUp in Border Layout");
    Form f = new Form(BoxLayout.y());
    f.setName("testBorderLayout");
    // f.add(showPopUp);
    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.");
    // showPopUp.addActionListener((e) -> {
    Runnable showPopup = () -> {
        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");
    showPopup.run();
    // give time for click to take effect
    waitFor(500);
    // (SpanLabel)findByName("messageSpanLabel");
    SpanLabel spanLabel = 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.");
    System.out.println("Finished SpanLabel BorderLayout test");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) CN.getCurrentForm(com.codename1.ui.CN.getCurrentForm) SpanLabel(com.codename1.components.SpanLabel) SpanLabel(com.codename1.components.SpanLabel) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Example 43 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class TestComponent method getComponentAt_int_int_label.

private void getComponentAt_int_int_label() {
    log("Testing getComponentAt(x, y) with label");
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();
    Form f = new Form("My Form", new BorderLayout());
    Label l = new Label("Hello");
    f.add(BorderLayout.CENTER, l);
    f.show();
    TestUtils.waitForFormTitle("My Form", 2000);
    Component middleComponent = f.getComponentAt(w / 2, h / 2);
    assertEqual(l, middleComponent, "Found wrong component");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Point(com.codename1.ui.geom.Point)

Example 44 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class TestComponent method getComponentAt_int_int_nested_focusable_container.

private void getComponentAt_int_int_nested_focusable_container() {
    log("Testing getComponentAt(x, y) with layered nesting");
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();
    Form f = new Form("My Form", new BorderLayout());
    Container bottom = new Container() {

        @Override
        protected Dimension calcPreferredSize() {
            return new Dimension(w, h);
        }
    };
    bottom.setGrabsPointerEvents(true);
    bottom.setName("Bottom");
    Container top = new Container(new BorderLayout());
    top.setFocusable(true);
    Label content = new Label("Hello");
    content.setName("Content");
    top.add(BorderLayout.CENTER, content);
    top.setName("Top");
    Container wrapper = new Container(new LayeredLayout());
    wrapper.add(bottom).add(top);
    f.add(BorderLayout.CENTER, wrapper);
    f.show();
    TestUtils.waitForFormTitle("My Form", 2000);
    Component middleComponent = f.getComponentAt(w / 2, h / 2);
    assertEqual(top, middleComponent, "Found wrong component");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Dimension(com.codename1.ui.geom.Dimension) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) Point(com.codename1.ui.geom.Point)

Example 45 with Label

use of com.codename1.rad.models.Property.Label in project CodenameOne by codenameone.

the class TestComponent method getComponentAt_int_int_button.

private void getComponentAt_int_int_button() {
    log("Testing getComponentAt(x, y) with button");
    int w = Display.getInstance().getDisplayWidth();
    int h = Display.getInstance().getDisplayHeight();
    Form f = new Form("My Form", new BorderLayout());
    Label l = new Button("Hello");
    f.add(BorderLayout.CENTER, l);
    f.show();
    TestUtils.waitForFormTitle("My Form");
    Component middleComponent = f.getComponentAt(w / 2, h / 2);
    assertEqual(l, middleComponent, "Found wrong component");
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Point(com.codename1.ui.geom.Point)

Aggregations

Label (com.codename1.ui.Label)129 Form (com.codename1.ui.Form)95 Button (com.codename1.ui.Button)50 BorderLayout (com.codename1.ui.layouts.BorderLayout)50 Container (com.codename1.ui.Container)49 Component (com.codename1.ui.Component)27 SpanLabel (com.codename1.components.SpanLabel)26 Style (com.codename1.ui.plaf.Style)24 BoxLayout (com.codename1.ui.layouts.BoxLayout)19 TextArea (com.codename1.ui.TextArea)18 ActionEvent (com.codename1.ui.events.ActionEvent)18 IOException (java.io.IOException)18 Image (com.codename1.ui.Image)17 Dimension (com.codename1.ui.geom.Dimension)16 TextField (com.codename1.ui.TextField)15 ActionListener (com.codename1.ui.events.ActionListener)15 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)15 Toolbar (com.codename1.ui.Toolbar)13 FlowLayout (com.codename1.ui.layouts.FlowLayout)12 EncodedImage (com.codename1.ui.EncodedImage)11