Search in sources :

Example 1 with TextualStyle

use of com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle in project servoy-client by Servoy.

the class ScrollResponseHeaderContainer method getStyleAttributeString.

/**
 * Returns for styleAttribute:
 * <p>
 *   <b>BGCOLOR</b>: an inline style string with background color to be applied to a component <br/>
 *   Needed because transparent colors are not supported in all browsers and a fallback color is also applied (if supplied)
 *            (ex: "background-color: #AAA;background-color: rgba(255,255,255,0.7)" )<br/>
 *            (<b>doesn't need further processing to be applyed on a component</b>)
 * </p>
 * <p>
 *   <b>FGCOLOR</b>: an inline style string to be applied to a component (same logic as GBcolor)
 *   (doesn't need further processing)
 * </p>
 * <p>
 *   <b>FONT</b>: string containing font font css rule values (needs further processing ,ex passed in ChangesRecorder.setFont())
 * </p>
 *   <b>BORDER</b>: string containing font border css rule values (needs further processing ,ex passed inChangesRecorder.setBorder())
 * @param style
 * @param styleAttribute
 * @return
 */
private String getStyleAttributeString(IStyleRule style, ISupportRowStyling.ATTRIBUTE styleAttribute) {
    IStyleSheet ss = getRowStyleSheet();
    if (ss != null && style != null) {
        switch(styleAttribute) {
            case BGIMAGE:
                String[] bgImageMediaUrls = style.getValues(CSS.Attribute.BACKGROUND_IMAGE.toString());
                if (bgImageMediaUrls != null) {
                    StringBuffer ret = new StringBuffer();
                    for (String val : bgImageMediaUrls) {
                        TextualStyle headerStyle = new TemplateGenerator.TextualStyle();
                        if (val.contains(MediaURLStreamHandler.MEDIA_URL_DEF)) {
                            // extract media://name from url("media:///name")
                            String urlContentVal = val.replaceAll(".*url\\([\"']?(.*?)[\"']?\\)", "$1");
                            String httpUrl = MediaURLStreamHandler.getTranslatedMediaURL(application.getFlattenedSolution(), urlContentVal);
                            headerStyle.setProperty(CSS.Attribute.BACKGROUND_IMAGE.toString(), "url(" + httpUrl + ")");
                        } else {
                            headerStyle.setProperty(CSS.Attribute.BACKGROUND_IMAGE.toString(), val);
                        }
                        // the returned string is style='...' , we nedd to get the ... part
                        String inlineStyle = headerStyle.toString();
                        if (inlineStyle != null)
                            ret.append(inlineStyle.substring(inlineStyle.indexOf('\'') + 1, inlineStyle.length() - 2));
                    }
                    // .replaceAll("(background-image:)(.*?)(;)(background-image:)", "$1");
                    return ret.toString();
                } else {
                    return null;
                }
            case BGCOLOR:
                if (style.getValues(CSS.Attribute.BACKGROUND_COLOR.toString()) != null) {
                    StringBuffer ret = new StringBuffer();
                    for (Color c : ss.getBackgrounds(style)) {
                        ret.append(CSS.Attribute.BACKGROUND_COLOR.toString()).append(':').append(PersistHelper.createColorString(c)).append(';');
                    }
                    return (ret.length() != 0) ? ret.toString() : null;
                } else {
                    return null;
                }
            case FGCOLOR:
                if (style.getValues(CSS.Attribute.COLOR.toString()) != null) {
                    StringBuffer ret = new StringBuffer();
                    for (Color c : ss.getForegrounds(style)) {
                        ret.append(CSS.Attribute.COLOR.toString()).append(':').append(PersistHelper.createColorString(c)).append(';');
                    }
                    return (ret.length() != 0) ? ret.toString() : null;
                } else {
                    return null;
                }
            case FONT:
                return ss.hasFont(style) ? PersistHelper.createFontString(ss.getFont(style)) : null;
            case BORDER:
                return ss.hasBorder(style) ? ComponentFactoryHelper.createBorderString(ss.getBorder(style)) : null;
            case MARGIN:
                // !WARNING! : Margin is applied as padding
                if (ss.hasMargin(style)) {
                    TextualStyle marginStyle = new TemplateGenerator.TextualStyle();
                    String marginTop = style.getValue(CSS.Attribute.MARGIN_TOP.toString());
                    if (marginTop != null)
                        marginStyle.setProperty(CSS.Attribute.PADDING_TOP.toString(), marginTop);
                    String marginBottom = style.getValue(CSS.Attribute.MARGIN_BOTTOM.toString());
                    if (marginBottom != null)
                        marginStyle.setProperty(CSS.Attribute.PADDING_BOTTOM.toString(), marginBottom);
                    String marginLeft = style.getValue(CSS.Attribute.MARGIN_LEFT.toString());
                    if (marginLeft != null)
                        marginStyle.setProperty(CSS.Attribute.PADDING_LEFT.toString(), marginLeft);
                    String marginRight = style.getValue(CSS.Attribute.MARGIN_RIGHT.toString());
                    if (marginRight != null)
                        marginStyle.setProperty(CSS.Attribute.PADDING_RIGHT.toString(), marginRight);
                    StringBuffer ret = new StringBuffer();
                    // the returned string is style='...' , we nedd to get the ... part
                    String inlineStyle = marginStyle.toString();
                    if (inlineStyle != null)
                        ret.append(inlineStyle.substring(inlineStyle.indexOf('\'') + 1, inlineStyle.length() - 2));
                    return ret.toString();
                }
        }
    }
    return null;
}
Also used : AppendingStringBuffer(org.apache.wicket.util.string.AppendingStringBuffer) IStyleSheet(com.servoy.j2db.util.IStyleSheet) TextualStyle(com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle) Color(java.awt.Color)

Example 2 with TextualStyle

use of com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle in project servoy-client by Servoy.

the class SortableCellViewHeader method setWidth.

public void setWidth(int width) {
    int borderWidth = 0;
    Iterator<IPersist> it2 = cellview.getAllObjects();
    while (it2.hasNext()) {
        IPersist element = it2.next();
        if (id.equals(ComponentFactory.getWebID(form, element))) {
            GraphicalComponent gc = (GraphicalComponent) view.labelsFor.get(((ISupportName) element).getName());
            if (gc != null) {
                TextualStyle styleObj = new TextualStyle();
                BorderAndPadding ins = TemplateGenerator.applyBaseComponentProperties(gc, view.fc.getForm(), styleObj, (Insets) TemplateGenerator.DEFAULT_LABEL_PADDING.clone(), null, application);
                if (ins.border != null)
                    borderWidth = ins.border.left + ins.border.right;
            }
        }
    }
    int headerPadding = TemplateGenerator.SORTABLE_HEADER_PADDING;
    // If there is no label-for, we leave place for the default border placed at the right of headers.
    if (view.labelsFor.size() == 0) {
        int extraWidth = TemplateGenerator.NO_LABELFOR_DEFAULT_BORDER_WIDTH;
        String headerBorder = view.getHeaderBorder();
        if (headerBorder != null) {
            Properties properties = new Properties();
            Insets borderIns = ComponentFactoryHelper.createBorderCSSProperties(headerBorder, properties);
            extraWidth = borderIns.left + borderIns.right;
            headerPadding = 0;
        }
        borderWidth += extraWidth;
    }
    // we have only left padding
    int clientWidth = width - headerPadding - borderWidth;
    // if we have grid_style for the header, then don't change the header width
    this.width = (view.labelsFor.size() == 0 && view.getHeaderBorder() != null) ? width : clientWidth;
    StyleAppendingModifier widthStyleModifier = new StyleAppendingModifier(new Model<String>() {

        @Override
        public String getObject() {
            // $NON-NLS-1$//$NON-NLS-2$
            return "width: " + SortableCellViewHeader.this.width + "px";
        }
    });
    add(widthStyleModifier);
    headerColumnTable.add(widthStyleModifier);
    labelResolver.setWidth(clientWidth - SortableCellViewHeader.ARROW_WIDTH);
    getStylePropertyChanges().setChanged();
}
Also used : Insets(java.awt.Insets) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportName(com.servoy.j2db.persistence.ISupportName) BorderAndPadding(com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.BorderAndPadding) Properties(java.util.Properties) TextualStyle(com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle) IPersist(com.servoy.j2db.persistence.IPersist)

Example 3 with TextualStyle

use of com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle in project servoy-client by Servoy.

the class AbstractFormLayoutProvider method renderOpenFormHTML.

public void renderOpenFormHTML(StringBuffer html, TextualCSS css) {
    // $NON-NLS-1$
    html.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
    // $NON-NLS-1$
    html.append("<!-- Servoy webclient page Copyright ");
    // $NON-NLS-1$
    html.append(Utils.formatTime(System.currentTimeMillis(), "yyyy"));
    // $NON-NLS-1$
    html.append(" Servoy -->\n");
    // $NON-NLS-1$
    html.append("<html xmlns:servoy>\n");
    // $NON-NLS-1$
    html.append("<head>\n");
    // $NON-NLS-1$
    html.append("<title>");
    html.append((f.getTitleText() != null ? TemplateGenerator.getSafeText(f.getTitleText()) : getFormInstanceName()));
    // $NON-NLS-1$
    html.append(" - Servoy");
    // $NON-NLS-1$
    html.append("</title>\n");
    // $NON-NLS-1$
    html.append("<servoy:head>\n");
    // $NON-NLS-1$
    html.append("</servoy:head>\n");
    // $NON-NLS-1$
    html.append("</head>\n");
    // $NON-NLS-1$
    html.append("<body id='servoy_page'>\n");
    // $NON-NLS-1$
    html.append("<form id='servoy_dataform'>\n");
    // $NON-NLS-1$
    html.append("<servoy:panel>\n");
    String buildFormID = buildFormID();
    // $NON-NLS-1$
    html.append("<div servoy:id='servoywebform' id='");
    html.append(buildFormID);
    // $NON-NLS-1$
    html.append("'" + TemplateGenerator.getCssClassForElement(f, new boolean[] { false }, "servoywebform") + "'>\n");
    // following two divs are here only because a bug in IE7 made divs that were anchored on all sides break iframe behavior (so dialogs)
    // $NON-NLS-1$
    html.append("<div id='sfw_");
    html.append(buildFormID);
    // $NON-NLS-1$
    html.append("' style='position: absolute; height: 0px; right: 0px; left: 0px;'/>");
    // $NON-NLS-1$
    html.append("<div id='sfh_");
    html.append(buildFormID);
    // $NON-NLS-1$
    html.append("' style='position: absolute; bottom: 0px; top: 0px; width: 0px;'/>");
    // the 2 divs above are used to keep track of the form's size when browser resizes
    // Put CSS properties for background color and border (if any).
    // $NON-NLS-1$
    TextualStyle formStyle = css.addStyle("#" + buildFormID());
    if (style != null && style.getValue(CSSName.BACKGROUND_COLOR.toString()) != null && !f.getTransparent()) {
        formStyle.setProperty(CSSName.BACKGROUND_COLOR.toString(), style.getValues(CSSName.BACKGROUND_COLOR.toString()), true);
    }
    if (border != null) {
        String type = ComponentFactoryHelper.createBorderString(border);
        ComponentFactoryHelper.createBorderCSSProperties(type, formStyle);
    } else if (style != null) {
        copyBorderAttributes(style, formStyle);
    }
    hasImage = addBackgroundImageAttributeIfExists(style, formStyle);
    fillFormLayoutCSS(formStyle);
}
Also used : TextualStyle(com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle)

Example 4 with TextualStyle

use of com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle in project servoy-client by Servoy.

the class PartWrapper method getStyle.

public String getStyle() {
    TextualStyle style = new TextualStyle() {

        @Override
        protected void appendValue(StringBuffer retval, String pSelector, String name, String value) {
            retval.append("\"");
            retval.append(name);
            retval.append("\"");
            retval.append(": ");
            retval.append("\"");
            retval.append(value);
            retval.append("\"");
            retval.append(',');
        }
    };
    layoutProvider.fillPartStyle(style, part);
    if (!design && FormLayoutGenerator.isTableOrListView(context, converterContext.getSolution())) {
        style.remove("overflow-x");
        style.remove("overflow-y");
        style.put("overflow", "hidden");
    }
    String partStyle = style.getValuesAsString(null);
    if (partStyle.endsWith(",")) {
        partStyle = partStyle.substring(0, partStyle.length() - 1);
    }
    return "{" + partStyle + "}";
}
Also used : TextualStyle(com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle)

Example 5 with TextualStyle

use of com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle in project servoy-client by Servoy.

the class UnanchoredFormLayoutProvider method getLayoutForForm.

public TextualStyle getLayoutForForm(int customNavigatorWidth, boolean isNavigator, boolean isInTabPanel) {
    TextualStyle formStyle = new TextualStyle();
    if (customNavigatorWidth > 0) {
        // $NON-NLS-1$ //$NON-NLS-2$
        formStyle.setProperty("position", "absolute");
        if (orientation.equals(OrientationApplier.RTL)) {
            int right = 0;
            if ((customNavigatorWidth > 0) && !isNavigator)
                right = customNavigatorWidth;
            // $NON-NLS-1$//$NON-NLS-2$
            formStyle.setProperty("right", right + "px");
        } else {
            int left = 0;
            if ((customNavigatorWidth > 0) && !isNavigator)
                left = customNavigatorWidth;
            // $NON-NLS-1$//$NON-NLS-2$
            formStyle.setProperty("left", left + "px");
        }
        if (// $NON-NLS-1$ //$NON-NLS-2$
        (customNavigatorWidth > 0) && isNavigator)
            // $NON-NLS-1$ //$NON-NLS-2$
            formStyle.setProperty("width", customNavigatorWidth + "px");
        else
            // $NON-NLS-1$ //$NON-NLS-2$
            formStyle.setProperty("width", "100%");
        // $NON-NLS-1$ //$NON-NLS-2$
        formStyle.setProperty("top", "0px");
        // $NON-NLS-1$ //$NON-NLS-2$
        formStyle.setProperty("height", "100%");
    } else if (isInTabPanel) {
        // formStyle.setProperty("height", tabPanelSize.height + "px"); //$NON-NLS-1$ //$NON-NLS-2$
        // $NON-NLS-1$ //$NON-NLS-2$
        formStyle.setProperty("height", "100%");
    }
    return formStyle;
}
Also used : TextualStyle(com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle)

Aggregations

TextualStyle (com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle)10 IFormUIInternal (com.servoy.j2db.IFormUIInternal)1 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)1 IPersist (com.servoy.j2db.persistence.IPersist)1 ISupportName (com.servoy.j2db.persistence.ISupportName)1 Solution (com.servoy.j2db.persistence.Solution)1 AbstractServoyLastVersionAjaxBehavior (com.servoy.j2db.server.headlessclient.dataui.AbstractServoyLastVersionAjaxBehavior)1 IFormLayoutProvider (com.servoy.j2db.server.headlessclient.dataui.IFormLayoutProvider)1 PageContributorRepeatingView (com.servoy.j2db.server.headlessclient.dataui.PageContributorRepeatingView)1 StyleAppendingModifier (com.servoy.j2db.server.headlessclient.dataui.StyleAppendingModifier)1 StylePropertyChangeMarkupContainer (com.servoy.j2db.server.headlessclient.dataui.StylePropertyChangeMarkupContainer)1 BorderAndPadding (com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.BorderAndPadding)1 WebSplitPane (com.servoy.j2db.server.headlessclient.dataui.WebSplitPane)1 WebTabPanel (com.servoy.j2db.server.headlessclient.dataui.WebTabPanel)1 IComponent (com.servoy.j2db.ui.IComponent)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 IStyleSheet (com.servoy.j2db.util.IStyleSheet)1 Color (java.awt.Color)1 Insets (java.awt.Insets)1 Point (java.awt.Point)1