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;
}
}
}
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);
}
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);
}
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;
}
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;
}
Aggregations