Search in sources :

Example 51 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 c the context component which is used to position the dialog and can also be pointed at
 * @return the command that might have been triggered by the user within the dialog if commands are placed in the dialog
 */
public Command showPopupDialog(Component c) {
    Rectangle componentPos = c.getSelectedRect();
    componentPos.setX(componentPos.getX() - c.getScrollX());
    componentPos.setY(componentPos.getY() - c.getScrollY());
    return showPopupDialog(componentPos);
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle)

Example 52 with Dialog

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

the class Dialog method getDialogPreferredSize.

/**
 * Returns the preferred size of the dialog, this allows developers to position a dialog
 * manually in arbitrary positions.
 *
 * @return the preferred size of this dialog
 */
public Dimension getDialogPreferredSize() {
    Component contentPane = super.getContentPane();
    Style contentPaneStyle = getDialogStyle();
    int width = Display.getInstance().getDisplayWidth();
    int prefHeight = contentPane.getPreferredH();
    int prefWidth = contentPane.getPreferredW();
    prefWidth = Math.min(prefWidth, width);
    if (contentPaneStyle.getBorder() != null) {
        prefWidth = Math.max(contentPaneStyle.getBorder().getMinimumWidth(), prefWidth);
        prefHeight = Math.max(contentPaneStyle.getBorder().getMinimumHeight(), prefHeight);
    }
    return new Dimension(prefWidth, prefHeight);
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Example 53 with Dialog

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

the class Dialog method showPackedImpl.

/**
 * Convenience method to show a dialog sized to match its content.
 *
 * @param position one of the values from the BorderLayout class e.g. BorderLayout.CENTER, BorderLayout.NORTH etc.
 * @param modal whether the dialog should be modal or modaless
 * @return the command selected if the dialog is modal and disposed via a command
 */
private Command showPackedImpl(String position, boolean modal, boolean stretch) {
    if (getTitle() == null) {
        setTitle("");
    }
    this.position = position;
    int height = Display.getInstance().getDisplayHeight();
    int width = Display.getInstance().getDisplayWidth();
    if (top > -1) {
        refreshTheme();
    }
    Component contentPane = super.getContentPane();
    Component title = super.getTitleComponent();
    // preferred size logic of the dialog won't work with large title borders
    if (dialogTitle != null && getUIManager().isThemeConstant("hideEmptyTitleBool", false)) {
        boolean b = getTitle().length() > 0;
        getTitleArea().setVisible(b);
        getTitleComponent().setVisible(b);
    }
    Style contentPaneStyle = getDialogStyle();
    int menuHeight = calcMenuHeight();
    // allows a text area to recalculate its preferred size if embedded within a dialog
    revalidate();
    int prefHeight = contentPane.getPreferredH();
    int prefWidth = contentPane.getPreferredW();
    prefWidth = Math.min(prefWidth, width);
    if (contentPaneStyle.getBorder() != null) {
        prefWidth = Math.max(contentPaneStyle.getBorder().getMinimumWidth(), prefWidth);
        prefHeight = Math.max(contentPaneStyle.getBorder().getMinimumHeight(), prefHeight);
    }
    height = height - menuHeight - title.getPreferredH();
    int topBottom = Math.max(0, (height - prefHeight) / 2);
    int leftRight = Math.max(0, (width - prefWidth) / 2);
    if (position.equals(BorderLayout.CENTER)) {
        show(topBottom, topBottom, leftRight, leftRight, true, modal);
        return lastCommandPressed;
    }
    if (position.equals(BorderLayout.EAST)) {
        if (stretch) {
            show(0, 0, Math.max(0, width - prefWidth), 0, true, modal);
        } else {
            show(topBottom, topBottom, Math.max(0, width - prefWidth), 0, true, modal);
        }
        return lastCommandPressed;
    }
    if (position.equals(BorderLayout.WEST)) {
        if (stretch) {
            show(0, 0, 0, Math.max(0, width - prefWidth), true, modal);
        } else {
            show(topBottom, topBottom, 0, Math.max(0, width - prefWidth), true, modal);
        }
        return lastCommandPressed;
    }
    if (position.equals(BorderLayout.NORTH)) {
        if (stretch) {
            show(0, Math.max(0, height - prefHeight), 0, 0, true, modal);
        } else {
            show(0, Math.max(0, height - prefHeight), leftRight, leftRight, true, modal);
        }
        return lastCommandPressed;
    }
    if (position.equals(BorderLayout.SOUTH)) {
        if (stretch) {
            show(Math.max(0, height - prefHeight), 0, 0, 0, true, modal);
        } else {
            show(Math.max(0, height - prefHeight), 0, leftRight, leftRight, true, modal);
        }
        return lastCommandPressed;
    }
    throw new IllegalArgumentException("Unknown position: " + position);
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 54 with Dialog

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

the class MenuBar method keyReleased.

/**
 * {@inheritDoc}
 */
public void keyReleased(int keyCode) {
    int commandBehavior = getCommandBehavior();
    if (commandBehavior >= Display.COMMAND_BEHAVIOR_BUTTON_BAR && keyCode != backSK && keyCode != clearSK && keyCode != backspaceSK) {
        return;
    }
    if (getCommandCount() > 0) {
        int softkeyCount = Display.getInstance().getImplementation().getSoftkeyCount();
        if (softkeyCount < 2 && keyCode == leftSK) {
            if (commandList != null) {
                Container parent = commandList.getParent();
                while (parent != null) {
                    if (parent instanceof Dialog && ((Dialog) parent).isMenu()) {
                        return;
                    }
                    parent = parent.getParent();
                }
            }
            showMenu();
            return;
        } else {
            if (keyCode == leftSK) {
                if (left != null) {
                    left.released();
                }
                return;
            } else {
                // it might be a back command...
                if ((keyCode == rightSK || keyCode == rightSK2)) {
                    if (right != null) {
                        right.released();
                    }
                    return;
                } else {
                    if (Display.getInstance().getGameAction(keyCode) == Display.GAME_FIRE) {
                        main.released();
                        return;
                    }
                }
            }
        }
    }
    // allows a back/clear command to occur regardless of whether the
    // command was added to the form
    Command c = null;
    if (keyCode == backSK) {
        // the back command should be invoked
        c = parent.getBackCommand();
        if (c == null && minimizeOnBack) {
            Display.getInstance().minimizeApplication();
            return;
        }
    } else {
        if (keyCode == clearSK || keyCode == backspaceSK) {
            c = getClearCommand();
        }
    }
    if (c != null) {
        ActionEvent ev = new ActionEvent(c, keyCode);
        c.actionPerformed(ev);
        if (!ev.isConsumed()) {
            parent.actionCommandImpl(c);
        }
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 55 with Dialog

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

the class MenuBar method initMenuBar.

/**
 * Initialize the MenuBar
 *
 * @param parent the associated Form
 */
protected void initMenuBar(Form parent) {
    this.parent = parent;
    selectMenuItem = createMenuSelectCommand();
    cancelMenuItem = createMenuCancelCommand();
    UIManager manager = parent.getUIManager();
    LookAndFeel lf = manager.getLookAndFeel();
    // don't minimize the app if it's a Dialog
    minimizeOnBack = manager.isThemeConstant("minimizeOnBackBool", true) && !(parent instanceof Dialog);
    hideEmptyCommands = manager.isThemeConstant("hideEmptyCommandsBool", false);
    menuStyle = manager.getComponentStyle("Menu");
    setUIID("SoftButton");
    menuCommand = new Command(manager.localize("menu", "Menu"), lf.getMenuIcons()[2]);
    // use the slide transition by default
    if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
        transitionIn = lf.getDefaultMenuTransitionIn();
        transitionOut = lf.getDefaultMenuTransitionOut();
    } else {
        transitionIn = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 300, true);
        transitionOut = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 300, true);
    }
    menuCellRenderer = lf.getMenuRenderer();
    int softkeyCount = Display.getInstance().getImplementation().getSoftkeyCount();
    thirdSoftButton = Display.getInstance().isThirdSoftButton();
    int commandBehavior = getCommandBehavior();
    if (softkeyCount > 1 && commandBehavior < Display.COMMAND_BEHAVIOR_BUTTON_BAR) {
        if (thirdSoftButton) {
            setLayout(new GridLayout(1, 3));
            soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
            main = soft[0];
            left = soft[1];
            right = soft[2];
            if (parent.isRTL()) {
                right.setUIID("SoftButtonLeft");
                left.setUIID("SoftButtonRight");
                addComponent(right);
                addComponent(main);
                addComponent(left);
            } else {
                addComponent(left);
                addComponent(main);
                addComponent(right);
            }
            if (isReverseSoftButtons()) {
                Button b = soft[1];
                soft[1] = soft[2];
                soft[2] = b;
            }
        } else {
            setLayout(new GridLayout(1, 2));
            soft = new Button[] { createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
            main = soft[0];
            left = soft[0];
            right = soft[1];
            if (parent.isRTL()) {
                right.setUIID("SoftButtonLeft");
                left.setUIID("SoftButtonRight");
                addComponent(right);
                addComponent(left);
            } else {
                addComponent(left);
                addComponent(right);
            }
            if (isReverseSoftButtons()) {
                Button b = soft[0];
                soft[0] = soft[1];
                soft[1] = b;
            }
        }
        // It doesn't make sense for softbuttons to have ... at the end
        for (int iter = 0; iter < soft.length; iter++) {
            soft[iter].setEndsWith3Points(false);
        }
    } else {
        // special case for touch screens we still want the 3 softbutton areas...
        if (thirdSoftButton) {
            setLayout(new GridLayout(1, 3));
            soft = new Button[] { createSoftButton("SoftButtonCenter"), createSoftButton("SoftButtonLeft"), createSoftButton("SoftButtonRight") };
            main = soft[0];
            left = soft[1];
            right = soft[2];
            addComponent(left);
            addComponent(main);
            addComponent(right);
            if (isReverseSoftButtons()) {
                Button b = soft[1];
                soft[1] = soft[2];
                soft[2] = b;
            }
        } else {
            soft = new Button[] { createSoftButton("SoftButtonCenter") };
        }
    }
    softCommand = new Command[soft.length];
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout) UIManager(com.codename1.ui.plaf.UIManager) LookAndFeel(com.codename1.ui.plaf.LookAndFeel)

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