Search in sources :

Example 1 with UIManager

use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.

the class DefaultLookAndFeel method updateRadioButtonConstants.

private void updateRadioButtonConstants(UIManager m, boolean focus, String append) {
    Image radioSel = m.getThemeImageConstant("radioSelected" + append + "Image");
    if (radioSel != null) {
        Image radioUnsel = m.getThemeImageConstant("radioUnselected" + append + "Image");
        if (radioUnsel != null) {
            Image disUnsel = m.getThemeImageConstant("radioUnselectedDis" + append + "Image");
            Image disSel = m.getThemeImageConstant("radioSelectedDis" + append + "Image");
            if (disUnsel == null) {
                disUnsel = radioUnsel;
            }
            if (disSel == null) {
                disSel = radioSel;
            }
            if (focus) {
                setRadioButtonFocusImages(radioSel, radioUnsel, disSel, disUnsel);
            } else {
                setRadioButtonImages(radioSel, radioUnsel, disSel, disUnsel);
            }
        }
    } else {
        if (!Font.isTrueTypeFileSupported()) {
            return;
        }
        UIManager uim = UIManager.getInstance();
        Style unsel = uim.createStyle("RadioButton.", "", false);
        Style sel = uim.createStyle("RadioButton.", "sel#", true);
        Style dis = uim.createStyle("RadioButton.", "dis#", false);
        FontImage checkedDis = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_CHECKED, dis);
        FontImage uncheckedDis = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_UNCHECKED, sel);
        if (focus) {
            FontImage checkedSelected = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_CHECKED, sel);
            FontImage uncheckedSelected = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_UNCHECKED, sel);
            setRadioButtonFocusImages(checkedSelected, uncheckedSelected, checkedDis, uncheckedDis);
        } else {
            FontImage checkedUnselected = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_CHECKED, unsel);
            FontImage uncheckedUnselected = FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_UNCHECKED, unsel);
            setRadioButtonImages(checkedUnselected, uncheckedUnselected, checkedDis, uncheckedDis);
        }
    }
}
Also used : Image(com.codename1.ui.Image) FontImage(com.codename1.ui.FontImage) FontImage(com.codename1.ui.FontImage)

Example 2 with UIManager

use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.

the class InteractionDialog 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
 */
public void showPopupDialog(Rectangle rect) {
    disposed = false;
    if (getUIID().equals("Dialog")) {
        setUIID("PopupDialog");
        if (getTitleComponent().getUIID().equals("DialogTitle")) {
            getTitleComponent().setUIID("PopupDialogTitle");
        }
        getContentPane().setUIID("PopupContentPane");
    }
    Component contentPane = getContentPane();
    Label title = getTitleComponent();
    UIManager manager = getUIManager();
    String dialogTitle = title.getText();
    // preferred size logic of the dialog won't work with large title borders
    if ((dialogTitle != null || dialogTitle.length() == 0) && manager.isThemeConstant("hideEmptyTitleBool", false)) {
        boolean b = getTitle().length() > 0;
        titleArea.setVisible(b);
        getTitleComponent().setVisible(b);
        if (!b && manager.isThemeConstant("shrinkPopupTitleBool", true)) {
            getTitleComponent().setPreferredSize(new Dimension(0, 0));
            getTitleComponent().getStyle().setBorder(null);
            titleArea.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 = getStyle();
    boolean restoreArrow = false;
    if (manager.isThemeConstant(getUIID() + "ArrowBool", false)) {
        Image t = manager.getThemeImageConstant(getUIID() + "ArrowTopImage");
        Image b = manager.getThemeImageConstant(getUIID() + "ArrowBottomImage");
        Image l = manager.getThemeImageConstant(getUIID() + "ArrowLeftImage");
        Image r = manager.getThemeImageConstant(getUIID() + "ArrowRightImage");
        Border border = contentPaneStyle.getBorder();
        if (border != null) {
            border.setImageBorderSpecialTile(t, b, l, r, rect);
            restoreArrow = true;
        }
    }
    calcPreferredSize();
    int prefHeight = getPreferredH();
    int prefWidth = getPreferredW();
    if (contentPaneStyle.getBorder() != null) {
        prefWidth = Math.max(contentPaneStyle.getBorder().getMinimumWidth(), prefWidth);
        prefHeight = Math.max(contentPaneStyle.getBorder().getMinimumHeight(), prefHeight);
    }
    Form f = Display.getInstance().getCurrent();
    int availableHeight = getLayeredPane(f).getParent().getHeight();
    int availableWidth = getLayeredPane(f).getParent().getWidth();
    int width = Math.min(availableWidth, prefWidth);
    int x = 0;
    int y = 0;
    boolean 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();
            int height = Math.min(prefHeight, availableHeight - y);
            show(y, Math.max(0, availableHeight - height - y), x, Math.max(0, availableWidth - width - x));
        } else {
            // popup upwards
            int height = Math.min(prefHeight, rect.getY() - getLayeredPane(f).getAbsoluteY());
            y = rect.getY() - height - getLayeredPane(f).getAbsoluteY();
            show(y, Math.max(0, getLayeredPane(f).getComponentForm().getHeight() - rect.getY()), x, Math.max(0, availableWidth - width - x));
        }
    } 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);
            show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x));
        } else {
            // popup left
            width = Math.min(prefWidth, availableWidth - (availableWidth - rect.getX()));
            x = rect.getX() - width;
            show(y, availableHeight - height - y, Math.max(0, x), Math.max(0, availableWidth - width - x));
        }
    }
/*if(restoreArrow) {
            contentPaneStyle.getBorder().clearImageBorderSpecialTile();
        }*/
}
Also used : Form(com.codename1.ui.Form) Label(com.codename1.ui.Label) UIManager(com.codename1.ui.plaf.UIManager) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component) Image(com.codename1.ui.Image) Border(com.codename1.ui.plaf.Border)

Example 3 with UIManager

use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.

the class Component method refreshTheme.

/**
 * Makes sure the component is up to date with the given UIID
 *
 * @param id The Style Id to update the Component with
 * @param merge indicates if the current styles should be merged with the new styles
 */
protected void refreshTheme(String id, boolean merge) {
    UIManager manager = getUIManager();
    if (merge) {
        Style unSelected = getUnselectedStyle();
        if (hasInlineUnselectedStyle()) {
            setUnselectedStyle(mergeStyle(unSelected, manager.parseComponentStyle(getInlineStylesTheme(), id, getInlineStylesUIID(id), getInlineUnselectedStyleStrings())));
        } else {
            setUnselectedStyle(mergeStyle(unSelected, manager.getComponentStyle(id)));
        }
        if (selectedStyle != null) {
            if (hasInlineSelectedStyle()) {
                setSelectedStyle(mergeStyle(selectedStyle, manager.parseComponentSelectedStyle(getInlineStylesTheme(), id, getInlineStylesUIID(id), getInlineSelectedStyleStrings())));
            } else {
                setSelectedStyle(mergeStyle(selectedStyle, manager.getComponentSelectedStyle(id)));
            }
        }
        if (disabledStyle != null) {
            if (hasInlineDisabledStyle()) {
                setDisabledStyle(mergeStyle(disabledStyle, manager.parseComponentCustomStyle(getInlineStylesTheme(), id, getInlineStylesUIID(id), "dis", getInlineDisabledStyleStrings())));
            } else {
                setDisabledStyle(mergeStyle(disabledStyle, manager.getComponentCustomStyle(id, "dis")));
            }
        }
        if (pressedStyle != null) {
            if (hasInlinePressedStyle()) {
                setPressedStyle(mergeStyle(pressedStyle, manager.parseComponentCustomStyle(getInlineStylesTheme(), id, getInlineStylesUIID(id), "press", getInlinePressedStyleStrings())));
            } else {
                setPressedStyle(mergeStyle(pressedStyle, manager.getComponentCustomStyle(id, "press")));
            }
        }
    } else {
        unSelectedStyle = null;
        unSelectedStyle = getUnselectedStyle();
        selectedStyle = null;
        disabledStyle = null;
        pressedStyle = null;
        allStyles = null;
    }
    checkAnimation();
    manager.getLookAndFeel().bind(this);
}
Also used : UIManager(com.codename1.ui.plaf.UIManager) Style(com.codename1.ui.plaf.Style)

Example 4 with UIManager

use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.

the class Component method initComponentImpl.

/**
 * Invoked internally to initialize and bind the component
 */
void initComponentImpl() {
    if (!initialized) {
        initialized = true;
        UIManager manager = getUIManager();
        Style stl = getStyle();
        lockStyleImages(stl);
        manager.getLookAndFeel().bind(this);
        checkAnimation();
        if (isRTL() && isScrollableX()) {
            setScrollX(getScrollDimension().getWidth() - getWidth());
        }
        initComponent();
        showNativeOverlay();
    }
}
Also used : UIManager(com.codename1.ui.plaf.UIManager) Style(com.codename1.ui.plaf.Style)

Example 5 with UIManager

use of com.codename1.ui.plaf.UIManager 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)

Aggregations

UIManager (com.codename1.ui.plaf.UIManager)21 LookAndFeel (com.codename1.ui.plaf.LookAndFeel)9 Style (com.codename1.ui.plaf.Style)5 Image (com.codename1.ui.Image)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 FontImage (com.codename1.ui.FontImage)3 ActionEvent (com.codename1.ui.events.ActionEvent)2 ActionListener (com.codename1.ui.events.ActionListener)2 Dimension (com.codename1.ui.geom.Dimension)2 GridLayout (com.codename1.ui.layouts.GridLayout)2 Border (com.codename1.ui.plaf.Border)2 Component (com.codename1.ui.Component)1 Form (com.codename1.ui.Form)1 Label (com.codename1.ui.Label)1 BubbleTransition (com.codename1.ui.animations.BubbleTransition)1 Transition (com.codename1.ui.animations.Transition)1 Rectangle (com.codename1.ui.geom.Rectangle)1 FlowLayout (com.codename1.ui.layouts.FlowLayout)1 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)1 DefaultLookAndFeel (com.codename1.ui.plaf.DefaultLookAndFeel)1