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);
}
}
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));
}
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);
}
}
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);
}
}
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.");
}
Aggregations