Search in sources :

Example 1 with ISupportTextSetup

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;
}
Also used : FormPartAnchorInfo(com.servoy.j2db.server.headlessclient.FormAnchorInfo.FormPartAnchorInfo) WebDataRenderer(com.servoy.j2db.server.headlessclient.dataui.WebDataRenderer) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) IImageDisplay(com.servoy.j2db.server.headlessclient.dataui.IImageDisplay) ISupportTextSetup(com.servoy.j2db.persistence.ISupportTextSetup) Rectangle(java.awt.Rectangle) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds) WebCellBasedView(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView) Point(java.awt.Point) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) ISupportWebBounds(com.servoy.j2db.ui.ISupportWebBounds) IPersist(com.servoy.j2db.persistence.IPersist) WebDefaultRecordNavigator(com.servoy.j2db.server.headlessclient.dataui.WebDefaultRecordNavigator) IButton(com.servoy.j2db.ui.IButton) WebTabPanel(com.servoy.j2db.server.headlessclient.dataui.WebTabPanel) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) IComponent(com.servoy.j2db.ui.IComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent)

Example 2 with ISupportTextSetup

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;
}
Also used : IStyleSheet(com.servoy.j2db.util.IStyleSheet) Insets(java.awt.Insets) ISupportTextSetup(com.servoy.j2db.persistence.ISupportTextSetup) Point(java.awt.Point) RemoteException(java.rmi.RemoteException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) MatteBorder(javax.swing.border.MatteBorder) IStyleRule(com.servoy.j2db.util.IStyleRule) EmptyBorder(javax.swing.border.EmptyBorder) MatteBorder(javax.swing.border.MatteBorder) Border(javax.swing.border.Border) TitledBorder(javax.swing.border.TitledBorder) EmptyBorder(javax.swing.border.EmptyBorder) Pair(com.servoy.j2db.util.Pair)

Aggregations

ISupportTextSetup (com.servoy.j2db.persistence.ISupportTextSetup)2 Point (java.awt.Point)2 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 IPersist (com.servoy.j2db.persistence.IPersist)1 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)1 ISupportBounds (com.servoy.j2db.persistence.ISupportBounds)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 FormPartAnchorInfo (com.servoy.j2db.server.headlessclient.FormAnchorInfo.FormPartAnchorInfo)1 IImageDisplay (com.servoy.j2db.server.headlessclient.dataui.IImageDisplay)1 WebCellBasedView (com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView)1 WebDataRenderer (com.servoy.j2db.server.headlessclient.dataui.WebDataRenderer)1 WebDefaultRecordNavigator (com.servoy.j2db.server.headlessclient.dataui.WebDefaultRecordNavigator)1 WebTabPanel (com.servoy.j2db.server.headlessclient.dataui.WebTabPanel)1 IButton (com.servoy.j2db.ui.IButton)1 IComponent (com.servoy.j2db.ui.IComponent)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 ISupportWebBounds (com.servoy.j2db.ui.ISupportWebBounds)1 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)1 IStyleRule (com.servoy.j2db.util.IStyleRule)1 IStyleSheet (com.servoy.j2db.util.IStyleSheet)1