Search in sources :

Example 56 with Dialog

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

the class MenuBar method createCommandComponent.

/**
 * Creates the component containing the commands within the given vector
 * used for showing the menu dialog, this method calls the createCommandList
 * method by default however it allows more elaborate menu creation.
 *
 * @param commands list of command objects
 * @return Component that will result in the parent menu dialog recieving a command event
 */
protected Component createCommandComponent(Vector commands) {
    UIManager manager = parent.getUIManager();
    // Create a touch based menu interface
    if (manager.getLookAndFeel().isTouchMenus()) {
        Container menu = new Container();
        menu.setScrollableY(true);
        for (int iter = 0; iter < commands.size(); iter++) {
            Command c = (Command) commands.elementAt(iter);
            menu.addComponent(createTouchCommandButton(c));
        }
        if (!manager.isThemeConstant("touchCommandFlowBool", false)) {
            int cols = calculateTouchCommandGridColumns(menu);
            if (cols > getCommandCount()) {
                cols = getCommandCount();
            }
            int rows = Math.max(1, getCommandCount() / cols + (getCommandCount() % cols != 0 ? 1 : 0));
            if (rows > 1) {
                // try to prevent too many columns concentraiting within a single row
                int remainingColumns = (rows * cols) % getCommandCount();
                int newCols = cols;
                int newRows = rows;
                while (remainingColumns != 0 && remainingColumns > 1 && newCols >= 2) {
                    newCols--;
                    newRows = Math.max(1, getCommandCount() / newCols + (getCommandCount() % newCols != 0 ? 1 : 0));
                    if (newRows != rows) {
                        break;
                    }
                    remainingColumns = (newRows * newCols) % getCommandCount();
                }
                if (newRows == rows) {
                    cols = newCols;
                    rows = newRows;
                }
            }
            GridLayout g = new GridLayout(rows, cols);
            g.setFillLastRow(manager.isThemeConstant("touchCommandFillBool", true));
            menu.setLayout(g);
        } else {
            ((FlowLayout) menu.getLayout()).setFillRows(true);
        }
        menu.setPreferredW(Display.getInstance().getDisplayWidth());
        return menu;
    }
    return createCommandList(commands);
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) UIManager(com.codename1.ui.plaf.UIManager)

Example 57 with Dialog

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

the class MenuBar method showMenuDialog.

/*private void fixCommandAlignment() {
    if (left != null) {
    if (parent.isRTL()) {
    left.setAlignment(Label.RIGHT);
    right.setAlignment(Label.LEFT);
    } else {
    left.setAlignment(Label.LEFT);
    right.setAlignment(Label.RIGHT);
    }
    if(main != null && main != left && main != right) {
    main.setAlignment(CENTER);
    }
    }
    }*/
/**
 * A menu is implemented as a dialog, this method allows you to override dialog
 * display in order to customize the dialog menu in various ways
 *
 * @param menu a dialog containing menu options that can be customized
 * @return the command selected by the user in the dialog (not menu) Select
 * or Cancel
 */
protected Command showMenuDialog(Dialog menu) {
    UIManager manager = parent.getUIManager();
    boolean pref = manager.isThemeConstant("menuPrefSizeBool", false);
    int height;
    int marginLeft;
    int marginRight = 0;
    if (pref) {
        Container dialogContentPane = menu.getDialogComponent();
        marginLeft = parent.getWidth() - (dialogContentPane.getPreferredW() + menu.getStyle().getHorizontalPadding());
        marginLeft = Math.max(0, marginLeft);
        if (parent.getSoftButtonCount() > 1) {
            height = parent.getHeight() - parent.getSoftButton(0).getParent().getPreferredH() - dialogContentPane.getPreferredH();
        } else {
            height = parent.getHeight() - dialogContentPane.getPreferredH();
        }
        height = Math.max(0, height);
    } else {
        float menuWidthPercent = 1 - Float.parseFloat(manager.getThemeConstant("menuWidthPercent", "75")) / 100;
        float menuHeightPercent = 1 - Float.parseFloat(manager.getThemeConstant("menuHeightPercent", "50")) / 100;
        height = (int) (parent.getHeight() * menuHeightPercent);
        marginLeft = (int) (parent.getWidth() * menuWidthPercent);
    }
    if (isReverseSoftButtons()) {
        marginRight = marginLeft;
        marginLeft = 0;
    }
    if (getCommandBehavior() == Display.COMMAND_BEHAVIOR_ICS) {
        menu.setTransitionOutAnimator(transitionIn);
        menu.setTransitionInAnimator(transitionOut);
        int th = getTitleAreaContainer().getHeight();
        return menu.show(th, height - th, marginLeft, marginRight, true);
    } else {
        if (manager.getLookAndFeel().isTouchMenus() && manager.isThemeConstant("PackTouchMenuBool", true)) {
            return menu.showPacked(BorderLayout.SOUTH, true);
        } else {
            return menu.show(height, 0, marginLeft, marginRight, true);
        }
    }
}
Also used : UIManager(com.codename1.ui.plaf.UIManager)

Example 58 with Dialog

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

the class MenuBar method addCommand.

/**
 * Add a Command to the MenuBar
 *
 * @param cmd Command to Add
 * @param index determines the order of the added commands
 */
protected void addCommand(Command cmd, int index) {
    if (getCommandCount() == 0 && parent != null) {
        installMenuBar();
    }
    // with the select command
    if (commands.contains(cmd)) {
        return;
    }
    commands.insertElementAt(cmd, index);
    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 || behavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION) {
            if (behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK && cmd == parent.getBackCommand()) {
                return;
            }
            if (behavior == Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION) {
                return;
            }
            if ((behavior == Display.COMMAND_BEHAVIOR_BUTTON_BAR_TITLE_BACK || behavior == Display.COMMAND_BEHAVIOR_ICS) && parent.getTitle() != null && parent.getTitle().length() > 0) {
                synchronizeCommandsWithButtonsInBackbutton();
                return;
            }
            if (parent.getBackCommand() != cmd) {
                if (behavior != Display.COMMAND_BEHAVIOR_ICS) {
                    setLayout(new GridLayout(1, getComponentCount() + 1));
                    addComponent(Math.min(getComponentCount(), index), createTouchCommandButton(cmd));
                    revalidate();
                }
            } else {
                commands.removeElement(cmd);
            }
            return;
        }
    }
    updateCommands();
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout)

Example 59 with Dialog

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

the class Toolbar method showOverflowMenu.

/*
     * A Overflow Menu is implemented as a dialog, this method allows you to 
     * override the dialog display in order to customize the dialog menu in 
     * various ways
     * 
     * @param menu a dialog containing Overflow Menu options that can be 
     * customized
     * @return the command selected by the user in the dialog
     */
protected Command showOverflowMenu(Dialog menu) {
    Form parent = sideMenu.getParentForm();
    int height;
    int marginLeft;
    int marginRight = 0;
    Container dialogContentPane = menu.getDialogComponent();
    marginLeft = parent.getWidth() - (dialogContentPane.getPreferredW() + menu.getStyle().getHorizontalPadding());
    marginLeft = Math.max(0, marginLeft);
    if (parent.getSoftButtonCount() > 1) {
        height = parent.getHeight() - parent.getSoftButton(0).getParent().getPreferredH() - dialogContentPane.getPreferredH();
    } else {
        height = parent.getHeight() - dialogContentPane.getPreferredH();
    }
    height = Math.max(0, height);
    int th = getHeight();
    Transition transitionIn;
    Transition transitionOut;
    UIManager manager = parent.getUIManager();
    LookAndFeel lf = manager.getLookAndFeel();
    if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
        transitionIn = lf.getDefaultMenuTransitionIn();
        if (transitionIn instanceof BubbleTransition) {
            ((BubbleTransition) transitionIn).setComponentName("OverflowButton");
        }
        transitionOut = lf.getDefaultMenuTransitionOut();
    } else {
        transitionIn = CommonTransitions.createEmpty();
        transitionOut = CommonTransitions.createEmpty();
    }
    menu.setTransitionInAnimator(transitionIn);
    menu.setTransitionOutAnimator(transitionOut);
    if (isRTL()) {
        marginRight = marginLeft;
        marginLeft = 0;
    }
    int tint = parent.getTintColor();
    parent.setTintColor(0x00FFFFFF);
    parent.tint = false;
    boolean showBelowTitle = manager.isThemeConstant("showMenuBelowTitleBool", true);
    int topPadding = 0;
    Component statusBar = ((BorderLayout) getLayout()).getNorth();
    if (statusBar != null) {
        topPadding = statusBar.getAbsoluteY() + statusBar.getHeight();
    }
    if (showBelowTitle) {
        topPadding = th;
    }
    Command r = menu.show(topPadding, Math.max(topPadding, height - topPadding), marginLeft, marginRight, true);
    parent.setTintColor(tint);
    return r;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Transition(com.codename1.ui.animations.Transition) BubbleTransition(com.codename1.ui.animations.BubbleTransition) UIManager(com.codename1.ui.plaf.UIManager) LookAndFeel(com.codename1.ui.plaf.LookAndFeel) BubbleTransition(com.codename1.ui.animations.BubbleTransition)

Example 60 with Dialog

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

the class BubbleTransition method initTransition.

@Override
public void initTransition() {
    Component source = getSource();
    Component destination = getDestination();
    int w = source.getWidth();
    int h = source.getHeight();
    // improper replace() calls, this may still be valid and shouldn't fail
    if (w <= 0 || h <= 0) {
        return;
    }
    Form sourceForm = source.getComponentForm();
    originSrc = findByName(sourceForm, componentName);
    Form destForm = destination.getComponentForm();
    originDest = findByName(destForm, componentName);
    Display d = Display.getInstance();
    if (getDestination() instanceof Dialog) {
        Dialog dlg = (Dialog) destination;
        // transparent image!
        destBuffer = Image.createImage(Math.min(d.getDisplayWidth(), getDialogParent(dlg).getWidth()), Math.min(d.getDisplayHeight(), dlg.getContentPane().getParent().getHeight()), 0);
        Graphics g = destBuffer.getGraphics();
        Style stl = dlg.getDialogComponent().getStyle();
        byte bgt = stl.getBgTransparency();
        stl.setBgTransparency(0xff);
        drawDialogCmp(destBuffer.getGraphics(), dlg);
        stl.setBgTransparency(bgt & 0xff, true);
    } else if (getSource() instanceof Dialog) {
        Dialog dlg = (Dialog) source;
        // transparent image!
        destBuffer = Image.createImage(Math.min(d.getDisplayWidth(), getDialogParent(dlg).getWidth()), Math.min(d.getDisplayHeight(), dlg.getContentPane().getParent().getHeight()), 0);
        Graphics g = destBuffer.getGraphics();
        Style stl = dlg.getDialogComponent().getStyle();
        byte bgt = stl.getBgTransparency();
        stl.setBgTransparency(0xff);
        drawDialogCmp(destBuffer.getGraphics(), dlg);
        stl.setBgTransparency(bgt & 0xff, true);
    } else {
        if (originDest != null) {
            destBuffer = createMutableImage(source.getWidth(), source.getHeight());
            paint(destBuffer.getGraphics(), source, -source.getAbsoluteX(), -source.getAbsoluteY());
        } else {
            destBuffer = createMutableImage(destination.getWidth(), destination.getHeight());
            paint(destBuffer.getGraphics(), destination, -destination.getAbsoluteX(), -destination.getAbsoluteY());
        }
    }
    Component dest = getDestination();
    if (dest instanceof Dialog) {
        dest = getDialogParent(dest);
    }
    Component src = getSource();
    if (src instanceof Dialog) {
        src = getDialogParent(src);
    }
    if (originSrc != null) {
        locMotionX = Motion.createLinearMotion(originSrc.getAbsoluteX() + originSrc.getWidth() / 2 - dest.getWidth() / 2, dest.getAbsoluteX(), duration);
        locMotionX.start();
        locMotionY = Motion.createLinearMotion(originSrc.getAbsoluteY() + originSrc.getHeight() / 2 - dest.getHeight() / 2, dest.getAbsoluteY(), duration);
        locMotionY.start();
        clipMotion = Motion.createLinearMotion(Math.min(originSrc.getWidth(), originSrc.getHeight()), Math.max(dest.getWidth(), dest.getHeight()) * 3 / 2, duration);
    } else {
        if (originDest != null) {
            locMotionX = Motion.createLinearMotion(src.getAbsoluteX(), originDest.getAbsoluteX() + originDest.getWidth() / 2 - src.getWidth() / 2, duration);
            locMotionX.start();
            locMotionY = Motion.createLinearMotion(src.getAbsoluteY(), originDest.getAbsoluteY() + originDest.getHeight() / 2 - src.getHeight() / 2, duration);
            locMotionY.start();
            clipMotion = Motion.createLinearMotion(Math.max(src.getWidth(), src.getHeight()) * 3 / 2, Math.min(originDest.getWidth(), originDest.getHeight()), duration);
        } else {
            x = dest.getAbsoluteX();
            y = dest.getAbsoluteY();
            clipMotion = Motion.createLinearMotion(0, Math.max(dest.getWidth(), dest.getHeight()) * 3 / 2, duration);
        }
    }
    clipMotion.start();
}
Also used : Graphics(com.codename1.ui.Graphics) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component) Display(com.codename1.ui.Display)

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