Search in sources :

Example 6 with Label

use of com.codename1.rad.models.Property.Label in project CodeRAD by shannah.

the class ProfileAvatarView method update.

@Override
public void update() {
    if (iconLoaded) {
        return;
    }
    iconLoaded = true;
    if (getEntity() != null) {
        if (iconProp != null && !getEntity().isEmpty(iconProp)) {
            int sizePx = CN.convertToPixels(sizeMM);
            Image img = getEntity().getEntity().createImageToStorage(iconProp, EncodedImage.createFromImage(label.getIcon().fill(sizePx, sizePx), false), "@avatar" + label.getIcon().getWidth() + "x" + label.getIcon().getHeight(), URLImage.createMaskAdapter(getCircleMask()));
            if (img != null) {
                label.setIcon(img);
                return;
            }
        }
        if (fallbackSettings == FallbackSettings.FirstChar && nameProp != null && !getEntity().isEmpty(nameProp)) {
            FirstCharEntityImageRenderer renderer = new FirstCharEntityImageRenderer(sizeMM);
            AsyncImage img = renderer.createImage(this, nameProp, 0, false, false);
            if (img != null) {
                img.ready(im -> {
                    label.setIcon(im);
                    Form f = label.getComponentForm();
                    if (f != null) {
                        label.repaint();
                    }
                });
                return;
            }
        }
        FontImage.setMaterialIcon(label, defaultMaterialIcon, sizeMM);
    } else {
        FontImage.setMaterialIcon(label, defaultMaterialIcon, sizeMM);
    }
}
Also used : FirstCharEntityImageRenderer(com.codename1.rad.ui.image.FirstCharEntityImageRenderer) Form(com.codename1.ui.Form) AsyncImage(com.codename1.rad.ui.image.AsyncImage) WrappedImage(com.codename1.rad.ui.image.WrappedImage) FontImage(com.codename1.ui.FontImage) EncodedImage(com.codename1.ui.EncodedImage) AsyncImage(com.codename1.rad.ui.image.AsyncImage) Image(com.codename1.ui.Image) ComponentImage(ca.weblite.shared.components.ComponentImage) URLImage(com.codename1.ui.URLImage)

Example 7 with Label

use of com.codename1.rad.models.Property.Label in project CodeRAD by shannah.

the class ProfileAvatarsTitleComponent method initUI.

private void initUI() {
    setLayout(new BorderLayout());
    wrapper = new Container(new FanLayout(FanLayout.X_AXIS));
    avatarWrapperViewController.setView(wrapper);
    $(wrapper).selectAllStyles().setPadding(0).setMargin(0).setBorder(Border.createEmpty());
    int len = getEntity().size();
    for (int i = len - 1; i >= 0; i--) {
        // for (Entity child : getEntity()) {
        Entity child = getEntity().get(i);
        ProfileAvatarView v = createAvatar(child);
        wrapper.add(v);
    }
    add(CENTER, wrapper);
    StringBuilder text = new StringBuilder();
    Property nameProp = getEntity().getRowType().findProperty(Thing.name);
    if (getEntity().size() > 0) {
        if (nameProp != null) {
            text.append(getEntity().get(0).getEntity().getText(nameProp));
        }
    }
    if (getEntity().size() == 2) {
        if (nameProp != null) {
            text.append(" & ").append(getEntity().get(1).getEntity().getText(nameProp));
        }
    }
    if (getEntity().size() > 2) {
        if (text.length() == 0) {
            text.append(getEntity().size()).append(" People");
        } else {
            text.append(" and ").append(getEntity().size() - 1).append(" others");
        }
    }
    Label lbl = new Label(text.toString());
    lbl.setUIID("AccountAvatarsTitleComponentText");
    add(SOUTH, FlowLayout.encloseCenter(lbl));
}
Also used : Entity(com.codename1.rad.models.Entity) Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) FanLayout(com.codename1.rad.layouts.FanLayout) Label(com.codename1.ui.Label) Property(com.codename1.rad.models.Property)

Example 8 with Label

use of com.codename1.rad.models.Property.Label in project codenameone-google-maps by codenameone.

the class MapInfoPanel method createMarkerButton.

private Button createMarkerButton(MapObject mo, String label, Image icon, final Coord location) {
    Button b = new Button(label, icon);
    b.addActionListener(e -> {
        map.zoom(location, (int) map.getZoom());
    });
    return b;
}
Also used : Button(com.codename1.ui.Button)

Example 9 with Label

use of com.codename1.rad.models.Property.Label in project codenameone-google-maps by codenameone.

the class MapInfoPanel method styleLabels.

private void styleLabels(Component... roots) {
    for (Component c : roots) {
        if (c instanceof Label) {
            Label l = (Label) c;
            l.getAllStyles().setFgColor(0xffffff);
            l.getAllStyles().setBgTransparency(0);
            l.getAllStyles().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL));
        }
        if (c instanceof Container) {
            Container cnt = (Container) c;
            for (Component child : cnt) {
                styleLabels(child);
            }
        }
    }
}
Also used : Container(com.codename1.ui.Container) MapContainer(com.codename1.googlemaps.MapContainer) Label(com.codename1.ui.Label) Component(com.codename1.ui.Component)

Example 10 with Label

use of com.codename1.rad.models.Property.Label 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)

Aggregations

Label (com.codename1.ui.Label)129 Form (com.codename1.ui.Form)95 Button (com.codename1.ui.Button)50 BorderLayout (com.codename1.ui.layouts.BorderLayout)50 Container (com.codename1.ui.Container)49 Component (com.codename1.ui.Component)27 SpanLabel (com.codename1.components.SpanLabel)26 Style (com.codename1.ui.plaf.Style)24 BoxLayout (com.codename1.ui.layouts.BoxLayout)19 TextArea (com.codename1.ui.TextArea)18 ActionEvent (com.codename1.ui.events.ActionEvent)18 IOException (java.io.IOException)18 Image (com.codename1.ui.Image)17 Dimension (com.codename1.ui.geom.Dimension)16 TextField (com.codename1.ui.TextField)15 ActionListener (com.codename1.ui.events.ActionListener)15 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)15 Toolbar (com.codename1.ui.Toolbar)13 FlowLayout (com.codename1.ui.layouts.FlowLayout)12 EncodedImage (com.codename1.ui.EncodedImage)11