Search in sources :

Example 61 with Form

use of com.codename1.ui.Form 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 62 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class TestUtils method executeToolbarCommandAtOffset.

/**
 * Executes a command from the offset returned by {@link #getToolbarCommands()}
 *
 * @param offset the offset of the command we want to execute
 */
public static void executeToolbarCommandAtOffset(final int offset) {
    Form f = Display.getInstance().getCurrent();
    if (!Display.getInstance().isEdt()) {
        Display.getInstance().callSerially(new Runnable() {

            public void run() {
                executeToolbarCommandAtOffset(offset);
            }
        });
        return;
    }
    Command cmd = getToolbarCommands()[offset];
    f.dispatchCommand(cmd, new ActionEvent(cmd));
}
Also used : Form(com.codename1.ui.Form) Command(com.codename1.ui.Command) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 63 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class Button method fireActionEvent.

/**
 * Allows subclasses to override action event behavior
 * {@inheritDoc}
 *
 * @param x the x position of the click if applicable (can be 0 or -1 otherwise)
 * @param y the y position of the click if applicable (can be 0 or -1 otherwise)
 */
protected void fireActionEvent(int x, int y) {
    super.fireActionEvent();
    if (cmd != null) {
        ActionEvent ev = new ActionEvent(cmd, this, x, y);
        dispatcher.fireActionEvent(ev);
        if (!ev.isConsumed()) {
            Form f = getComponentForm();
            if (f != null) {
                f.actionCommandImplNoRecurseComponent(cmd, ev);
            }
        }
    } else {
        dispatcher.fireActionEvent(new ActionEvent(this, ActionEvent.Type.PointerPressed, x, y));
    }
    Display d = Display.getInstance();
    if (d.isBuiltinSoundsEnabled()) {
        d.playBuiltinSound(Display.SOUND_TYPE_BUTTON_PRESS);
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 64 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class Button method pointerPressed.

/**
 * {@inheritDoc}
 */
public void pointerPressed(int x, int y) {
    clearDrag();
    setDragActivated(false);
    if (pointerPressedListeners != null && pointerPressedListeners.hasListeners()) {
        pointerPressedListeners.fireActionEvent(new ActionEvent(this, ActionEvent.Type.PointerPressed, x, y));
    }
    pressed();
    Form f = getComponentForm();
    // might happen when programmatically triggering press
    if (f != null) {
        if (f.buttonsAwatingRelease == null) {
            f.buttonsAwatingRelease = new ArrayList<Component>();
        }
        f.buttonsAwatingRelease.add(this);
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 65 with Form

use of com.codename1.ui.Form 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)

Aggregations

Form (com.codename1.ui.Form)90 ActionEvent (com.codename1.ui.events.ActionEvent)41 Component (com.codename1.ui.Component)38 BorderLayout (com.codename1.ui.layouts.BorderLayout)38 Container (com.codename1.ui.Container)26 ActionListener (com.codename1.ui.events.ActionListener)25 Dialog (com.codename1.ui.Dialog)21 Command (com.codename1.ui.Command)19 Hashtable (java.util.Hashtable)17 Label (com.codename1.ui.Label)14 Style (com.codename1.ui.plaf.Style)14 IOException (java.io.IOException)14 TextArea (com.codename1.ui.TextArea)13 Vector (java.util.Vector)12 Button (com.codename1.ui.Button)11 Graphics (com.codename1.ui.Graphics)9 RadioButton (com.codename1.ui.RadioButton)9 Animation (com.codename1.ui.animations.Animation)9 Image (com.codename1.ui.Image)8 UIManager (com.codename1.ui.plaf.UIManager)8