Search in sources :

Example 41 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class BorderLayout method addLayoutComponent.

/**
 * {@inheritDoc}
 */
public void addLayoutComponent(Object name, Component comp, Container c) {
    // helper check for a common mistake...
    if (name == null) {
        throw new IllegalArgumentException("Cannot add component to BorderLayout Container without constraint parameter");
    }
    // allows us to work with Component constraints too which makes some code simpler
    if (name instanceof Integer) {
        switch(((Integer) name).intValue()) {
            case Component.TOP:
                name = NORTH;
                break;
            case Component.BOTTOM:
                name = SOUTH;
                break;
            case Component.LEFT:
                name = WEST;
                break;
            case Component.RIGHT:
                name = EAST;
                break;
            case Component.CENTER:
                name = CENTER;
                break;
            default:
                throw new IllegalArgumentException("BorderLayout Container expects one of the constraints BorderLayout.NORTH/SOUTH/EAST/WEST/CENTER");
        }
    }
    Component previous = null;
    /* Assign the component to one of the known regions of the layout.
         */
    if (CENTER.equals(name)) {
        previous = portraitCenter;
        portraitCenter = comp;
    } else if (NORTH.equals(name)) {
        previous = portraitNorth;
        portraitNorth = comp;
    } else if (SOUTH.equals(name)) {
        previous = portraitSouth;
        portraitSouth = comp;
    } else if (EAST.equals(name)) {
        previous = portraitEast;
        portraitEast = comp;
    } else if (WEST.equals(name)) {
        previous = portraitWest;
        portraitWest = comp;
    } else if (OVERLAY.equals(name)) {
        previous = overlay;
        overlay = comp;
    } else {
        throw new IllegalArgumentException("cannot add to layout: unknown constraint: " + name);
    }
    if (previous != null && previous != comp) {
        c.removeComponent(previous);
    }
}
Also used : Component(com.codename1.ui.Component)

Example 42 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout 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 BorderLayout

use of com.codename1.ui.layouts.BorderLayout 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 44 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class FloatingActionButton method createPopupContent.

/**
 * Creates the popup content container to display on the dialog.
 *
 * @param fabs List of sub FloatingActionButton
 * @return a Container that contains all fabs
 */
protected Container createPopupContent(List<FloatingActionButton> fabs) {
    Container con = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    for (FloatingActionButton next : subMenu) {
        next.setPreferredW(getWidth());
        Container c = new Container(new BorderLayout());
        Label txt = new Label(next.text);
        txt.setUIID("FloatingActionText");
        c.add(BorderLayout.CENTER, FlowLayout.encloseRight(txt));
        c.add(BorderLayout.EAST, next);
        con.add(c);
    }
    return con;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label)

Example 45 with BorderLayout

use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.

the class FloatingActionButton method released.

@Override
public void released(int x, int y) {
    super.released(x, y);
    if (current != null) {
        current.dispose();
        current = null;
    }
    // if this fab has sub fab's display them
    if (subMenu != null) {
        final Container con = createPopupContent(subMenu);
        Dialog d = new Dialog();
        d.setDialogUIID("Container");
        d.getContentPane().setUIID("Container");
        d.setLayout(new BorderLayout());
        d.add(BorderLayout.CENTER, con);
        for (FloatingActionButton next : subMenu) {
            next.current = d;
        }
        d.setTransitionInAnimator(CommonTransitions.createEmpty());
        d.setTransitionOutAnimator(CommonTransitions.createEmpty());
        for (Component c : con) {
            c.setVisible(false);
        }
        Form f = getComponentForm();
        int oldTint = f.getTintColor();
        f.setTintColor(0);
        d.setBlurBackgroundRadius(-1);
        d.addShowListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                for (Component c : con) {
                    c.setY(con.getHeight());
                    c.setVisible(true);
                }
                con.animateLayout(200);
            }
        });
        showPopupDialog(d);
        f.setTintColor(oldTint);
        for (FloatingActionButton next : subMenu) {
            next.remove();
        }
        con.removeAll();
    }
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) ActionEvent(com.codename1.ui.events.ActionEvent) Component(com.codename1.ui.Component)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)64 ActionEvent (com.codename1.ui.events.ActionEvent)27 Container (com.codename1.ui.Container)21 Form (com.codename1.ui.Form)18 ActionListener (com.codename1.ui.events.ActionListener)18 Component (com.codename1.ui.Component)15 BoxLayout (com.codename1.ui.layouts.BoxLayout)14 Label (com.codename1.ui.Label)12 Button (com.codename1.ui.Button)10 IOException (java.io.IOException)9 Dialog (com.codename1.ui.Dialog)8 Hashtable (java.util.Hashtable)8 Command (com.codename1.ui.Command)6 TextArea (com.codename1.ui.TextArea)6 FlowLayout (com.codename1.ui.layouts.FlowLayout)6 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)6 Vector (java.util.Vector)6 RadioButton (com.codename1.ui.RadioButton)5 Animation (com.codename1.ui.animations.Animation)4 Style (com.codename1.ui.plaf.Style)4