Java Code Examples for com.codename1.ui.events.ActionListener#actionPerformed()

The following examples show how to use com.codename1.ui.events.ActionListener#actionPerformed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Toolbar.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Shows the search bar manually which is useful for use cases of popping 
 * up search from code
 * 
 * @param callback gets the search string callbacks
 */
public void showSearchBar(final ActionListener callback) {        
    SearchBar s = new SearchBar(Toolbar.this, searchIconSize) {

        @Override
        public void onSearch(String text) {
            callback.actionPerformed(new ActionEvent(text));
        }

    };
    Form f = (Form) Toolbar.this.getComponentForm();
    setHidden(true);
    f.removeComponentFromForm(Toolbar.this);
    f.setToolbar(s);
    s.initSearchBar();
    if(f == Display.INSTANCE.getCurrent()) {
        f.animateLayout(100);
    }
}
 
Example 2
Source File: Command.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new command instance that encapsulates the action listener and details, the main
 * value of this approach is in our ability to write commands using the shorthand lambda syntax
 * of Java 8.
 * @param name the name/title of the command
 * @param icon the icon for the command
 * @param ev the even handler
 * @return a newly created Command instance
 */
public static Command create(String name, Image icon, final ActionListener ev) {
    Command cmd = new Command(name) {
        @Override
        public void actionPerformed(ActionEvent evt) {
            ev.actionPerformed(evt);
        }
    };
    cmd.setIcon(icon);
    return cmd;
}
 
Example 3
Source File: Command.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new command instance that encapsulates the action listener and details, the main
 * value of this approach is in our ability to write commands using the shorthand lambda syntax
 * of Java 8.
 * @param name the name/title of the command
 * @param icon the icon for the command
 * @param ev the even handler
 * @return a newly created Command instance
 * @since 6.0
 */
public static Command createMaterial(String name, char icon, final ActionListener ev) {
    Command cmd = new Command(name) {
        @Override
        public void actionPerformed(ActionEvent evt) {
            ev.actionPerformed(evt);
        }
    };
    cmd.setMaterialIcon(icon);
    return cmd;
}
 
Example 4
Source File: ImageDownloadService.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs an image request that will automatically populate the given Label
 * when the response arrives, it will cache the file locally.
 *
 * @param url the image URL
 * @param callback the callback that should be updated when the data arrives
 * @param destFile local file to store the data into the given path
 */
public static void createImageToFileSystem(String url, ActionListener callback, String destFile) {

    Image im = cacheImage(null, false, destFile, null, null, defaultMaintainAspectRatio);
    if (im != null) {
        callback.actionPerformed(new NetworkEvent(null, im));
        return;
    }
    //image not found on cache go and download from the url
    ImageDownloadService i = new ImageDownloadService(url, callback);
    i.cacheImages = true;
    i.destinationFile = destFile;
    i.setFailSilently(true);
    NetworkManager.getInstance().addToQueue(i);
}
 
Example 5
Source File: ImageDownloadService.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs an image request that will automatically populate the given Label
 * when the response arrives, it will cache the file locally.
 *
 * @param url the image URL
 * @param callback the callback that should be updated when the data arrives
 * @param cacheId a unique identifier to be used to store the image into storage
 * @param keep if set to true keeps the file in RAM once loaded
 */
public static void createImageToStorage(String url, ActionListener callback, String cacheId, boolean keep) {

    Image im = cacheImage(cacheId, keep, null, null, null, defaultMaintainAspectRatio);
    if (im != null) {
        callback.actionPerformed(new NetworkEvent(null, im));
        return;
    }
    //image not found on cache go and download from the url
    ImageDownloadService i = new ImageDownloadService(url, callback);
    i.cacheImages = true;
    i.cacheId = cacheId;
    i.setFailSilently(true);
    NetworkManager.getInstance().addToQueue(i);
}