use of com.servoy.j2db.persistence.ISupportTextSetup in project servoy-client by Servoy.
the class WebForm method getFormAnchorInfo.
@SuppressWarnings("unchecked")
public FormAnchorInfo getFormAnchorInfo() {
formAnchorInfo = new FormAnchorInfo(formController.getName(), formController.getForm().getSize(), formController.getForm().getUUID());
final Map<String, ISupportAnchors> elements = new HashMap<String, ISupportAnchors>();
Iterator<IPersist> e1 = formController.getForm().getAllObjects();
while (e1.hasNext()) {
IPersist obj = e1.next();
if (obj instanceof ISupportAnchors && obj instanceof ISupportBounds) {
elements.put(ComponentFactory.getWebID(formController.getForm(), obj), (ISupportAnchors) obj);
}
}
// In case we are in table view.
if (view instanceof WebCellBasedView) {
WebCellBasedView formPart = (WebCellBasedView) view;
formAnchorInfo.addPart(Part.getDisplayName(Part.BODY), formPart.getMarkupId(), 50);
formAnchorInfo.isTableView = true;
formAnchorInfo.bodyContainerId = formPart.getMarkupId();
}
// Find the id of the form navigator, if any.
visitChildren(Component.class, new IVisitor() {
public Object component(Component component) {
if (component instanceof WebDefaultRecordNavigator) {
formAnchorInfo.navigatorWebId = component.getMarkupId();
return IVisitor.CONTINUE_TRAVERSAL;
} else if (component instanceof WebTabPanel) {
return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
} else
return IVisitor.CONTINUE_TRAVERSAL;
}
});
visitChildren(WebDataRenderer.class, new IVisitor() {
public Object component(Component component) {
WebDataRenderer formPart = (WebDataRenderer) component;
final FormPartAnchorInfo part = formAnchorInfo.addPart(formPart.getFormPartName(), formPart.getMarkupId(), formPart.getSize().height);
if (Part.getDisplayName(Part.BODY).equals(formPart.getFormPartName())) {
Component parent = formPart.getParent();
formAnchorInfo.bodyContainerId = parent.getMarkupId();
}
formPart.visitChildren(ISupportWebBounds.class, new IVisitor() {
public Object component(Component comp) {
String id = comp.getId();
ISupportAnchors obj = elements.get(id);
if (obj != null) {
int anchors = obj.getAnchors();
if (((anchors > 0 && anchors != IAnchorConstants.DEFAULT)) || (comp instanceof WebTabPanel) || (comp instanceof IButton)) {
Rectangle r = ((ISupportWebBounds) comp).getWebBounds();
if (r != null) {
if (anchors == 0)
anchors = IAnchorConstants.DEFAULT;
int hAlign = -1;
int vAlign = -1;
if (obj instanceof ISupportTextSetup) {
ISupportTextSetup alignedObj = (ISupportTextSetup) obj;
hAlign = alignedObj.getHorizontalAlignment();
vAlign = alignedObj.getVerticalAlignment();
}
String imageDisplayURL = null;
boolean isRandomParamRemoved = false;
if (comp instanceof IImageDisplay) {
Object[] aImageDisplayURL = WebBaseButton.getImageDisplayURL((IImageDisplay) comp, false);
imageDisplayURL = (String) aImageDisplayURL[0];
isRandomParamRemoved = ((Boolean) aImageDisplayURL[1]).booleanValue();
}
part.addAnchoredElement(comp.getMarkupId(), anchors, r, hAlign, vAlign, comp.getClass(), imageDisplayURL, isRandomParamRemoved);
}
}
}
return IVisitor.CONTINUE_TRAVERSAL;
}
});
return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
}
});
return formAnchorInfo;
}
use of com.servoy.j2db.persistence.ISupportTextSetup in project servoy-client by Servoy.
the class TemplateGenerator method applyBaseComponentProperties.
protected static BorderAndPadding applyBaseComponentProperties(BaseComponent component, Form form, TextualStyle styleObj, Insets defaultPadding, Insets defaultBorder, IServiceProvider sp) {
Pair<IStyleSheet, IStyleRule> styleInfo = ComponentFactory.getStyleForBasicComponent(sp, component, form);
Insets insetsBorder = null;
Border designBorder = null;
if (component.getBorderType() != null) {
insetsBorder = ComponentFactoryHelper.createBorderCSSProperties(component.getBorderType(), styleObj);
designBorder = ComponentFactoryHelper.createBorder(component.getBorderType());
}
Insets insetsMargin = null;
if (component instanceof ISupportTextSetup) {
insetsMargin = ((ISupportTextSetup) component).getMargin();
}
if (styleInfo != null) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
List<String> attributeNames = s.getAttributeNames();
for (String s_attr : attributeNames) {
// Skip margin related attributes. Margin is computed separately below, and rendered as padding.
if (s_attr.toLowerCase().contains("margin"))
continue;
// do not add any border attributes if set on component
if (s_attr.toLowerCase().contains("border") && component.getBorderType() != null)
continue;
String val = s.getValue(s_attr);
if (s_attr.equals("font-size")) {
String tmp = val;
if (tmp.endsWith("px")) {
int size = Utils.getAsInteger(tmp.substring(0, tmp.length() - 2));
// 9 should be defined hard. Because 12 (1.33*9) is to big.
if (size == 9) {
size = 11;
} else {
size = (int) (size * (4 / (double) 3));
}
styleObj.setProperty(s_attr, size + "px");
} else {
int size = 0;
if (tmp.endsWith("pt")) {
size = Utils.getAsInteger(tmp.substring(0, tmp.length() - 2));
} else {
size = Utils.getAsInteger(tmp);
}
// 9 should be defined hard. Because 6 (0.75*9) is to small.
if (size == 9) {
size = 7;
} else {
size = (int) (size * (3 / (double) 4));
}
styleObj.setProperty(s_attr, size + "pt");
}
} else {
if (val.toString() != null)
styleObj.setProperty(s_attr, s.getValues(s_attr), false);
}
}
if (component.getBorderType() == null) {
if (ss.hasBorder(s)) {
Border b = ss.getBorder(s);
if (b != null) {
try {
insetsBorder = ComponentFactoryHelper.getBorderInsetsForNoComponent(b);
} catch (Exception e) {
Debug.error("for border " + b + " no insets could be extracted.", e);
}
TextualStyle borderStyle = new TextualStyle();
ComponentFactoryHelper.createBorderCSSProperties(ComponentFactoryHelper.createBorderString(b), borderStyle);
Enumeration<Object> cssAttributes = borderStyle.keys();
while (cssAttributes.hasMoreElements()) {
String att = (String) cssAttributes.nextElement();
// put the default values, if not all specified in css
styleObj.setProperty(att, borderStyle.getProperty(att), false);
}
}
}
}
if (insetsMargin == null) {
if (ss.hasMargin(s)) {
insetsMargin = ss.getMargin(s);
}
}
}
}
if (component.getFontType() != null) {
Pair<String, String>[] props = PersistHelper.createFontCSSProperties(component.getFontType());
if (props != null) {
for (Pair<String, String> element : props) {
if (element == null)
continue;
styleObj.setProperty(element.getLeft(), element.getRight());
}
}
}
if (component.getForeground() != null) {
styleObj.setProperty("color", PersistHelper.createColorString(component.getForeground()));
}
if (component.getTransparent()) {
styleObj.setProperty("background-color", IStyleSheet.COLOR_TRANSPARENT);
} else if (component.getBackground() != null) {
styleObj.setProperty("background-color", PersistHelper.createColorString(component.getBackground()));
}
if (insetsBorder == null)
insetsBorder = defaultBorder;
if (insetsMargin == null && defaultPadding != null)
insetsMargin = defaultPadding;
BorderAndPadding bp = new BorderAndPadding(insetsBorder, insetsMargin);
styleObj.setProperty("padding", (designBorder instanceof EmptyBorder && !(designBorder instanceof MatteBorder)) ? createInsetsText(bp.getSum()) : createInsetsText(bp.getPadding()));
return bp;
}
Aggregations