Search in sources :

Example 16 with Dialog

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

the class ComboBox method createPopupList.

/**
 * Creates the list object used within the popup dialog. This method allows subclasses
 * to customize the list creation for the popup dialog shown when the combo box is pressed.
 *
 * @return a newly created list object used when the user presses the combo box.
 */
protected List<T> createPopupList() {
    List<T> l = new List<T>(getModel());
    l.setCommandList(isCommandList());
    l.setSmoothScrolling(isSmoothScrolling());
    l.setFixedSelection(getFixedSelection());
    l.setListCellRenderer(getRenderer());
    l.setItemGap(getItemGap());
    l.setUIID("ComboBoxList");
    if (getUIManager().isThemeConstant("otherPopupRendererBool", false)) {
        DefaultListCellRenderer renderer = new DefaultListCellRenderer();
        renderer.setUIID("PopupItem");
        renderer.getListFocusComponent(l).setUIID("PopupFocus");
        l.setListCellRenderer(renderer);
    }
    return l;
}
Also used : DefaultListCellRenderer(com.codename1.ui.list.DefaultListCellRenderer)

Example 17 with Dialog

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

the class Dialog method placeButtonCommands.

/**
 * Places the given commands in the dialog command area, this is very useful for touch devices.
 *
 * @param cmds the commands to place
 * @deprecated this method shouldn't be invoked externally, it should have been private
 */
public void placeButtonCommands(Command[] cmds) {
    buttonCommands = cmds;
    Container buttonArea;
    if (getUIManager().isThemeConstant("dlgCommandGridBool", false)) {
        buttonArea = new Container(new GridLayout(1, cmds.length));
    } else {
        buttonArea = new Container(new FlowLayout(CENTER));
    }
    buttonArea.setUIID("DialogCommandArea");
    String uiid = getUIManager().getThemeConstant("dlgButtonCommandUIID", null);
    addButtonBar(buttonArea);
    if (cmds.length > 0) {
        String lineColor = getUIManager().getThemeConstant("dlgInvisibleButtons", null);
        if (cmds.length > 3) {
            lineColor = null;
        }
        int largest = Integer.parseInt(getUIManager().getThemeConstant("dlgCommandButtonSizeInt", "0"));
        for (int iter = 0; iter < cmds.length; iter++) {
            Button b = new Button(cmds[iter]);
            if (uiid != null) {
                b.setUIID(uiid);
            }
            // special case for dialog butons uppercase on Android
            if (Button.isCapsTextDefault()) {
                b.setCapsText(true);
            }
            largest = Math.max(b.getPreferredW(), largest);
            if (lineColor != null && lineColor.length() > 0) {
                int color = Integer.parseInt(lineColor, 16);
                Border brd = null;
                if (iter < cmds.length - 1) {
                    brd = Border.createCompoundBorder(Border.createLineBorder(1, color), null, null, Border.createLineBorder(1, color));
                } else {
                    brd = Border.createCompoundBorder(Border.createLineBorder(1, color), null, null, null);
                }
                b.getUnselectedStyle().setBorder(brd);
                b.getSelectedStyle().setBorder(brd);
                b.getPressedStyle().setBorder(brd);
            }
            buttonArea.addComponent(b);
        }
        for (int iter = 0; iter < cmds.length; iter++) {
            buttonArea.getComponentAt(iter).setPreferredW(largest);
        }
        buttonArea.getComponentAt(0).requestFocus();
    }
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) Border(com.codename1.ui.plaf.Border)

Example 18 with Dialog

use of com.codename1.ui.Dialog 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 19 with Dialog

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

the class Dialog method showPopupDialog.

/**
 * A popup dialog is shown with the context of a component and  its selection, it is disposed seamlessly if the back button is pressed
 * or if the user touches outside its bounds. It can optionally provide an arrow in the theme to point at the context component. The popup
 * dialog has the PopupDialog style by default.
 *
 * @param rect the screen rectangle to which the popup should point
 * @return the command that might have been triggered by the user within the dialog if commands are placed in the dialog
 */
public Command showPopupDialog(Rectangle rect) {
    if (getDialogUIID().equals("Dialog")) {
        setDialogUIID("PopupDialog");
        if (getTitleComponent().getUIID().equals("DialogTitle")) {
            getTitleComponent().setUIID("PopupDialogTitle");
        }
        getContentPane().setUIID("PopupContentPane");
    }
    disposeOnRotation = true;
    disposeWhenPointerOutOfBounds = true;
    Command backCommand = null;
    if (getBackCommand() == null) {
        backCommand = new Command("Back");
        setBackCommand(backCommand);
    }
    Component contentPane = super.getContentPane();
    Label title = super.getTitleComponent();
    int menuHeight = calcMenuHeight();
    UIManager manager = getUIManager();
    // preferred size logic of the dialog won't work with large title borders
    if (dialogTitle != null && manager.isThemeConstant("hideEmptyTitleBool", false)) {
        boolean b = getTitle().length() > 0;
        getTitleArea().setVisible(b);
        getTitleComponent().setVisible(b);
        if (!b && manager.isThemeConstant("shrinkPopupTitleBool", true)) {
            getTitleComponent().setPreferredSize(new Dimension(0, 0));
            getTitleComponent().getStyle().setBorder(null);
            getTitleArea().setPreferredSize(new Dimension(0, 0));
            if (getContentPane().getClientProperty("$ENLARGED_POP") == null) {
                getContentPane().putClientProperty("$ENLARGED_POP", Boolean.TRUE);
                int cpPaddingTop = getContentPane().getStyle().getPaddingTop();
                int titlePT = getTitleComponent().getStyle().getPaddingTop();
                byte[] pu = getContentPane().getStyle().getPaddingUnit();
                if (pu == null) {
                    pu = new byte[4];
                }
                pu[0] = Style.UNIT_TYPE_PIXELS;
                getContentPane().getStyle().setPaddingUnit(pu);
                int pop = Display.getInstance().convertToPixels(manager.getThemeConstant("popupNoTitleAddPaddingInt", 1), false);
                getContentPane().getStyle().setPadding(TOP, pop + cpPaddingTop + titlePT);
            }
        }
    }
    // allows a text area to recalculate its preferred size if embedded within a dialog
    revalidate();
    Style contentPaneStyle = getDialogStyle();
    boolean restoreArrow = false;
    if (manager.isThemeConstant(getDialogUIID() + "ArrowBool", false)) {
        Image t = manager.getThemeImageConstant(getDialogUIID() + "ArrowTopImage");
        Image b = manager.getThemeImageConstant(getDialogUIID() + "ArrowBottomImage");
        Image l = manager.getThemeImageConstant(getDialogUIID() + "ArrowLeftImage");
        Image r = manager.getThemeImageConstant(getDialogUIID() + "ArrowRightImage");
        Border border = contentPaneStyle.getBorder();
        if (border != null) {
            border.setImageBorderSpecialTile(t, b, l, r, rect);
            restoreArrow = true;
        }
    }
    int prefHeight = contentPane.getPreferredH();
    int prefWidth = contentPane.getPreferredW();
    if (contentPaneStyle.getBorder() != null) {
        prefWidth = Math.max(contentPaneStyle.getBorder().getMinimumWidth(), prefWidth);
        prefHeight = Math.max(contentPaneStyle.getBorder().getMinimumHeight(), prefHeight);
    }
    prefWidth += getUIManager().getLookAndFeel().getVerticalScrollWidth();
    int availableHeight = Display.getInstance().getDisplayHeight() - menuHeight - title.getPreferredH();
    int availableWidth = Display.getInstance().getDisplayWidth();
    int width = Math.min(availableWidth, prefWidth);
    int x = 0;
    int y = 0;
    Command result;
    boolean showPortrait;
    if (popupDirectionBiasPortrait != null) {
        showPortrait = popupDirectionBiasPortrait.booleanValue();
    } else {
        showPortrait = Display.getInstance().isPortrait();
    }
    // if we don't have enough space then disregard device orientation
    if (showPortrait) {
        if (availableHeight < (availableWidth - rect.getWidth()) / 2) {
            showPortrait = false;
        }
    } else {
        if (availableHeight / 2 > availableWidth - rect.getWidth()) {
            showPortrait = true;
        }
    }
    if (showPortrait) {
        if (width < availableWidth) {
            int idealX = rect.getX() - width / 2 + rect.getSize().getWidth() / 2;
            // if the ideal position is less than 0 just use 0
            if (idealX > 0) {
                // if the idealX is too far to the right just align to the right
                if (idealX + width > availableWidth) {
                    x = availableWidth - width;
                } else {
                    x = idealX;
                }
            }
        }
        if (rect.getY() < availableHeight / 2) {
            // popup downwards
            y = rect.getY() + rect.getSize().getHeight();
            int height = Math.min(prefHeight, availableHeight - y);
            result = show(y, availableHeight - height - y, x, availableWidth - width - x, true, true);
        } else {
            // popup upwards
            int height = Math.min(prefHeight, availableHeight - (availableHeight - rect.getY()));
            y = rect.getY() - height;
            result = show(y, availableHeight - height - y, x, availableWidth - width - x, true, true);
        }
    } else {
        int height = Math.min(prefHeight, availableHeight);
        if (height < availableHeight) {
            int idealY = rect.getY() - height / 2 + rect.getSize().getHeight() / 2;
            // if the ideal position is less than 0 just use 0
            if (idealY > 0) {
                // if the idealY is too far up just align to the top
                if (idealY + height > availableHeight) {
                    y = availableHeight - height;
                } else {
                    y = idealY;
                }
            }
        }
        if (prefWidth > rect.getX()) {
            // popup right
            x = rect.getX() + rect.getSize().getWidth();
            if (x + prefWidth > availableWidth) {
                x = availableWidth - prefWidth;
            }
            width = Math.min(prefWidth, availableWidth - x);
            result = show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x), true, true);
        } else {
            // popup left
            width = Math.min(prefWidth, availableWidth - (availableWidth - rect.getX()));
            x = rect.getX() - width;
            result = show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x), true, true);
        }
    }
    if (restoreArrow) {
        contentPaneStyle.getBorder().clearImageBorderSpecialTile();
    }
    if (result == backCommand) {
        return null;
    }
    return result;
}
Also used : UIManager(com.codename1.ui.plaf.UIManager) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Border(com.codename1.ui.plaf.Border)

Example 20 with Dialog

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

the class Display method setCurrent.

/**
 * Displays the given Form on the screen.
 *
 * @param newForm the Form to Display
 */
void setCurrent(final Form newForm, boolean reverse) {
    if (edt == null) {
        throw new IllegalStateException("Initialize must be invoked before setCurrent!");
    }
    Form current = impl.getCurrentForm();
    if (autoFoldVKBOnFormSwitch && !(newForm instanceof Dialog)) {
        setShowVirtualKeyboard(false);
    }
    if (current == newForm) {
        current.revalidate();
        current.repaint();
        current.onShowCompletedImpl();
        return;
    }
    if (impl.isEditingText()) {
        switch(showDuringEdit) {
            case SHOW_DURING_EDIT_ALLOW_DISCARD:
                break;
            case SHOW_DURING_EDIT_ALLOW_SAVE:
                impl.saveTextEditingState();
                break;
            case SHOW_DURING_EDIT_EXCEPTION:
                throw new IllegalStateException("Show during edit");
            case SHOW_DURING_EDIT_IGNORE:
                return;
            case SHOW_DURING_EDIT_SET_AS_NEXT:
                impl.setCurrentForm(newForm);
                return;
        }
    }
    if (!isEdt()) {
        callSerially(new RunnableWrapper(newForm, null, reverse));
        return;
    }
    if (current != null) {
        if (current.isInitialized()) {
            current.deinitializeImpl();
        } else {
            Form fg = getCurrentUpcoming();
            if (fg != current) {
                if (fg.isInitialized()) {
                    fg.deinitializeImpl();
                }
            }
        }
    }
    if (!newForm.isInitialized()) {
        newForm.initComponentImpl();
    }
    if (newForm.getWidth() != getDisplayWidth() || newForm.getHeight() != getDisplayHeight()) {
        newForm.setSize(new Dimension(getDisplayWidth(), getDisplayHeight()));
        newForm.setShouldCalcPreferredSize(true);
        newForm.layoutContainer();
    } else {
        // if shouldLayout is true
        newForm.layoutContainer();
    }
    boolean transitionExists = false;
    if (animationQueue != null && animationQueue.size() > 0) {
        Object o = animationQueue.get(animationQueue.size() - 1);
        if (o instanceof Transition) {
            current = (Form) ((Transition) o).getDestination();
            impl.setCurrentForm(current);
        }
    }
    if (current != null) {
        // to the correct parent!
        if (current instanceof Dialog && ((Dialog) current).isMenu()) {
            Transition t = current.getTransitionOutAnimator();
            if (t != null) {
                // go back to the parent form first
                if (((Dialog) current).getPreviousForm() != null) {
                    initTransition(t.copy(false), current, ((Dialog) current).getPreviousForm());
                }
            }
            current = ((Dialog) current).getPreviousForm();
            impl.setCurrentForm(current);
        }
        // prevent the transition from occurring from a form into itself
        if (newForm != current) {
            if ((current != null && current.getTransitionOutAnimator() != null) || newForm.getTransitionInAnimator() != null) {
                if (animationQueue == null) {
                    animationQueue = new ArrayList<Animation>();
                }
                // transitions which are a bit sensitive
                if (current != null && (!(newForm instanceof Dialog))) {
                    Transition t = current.getTransitionOutAnimator();
                    if (current != null && t != null) {
                        transitionExists = initTransition(t.copy(reverse), current, newForm);
                    }
                }
                if (current != null && !(current instanceof Dialog)) {
                    Transition t = newForm.getTransitionInAnimator();
                    if (t != null) {
                        transitionExists = initTransition(t.copy(reverse), current, newForm);
                    }
                }
            }
        }
    }
    synchronized (lock) {
        lock.notify();
    }
    if (!transitionExists) {
        if (animationQueue == null || animationQueue.size() == 0) {
            setCurrentForm(newForm);
        } else {
            // we need to add an empty transition to "serialize" this
            // screen change...
            Transition t = CommonTransitions.createEmpty();
            initTransition(t, current, newForm);
        }
    }
}
Also used : Transition(com.codename1.ui.animations.Transition) Animation(com.codename1.ui.animations.Animation) Dimension(com.codename1.ui.geom.Dimension)

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