use of com.servoy.j2db.persistence.CSSPosition in project servoy-client by Servoy.
the class AngularFormGenerator method writePosition.
/**
* @param writer
* @param o
*/
@SuppressWarnings("nls")
public static void writePosition(JSONWriter writer, IPersist o, Form form, WebFormComponent webComponent, boolean isDesigner) {
if (o instanceof BaseComponent && ((BaseComponent) o).getCssPosition() != null) {
CSSPosition position = ((BaseComponent) o).getCssPosition();
if (webComponent != null) {
Object runtimeValue = webComponent.getProperty(IContentSpecConstants.PROPERTY_CSS_POSITION);
if (runtimeValue instanceof CSSPosition) {
position = (CSSPosition) runtimeValue;
}
}
writer.key("position");
writer.object();
if (CSSPositionUtils.isSet(position.left)) {
writer.key("left").value(CSSPositionUtils.getCSSValue(position.left));
}
if (CSSPositionUtils.isSet(position.top)) {
String top = position.top;
if (!isDesigner) {
Point location = CSSPositionUtils.getLocation((BaseComponent) o);
Part prt = form.getPartAt(location.y);
if (prt != null) {
int topStart = form.getPartStartYPos(prt.getID());
if (topStart > 0) {
if (top.endsWith("px")) {
top = top.substring(0, top.length() - 2);
}
int topInteger = Utils.getAsInteger(top, -1);
if (topInteger != -1) {
top = String.valueOf(topInteger - topStart);
} else {
top = "calc(" + top + "-" + topStart + "px)";
}
}
}
}
writer.key("top").value(CSSPositionUtils.getCSSValue(top));
}
if (CSSPositionUtils.isSet(position.bottom)) {
writer.key("bottom").value(CSSPositionUtils.getCSSValue(position.bottom));
}
if (CSSPositionUtils.isSet(position.right)) {
writer.key("right").value(CSSPositionUtils.getCSSValue(position.right));
}
if (CSSPositionUtils.isSet(position.width)) {
if (CSSPositionUtils.isSet(position.left) && CSSPositionUtils.isSet(position.right)) {
writer.key("min-width").value(CSSPositionUtils.getCSSValue(position.width));
} else {
writer.key("width").value(CSSPositionUtils.getCSSValue(position.width));
}
}
if (CSSPositionUtils.isSet(position.height)) {
if (CSSPositionUtils.isSet(position.top) && CSSPositionUtils.isSet(position.bottom)) {
writer.key("min-height").value(CSSPositionUtils.getCSSValue(position.height));
} else {
writer.key("height").value(CSSPositionUtils.getCSSValue(position.height));
}
}
writer.endObject();
} else {
Point location = ((IFormElement) o).getLocation();
Dimension size = ((IFormElement) o).getSize();
if (webComponent != null) {
Object runtimeValue = webComponent.getProperty(IContentSpecConstantsBase.PROPERTY_LOCATION);
if (runtimeValue instanceof Point) {
location = (Point) runtimeValue;
}
runtimeValue = webComponent.getProperty(IContentSpecConstantsBase.PROPERTY_SIZE);
if (runtimeValue instanceof Dimension) {
size = (Dimension) runtimeValue;
}
}
if (location != null && size != null) {
int anchorFlags = ((BaseComponent) o).getAnchors();
boolean anchoredTop = (anchorFlags & IAnchorConstants.NORTH) != 0;
boolean anchoredRight = (anchorFlags & IAnchorConstants.EAST) != 0;
boolean anchoredBottom = (anchorFlags & IAnchorConstants.SOUTH) != 0;
boolean anchoredLeft = (anchorFlags & IAnchorConstants.WEST) != 0;
if (!anchoredLeft && !anchoredRight)
anchoredLeft = true;
if (!anchoredTop && !anchoredBottom)
anchoredTop = true;
writer.key("position");
writer.object();
if (anchoredTop) {
writer.key("top");
writer.value(location.y + "px");
}
if (anchoredBottom) {
writer.key("bottom");
int partHeight = form.getSize().height;
if (!isDesigner) {
// search for element's part using its design time location
Part prt = form.getPartAt(((IFormElement) o).getLocation().y);
if (prt != null) {
int prtEnd = form.getPartEndYPos(prt.getID());
if (prtEnd > form.getSize().height)
prtEnd = form.getSize().height;
partHeight = prtEnd - form.getPartStartYPos(prt.getID());
}
}
writer.value(partHeight - location.y - size.height + "px");
}
if (!anchoredTop || !anchoredBottom) {
writer.key("height");
writer.value(size.height + "px");
}
if (anchoredLeft) {
writer.key("left");
writer.value(location.x + "px");
}
if (anchoredRight) {
writer.key("right");
writer.value((form.getWidth() - location.x - size.width) + "px");
}
if (!anchoredLeft || !anchoredRight) {
writer.key("width");
writer.value(size.width + "px");
}
if (anchoredTop && anchoredBottom) {
writer.key("min-height");
writer.value(size.height + "px");
}
if (anchoredLeft && anchoredRight) {
writer.key("min-width");
writer.value(size.width + "px");
}
writer.endObject();
}
}
}
use of com.servoy.j2db.persistence.CSSPosition in project servoy-client by Servoy.
the class JSCSSPosition method setWidth.
@JSSetter
public void setWidth(String width) {
CSSPosition position = component.getBaseComponent(true).getCssPosition();
if (position != null) {
position.width = width;
component.getBaseComponent(true).setCssPosition(position);
}
}
use of com.servoy.j2db.persistence.CSSPosition in project servoy-client by Servoy.
the class JSCSSPosition method setHeight.
@JSGetter
public void setHeight(String height) {
CSSPosition position = component.getBaseComponent(true).getCssPosition();
if (position != null) {
position.height = height;
component.getBaseComponent(true).setCssPosition(position);
}
}
use of com.servoy.j2db.persistence.CSSPosition in project servoy-client by Servoy.
the class JSCSSPosition method setTop.
@JSSetter
public void setTop(String top) {
CSSPosition position = component.getBaseComponent(true).getCssPosition();
if (position != null) {
position.top = top;
component.getBaseComponent(true).setCssPosition(position);
}
}
use of com.servoy.j2db.persistence.CSSPosition in project servoy-client by Servoy.
the class JSCSSPosition method setRight.
@JSSetter
public void setRight(String right) {
CSSPosition position = component.getBaseComponent(true).getCssPosition();
if (position != null) {
position.right = right;
component.getBaseComponent(true).setCssPosition(position);
}
}
Aggregations