Search in sources :

Example 11 with BorderLayout

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

the class Oauth2 method showAuthentication.

/**
 * This method shows an authentication for login form
 *
 * @param al a listener that will receive at its source either a token for
 * the service or an exception in case of a failure
 * @return a component that should be displayed to the user in order to
 * perform the authentication
 */
public void showAuthentication(ActionListener al) {
    final Form old = Display.getInstance().getCurrent();
    InfiniteProgress inf = new InfiniteProgress();
    final Dialog progress = inf.showInifiniteBlocking();
    Form authenticationForm = new Form("Login");
    authenticationForm.setScrollable(false);
    if (old != null) {
        Command cancel = new Command("Cancel") {

            public void actionPerformed(ActionEvent ev) {
                if (Display.getInstance().getCurrent() == progress) {
                    progress.dispose();
                }
                old.showBack();
            }
        };
        if (authenticationForm.getToolbar() != null) {
            authenticationForm.getToolbar().addCommandToLeftBar(cancel);
        } else {
            authenticationForm.addCommand(cancel);
        }
        authenticationForm.setBackCommand(cancel);
    }
    authenticationForm.setLayout(new BorderLayout());
    authenticationForm.addComponent(BorderLayout.CENTER, createLoginComponent(al, authenticationForm, old, progress));
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) InfiniteProgress(com.codename1.components.InfiniteProgress) Command(com.codename1.ui.Command) Dialog(com.codename1.ui.Dialog) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 12 with BorderLayout

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

the class RSSReader method createRendererContainer.

private Container createRendererContainer() {
    Container entries = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    entries.setUIID("RSSEntry");
    Label title = new Label();
    title.setName("title");
    title.setUIID("RSSTitle");
    entries.addComponent(title);
    TextArea description = new TextArea(2, 30);
    description.setGrowByContent(false);
    description.setName("details");
    description.setUIID("RSSDescription");
    description.setScrollVisible(false);
    entries.addComponent(description);
    if (iconPlaceholder != null) {
        Container wrap = new Container(new BorderLayout());
        wrap.addComponent(BorderLayout.CENTER, entries);
        Label icon = new Label();
        icon.setIcon(iconPlaceholder);
        icon.setUIID("RSSIcon");
        icon.setName("icon");
        wrap.addComponent(BorderLayout.WEST, icon);
        entries = wrap;
    }
    return entries;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) TextArea(com.codename1.ui.TextArea) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label)

Example 13 with BorderLayout

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

the class RSSReader method showRSSEntry.

/**
 * Shows a form containing the RSS entry
 *
 * @param h the parsed entry
 */
protected void showRSSEntry(Hashtable h) {
    Form newForm = null;
    if (targetContainer != null) {
        if (targetContainer instanceof Form) {
            newForm = (Form) targetContainer;
        } else {
            newForm = new Form((String) h.get("title"));
            newForm.setLayout(new BorderLayout());
            newForm.addComponent(BorderLayout.CENTER, targetContainer);
        }
        updateComponentValues(newForm, h);
    } else {
        newForm = new Form((String) h.get("title"));
        newForm.setScrollable(false);
        WebBrowser c = new WebBrowser();
        String s = (String) h.get("description");
        s = "<html><body>" + s + "</body></html>";
        c.setPage(s, null);
        newForm.setLayout(new BorderLayout());
        newForm.addComponent(BorderLayout.CENTER, c);
    }
    if (addBackToTaget) {
        final Form sourceForm = Display.getInstance().getCurrent();
        Command back = new BackCommand(sourceForm);
        newForm.addCommand(back);
        newForm.setBackCommand(back);
    }
    newForm.show();
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Command(com.codename1.ui.Command)

Example 14 with BorderLayout

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

the class ToastBar method getToastBarComponent.

private ToastBarComponent getToastBarComponent() {
    Form f = Display.getInstance().getCurrent();
    if (f != null && !(f instanceof Dialog)) {
        ToastBarComponent c = (ToastBarComponent) f.getClientProperty("ToastBarComponent");
        if (c == null || c.getParent() == null) {
            c = new ToastBarComponent();
            c.hidden = true;
            f.putClientProperty("ToastBarComponent", c);
            Container layered = f.getLayeredPane(this.getClass(), true);
            layered.setLayout(new BorderLayout());
            layered.addComponent(position == Component.TOP ? BorderLayout.NORTH : BorderLayout.SOUTH, c);
            updateStatus();
        }
        if (position == Component.BOTTOM && f.getInvisibleAreaUnderVKB() > 0) {
            Style s = c.getAllStyles();
            s.setMarginUnit(Style.UNIT_TYPE_PIXELS);
            s.setMarginBottom(f.getInvisibleAreaUnderVKB());
        }
        return c;
    }
    return null;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) Style(com.codename1.ui.plaf.Style)

Example 15 with BorderLayout

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

the class GameCanvasImplementation method captureAudio.

public void captureAudio(ActionListener response) {
    captureResponse = response;
    try {
        final Form current = Display.getInstance().getCurrent();
        final MMAPIPlayer player = MMAPIPlayer.createPlayer("capture://audio", null);
        RecordControl record = (RecordControl) player.nativePlayer.getControl("RecordControl");
        if (record == null) {
            player.cleanup();
            throw new RuntimeException("Capture Audio is not supported on this device");
        }
        final Form cam = new Form();
        cam.setTransitionInAnimator(CommonTransitions.createEmpty());
        cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
        cam.setLayout(new BorderLayout());
        cam.show();
        player.play();
        final Label time = new Label("0:00");
        cam.addComponent(BorderLayout.SOUTH, time);
        cam.revalidate();
        ActionListener l = new ActionListener() {

            boolean recording = false;

            OutputStream out = null;

            String audioPath = null;

            RecordControl record;

            public void actionPerformed(ActionEvent evt) {
                if (!recording) {
                    record = (RecordControl) player.nativePlayer.getControl("RecordControl");
                    recording = true;
                    String type = record.getContentType();
                    String prefix = "";
                    if (type.endsWith("wav")) {
                        prefix = ".wav";
                    } else if (type.endsWith("amr")) {
                        prefix = ".amr";
                    } else if (type.endsWith("3gpp")) {
                        prefix = ".3gp";
                    }
                    audioPath = getOutputMediaFile() + prefix;
                    try {
                        out = FileSystemStorage.getInstance().openOutputStream(audioPath);
                        record.setRecordStream(out);
                        record.startRecord();
                        cam.registerAnimated(new Animation() {

                            long current = System.currentTimeMillis();

                            long zero = current;

                            int sec = 0;

                            public boolean animate() {
                                long now = System.currentTimeMillis();
                                if (now - current > 1000) {
                                    current = now;
                                    sec++;
                                    return true;
                                }
                                return false;
                            }

                            public void paint(Graphics g) {
                                String txt = sec / 60 + ":" + sec % 60;
                                time.setText(txt);
                            }
                        });
                    } catch (IOException ex) {
                        ex.printStackTrace();
                        System.out.println("failed to store audio to " + audioPath);
                    } finally {
                    }
                } else {
                    if (out != null) {
                        try {
                            record.stopRecord();
                            record.commit();
                            out.close();
                            player.cleanup();
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                    captureResponse.actionPerformed(new ActionEvent(audioPath));
                    current.showBack();
                }
            }
        };
        cam.addGameKeyListener(Display.GAME_FIRE, l);
        cam.addPointerReleasedListener(l);
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new RuntimeException("failed to start camera");
    }
}
Also used : Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(com.codename1.io.BufferedOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException) Graphics(com.codename1.ui.Graphics) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) Animation(com.codename1.ui.animations.Animation) RecordControl(javax.microedition.media.control.RecordControl)

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