Search in sources :

Example 46 with ActionEvent

use of com.codename1.ui.events.ActionEvent 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 47 with ActionEvent

use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.

the class MasterDetail method bindTabletLandscapeMaster.

/**
 * @deprecated this was a half baked idea that made it into the public API
 */
public static void bindTabletLandscapeMaster(final Form rootForm, Container parentContainer, Component landscapeUI, final Component portraitUI, final String commandTitle, Image commandIcon) {
    landscapeUI.setHideInPortrait(true);
    parentContainer.addComponent(BorderLayout.WEST, landscapeUI);
    final Command masterCommand = new Command(commandTitle, commandIcon) {

        public void actionPerformed(ActionEvent ev) {
            Dialog dlg = new Dialog();
            dlg.setLayout(new BorderLayout());
            dlg.setDialogUIID("Container");
            dlg.getContentPane().setUIID("Container");
            Container titleArea = new Container(new BorderLayout());
            dlg.addComponent(BorderLayout.NORTH, titleArea);
            titleArea.setUIID("TitleArea");
            Label title = new Label(commandTitle);
            titleArea.addComponent(BorderLayout.CENTER, title);
            title.setUIID("Title");
            Container body = new Container(new BorderLayout());
            body.setUIID("Form");
            body.addComponent(BorderLayout.CENTER, portraitUI);
            dlg.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 250));
            dlg.setTransitionOutAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, true, 250));
            dlg.addComponent(BorderLayout.CENTER, body);
            dlg.setDisposeWhenPointerOutOfBounds(true);
            dlg.showStetched(BorderLayout.WEST, true);
            dlg.removeComponent(portraitUI);
        }
    };
    if (Display.getInstance().isPortrait()) {
        if (rootForm.getCommandCount() > 0) {
            rootForm.addCommand(masterCommand, 1);
        } else {
            rootForm.addCommand(masterCommand);
        }
    }
    rootForm.addOrientationListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (portraitUI.getParent() != null) {
                Form f = Display.getInstance().getCurrent();
                if (f instanceof Dialog) {
                    ((Dialog) f).dispose();
                }
            }
            if (Display.getInstance().isPortrait()) {
                rootForm.addCommand(masterCommand, 1);
            } else {
                rootForm.removeCommand(masterCommand);
                rootForm.revalidate();
            }
        }
    });
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) Command(com.codename1.ui.Command) Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) Dialog(com.codename1.ui.Dialog) Label(com.codename1.ui.Label)

Example 48 with ActionEvent

use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.

the class OnOffSwitch method initialize.

private void initialize() {
    iosMode = UIManager.getInstance().isThemeConstant("onOffIOSModeBool", false);
    removeAll();
    setFocusable(true);
    if (iosMode) {
        button = null;
        switchMaskImage = UIManager.getInstance().getThemeImageConstant("switchMaskImage");
        switchOnImage = UIManager.getInstance().getThemeImageConstant("switchOnImage");
        switchOffImage = UIManager.getInstance().getThemeImageConstant("switchOffImage");
        noTextMode = UIManager.getInstance().isThemeConstant("noTextModeBool", false);
    } else {
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        button = new CheckBox(on);
        button.setToggle(true);
        button.setUIID("Button");
        button.setEndsWith3Points(false);
        button.getUnselectedStyle().setFont(getUnselectedStyle().getFont());
        button.getSelectedStyle().setFont(getSelectedStyle().getFont());
        button.getPressedStyle().setFont(getSelectedStyle().getFont());
        Dimension d = button.getPreferredSize();
        button.setText(off);
        int pw = button.getPreferredW();
        d.setWidth(Math.max(pw, d.getWidth()));
        // prevents the button from growing/shrinking as its states flip
        button.setPreferredSize(d);
        buttonWidth = button.getPreferredW();
        button.setFocusable(false);
        updateButton();
        addComponent(button);
        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                flip();
            }
        });
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) CheckBox(com.codename1.ui.CheckBox) ActionEvent(com.codename1.ui.events.ActionEvent) BoxLayout(com.codename1.ui.layouts.BoxLayout) Dimension(com.codename1.ui.geom.Dimension)

Example 49 with ActionEvent

use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.

the class Progress method actionPerformed.

/**
 * {@inheritDoc}
 */
public void actionPerformed(ActionEvent evt) {
    NetworkEvent ev = (NetworkEvent) evt;
    if (ev.getConnectionRequest() == request) {
        if (disposeOnCompletion && ev.getProgressType() == NetworkEvent.PROGRESS_TYPE_COMPLETED) {
            dispose();
            return;
        }
        if (autoShow && !showing) {
            showing = true;
            showModeless();
        }
    }
}
Also used : NetworkEvent(com.codename1.io.NetworkEvent)

Example 50 with ActionEvent

use of com.codename1.ui.events.ActionEvent in project CodenameOne by codenameone.

the class Ads method setAd.

/**
 * HTML ad received from the server
 * @param ad the ad to set
 */
public void setAd(String ad) {
    HTMLComponent html = new HTMLComponent(new AsyncDocumentRequestHandlerImpl() {

        protected ConnectionRequest createConnectionRequest(DocumentInfo docInfo, IOCallback callback, Object[] response) {
            ConnectionRequest req = super.createConnectionRequest(docInfo, callback, response);
            req.setFailSilently(true);
            req.addResponseCodeListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                // do nothing, just make sure the html won't throw an error
                }
            });
            return req;
        }
    });
    html.setSupressExceptions(true);
    html.setHTMLCallback(this);
    html.setBodyText("<html><body><div align='center'>" + ad + "</div></body></html>");
    replace(getComponentAt(0), html, null);
    revalidate();
    html.setPageUIID("Container");
    html.getStyle().setBgTransparency(0);
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) AsyncDocumentRequestHandlerImpl(com.codename1.ui.html.AsyncDocumentRequestHandlerImpl) IOCallback(com.codename1.ui.html.IOCallback) HTMLComponent(com.codename1.ui.html.HTMLComponent) DocumentInfo(com.codename1.ui.html.DocumentInfo)

Aggregations

ActionEvent (com.codename1.ui.events.ActionEvent)98 ActionListener (com.codename1.ui.events.ActionListener)55 IOException (java.io.IOException)30 BorderLayout (com.codename1.ui.layouts.BorderLayout)28 Form (com.codename1.ui.Form)18 Hashtable (java.util.Hashtable)14 Vector (java.util.Vector)11 NetworkEvent (com.codename1.io.NetworkEvent)10 Container (com.codename1.ui.Container)9 ActionEvent (java.awt.event.ActionEvent)9 Command (com.codename1.ui.Command)8 ActionListener (java.awt.event.ActionListener)8 Button (com.codename1.ui.Button)7 Style (com.codename1.ui.plaf.Style)7 Rectangle (com.codename1.ui.geom.Rectangle)6 File (java.io.File)6 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)6 MediaException (javax.microedition.media.MediaException)6 RecordStoreException (javax.microedition.rms.RecordStoreException)6 BufferedOutputStream (com.codename1.io.BufferedOutputStream)5