Search in sources :

Example 26 with Label

use of com.codename1.ui.Label 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 27 with Label

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

the class FontImage method setMaterialIcon.

/**
 * <p>Applies a material design icon (one of the MATERIAL_* icons above) to the given component using the
 * styling of the label</p>
 * <script src="https://gist.github.com/codenameone/8cf6f70188959524474b.js"></script>
 * @param l a multibutton
 * @param icon one of the MATERIAL_* icons
 * @param size the size of the icon in millimeters
 */
public static void setMaterialIcon(MultiButton l, char icon, float size) {
    if (Font.isTrueTypeFileSupported()) {
        Style s = new Style(l.getUnselectedStyle());
        s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
        l.setIcon(FontImage.create("" + icon, s));
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 28 with Label

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

the class FontImage method setMaterialIcon.

/**
 * <p>Applies a material design icon (one of the MATERIAL_* icons above) to the given component using the
 * styling of the label</p>
 * <script src="https://gist.github.com/codenameone/8cf6f70188959524474b.js"></script>
 * @param l a SpanButton
 * @param icon one of the MATERIAL_* icons
 * @param size the size of the icon in millimeters
 */
public static void setMaterialIcon(SpanButton l, char icon, float size) {
    if (Font.isTrueTypeFileSupported()) {
        Style s = new Style(l.getUnselectedStyle());
        s.setFont(getMaterialDesignFont().derive(rightSize(s, size), Font.STYLE_PLAIN));
        l.setIcon(FontImage.create("" + icon, s));
        Style sel = l.getSelectedStyle();
        Style pre = l.getPressedStyle();
        Style dis = l.getDisabledStyle();
        if (sel.getFgColor() != s.getFgColor() || (sel.getBgColor() != s.getBgColor()) || (sel.getBgTransparency() != s.getBgTransparency())) {
            sel = new Style(sel);
            sel.setFont(getMaterialDesignFont().derive(rightSize(sel, size), Font.STYLE_PLAIN));
            l.setRolloverIcon(FontImage.create("" + icon, sel));
        }
        if (pre.getFgColor() != s.getFgColor() || (pre.getBgColor() != s.getBgColor()) || (pre.getBgTransparency() != s.getBgTransparency())) {
            pre = new Style(pre);
            pre.setFont(getMaterialDesignFont().derive(rightSize(pre, size), Font.STYLE_PLAIN));
            l.setPressedIcon(FontImage.create("" + icon, pre));
        }
        if (dis.getFgColor() != s.getFgColor() || (dis.getBgColor() != s.getBgColor()) || (dis.getBgTransparency() != s.getBgTransparency())) {
            dis = new Style(dis);
            dis.setFont(getMaterialDesignFont().derive(rightSize(dis, size), Font.STYLE_PLAIN));
            l.setDisabledIcon(FontImage.create("" + icon, dis));
        }
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 29 with Label

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

the class List method calcPreferredSize.

/**
 * {@inheritDoc}
 */
protected Dimension calcPreferredSize() {
    if (shouldShowHint()) {
        Label l = getHintLabelImpl();
        if (l != null) {
            Dimension d1 = getUIManager().getLookAndFeel().getListPreferredSize(this);
            Dimension d2 = l.getPreferredSize();
            return new Dimension(d1.getWidth() + d2.getWidth(), d1.getHeight() + d2.getHeight());
        }
    }
    Dimension d = getUIManager().getLookAndFeel().getListPreferredSize(this);
    if (spinnerOverlay != null) {
        if (spinnerOverlay.getBorder() != null) {
            d.setWidth(Math.max(spinnerOverlay.getBorder().getMinimumWidth(), d.getWidth()));
            d.setHeight(Math.max(spinnerOverlay.getBorder().getMinimumHeight(), d.getHeight()));
        }
    }
    return d;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 30 with Label

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

the class EmailShare method createRendererMultiButton.

private MultiButton createRendererMultiButton() {
    MultiButton b = new MultiButton();
    b.setIconName("icon");
    b.setNameLine1("fname");
    b.setNameLine2("phone");
    b.setUIID("Label");
    return b;
}
Also used : MultiButton(com.codename1.components.MultiButton)

Aggregations

Label (com.codename1.ui.Label)41 BorderLayout (com.codename1.ui.layouts.BorderLayout)22 Container (com.codename1.ui.Container)21 Component (com.codename1.ui.Component)16 Form (com.codename1.ui.Form)15 Button (com.codename1.ui.Button)14 TextArea (com.codename1.ui.TextArea)14 Style (com.codename1.ui.plaf.Style)13 ActionListener (com.codename1.ui.events.ActionListener)12 ActionEvent (com.codename1.ui.events.ActionEvent)11 Image (com.codename1.ui.Image)10 Dimension (com.codename1.ui.geom.Dimension)10 Vector (java.util.Vector)10 BoxLayout (com.codename1.ui.layouts.BoxLayout)9 EncodedImage (com.codename1.ui.EncodedImage)8 RadioButton (com.codename1.ui.RadioButton)7 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)6 Hashtable (java.util.Hashtable)6 Paint (com.codename1.charts.compat.Paint)5 Font (com.codename1.ui.Font)5