use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class Form method pointerReleased.
/**
* {@inheritDoc}
*/
public void pointerReleased(int x, int y) {
rippleMotion = null;
pressedCmp = null;
boolean isScrollWheeling = Display.INSTANCE.impl.isScrollWheeling();
Container actual = getActualPane(formLayeredPane, x, y);
if (buttonsAwatingRelease != null && buttonsAwatingRelease.size() == 1) {
// special case allowing drag within a button
Component atXY = actual.getComponentAt(x, y);
Component pendingButton = (Component) buttonsAwatingRelease.get(0);
if (atXY == pendingButton) {
buttonsAwatingRelease = null;
if (dragged == pendingButton) {
if (pendingButton.isDragAndDropInitialized()) {
pendingButton.dragFinishedImpl(x, y);
} else {
pendingButton.pointerReleased(x, y);
}
dragged = null;
} else {
pendingButton.pointerReleased(x, y);
if (dragged != null) {
if (dragged.isDragAndDropInitialized()) {
dragged.dragFinishedImpl(x, y);
dragged = null;
} else {
dragged.pointerReleased(x, y);
dragged = null;
}
}
}
return;
}
if (pendingButton instanceof Button) {
Button b = (Button) pendingButton;
int relRadius = b.getReleaseRadius();
if (relRadius > 0 || b.contains(x, y)) {
Rectangle r = new Rectangle(b.getAbsoluteX() - relRadius, b.getAbsoluteY() - relRadius, b.getWidth() + relRadius * 2, b.getHeight() + relRadius * 2);
if (r.contains(x, y)) {
buttonsAwatingRelease = null;
pointerReleased(b.getAbsoluteX() + 1, b.getAbsoluteY() + 1);
return;
}
}
}
}
if (pointerReleasedListeners != null && pointerReleasedListeners.hasListeners()) {
ActionEvent ev = new ActionEvent(this, ActionEvent.Type.PointerReleased, x, y);
pointerReleasedListeners.fireActionEvent(ev);
if (ev.isConsumed()) {
if (dragged != null) {
if (dragged.isDragAndDropInitialized()) {
dragged.dragFinishedImpl(x, y);
}
dragged = null;
}
return;
}
}
if (dragStopFlag) {
if (dragged != null) {
if (dragged.isDragAndDropInitialized()) {
dragged.dragFinishedImpl(x, y);
}
dragged = null;
}
dragStopFlag = false;
return;
}
if (dragged == null) {
// soft button.
if (menuBar.contains(x, y)) {
Component cmp = menuBar.getComponentAt(x, y);
if (cmp != null && cmp.isEnabled()) {
cmp.pointerReleased(x, y);
}
return;
}
if (stickyDrag != null) {
stickyDrag.pointerReleased(x, y);
repaint();
} else {
// Container actual = getActualPane();
if (y >= actual.getY() && x >= actual.getX()) {
Component cmp = actual.getComponentAt(x, y);
while (cmp != null && cmp.isIgnorePointerEvents()) {
cmp = cmp.getParent();
}
if (cmp != null && cmp.isEnabled()) {
if (cmp.hasLead) {
Container leadParent;
if (cmp instanceof Container) {
leadParent = ((Container) cmp).getLeadParent();
} else {
leadParent = cmp.getParent().getLeadParent();
}
leadParent.repaint();
if (!isScrollWheeling) {
setFocused(leadParent);
}
cmp.getLeadComponent().pointerReleased(x, y);
} else {
if (cmp.isEnabled()) {
if (!isScrollWheeling && cmp.isFocusable()) {
setFocused(cmp);
}
cmp.pointerReleased(x, y);
}
}
}
} else {
if (y < actual.getY()) {
Component cmp = getTitleArea().getComponentAt(x, y);
while (cmp != null && cmp.isIgnorePointerEvents()) {
cmp = cmp.getParent();
}
if (cmp != null && cmp.isEnabled()) {
cmp.pointerReleased(x, y);
}
} else {
Component cmp = ((BorderLayout) super.getLayout()).getWest();
if (cmp != null) {
cmp = ((Container) cmp).getComponentAt(x, y);
while (cmp != null && cmp.isIgnorePointerEvents()) {
cmp = cmp.getParent();
}
if (cmp != null && cmp.isEnabled()) {
if (cmp.hasLead) {
Container leadParent;
if (cmp instanceof Container) {
leadParent = ((Container) cmp).getLeadParent();
} else {
leadParent = cmp.getParent().getLeadParent();
}
leadParent.repaint();
if (!isScrollWheeling) {
setFocused(leadParent);
}
cmp = cmp.getLeadComponent();
cmp.pointerReleased(x, y);
} else {
cmp.pointerReleased(x, y);
}
}
}
}
}
}
} else {
if (dragged.isDragAndDropInitialized()) {
dragged.dragFinishedImpl(x, y);
dragged = null;
} else {
dragged.pointerReleased(x, y);
dragged = null;
}
}
stickyDrag = null;
if (buttonsAwatingRelease != null && !Display.getInstance().isRecursivePointerRelease()) {
for (int iter = 0; iter < buttonsAwatingRelease.size(); iter++) {
Button b = (Button) buttonsAwatingRelease.get(iter);
b.setState(Button.STATE_DEFAULT);
b.repaint();
}
buttonsAwatingRelease = null;
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class MenuBar method actionPerformed.
/**
* Invoked when a softbutton is pressed
*/
public void actionPerformed(ActionEvent evt) {
if (evt.isConsumed()) {
return;
}
Object src = evt.getSource();
if (commandList == null) {
Button source = (Button) src;
for (int iter = 0; iter < soft.length; iter++) {
if (source == soft[iter]) {
if (softCommand[iter] == menuCommand) {
showMenu();
return;
}
if (softCommand[iter] != null) {
ActionEvent e = new ActionEvent(softCommand[iter], ActionEvent.Type.Command);
softCommand[iter].actionPerformed(e);
if (!e.isConsumed()) {
parent.actionCommandImpl(softCommand[iter]);
}
}
return;
}
}
} else {
// the list for the menu sent the event
if (src instanceof Button) {
for (int iter = 0; iter < soft.length; iter++) {
if (src == soft[iter]) {
Container parent = commandList.getParent();
while (parent != null) {
if (parent instanceof Dialog) {
((Dialog) parent).actionCommand(softCommand[iter]);
return;
}
parent = parent.getParent();
}
}
}
}
Command c = getComponentSelectedCommand(commandList);
if (!c.isEnabled()) {
return;
}
Container p = commandList.getParent();
while (p != null) {
if (p instanceof Dialog) {
((Dialog) p).actionCommand(c);
return;
}
p = p.getParent();
}
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class MenuBar method showMenu.
/**
* This method shows the menu on the Form.
* The method creates a Dialog with the commands and calls showMenuDialog.
* The method blocks until the user dispose the dialog.
*/
public void showMenu() {
final Dialog d = new Dialog("Menu", "");
d.setDisposeWhenPointerOutOfBounds(true);
d.setMenu(true);
d.addOrientationListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
d.dispose();
}
});
d.setTransitionInAnimator(transitionIn);
d.setTransitionOutAnimator(transitionOut);
d.setLayout(new BorderLayout());
d.setScrollable(false);
// calling parent.createCommandComponent is done only for backward
// compatability reasons, in the next version this call be replaced with
// calling directly to createCommandComponent
((Form) d).getMenuBar().commandList = createCommandComponent(commands);
if (menuCellRenderer != null && ((Form) d).getMenuBar().commandList instanceof List) {
((List) ((Form) d).getMenuBar().commandList).setListCellRenderer(menuCellRenderer);
}
d.getContentPane().getStyle().setMargin(0, 0, 0, 0);
d.addComponent(BorderLayout.CENTER, ((Form) d).getMenuBar().commandList);
if (thirdSoftButton) {
d.addCommand(selectMenuItem);
d.addCommand(cancelMenuItem);
} else {
d.addCommand(cancelMenuItem);
if (soft.length > 1) {
d.addCommand(selectMenuItem);
}
}
d.setClearCommand(cancelMenuItem);
d.setBackCommand(cancelMenuItem);
if (((Form) d).getMenuBar().commandList instanceof List) {
((List) ((Form) d).getMenuBar().commandList).addActionListener(((Form) d).getMenuBar());
}
menuDisplaying = true;
Command result = showMenuDialog(d);
menuDisplaying = false;
if (result != cancelMenuItem) {
Command c = null;
if (result == selectMenuItem) {
c = getComponentSelectedCommand(((Form) d).getMenuBar().commandList);
if (c != null) {
ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
c.actionPerformed(e);
}
} else {
c = result;
// a touch menu will always send its commands on its own...
if (!isTouchMenus()) {
c = result;
if (c != null) {
ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
c.actionPerformed(e);
}
}
}
// menu item was handled internally in a touch interface that is not a touch menu
if (c != null) {
parent.actionCommandImpl(c);
}
}
if (((Form) d).getMenuBar().commandList instanceof List) {
((List) ((Form) d).getMenuBar().commandList).removeActionListener(((Form) d).getMenuBar());
}
Form upcoming = Display.getInstance().getCurrentUpcoming();
if (upcoming == parent) {
d.disposeImpl();
} else {
parent.tint = (upcoming instanceof Dialog);
}
}
use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.
the class EmailShare method share.
/**
* {@inheritDoc}
*/
public void share(final String toShare, final String image, final String mimeType) {
final Form currentForm = Display.getInstance().getCurrent();
final Form contactsForm = new Form("Contacts");
contactsForm.setLayout(new BorderLayout());
contactsForm.setScrollable(false);
contactsForm.addComponent(BorderLayout.CENTER, new Label("Please wait..."));
contactsForm.show();
Display.getInstance().startThread(new Runnable() {
public void run() {
String[] ids = ContactsManager.getAllContacts();
if (ids == null || ids.length == 0) {
Display.getInstance().callSerially(new Runnable() {
public void run() {
Dialog.show("Failed to Share", "No Contacts Found", "Ok", null);
currentForm.showBack();
}
});
return;
}
ContactsModel model = new ContactsModel(ids);
final List contacts = new List(model);
contacts.setRenderer(createListRenderer());
Display.getInstance().callSerially(new Runnable() {
public void run() {
contacts.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
final ShareForm[] f = new ShareForm[1];
Hashtable contact = (Hashtable) contacts.getSelectedItem();
if (image == null) {
f[0] = new ShareForm(contactsForm, "Send Email", (String) contact.get("email"), toShare, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
String[] recieptents = new String[1];
recieptents[0] = f[0].getTo();
Message msg = new Message(toShare);
Message.sendMessage(recieptents, "share", msg);
finish();
}
});
f[0].show();
} else {
f[0] = new ShareForm(contactsForm, "Send Email", (String) contact.get("email"), toShare, image, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
String[] recieptents = new String[1];
recieptents[0] = f[0].getTo();
Message msg = new Message(toShare);
msg.setAttachment(image);
msg.setMimeType(mimeType);
Message.sendMessage(recieptents, "share", msg);
finish();
}
});
f[0].show();
}
}
});
contactsForm.addComponent(BorderLayout.CENTER, contacts);
Command back = new Command("Back") {
public void actionPerformed(ActionEvent evt) {
currentForm.showBack();
}
};
contactsForm.addCommand(back);
contactsForm.setBackCommand(back);
contactsForm.revalidate();
}
});
}
}, "Email Thread").start();
}
use of com.codename1.ui.events.ActionEvent 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));
}
Aggregations