Search in sources :

Example 26 with UIID

use of com.codename1.rad.attributes.UIID in project CodenameOne by codenameone.

the class Label method initAutoResize.

void initAutoResize() {
    if (autoSizeMode) {
        Style s = getUnselectedStyle();
        int p = s.getHorizontalPadding();
        int w = getWidth();
        if (w > p + 10) {
            if (originalFont == null) {
                originalFont = s.getFont();
            } else {
                if (w == widthAtLastCheck) {
                    return;
                }
            }
            Font currentFont = getUnselectedStyle().getFont();
            float fontSize = currentFont.getPixelSize();
            if (fontSize < 1) {
                Log.p("Autosize disabled probably because component wasn't using native fonts for UIID: " + getUIID());
                autoSizeMode = false;
                return;
            }
            widthAtLastCheck = w;
            autoSizeMode = false;
            int currentWidth = calcPreferredSize().getWidth();
            int maxSizePixel = Display.getInstance().convertToPixels(maxAutoSize);
            while (currentWidth < w) {
                fontSize++;
                if (fontSize >= maxSizePixel) {
                    fontSize = maxSizePixel;
                    currentFont = currentFont.derive(maxSizePixel, currentFont.getStyle());
                    getAllStyles().setFont(currentFont);
                    currentWidth = calcPreferredSize().getWidth();
                    break;
                }
                currentFont = currentFont.derive(fontSize, currentFont.getStyle());
                getAllStyles().setFont(currentFont);
                currentWidth = calcPreferredSize().getWidth();
            }
            int minSizePixel = Display.getInstance().convertToPixels(minAutoSize);
            while (currentWidth > w) {
                fontSize--;
                if (fontSize <= minSizePixel) {
                    fontSize = minSizePixel;
                    currentFont = currentFont.derive(minSizePixel, currentFont.getStyle());
                    getAllStyles().setFont(currentFont);
                    currentWidth = calcPreferredSize().getWidth();
                    break;
                }
                currentFont = currentFont.derive(fontSize, currentFont.getStyle());
                getAllStyles().setFont(currentFont);
                currentWidth = calcPreferredSize().getWidth();
            }
            autoSizeMode = true;
        }
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 27 with UIID

use of com.codename1.rad.attributes.UIID in project CodeRAD by shannah.

the class DefaultActionViewFactory method initUI.

public static void initUI(Button btn, Entity entity, ActionNode action) {
    btn.setBlockLead(true);
    boolean text = action.isTextStyle();
    boolean includeIcon = action.isIconStyle();
    UIID uiid = action.getUIID();
    if (uiid != null) {
        btn.setUIID(uiid.getValue(entity));
    }
    IconUIID iconUiid = action.getIconUIID();
    if (iconUiid != null) {
        btn.setIconUIID(iconUiid.getValue());
    }
    Button button = btn;
    if (action.getLabel() != null && text) {
        button.setText(action.getLabel().getValue(entity.getEntity()));
    }
    if (!text && button.getText().length() > 0) {
        button.setText("");
    }
    if (action.getImageIcon() != null && includeIcon) {
        button.setIcon(action.getImageIcon().getValue());
        if (action.getSelected() != action && action.getSelected().getImageIcon() != action.getImageIcon()) {
            button.setRolloverIcon(action.getSelected().getImageIcon().getValue());
        }
        if (action.getPressed() != action && action.getPressed().getImageIcon() != action.getImageIcon()) {
            button.setPressedIcon(action.getPressed().getImageIcon().getValue());
        }
        if (action.getDisabled() != action && action.getDisabled().getImageIcon() != action.getImageIcon()) {
            button.setDisabledIcon(action.getDisabled().getImageIcon().getValue());
        }
    }
    if (action.getMaterialIcon() != null && includeIcon) {
        char unselectedIcon = action.getMaterialIcon().getValue();
        char selectedIcon = action.getSelected().getMaterialIcon().getValue();
        char pressedIcon = action.getPressed().getMaterialIcon().getValue();
        char selectedPressed = pressedIcon;
        if (action.getPressed() == action) {
            selectedPressed = selectedIcon;
        }
        char disabledIcon = action.getDisabled().getMaterialIcon().getValue();
        // button.setMaterialIcon(action.getMaterialIcon().getValue());
        FontImage.setMaterialIcon(btn, new char[] { unselectedIcon, selectedIcon, pressedIcon, selectedPressed, disabledIcon }, -1);
    }
    if (action.getTextIcon() != null && includeIcon) {
        String iconText = action.getTextIcon().getValue(entity);
        Button iconLabel = new Button(iconText);
        if (btn.getIconStyleComponent() != btn) {
            iconLabel.setUIID(btn.getIconStyleComponent().getUIID());
        } else {
            iconLabel.setUIID(btn.getUIID());
            // IF the button has a border and padding set, we don't
            // want to to also be applied to the icon.
            iconLabel.getAllStyles().stripMarginAndPadding();
        }
        iconLabel.setWidth(iconLabel.getPreferredW());
        iconLabel.setHeight(iconLabel.getPreferredH());
        btn.setIcon(new ComponentImage(iconLabel, iconLabel.getWidth(), iconLabel.getHeight()));
    }
    if (includeIcon && text) {
        ActionStyle style = action.getActionStyle();
        if (style != null) {
            switch(style) {
                case IconTop:
                    button.setTextPosition(BOTTOM);
                    break;
                case IconBottom:
                    button.setTextPosition(TOP);
                    break;
                case IconLeft:
                    button.setTextPosition(RIGHT);
                    break;
                case IconRight:
                    button.setTextPosition(LEFT);
            }
        }
    }
    button.addActionListener(evt -> {
        action.fireEvent(entity, button);
        update(button, entity, action);
    });
    update(button, entity, action);
    action.decorateComponent(btn);
}
Also used : ComponentImage(ca.weblite.shared.components.ComponentImage) Button(com.codename1.ui.Button) MultiButton(com.codename1.components.MultiButton) IconUIID(com.codename1.rad.attributes.IconUIID) IconUIID(com.codename1.rad.attributes.IconUIID) BadgeUIID(com.codename1.rad.attributes.BadgeUIID) UIID(com.codename1.rad.attributes.UIID)

Example 28 with UIID

use of com.codename1.rad.attributes.UIID in project CodeRAD by shannah.

the class DefaultActionViewFactory method initUI.

public static void initUI(MultiButton btn, Entity entity, ActionNode action) {
    btn.setBlockLead(true);
    boolean text = action.isTextStyle();
    boolean includeIcon = action.isIconStyle();
    UIID uiid = action.getUIID();
    if (uiid != null) {
        btn.setUIID(uiid.getValue(entity));
    }
    IconUIID iconUiid = action.getIconUIID();
    if (iconUiid != null) {
        btn.setIconUIID(iconUiid.getValue());
    }
    MultiButton button = btn;
    if (action.getLabel() != null && text) {
        button.setTextLines(action.getLabel().getValue(entity.getEntity()));
    }
    if (action.getImageIcon() != null && includeIcon) {
        button.setIcon(action.getImageIcon().getValue());
        if (action.getSelected() != action && action.getSelected().getImageIcon() != action.getImageIcon()) {
            button.setRolloverIcon(action.getSelected().getImageIcon().getValue());
        }
        if (action.getPressed() != action && action.getPressed().getImageIcon() != action.getImageIcon()) {
            button.setPressedIcon(action.getPressed().getImageIcon().getValue());
        }
        if (action.getDisabled() != action && action.getDisabled().getImageIcon() != action.getImageIcon()) {
            button.setDisabledIcon(action.getDisabled().getImageIcon().getValue());
        }
    }
    if (action.getMaterialIcon() != null && includeIcon) {
        char unselectedIcon = action.getMaterialIcon().getValue();
        char selectedIcon = action.getSelected().getMaterialIcon().getValue();
        char pressedIcon = action.getPressed().getMaterialIcon().getValue();
        char selectedPressed = pressedIcon;
        if (action.getPressed() == action) {
            selectedPressed = selectedIcon;
        }
        char disabledIcon = action.getDisabled().getMaterialIcon().getValue();
        // button.setMaterialIcon(action.getMaterialIcon().getValue());
        FontImage.setMaterialIcon(btn, new char[] { unselectedIcon, selectedIcon, pressedIcon, selectedPressed, disabledIcon }, -1);
    }
    if (action.getTextIcon() != null && includeIcon) {
        String iconText = action.getTextIcon().getValue(entity);
        Button iconLabel = new Button(iconText);
        if (btn.getIconStyleComponent() != btn) {
            iconLabel.setUIID(btn.getIconStyleComponent().getUIID());
        } else {
            iconLabel.setUIID(btn.getUIID());
            // IF the button has a border and padding set, we don't
            // want to to also be applied to the icon.
            iconLabel.getAllStyles().stripMarginAndPadding();
        }
        iconLabel.setWidth(iconLabel.getPreferredW());
        iconLabel.setHeight(iconLabel.getPreferredH());
        btn.setIcon(new ComponentImage(iconLabel, iconLabel.getWidth(), iconLabel.getHeight()));
    }
    if (includeIcon && text) {
        ActionStyle style = action.getActionStyle();
        if (style != null) {
            switch(style) {
                case IconTop:
                    button.setTextPosition(BOTTOM);
                    break;
                case IconBottom:
                    button.setTextPosition(TOP);
                    break;
                case IconLeft:
                    button.setTextPosition(RIGHT);
                    break;
                case IconRight:
                    button.setTextPosition(LEFT);
            }
        }
    }
    if (!text) {
        button.setText("");
    }
    button.addActionListener(evt -> {
        action.fireEvent(entity, button);
        update(button, entity, action);
    });
    update(button, entity, action);
    action.decorateComponent(btn);
}
Also used : ComponentImage(ca.weblite.shared.components.ComponentImage) Button(com.codename1.ui.Button) MultiButton(com.codename1.components.MultiButton) IconUIID(com.codename1.rad.attributes.IconUIID) IconUIID(com.codename1.rad.attributes.IconUIID) BadgeUIID(com.codename1.rad.attributes.BadgeUIID) UIID(com.codename1.rad.attributes.UIID) MultiButton(com.codename1.components.MultiButton)

Example 29 with UIID

use of com.codename1.rad.attributes.UIID in project CodeRAD by shannah.

the class ButtonListPropertyView method decorateButtonList.

private static ButtonList decorateButtonList(FieldNode field, ButtonList bl) {
    ButtonListLayoutAttribute att = (ButtonListLayoutAttribute) field.findInheritedAttribute(ButtonListLayoutAttribute.class);
    if (att != null) {
        switch(att.getValue()) {
            case Flow:
                bl.setLayout(new FlowLayout());
                break;
            case Y:
                bl.setLayout(BoxLayout.y());
                break;
            case X:
                bl.setLayout(BoxLayout.x());
                break;
            case Grid:
                Columns cols = (Columns) field.findAttribute(Columns.class);
                int numCols = 2;
                if (cols != null) {
                    numCols = cols.getValue();
                }
                bl.setLayout(new GridLayout(numCols));
                break;
        }
    }
    String uiid = field.getUIID(null);
    if (uiid != null) {
        bl.setUIID(uiid);
        bl.setCellUIID(uiid + "Cell");
    }
    return bl;
}
Also used : GridLayout(com.codename1.ui.layouts.GridLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) Columns(com.codename1.rad.attributes.Columns)

Example 30 with UIID

use of com.codename1.rad.attributes.UIID in project CodeRAD by shannah.

the class FloatingActionButtonBuilder method build.

@Override
public FloatingActionButton build() {
    if (icon == 0)
        icon = FontImage.MATERIAL_ADD;
    FloatingActionButton out;
    if (uiid == null) {
        out = FloatingActionButton.createFAB(icon);
    } else {
        out = FloatingActionButton.createFAB(icon, uiid);
    }
    // We don't want the fab added to the direct parent.
    doNotAddToParentContainer(out);
    EntityView ev = getContext().getEntityView();
    if (ev != null) {
        // Register a decorator that will be executed when the ViewController calls setView()
        // This is when we will wrap the target element
        getContext().getController().addViewDecorator(cmp -> {
            if (done)
                return cmp;
            done = true;
            Component parentContainer = getParentContainer();
            if (target != null) {
                Component targetComponent = $(target, (Container) getContext().getEntityView()).asComponent();
                if (targetComponent != null) {
                    parentContainer = targetComponent;
                }
            }
            // TODO:  We have problems here due to new structure of a Root ViewController
            Container parentParent = parentContainer.getParent();
            if (parentParent != null) {
                Container dummy = new Container();
                parentParent.replace(parentContainer, dummy, null);
                Container wrapped = out.bindFabToContainer(parentContainer);
                parentParent.replace(dummy, wrapped, null);
            } else {
                Container bound = out.bindFabToContainer(parentContainer);
                if (parentContainer == cmp) {
                    return bound;
                }
            }
            return cmp;
        });
    }
    return out;
}
Also used : Container(com.codename1.ui.Container) EntityView(com.codename1.rad.ui.EntityView) FloatingActionButton(com.codename1.components.FloatingActionButton) Component(com.codename1.ui.Component)

Aggregations

UIID (com.codename1.rad.attributes.UIID)7 Style (com.codename1.ui.plaf.Style)7 Container (com.codename1.ui.Container)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 File (java.io.File)4 Component (com.codename1.ui.Component)3 Label (com.codename1.ui.Label)3 UIManager (com.codename1.ui.plaf.UIManager)3 IOException (java.io.IOException)3 ComponentImage (ca.weblite.shared.components.ComponentImage)2 MultiButton (com.codename1.components.MultiButton)2 BadgeUIID (com.codename1.rad.attributes.BadgeUIID)2 IconUIID (com.codename1.rad.attributes.IconUIID)2 ActionNode (com.codename1.rad.nodes.ActionNode)2 ListNode (com.codename1.rad.nodes.ListNode)2 Node (com.codename1.rad.nodes.Node)2 EntityView (com.codename1.rad.ui.EntityView)2 Button (com.codename1.ui.Button)2 Font (com.codename1.ui.Font)2 Image (com.codename1.ui.Image)2