use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class BrowserComponent method fireWebEvent.
/**
* Used internally by the implementation to fire an event from the native browser widget
*
* @param type the type of the event
* @param ev the event
*/
public void fireWebEvent(String type, ActionEvent ev) {
if (onLoad.equals(type)) {
synchronized (readyLock) {
ready = true;
readyLock.notifyAll();
}
}
EventDispatcher e = getEventDispatcher(type, false);
if (e != null) {
e.fireActionEvent(ev);
}
}
use of com.codename1.ui.events.ActionEvent 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.events.ActionEvent 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.events.ActionEvent 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.");
}
use of com.codename1.ui.events.ActionEvent 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);
}
Aggregations