Search in sources :

Example 16 with BorderLayout

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

the class GameCanvasImplementation method capturePhoto.

public void capturePhoto(ActionListener response) {
    captureResponse = response;
    final Form current = Display.getInstance().getCurrent();
    final Form cam = new Form();
    cam.setScrollable(false);
    cam.setTransitionInAnimator(CommonTransitions.createEmpty());
    cam.setTransitionOutAnimator(CommonTransitions.createEmpty());
    cam.setLayout(new BorderLayout());
    cam.show();
    String platform = System.getProperty("microedition.platform");
    MMAPIPlayer p = null;
    if (platform != null && platform.indexOf("Nokia") >= 0) {
        try {
            p = MMAPIPlayer.createPlayer("capture://image", null);
        } catch (Throwable e) {
        // Ignore all exceptions for image capture, continue with video capture...
        }
    }
    if (p == null) {
        try {
            p = MMAPIPlayer.createPlayer("capture://video", null);
        } catch (Exception e) {
            // The Nokia 2630 throws this if image/video capture is not supported
            throw new RuntimeException("Image/video capture not supported on this phone");
        }
    }
    final MMAPIPlayer player = p;
    MIDPVideoComponent video = new MIDPVideoComponent(player, canvas);
    video.play();
    video.setVisible(true);
    cam.addCommand(new com.codename1.ui.Command("Cancel") {

        public void actionPerformed(ActionEvent evt) {
            if (player != null) {
                player.cleanup();
            }
            captureResponse.actionPerformed(null);
            current.showBack();
        }
    });
    final ActionListener l = new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            try {
                cam.removeAll();
                VideoControl cnt = (VideoControl) player.nativePlayer.getControl("VideoControl");
                byte[] pic = cnt.getSnapshot("encoding=jpeg&width=" + current.getWidth() + "&height=" + current.getHeight());
                String imagePath = getOutputMediaFile() + ".jpg";
                OutputStream out = null;
                try {
                    if (pic != null) {
                        out = FileSystemStorage.getInstance().openOutputStream(imagePath);
                        out.write(pic);
                    }
                } catch (Throwable ex) {
                    ex.printStackTrace();
                    System.out.println("failed to store picture to " + imagePath);
                } finally {
                    try {
                        if (out != null) {
                            out.close();
                        }
                        player.cleanup();
                    } catch (Throwable ex) {
                        ex.printStackTrace();
                    }
                }
                captureResponse.actionPerformed(new ActionEvent(imagePath));
                current.showBack();
            } catch (Throwable ex) {
                ex.printStackTrace();
                System.out.println("failed to take picture");
                current.showBack();
            }
        }
    };
    cam.addGameKeyListener(Display.GAME_FIRE, l);
    Container cn = new Container(new BorderLayout()) {

        public void pointerReleased(int x, int y) {
            l.actionPerformed(null);
        }
    };
    cn.setFocusable(true);
    cn.addComponent(BorderLayout.CENTER, video);
    cam.addComponent(BorderLayout.CENTER, cn);
    cam.revalidate();
// cam.addPointerReleasedListener(l);
}
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) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException) BorderLayout(com.codename1.ui.layouts.BorderLayout) com.codename1.ui(com.codename1.ui) ActionListener(com.codename1.ui.events.ActionListener) VideoControl(javax.microedition.media.control.VideoControl)

Example 17 with BorderLayout

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

the class BarCodeScanner method startScaning.

private void startScaning(ScanResult callback) {
    this.callback = callback;
    try {
        // Add the listener for scan and cancel
        Container cmdContainer = new Container(new FlowLayout(Component.CENTER));
        Button scanButton = new Button(new Command("Scan") {

            public void actionPerformed(ActionEvent evt) {
                cameraForm.repaint();
                if (snapshotThread != null) {
                    snapshotThread.continueRun();
                }
            }
        });
        Button cancelButton = new Button(new Command("Cancel") {

            public void actionPerformed(ActionEvent evt) {
                if (snapshotThread != null) {
                    snapshotThread.stop();
                    cancelScan();
                }
            }
        });
        cmdContainer.addComponent(scanButton);
        cmdContainer.addComponent(cancelButton);
        cameraForm = new Form();
        cameraForm.setScrollable(false);
        cameraForm.setLayout(new BorderLayout());
        cameraForm.addComponent(BorderLayout.CENTER, media.getVideoComponent());
        cameraForm.addComponent(BorderLayout.SOUTH, cmdContainer);
    } catch (Exception e) {
        // throw new AppException("Image/video capture not supported on this phone", e).setCode(97);
        e.printStackTrace();
    }
    startScan();
}
Also used : Container(com.codename1.ui.Container) FlowLayout(com.codename1.ui.layouts.FlowLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) Button(com.codename1.ui.Button) Command(com.codename1.ui.Command) Form(com.codename1.ui.Form) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 18 with BorderLayout

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

the class ComboBox method createPopupDialog.

/**
 * Subclasses can override this method to change the creation of the dialog
 *
 * @param l the list of the popup
 * @return a dialog instance
 */
protected Dialog createPopupDialog(List<T> l) {
    Dialog popupDialog = new Dialog(getUIID() + "Popup", getUIID() + "PopupTitle") {

        void sizeChangedInternal(int w, int h) {
            // resize the popup just resize the parent form
            if (getWidth() == w && getHeight() != h) {
                Form frm = getPreviousForm();
                if (frm != null) {
                    frm.sizeChangedInternal(w, h);
                }
                setSize(new Dimension(w, h));
                repaint();
            } else {
                dispose();
            }
        }
    };
    popupDialog.setScrollable(false);
    popupDialog.getContentPane().setAlwaysTensile(false);
    popupDialog.setAlwaysTensile(false);
    popupDialog.getContentPane().setUIID("PopupContentPane");
    popupDialog.setDisposeWhenPointerOutOfBounds(true);
    popupDialog.setTransitionInAnimator(CommonTransitions.createEmpty());
    popupDialog.setTransitionOutAnimator(CommonTransitions.createEmpty());
    popupDialog.setLayout(new BorderLayout());
    popupDialog.addComponent(BorderLayout.CENTER, l);
    return popupDialog;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Dimension(com.codename1.ui.geom.Dimension)

Example 19 with BorderLayout

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

the class Dialog method show.

/**
 * Shows a modal dialog with the given component as its "body" placed in the
 * center.
 *
 * @param title title for the dialog
 * @param body component placed in the center of the dialog
 * @param defaultCommand command to be assigned as the default command or null
 * @param cmds commands that are added to the form any click on any command
 * will dispose the form
 * @param type the type of the alert one of TYPE_WARNING, TYPE_INFO,
 * TYPE_ERROR, TYPE_CONFIRMATION or TYPE_ALARM
 * @param icon the icon for the dialog, can be null
 * @param timeout a timeout after which null would be returned if timeout is 0 inifinite time is used
 * @param transition the transition installed when the dialog enters/leaves
 * @return the command pressed by the user
 */
public static Command show(String title, Component body, Command defaultCommand, Command[] cmds, int type, Image icon, long timeout, Transition transition) {
    Dialog dialog = new Dialog(title);
    dialog.dialogType = type;
    dialog.setTransitionInAnimator(transition);
    dialog.setTransitionOutAnimator(transition);
    dialog.lastCommandPressed = null;
    dialog.setLayout(new BorderLayout());
    if (cmds != null) {
        if (commandsAsButtons) {
            dialog.placeButtonCommands(cmds);
        } else {
            for (int iter = 0; iter < cmds.length; iter++) {
                dialog.addCommand(cmds[iter]);
            }
        }
        // maps the first command to back
        if (cmds.length == 1 || cmds.length == 2) {
            dialog.setBackCommand(cmds[0]);
        }
    }
    if (defaultCommand != null) {
        dialog.setDefaultCommand(defaultCommand);
    }
    dialog.addComponent(BorderLayout.CENTER, body);
    if (icon != null) {
        dialog.addComponent(BorderLayout.EAST, new Label(icon));
    }
    if (timeout != 0) {
        dialog.setTimeout(timeout);
    }
    if (body.isScrollable() || disableStaticDialogScrolling) {
        dialog.setScrollable(false);
    }
    dialog.show();
    return dialog.lastCommandPressed;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 20 with BorderLayout

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

the class Form method pointerPressed.

/**
 * {@inheritDoc}
 */
public void pointerPressed(int x, int y) {
    pressedCmp = null;
    stickyDrag = null;
    dragStopFlag = false;
    dragged = null;
    boolean isScrollWheeling = Display.INSTANCE.impl.isScrollWheeling();
    if (pointerPressedListeners != null && pointerPressedListeners.hasListeners()) {
        pointerPressedListeners.fireActionEvent(new ActionEvent(this, ActionEvent.Type.PointerPressed, x, y));
    }
    // check if the click is relevant to the menu bar.
    /*
        if (menuBar.contains(x, y)) {
            Component cmp = menuBar.getComponentAt(x, y);
            while (cmp != null && cmp.isIgnorePointerEvents()) {
                cmp = cmp.getParent();
            }
            if (cmp != null && cmp.isEnabled()) {
                cmp.pointerPressed(x, y);
                tactileTouchVibe(x, y, cmp);
                initRippleEffect(x, y, cmp);
            }
            return;
        }
        */
    Container actual = getActualPane(formLayeredPane, x, y);
    if (y >= actual.getY() && x >= actual.getX()) {
        Component cmp = actual.getComponentAt(x, y);
        while (cmp != null && cmp.isIgnorePointerEvents()) {
            cmp = cmp.getParent();
        }
        if (cmp != null) {
            cmp.initDragAndDrop(x, y);
            if (cmp.hasLead) {
                if (isCurrentlyScrolling(cmp)) {
                    dragStopFlag = true;
                    cmp.clearDrag();
                    return;
                }
                Container leadParent;
                if (cmp instanceof Container) {
                    leadParent = ((Container) cmp).getLeadParent();
                } else {
                    leadParent = cmp.getParent().getLeadParent();
                }
                leadParent.repaint();
                if (!isScrollWheeling) {
                    setFocused(leadParent);
                }
                pressedCmp = cmp.getLeadComponent();
                cmp.getLeadComponent().pointerPressed(x, y);
            } else {
                if (isCurrentlyScrolling(cmp)) {
                    dragStopFlag = true;
                    cmp.clearDrag();
                    return;
                }
                if (cmp.isEnabled()) {
                    if (!isScrollWheeling && cmp.isFocusable()) {
                        setFocused(cmp);
                    }
                    pressedCmp = cmp;
                    cmp.pointerPressed(x, y);
                    tactileTouchVibe(x, y, cmp);
                    initRippleEffect(x, y, cmp);
                }
            }
        }
    } else {
        if (y < actual.getY()) {
            Component cmp = getTitleArea().getComponentAt(x, y);
            while (cmp != null && cmp.isIgnorePointerEvents()) {
                cmp = cmp.getParent();
            }
            if (cmp != null && cmp.isEnabled() && cmp.isFocusable()) {
                pressedCmp = cmp;
                cmp.pointerPressed(x, y);
                tactileTouchVibe(x, y, cmp);
                initRippleEffect(x, y, cmp);
            }
        } else {
            Component cmp = ((BorderLayout) super.getLayout()).getWest();
            if (cmp != null) {
                cmp = ((Container) cmp).getComponentAt(x, y);
                while (cmp != null && cmp.isIgnorePointerEvents()) {
                    cmp = cmp.getParent();
                }
                if (cmp != null && cmp.isEnabled() && cmp.isFocusable()) {
                    if (cmp.hasLead) {
                        Container leadParent;
                        if (cmp instanceof Container) {
                            leadParent = ((Container) cmp).getLeadParent();
                        } else {
                            leadParent = cmp.getParent().getLeadParent();
                        }
                        if (!isScrollWheeling) {
                            setFocused(leadParent);
                        }
                        cmp = cmp.getLeadComponent();
                    }
                    cmp.initDragAndDrop(x, y);
                    pressedCmp = cmp;
                    cmp.pointerPressed(x, y);
                    tactileTouchVibe(x, y, cmp);
                    initRippleEffect(x, y, cmp);
                }
            }
        }
    }
    initialPressX = x;
    initialPressY = y;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionEvent(com.codename1.ui.events.ActionEvent)

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