Search in sources :

Example 21 with Dialog

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

the class Form method showModal.

/**
 * This method shows the form as a modal alert allowing us to produce a behavior
 * of an alert/dialog box. This method will block the calling thread even if the
 * calling thread is the EDT. Notice that this method will not release the block
 * until dispose is called even if show() from another form is called!
 * <p>Modal dialogs Allow the forms "content" to "hang in mid air" this is especially useful for
 * dialogs where you would want the underlying form to "peek" from behind the
 * form.
 *
 * @param top space in pixels between the top of the screen and the form
 * @param bottom space in pixels between the bottom of the screen and the form
 * @param left space in pixels between the left of the screen and the form
 * @param right space in pixels between the right of the screen and the form
 * @param includeTitle whether the title should hang in the top of the screen or
 * be glued onto the content pane
 * @param modal indictes if this is a modal or modeless dialog true for modal dialogs
 */
void showModal(int top, int bottom, int left, int right, boolean includeTitle, boolean modal, boolean reverse) {
    Display.getInstance().flushEdt();
    if (previousForm == null) {
        previousForm = Display.getInstance().getCurrent();
        // special case for application opening with a dialog before any form is shown
        if (previousForm == null) {
            previousForm = new Form();
            previousForm.show();
        } else {
            if (previousForm instanceof Dialog) {
                Dialog previousDialog = (Dialog) previousForm;
                if (previousDialog.isDisposed()) {
                    previousForm = Display.getInstance().getCurrentUpcoming();
                }
            }
        }
    }
    previousForm.tint = true;
    Painter p = getStyle().getBgPainter();
    if (top > 0 || bottom > 0 || left > 0 || right > 0) {
        if (!title.isVisible()) {
            includeTitle = false;
        }
        Style titleStyle = title.getStyle();
        titleStyle.removeListeners();
        Style contentStyle = contentPane.getUnselectedStyle();
        contentStyle.removeListeners();
        if (includeTitle) {
            titleStyle.setMargin(Component.TOP, top, false);
            titleStyle.setMargin(Component.BOTTOM, 0, false);
            titleStyle.setMargin(Component.LEFT, left, false);
            titleStyle.setMargin(Component.RIGHT, right, false);
            contentStyle.setMargin(Component.TOP, 0, false);
            contentStyle.setMargin(Component.BOTTOM, bottom, false);
            contentStyle.setMargin(Component.LEFT, left, false);
            contentStyle.setMargin(Component.RIGHT, right, false);
        } else {
            titleStyle.setMargin(Component.TOP, 0, false);
            titleStyle.setMargin(Component.BOTTOM, 0, false);
            titleStyle.setMargin(Component.LEFT, 0, false);
            titleStyle.setMargin(Component.RIGHT, 0, false);
            contentStyle.setMargin(Component.TOP, top, false);
            contentStyle.setMargin(Component.BOTTOM, bottom, false);
            contentStyle.setMargin(Component.LEFT, left, false);
            contentStyle.setMargin(Component.RIGHT, right, false);
        }
        titleStyle.setMarginUnit(null);
        contentStyle.setMarginUnit(null);
        initDialogBgPainter(p, previousForm);
        revalidate();
    }
    initFocused();
    if (getTransitionOutAnimator() == null && getTransitionInAnimator() == null) {
        initLaf(getUIManager());
    }
    initComponentImpl();
    Display.getInstance().setCurrent(this, reverse);
    onShow();
    if (modal) {
        // called to display a dialog and wait for modality
        Display.getInstance().invokeAndBlock(new RunnableWrapper(this, p, reverse));
        // if the virtual keyboard was opend by the dialog close it
        Display.getInstance().setShowVirtualKeyboard(false);
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 22 with Dialog

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

the class MenuBar method addCommand.

/**
 * Adds a Command to the MenuBar
 *
 * @param cmd Command to add
 */
public void addCommand(Command cmd) {
    // with the select command
    if (commands.contains(cmd)) {
        return;
    }
    if (getBackCommand() == cmd && UIManager.getInstance().isThemeConstant("hideBackCommandBool", false)) {
        return;
    }
    // special case for default commands which are placed at the end and aren't overriden later
    if (soft.length > 2 && cmd == parent.getDefaultCommand()) {
        commands.addElement(cmd);
    } else {
        commands.insertElementAt(cmd, 0);
    }
    if (!(parent instanceof Dialog)) {
        int behavior = getCommandBehavior();
        if (behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR || behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK || behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT || behavior == Display.COMMAND_BEHAVIOR_ICS) {
            if (behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK && (cmd == parent.getBackCommand() || findCommandComponent(cmd) != null)) {
                return;
            }
            if (parent.getBackCommand() != cmd) {
                if ((behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK || behavior == Display.COMMAND_BEHAVIOR_ICS || behavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION) && parent.getTitle() != null && parent.getTitle().length() > 0) {
                    synchronizeCommandsWithButtonsInBackbutton();
                    return;
                }
                setLayout(new GridLayout(1, getCommandCount()));
                addComponent(createTouchCommandButton(cmd));
            } else {
                commands.removeElement(cmd);
            }
            return;
        }
    }
    updateCommands();
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout)

Example 23 with Dialog

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

the class MenuBar method updateTitleCommandPlacement.

private void updateTitleCommandPlacement() {
    int commandBehavior = getCommandBehavior();
    Container t = getTitleAreaContainer();
    BorderLayout titleLayout = (BorderLayout) t.getLayout();
    if (getParent() == null) {
        installMenuBar();
    } else {
        if (getParent() == getTitleAreaContainer() && commandBehavior != Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT && commandBehavior != Display.COMMAND_BEHAVIOR_ICS) {
            getParent().removeComponent(this);
            installMenuBar();
        }
    }
    if (!(parent instanceof Dialog)) {
        if ((commandBehavior == Display.COMMAND_BEHAVIOR_ICS || commandBehavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION || commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK) && parent.getTitle() != null && parent.getTitle().length() > 0) {
            synchronizeCommandsWithButtonsInBackbutton();
            return;
        } else {
            if (commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_RIGHT || commandBehavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK) {
                if (getParent() != null) {
                    if (getParent() == getTitleAreaContainer()) {
                        return;
                    }
                    getParent().removeComponent(this);
                }
                // getTitleAreaContainer().addComponent(BorderLayout.EAST, findRightTitleContainer());
                return;
            }
        }
    }
    if (t.getComponentCount() - componentCountOffset(t) > 1) {
        if (Display.COMMAND_BEHAVIOR_ICS == getCommandBehavior()) {
            titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
        } else {
            titleLayout.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
        }
        Component l = getTitleComponent();
        if (l.getParent() != null) {
            l.getParent().removeComponent(l);
        }
        t.removeAll();
        t.addComponent(BorderLayout.CENTER, l);
        initTitleBarStatus();
    }
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout)

Example 24 with Dialog

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

the class MenuBar method actionPerformed.

/**
 * Invoked when a softbutton is pressed
 */
public void actionPerformed(ActionEvent evt) {
    if (evt.isConsumed()) {
        return;
    }
    Object src = evt.getSource();
    if (commandList == null) {
        Button source = (Button) src;
        for (int iter = 0; iter < soft.length; iter++) {
            if (source == soft[iter]) {
                if (softCommand[iter] == menuCommand) {
                    showMenu();
                    return;
                }
                if (softCommand[iter] != null) {
                    ActionEvent e = new ActionEvent(softCommand[iter], ActionEvent.Type.Command);
                    softCommand[iter].actionPerformed(e);
                    if (!e.isConsumed()) {
                        parent.actionCommandImpl(softCommand[iter]);
                    }
                }
                return;
            }
        }
    } else {
        // the list for the menu sent the event
        if (src instanceof Button) {
            for (int iter = 0; iter < soft.length; iter++) {
                if (src == soft[iter]) {
                    Container parent = commandList.getParent();
                    while (parent != null) {
                        if (parent instanceof Dialog) {
                            ((Dialog) parent).actionCommand(softCommand[iter]);
                            return;
                        }
                        parent = parent.getParent();
                    }
                }
            }
        }
        Command c = getComponentSelectedCommand(commandList);
        if (!c.isEnabled()) {
            return;
        }
        Container p = commandList.getParent();
        while (p != null) {
            if (p instanceof Dialog) {
                ((Dialog) p).actionCommand(c);
                return;
            }
            p = p.getParent();
        }
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 25 with Dialog

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

the class MenuBar method showMenu.

/**
 * This method shows the menu on the Form.
 * The method creates a Dialog with the commands and calls showMenuDialog.
 * The method blocks until the user dispose the dialog.
 */
public void showMenu() {
    final Dialog d = new Dialog("Menu", "");
    d.setDisposeWhenPointerOutOfBounds(true);
    d.setMenu(true);
    d.addOrientationListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            d.dispose();
        }
    });
    d.setTransitionInAnimator(transitionIn);
    d.setTransitionOutAnimator(transitionOut);
    d.setLayout(new BorderLayout());
    d.setScrollable(false);
    // calling parent.createCommandComponent is done only for backward
    // compatability reasons, in the next version this call be replaced with
    // calling directly to createCommandComponent
    ((Form) d).getMenuBar().commandList = createCommandComponent(commands);
    if (menuCellRenderer != null && ((Form) d).getMenuBar().commandList instanceof List) {
        ((List) ((Form) d).getMenuBar().commandList).setListCellRenderer(menuCellRenderer);
    }
    d.getContentPane().getStyle().setMargin(0, 0, 0, 0);
    d.addComponent(BorderLayout.CENTER, ((Form) d).getMenuBar().commandList);
    if (thirdSoftButton) {
        d.addCommand(selectMenuItem);
        d.addCommand(cancelMenuItem);
    } else {
        d.addCommand(cancelMenuItem);
        if (soft.length > 1) {
            d.addCommand(selectMenuItem);
        }
    }
    d.setClearCommand(cancelMenuItem);
    d.setBackCommand(cancelMenuItem);
    if (((Form) d).getMenuBar().commandList instanceof List) {
        ((List) ((Form) d).getMenuBar().commandList).addActionListener(((Form) d).getMenuBar());
    }
    menuDisplaying = true;
    Command result = showMenuDialog(d);
    menuDisplaying = false;
    if (result != cancelMenuItem) {
        Command c = null;
        if (result == selectMenuItem) {
            c = getComponentSelectedCommand(((Form) d).getMenuBar().commandList);
            if (c != null) {
                ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
                c.actionPerformed(e);
            }
        } else {
            c = result;
            // a touch menu will always send its commands on its own...
            if (!isTouchMenus()) {
                c = result;
                if (c != null) {
                    ActionEvent e = new ActionEvent(c, ActionEvent.Type.Command);
                    c.actionPerformed(e);
                }
            }
        }
        // menu item was handled internally in a touch interface that is not a touch menu
        if (c != null) {
            parent.actionCommandImpl(c);
        }
    }
    if (((Form) d).getMenuBar().commandList instanceof List) {
        ((List) ((Form) d).getMenuBar().commandList).removeActionListener(((Form) d).getMenuBar());
    }
    Form upcoming = Display.getInstance().getCurrentUpcoming();
    if (upcoming == parent) {
        d.disposeImpl();
    } else {
        parent.tint = (upcoming instanceof Dialog);
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionEvent(com.codename1.ui.events.ActionEvent)

Aggregations

Dialog (com.codename1.ui.Dialog)28 Form (com.codename1.ui.Form)23 BorderLayout (com.codename1.ui.layouts.BorderLayout)17 Component (com.codename1.ui.Component)16 ActionEvent (com.codename1.ui.events.ActionEvent)14 Container (com.codename1.ui.Container)13 Style (com.codename1.ui.plaf.Style)12 ActionListener (com.codename1.ui.events.ActionListener)10 GridLayout (com.codename1.ui.layouts.GridLayout)8 UIManager (com.codename1.ui.plaf.UIManager)7 IOException (java.io.IOException)7 InfiniteProgress (com.codename1.components.InfiniteProgress)6 Command (com.codename1.ui.Command)6 Label (com.codename1.ui.Label)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)6 ConnectionRequest (com.codename1.io.ConnectionRequest)4 Button (com.codename1.ui.Button)4 CheckBox (com.codename1.ui.CheckBox)4 Painter (com.codename1.ui.Painter)4 TextArea (com.codename1.ui.TextArea)4