use of com.codename1.ui.Form in project CodenameOne by codenameone.
the class MenuBar method createMenuCancelCommand.
/**
* Factory method that returns the Form Menu cancel Command.
* This method can be overridden to customize the Command on the Form.
*
* @return Command
*/
protected Command createMenuCancelCommand() {
UIManager manager = parent.getUIManager();
LookAndFeel lf = manager.getLookAndFeel();
return new Command(manager.localize("cancel", "Cancel"), lf.getMenuIcons()[1]);
}
use of com.codename1.ui.Form 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.Form in project CodenameOne by codenameone.
the class MenuBar method createMenuSelectCommand.
/**
* Factory method that returns the Form Menu select Command.
* This method can be overridden to customize the Command on the Form.
*
* @return Command
*/
protected Command createMenuSelectCommand() {
UIManager manager = parent.getUIManager();
LookAndFeel lf = manager.getLookAndFeel();
return new Command(manager.localize("select", "Select"), lf.getMenuIcons()[0]);
}
use of com.codename1.ui.Form 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.Form in project CodenameOne by codenameone.
the class TestUtils method ensureVisible.
/**
* Scrolls to show the component in case it is invisible currently
* @param c the component
*/
public static void ensureVisible(Component c) {
if (verbose) {
log("ensureVisible(" + c + ")");
}
Form f = Display.getInstance().getCurrent();
f.scrollComponentToVisible(c);
}
Aggregations