Search in sources :

Example 41 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class VServAds method getPendingAd.

/**
 * {@inheritDoc}
 */
protected Component getPendingAd() {
    if (imageURL == null) {
        return null;
    }
    if (renderNotify != null && renderNotify.length() > 0) {
        ConnectionRequest c = new ConnectionRequest();
        c.setFailSilently(true);
        c.setUrl(renderNotify);
        c.setPost(false);
        NetworkManager.getInstance().addToQueue(c);
    }
    if ("image".equalsIgnoreCase(contentType)) {
        Button adComponent = new Button() {

            public void setIcon(Image icon) {
                if (icon != null && isScaleMode()) {
                    icon = icon.scaledWidth(Display.getInstance().getDisplayWidth());
                }
                super.setIcon(icon);
            }
        };
        adComponent.setUIID("Container");
        adComponent.getStyle().setBgColor(backgroundColor);
        adComponent.getStyle().setOpacity(0xff);
        ImageDownloadService imd = new ImageDownloadService(imageURL, adComponent);
        NetworkManager.getInstance().addToQueueAndWait(imd);
        /*adComponent.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    Display.getInstance().execute(getAdDestination());
                }
            });*/
        return adComponent;
    } else {
        WebBrowser wb = new WebBrowser();
        if (wb.getInternal() instanceof BrowserComponent) {
            BrowserComponent bc = (BrowserComponent) wb.getInternal();
            bc.setBrowserNavigationCallback(new BrowserNavigationCallback() {

                public boolean shouldNavigate(final String url) {
                    unlock(new ActionListener() {

                        public void actionPerformed(ActionEvent evt) {
                            Display.getInstance().execute(url);
                        }
                    });
                    return false;
                }
            });
        }
        wb.setURL(imageURL);
        return wb;
    }
}
Also used : ImageDownloadService(com.codename1.io.services.ImageDownloadService) ConnectionRequest(com.codename1.io.ConnectionRequest) WebBrowser(com.codename1.components.WebBrowser) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) BrowserNavigationCallback(com.codename1.ui.events.BrowserNavigationCallback)

Example 42 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class MediaPlayer method initUI.

private void initUI() {
    removeAll();
    setLayout(new BorderLayout());
    if (video != null && video.getVideoComponent() != null) {
        Component videoComponent = video.getVideoComponent();
        if (videoComponent != null) {
            addComponent(BorderLayout.CENTER, videoComponent);
        }
    }
    buttonsBar = new Container(new FlowLayout(Container.CENTER));
    addComponent(BorderLayout.SOUTH, buttonsBar);
    if (usesNativeVideoControls() || !showControls) {
        buttonsBar.setVisible(false);
        buttonsBar.setHidden(true);
    }
    // if(video == null || !video.isNativePlayerMode()){
    Button back = new Button();
    back.setUIID("MediaPlayerBack");
    if (backIcon != null) {
        back.setIcon(backIcon);
    } else {
        back.setText("Back");
    }
    buttonsBar.addComponent(back);
    back.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (video == null) {
                return;
            }
            int t = video.getTime();
            video.setTime(t - 2);
        }
    });
    // }
    final Button play = new Button();
    play.setUIID("MediaPlayerPlay");
    if (playIcon != null) {
        play.setIcon(playIcon);
    } else {
        play.setText("play");
    }
    if (autoplay) {
        if (video != null && !video.isPlaying()) {
            if (getPauseIcon() != null) {
                play.setIcon(getPauseIcon());
            } else {
                play.setText("pause");
            }
            Timer t = new Timer();
            t.schedule(new TimerTask() {

                public void run() {
                    if (isInitialized()) {
                        Display.getInstance().callSerially(new Runnable() {

                            public void run() {
                                if (video != null && !video.isPlaying() && isInitialized()) {
                                    video.play();
                                }
                            }
                        });
                    }
                }
            }, 300l);
        // video.play();
        }
    }
    play.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (video == null) {
                return;
            }
            if (!video.isPlaying()) {
                video.play();
                play.setUIID("MediaPlayerPause");
                if (getPauseIcon() != null) {
                    play.setIcon(getPauseIcon());
                } else {
                    play.setText("pause");
                }
                play.repaint();
            } else {
                video.pause();
                play.setUIID("MediaPlayerPlay");
                if (getPlayIcon() != null) {
                    play.setIcon(getPlayIcon());
                } else {
                    play.setText("play");
                }
                play.repaint();
            }
        }
    });
    Display.getInstance().callSerially(new Runnable() {

        public void run() {
            if (video != null && video.isPlaying()) {
                play.setUIID("MediaPlayerPause");
                if (getPauseIcon() != null) {
                    play.setIcon(getPauseIcon());
                } else {
                    play.setText("pause");
                }
            } else if (video != null && !video.isPlaying()) {
                play.setUIID("MediaPlayerPlay");
                if (getPlayIcon() != null) {
                    play.setIcon(getPlayIcon());
                } else {
                    play.setText("play");
                }
            }
        }
    });
    buttonsBar.addComponent(play);
    // if(video == null || !video.isNativePlayerMode()){
    Button fwd = new Button();
    fwd.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (video == null) {
                return;
            }
            int t = video.getTime();
            video.setTime(t + 1);
        }
    });
    fwd.setUIID("MediaPlayerFwd");
    if (fwdIcon != null) {
        fwd.setIcon(fwdIcon);
    } else {
        fwd.setText("fwd");
    }
    buttonsBar.addComponent(fwd);
    // }
    if (isInitialized()) {
        revalidate();
    }
}
Also used : Container(com.codename1.ui.Container) FlowLayout(com.codename1.ui.layouts.FlowLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) UITimer(com.codename1.ui.util.UITimer) Timer(java.util.Timer) TimerTask(java.util.TimerTask) Button(com.codename1.ui.Button) ActionEvent(com.codename1.ui.events.ActionEvent) Component(com.codename1.ui.Component)

Example 43 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class MultiButton method setCheckBox.

/**
 * Turns the multi-button into a checkbox multi-button
 *
 * @param b true for a checkbox multi-button
 */
public void setCheckBox(boolean b) {
    if (b != isCheckBox()) {
        Container par = emblem.getParent();
        Button old = emblem;
        if (b) {
            emblem = new CheckBox();
        } else {
            emblem = new Button();
        }
        emblem.setUIID(old.getUIID());
        emblem.setName(old.getName());
        java.util.List actionListeners = (java.util.List) old.getListeners();
        if (actionListeners != null) {
            for (int iter = 0; iter < actionListeners.size(); iter++) {
                emblem.addActionListener((ActionListener) actionListeners.get(iter));
            }
        }
        if (old.getCommand() != null) {
            Image img = old.getIcon();
            emblem.setCommand(old.getCommand());
            emblem.setText("");
            emblem.setIcon(img);
        } else {
            emblem.setText(old.getText());
            if (old.getIcon() != null) {
                emblem.setIcon(old.getIcon());
            }
        }
        par.replace(old, emblem, null);
        setLeadComponent(emblem);
    }
}
Also used : Container(com.codename1.ui.Container) RadioButton(com.codename1.ui.RadioButton) Button(com.codename1.ui.Button) CheckBox(com.codename1.ui.CheckBox) Image(com.codename1.ui.Image)

Example 44 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class MultiButton method setLinesTogetherMode.

/**
 * Changes the layout so the lines of the button are grouped together
 * @param l true to group the lines together
 */
public void setLinesTogetherMode(boolean l) {
    if (l != isLinesTogetherMode()) {
        if (l) {
            firstRow.getParent().removeComponent(firstRow);
            Container p = secondRow.getParent();
            p.addComponent(0, firstRow);
            Container pp = p.getParent();
            pp.removeComponent(p);
            pp.addComponent(BorderLayout.CENTER, p);
        } else {
            secondRow.getParent().removeComponent(secondRow);
            thirdRow.getParent().addComponent(0, secondRow);
        }
    }
}
Also used : Container(com.codename1.ui.Container)

Example 45 with Button

use of com.codename1.ui.Button in project CodenameOne by codenameone.

the class MultiButton method setRadioButton.

/**
 * Turns the multi-button into a radio multi-button
 *
 * @param b true for a radio multi-button
 */
public void setRadioButton(boolean b) {
    if (b != isRadioButton()) {
        Container par = emblem.getParent();
        Button old = emblem;
        if (b) {
            emblem = new RadioButton();
            if (group != null) {
                ((RadioButton) emblem).setGroup(group);
            }
        } else {
            emblem = new Button();
        }
        emblem.setName(old.getName());
        emblem.setUIID(old.getUIID());
        java.util.List actionListeners = (java.util.List) old.getListeners();
        if (actionListeners != null) {
            for (int iter = 0; iter < actionListeners.size(); iter++) {
                emblem.addActionListener((ActionListener) actionListeners.get(iter));
            }
        }
        if (old.getCommand() != null) {
            Image img = old.getIcon();
            emblem.setCommand(old.getCommand());
            emblem.setText("");
            emblem.setIcon(img);
        }
        par.replace(old, emblem, null);
        setLeadComponent(emblem);
        emblem.setShowEvenIfBlank(true);
    }
}
Also used : Container(com.codename1.ui.Container) RadioButton(com.codename1.ui.RadioButton) Button(com.codename1.ui.Button) RadioButton(com.codename1.ui.RadioButton) Image(com.codename1.ui.Image)

Aggregations

Button (com.codename1.ui.Button)31 BorderLayout (com.codename1.ui.layouts.BorderLayout)25 ActionEvent (com.codename1.ui.events.ActionEvent)21 Container (com.codename1.ui.Container)18 ActionListener (com.codename1.ui.events.ActionListener)17 Component (com.codename1.ui.Component)14 RadioButton (com.codename1.ui.RadioButton)14 Form (com.codename1.ui.Form)12 Label (com.codename1.ui.Label)11 BoxLayout (com.codename1.ui.layouts.BoxLayout)11 TextArea (com.codename1.ui.TextArea)10 Hashtable (java.util.Hashtable)9 Command (com.codename1.ui.Command)8 Image (com.codename1.ui.Image)8 TextField (com.codename1.ui.TextField)8 FlowLayout (com.codename1.ui.layouts.FlowLayout)8 GridLayout (com.codename1.ui.layouts.GridLayout)8 UIManager (com.codename1.ui.plaf.UIManager)8 CheckBox (com.codename1.ui.CheckBox)7 Style (com.codename1.ui.plaf.Style)7