Search in sources :

Example 11 with IStyleRule

use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.

the class WebDataRenderer method getParentViewBgColor.

private String getParentViewBgColor() {
    if (parentView != null) {
        String rowBGColorCalculation = parentView.getRowBGColorScript();
        IRecordInternal rec = (IRecordInternal) getDefaultModelObject();
        if (rec != null && rec.getRawData() != null) {
            IFoundSetInternal parentFoundSet = rec.getParentFoundSet();
            int recIndex = parentFoundSet.getSelectedIndex();
            boolean isSelected = recIndex == parentFoundSet.getRecordIndex(rec);
            if (rowBGColorCalculation != null) {
                Object bg_color = null;
                if (rec.getRawData().containsCalculation(rowBGColorCalculation)) {
                    // data renderer is always on the selected index.
                    bg_color = parentFoundSet.getCalculationValue(rec, rowBGColorCalculation, Utils.arrayMerge(new Object[] { new Integer(recIndex), new Boolean(isSelected), null, null, Boolean.FALSE }, Utils.parseJSExpressions(parentView.getRowBGColorArgs())), null);
                } else {
                    try {
                        FormController currentForm = dataAdapterList.getFormController();
                        bg_color = currentForm.executeFunction(rowBGColorCalculation, Utils.arrayMerge(new Object[] { new Integer(parentFoundSet.getSelectedIndex()), new Boolean(isSelected), null, null, currentForm.getName(), rec, Boolean.FALSE }, Utils.parseJSExpressions(parentView.getRowBGColorArgs())), true, null, true, null);
                    } catch (Exception ex) {
                        Debug.error(ex);
                    }
                }
                if (bg_color != null && !(bg_color.toString().trim().length() == 0) && !(bg_color instanceof Undefined)) {
                    return bg_color.toString();
                }
            }
            if (parentView instanceof ISupportRowStyling) {
                ISupportRowStyling parentViewWithRowStyling = (ISupportRowStyling) parentView;
                IStyleSheet ss = parentViewWithRowStyling.getRowStyleSheet();
                IStyleRule style = isSelected ? parentViewWithRowStyling.getRowSelectedStyle() : null;
                if (style != null && style.getAttributeCount() == 0)
                    style = null;
                if (style == null) {
                    style = (recIndex % 2 == 0) ? parentViewWithRowStyling.getRowEvenStyle() : parentViewWithRowStyling.getRowOddStyle();
                }
                if (ss != null && style != null) {
                    return PersistHelper.createColorString(ss.getBackground(style));
                }
            }
        }
    }
    return null;
}
Also used : FormController(com.servoy.j2db.FormController) Undefined(org.mozilla.javascript.Undefined) ISupportRowStyling(com.servoy.j2db.ui.ISupportRowStyling) IStyleSheet(com.servoy.j2db.util.IStyleSheet) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Point(java.awt.Point) NoSuchElementException(java.util.NoSuchElementException) IStyleRule(com.servoy.j2db.util.IStyleRule)

Example 12 with IStyleRule

use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.

the class WebDataRendererFactory method completeRenderers.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.servoy.j2db.IDataRendererFactory#completeRenderers(com.servoy.j2db.IApplication, com.servoy.j2db.persistence.Form,
	 * com.servoy.j2db.IScriptExecuter, java.util.Map, int, boolean, com.servoy.j2db.ControllerUndoManager)
	 */
public Map completeRenderers(IApplication application, Form form, IScriptExecuter scriptExecuter, Map emptyDataRenderers, int width, boolean printing, ControllerUndoManager undoManager, TabSequenceHelper<Component> tabSequence) throws Exception {
    int partHeight = 0;
    Iterator e2 = form.getParts();
    while (e2.hasNext()) {
        Part part = (Part) e2.next();
        Color bg = ComponentFactory.getPartBackground(application, part, form);
        if (bg != null) {
            Pair<IStyleSheet, IStyleRule> formStyle = ComponentFactory.getCSSPairStyleForForm(application, form);
            if (formStyle != null && formStyle.getRight() != null && formStyle.getRight().hasAttribute(CSSName.BACKGROUND_IMAGE.toString())) {
                bg = null;
            }
        }
        if (bg == null && printing)
            bg = Color.white;
        IDataRenderer panel = (IDataRenderer) emptyDataRenderers.get(part);
        if (panel != null) {
            int total = Math.abs(part.getHeight() - partHeight);
            setBasicSettings(panel, bg, new Dimension(width, total), new Point(0, partHeight), printing);
        }
        partHeight = part.getHeight();
    }
    // place all the elements
    return placeElements(application, form, scriptExecuter, emptyDataRenderers, printing, undoManager, tabSequence);
}
Also used : IStyleSheet(com.servoy.j2db.util.IStyleSheet) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) Part(com.servoy.j2db.persistence.Part) Color(java.awt.Color) Iterator(java.util.Iterator) IStyleRule(com.servoy.j2db.util.IStyleRule) Dimension(java.awt.Dimension) Point(java.awt.Point) Point(java.awt.Point)

Example 13 with IStyleRule

use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.

the class TemplateGenerator method createCellBasedView.

private static void createCellBasedView(AbstractBase obj, Form form, StringBuffer html, TextualCSS css, boolean addHeaders, int startY, int endY, Color bgColor, IServiceProvider sp, int viewType, boolean enableAnchoring, int partStartY, int partEndY) throws RepositoryException {
    try {
        html.append('\n');
        boolean sortable = true;
        boolean shouldFillAllHorizSpace = false;
        boolean[] userCssClassAdded = new boolean[] { false };
        if (obj instanceof ISupportScrollbars) {
            int scrollbars = ((ISupportScrollbars) obj).getScrollbars();
            if ((scrollbars & ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER) == ISupportScrollbars.HORIZONTAL_SCROLLBAR_NEVER) {
                boolean hasAtLeastOneAnchored = false;
                Iterator<IPersist> it2 = obj.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
                while (it2.hasNext()) {
                    IPersist element = it2.next();
                    if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
                        if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null) {
                            continue;
                        }
                        Point l = ((IFormElement) element).getLocation();
                        if (l == null) {
                            // unkown where to add
                            continue;
                        }
                        if (l.y >= startY && l.y < endY) {
                            if (element instanceof ISupportAnchors) {
                                int anchors = ((ISupportAnchors) element).getAnchors();
                                if (((anchors & IAnchorConstants.EAST) != 0) && ((anchors & IAnchorConstants.WEST) != 0)) {
                                    hasAtLeastOneAnchored = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (hasAtLeastOneAnchored)
                    shouldFillAllHorizSpace = true;
            }
        }
        // true for list view type and multi-line portals
        boolean listViewMode = viewType == IForm.LIST_VIEW || viewType == FormController.LOCKED_LIST_VIEW;
        if (obj instanceof Form) {
            html.append("<span servoy:id='info'></span>\n<table border=0 cellpadding=0 cellspacing=0 width='100%'>\n");
            html.append(getCssClassForElement(obj, ""));
        } else // is portal
        {
            Portal p = (Portal) obj;
            listViewMode = p.getMultiLine();
            sortable = p.getSortable();
            TextualStyle styleObj = css.addStyle('#' + ComponentFactory.getWebID(form, p));
            BorderAndPadding ins = applyBaseComponentProperties(p, form, styleObj, null, null, sp);
            applyLocationAndSize(p, styleObj, ins, partStartY, partEndY, form.getSize().width, true, p.getAnchors(), sp);
            html.append("<div style='overflow: auto' ");
            html.append(getWicketIDParameter(form, p));
            // html.append(getJavaScriptIDParameter(p));
            html.append(getCssClassForElement(obj, userCssClassAdded, "portal"));
            // $NON-NLS-1$
            html.append("><span servoy:id='info'></span>\n<table cellpadding='0' cellspacing='0' class='portal'>\n");
        }
        int yOffset = 0;
        if (listViewMode) {
            if (obj instanceof Portal) {
                Iterator<IPersist> it = obj.getAllObjects();
                boolean isYOffsetSet = false;
                while (it.hasNext()) {
                    IPersist element = it.next();
                    if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
                        Point l = ((IFormElement) element).getLocation();
                        // unknown where to add
                        if (l == null)
                            continue;
                        if (l.y >= startY && l.y < endY) {
                            if (!isYOffsetSet || yOffset > (l.y - startY)) {
                                yOffset = l.y - startY;
                                isYOffsetSet = true;
                            }
                        }
                    }
                }
            }
            css.addCSSBoundsHandler(new YOffsetCSSBoundsHandler(-startY - yOffset));
        } else {
            css.addCSSBoundsHandler(NoLocationCSSBoundsHandler.INSTANCE);
        }
        html.append("<tr><td height='99%'><table border=0 cellpadding=0 cellspacing=0 width='100%'>\n");
        if (addHeaders) {
            Map<String, GraphicalComponent> labelsFor = new HashMap<String, GraphicalComponent>();
            html.append("<thead ");
            // if (sortable) html.append("servoy:id='header'");
            html.append("servoy:id='header'");
            html.append("><tr class='headerbuttons'>\n");
            Iterator<IPersist> it1 = obj.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
            while (it1.hasNext()) {
                IPersist element = it1.next();
                if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null && !((GraphicalComponent) element).getLabelFor().equals("")) {
                    labelsFor.put(((GraphicalComponent) element).getLabelFor(), (GraphicalComponent) element);
                }
            }
            boolean usesImageMedia = false;
            boolean hasAtLeastOneLabelFor = false;
            Iterator<IPersist> it2 = obj.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
            while (it2.hasNext()) {
                IPersist element = it2.next();
                if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
                    if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null) {
                        continue;
                    }
                    Point l = ((IFormElement) element).getLocation();
                    if (l == null) {
                        // unkown where to add
                        continue;
                    }
                    if (l.y >= startY && l.y < endY) {
                        GraphicalComponent label = labelsFor.get(((IFormElement) element).getName());
                        if (label != null)
                            hasAtLeastOneLabelFor = true;
                    }
                }
            }
            int currentColumnCount = 0;
            int headerHeight = 0;
            it2 = obj.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
            while (it2.hasNext()) {
                IPersist element = it2.next();
                if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
                    if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null) {
                        continue;
                    }
                    Point l = ((IFormElement) element).getLocation();
                    if (l == null) {
                        // unkown where to add
                        continue;
                    }
                    if (l.y >= startY && l.y < endY) {
                        currentColumnCount++;
                        html.append("<th ");
                        // if (sortable) html.append(getWicketIDParameter(element));
                        html.append(getWicketIDParameter(form, element));
                        int w = ((IFormElement) element).getSize().width;
                        // minus left padding from css for th
                        w = w - 2;
                        // html.append("height='");
                        // html.append( ((IFormElement)element).getSize().height );
                        // html.append("' ");
                        TextualStyle styleObj = new TextualStyle();
                        GraphicalComponent label = labelsFor.get(((IFormElement) element).getName());
                        if (label != null) {
                            if (currentColumnCount == 1)
                                headerHeight = label.getSize().height;
                            html.append(' ');
                            BorderAndPadding ins = applyBaseComponentProperties(label, form, styleObj, (Insets) DEFAULT_LABEL_PADDING.clone(), null, sp);
                            // some css attributes were not applied
                            Pair<IStyleSheet, IStyleRule> styleInfo = ComponentFactory.getStyleForBasicComponent(sp, label, form);
                            Border cssBorder = null;
                            if (styleInfo != null) {
                                IStyleRule s = styleInfo.getRight();
                                IStyleSheet ss = styleInfo.getLeft();
                                if (ss != null && s != null) {
                                    addAttributeToStyle(styleObj, CSS.Attribute.COLOR.toString(), s.getValue(CSS.Attribute.COLOR.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.BACKGROUND_COLOR.toString(), s.getValue(CSS.Attribute.BACKGROUND_COLOR.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.FONT.toString(), s.getValue(CSS.Attribute.FONT.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.FONT_FAMILY.toString(), s.getValue(CSS.Attribute.FONT_FAMILY.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.FONT_SIZE.toString(), s.getValue(CSS.Attribute.FONT_SIZE.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.FONT_STYLE.toString(), s.getValue(CSS.Attribute.FONT_STYLE.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.FONT_VARIANT.toString(), s.getValue(CSS.Attribute.FONT_VARIANT.toString()));
                                    addAttributeToStyle(styleObj, CSS.Attribute.FONT_WEIGHT.toString(), s.getValue(CSS.Attribute.FONT_WEIGHT.toString()));
                                    cssBorder = ss.getBorder(s);
                                }
                            }
                            if (ins.border != null)
                                w = w - ins.border.left - ins.border.right;
                            applyTextProperties(label, styleObj);
                            TextualStyle bgborderstyleObj = new TextualStyle();
                            if (!sortable) {
                                bgborderstyleObj.setProperty("text-align", styleObj.getProperty("text-align"));
                                bgborderstyleObj.setProperty("color", styleObj.getProperty("color"));
                            }
                            if (label.getImageMediaID() <= 0) {
                                bgborderstyleObj.setProperty("background-image", "none");
                                usesImageMedia = false;
                            } else {
                                usesImageMedia = true;
                                // always remove background image here
                                styleObj.remove(CSS.Attribute.BACKGROUND_IMAGE.toString());
                            }
                            String styleObjBgColor = styleObj.getProperty("background-color");
                            if (styleObjBgColor != null && !"".equals(styleObjBgColor)) {
                                bgborderstyleObj.setProperty("background-color", styleObjBgColor);
                            }
                            // unless specified, set the font-weight for <th> to normal, as disabled parent component will make the font bold by default and we don't want that
                            if (styleObj.getProperty(CSS.Attribute.FONT_WEIGHT.toString()) == null) {
                                bgborderstyleObj.setProperty(CSS.Attribute.FONT_WEIGHT.toString(), "normal", false);
                            }
                            if (cssBorder != null && label.getBorderType() == null)
                                ComponentFactoryHelper.createBorderCSSProperties(ComponentFactoryHelper.createBorderString(cssBorder), bgborderstyleObj);
                            else
                                ComponentFactoryHelper.createBorderCSSProperties(label.getBorderType(), bgborderstyleObj);
                            if (headerHeight > 0)
                                bgborderstyleObj.setProperty(CSS.Attribute.HEIGHT.toString(), headerHeight + "px");
                            html.append(bgborderstyleObj.toString());
                            Enumeration<Object> e = bgborderstyleObj.keys();
                            while (e.hasMoreElements()) {
                                String key = (String) e.nextElement();
                                styleObj.remove(key);
                            }
                            if (cssBorder != null || label.getBorderType() != null) {
                                for (Attribute att : ServoyStyleSheet.borderAttributes) {
                                    // make sure all border attributes are removed
                                    styleObj.remove(att.toString());
                                }
                                for (String extendedStyleAttribute : ServoyStyleSheet.borderAttributesExtensions) {
                                    // make sure all border attributes are removed
                                    styleObj.remove(extendedStyleAttribute);
                                }
                            }
                        } else {
                            // If there is no label-for, we put a default right-border to all columns except the last.
                            if (!hasAtLeastOneLabelFor) {
                                TextualStyle defaultBorder = new TextualStyle();
                                defaultBorder.setProperty("border-right", NO_LABELFOR_DEFAULT_BORDER_WIDTH + "px solid gray");
                                html.append(defaultBorder.toString());
                            }
                        }
                        if (sortable && !usesImageMedia) {
                            html.append(getCssClassForElement((AbstractBase) element, "sortable"));
                        } else {
                            html.append(getCssClassForElement((AbstractBase) element, "nosort"));
                        }
                        html.append("width='");
                        html.append(w);
                        html.append("' ");
                        html.append('>');
                        int headerW = w;
                        if (!hasAtLeastOneLabelFor)
                            headerW -= 1;
                        html.append("<table servoy:id='headerColumnTable' cellspacing='0' cellpadding='0' width='");
                        html.append(headerW).append("px'><tr>");
                        Object fontHeight = styleObj.get(CSS.Attribute.FONT_SIZE.toString());
                        int cellHeight = 13;
                        if (fontHeight != null) {
                            String sFontHeight = fontHeight.toString().toLowerCase();
                            if (sFontHeight.endsWith("px") || sFontHeight.endsWith("pt"))
                                sFontHeight = sFontHeight.substring(0, sFontHeight.length() - 2);
                            try {
                                cellHeight = Integer.parseInt(sFontHeight);
                                cellHeight += 2;
                            } catch (NumberFormatException ex) {
                                Debug.error(ex);
                            }
                        }
                        html.append("<td height='").append(cellHeight).append("px'>");
                        styleObj.setProperty("overflow", "hidden");
                        styleObj.setProperty("left", "0px");
                        styleObj.setProperty("right", "0px");
                        styleObj.setProperty("position", "absolute");
                        TextualStyle sortLinkStyle = new TextualStyle();
                        sortLinkStyle.setProperty("position", "relative");
                        int cellWidth = (headerW - SortableCellViewHeader.ARROW_WIDTH);
                        sortLinkStyle.setProperty("width", cellWidth + "px");
                        if (sortable) {
                            sortLinkStyle.setProperty("text-align", styleObj.getProperty("text-align"));
                            html.append("<a servoy:id='sortLink' ");
                            // if (element instanceof ISupportDataProviderID && ((ISupportDataProviderID)element).getDataProviderID() != null)
                            // {
                            // html.append("class='orderOff' ");
                            // }
                            html.append(sortLinkStyle.toString());
                            html.append('>');
                            html.append("<div servoy:id='headertext' ");
                            styleObj.setProperty("cursor", "pointer");
                            styleObj.setProperty("width", cellWidth + "px");
                            html.append(styleObj.toString());
                            html.append("></div>");
                            html.append("</a>");
                        } else {
                            html.append("<div servoy:id='sortLink' ");
                            html.append(sortLinkStyle.toString());
                            html.append('>');
                            html.append("<div servoy:id='headertext' ");
                            html.append(styleObj.toString());
                            html.append("></div>");
                            html.append("</div>");
                        }
                        html.append("</td><td valign='middle' align='right'>");
                        if (sortable) {
                            html.append("<img servoy:id='resizeBar'></img>");
                        } else {
                            html.append("<span servoy:id='resizeBar'>&nbsp;</span>");
                        // html.append("<span ");
                        // html.append(getWicketIDParameter(element));
                        // html.append(styleObj.toString());
                        // html.append("></span>");
                        }
                        html.append("</td></tr></table>\n");
                        html.append("</th>\n");
                    }
                }
            }
            // when the table has no horizontal scrollbar, then there should be no filler.
            if (!shouldFillAllHorizSpace) {
                html.append("<th");
                if (bgColor != null) {
                    html.append(" style=\"background-image: none; background-color: ");
                    html.append(PersistHelper.createColorString(bgColor));
                    html.append(";\"");
                }
                // add filler (need to be a space else safari & ie7 will not display correctly)
                html.append(">&nbsp;</th>\n");
            }
            html.append("</tr></thead>\n");
        }
        html.append("<tbody servoy:id='rowsContainerBody'>\n");
        StringBuffer columns = new StringBuffer();
        int firstComponentHeight = -1;
        if (listViewMode) {
            if (!(obj instanceof Portal)) {
                Iterator<Part> partIte = form.getParts();
                while (partIte.hasNext()) {
                    Part p = partIte.next();
                    if (p.getPartType() == Part.BODY) {
                        firstComponentHeight = p.getHeight() - startY;
                        break;
                    }
                }
            }
            StringBuffer sbElements = new StringBuffer();
            Iterator<?> it = obj instanceof Portal ? obj.getAllObjects() : form.getFormElementsSortedByFormIndex();
            while (it.hasNext()) {
                Object element = it.next();
                if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
                    Point l = ((IFormElement) element).getLocation();
                    // unknown where to add
                    if (l == null)
                        continue;
                    if (l.y >= startY && l.y < endY) {
                        if (obj instanceof Portal) {
                            Dimension d = ((IFormElement) element).getSize();
                            if (l.y + d.height - startY > firstComponentHeight)
                                firstComponentHeight = l.y + d.height - startY;
                        }
                        createTableViewComponentHTMLAndStyles((IFormElement) element, form, sbElements, css, bgColor, startY, endY, enableAnchoring, sp);
                        sbElements.append('\n');
                    }
                }
            }
            columns.append("<td><div servoy:id='listViewItem' class=\"listViewItem\" tabindex=\"-1\" style=\"position: absolute; height: ").append(firstComponentHeight - yOffset).append("px;");
            if (enableAnchoring || obj instanceof Portal) {
                columns.append(" left: 0px; right: 0px;");
            } else {
                columns.append(" width: ").append(form.getWidth()).append("px;");
            }
            columns.append("\">");
            columns.append(sbElements);
            columns.append("</div></td>\n");
        } else {
            Iterator<IPersist> it = obj.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
            while (it.hasNext()) {
                IPersist element = it.next();
                if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
                    if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null) {
                        continue;
                    }
                    Point l = ((IFormElement) element).getLocation();
                    if (l == null) {
                        // unkown where to add
                        continue;
                    }
                    if (l.y >= startY && l.y < endY) {
                        columns.append("<td ");
                        if (element instanceof ISupportName) {
                            String name = ((ISupportName) element).getName();
                            if (((name != null) && (name.trim().length() > 0)) || addHeaders) {
                                // this column's cells can be made invisible (and <td> tag is the one that has to change)
                                // so we will link this <td> to a wicket component
                                columns.append("servoy:id='");
                                columns.append(ComponentFactory.getWebID(form, element));
                                columns.append("_' ");
                            }
                        }
                        if (firstComponentHeight == -1)
                            firstComponentHeight = ((IFormElement) element).getSize().height;
                        if (!addHeaders && !shouldFillAllHorizSpace) {
                            columns.append("width='");
                            int w = ((IFormElement) element).getSize().width;
                            // w = w - (2+2);  //minus left+rigth padding from css for th
                            columns.append(w);
                            columns.append("' ");
                        }
                        // columns.append("valign='middle' ");
                        columns.append('>');
                        String cssClass = TABLE_VIEW_CELL_CLASS;
                        if (element instanceof Field && ((Field) element).getDisplayType() == Field.COMBOBOX) {
                            cssClass += " " + COMBOBOX_CLASS;
                        }
                        columns.append("<div class='" + cssClass + "' style='position:relative'>");
                        TextualStyle classBasedStyle = createTableViewComponentHTMLAndStyles(element, form, columns, css, bgColor, startY, endY, false, sp);
                        if (element instanceof Field) {
                            int type = ((Field) element).getDisplayType();
                            if (type == Field.PASSWORD || type == Field.TEXT_FIELD || type == Field.TYPE_AHEAD || type == Field.TEXT_AREA) {
                                classBasedStyle.setProperty("float", "left");
                            }
                        }
                        columns.append("</div>\n");
                        columns.append("</td>\n");
                    }
                }
            }
        }
        // no filler when the tableview has no horizontal scrollbar.
        if (!shouldFillAllHorizSpace) {
            // add filler (need to be a space else safari & ie7 will not display correctly)
            columns.append("<td>&nbsp;</td>\n");
        }
        html.append("<tr servoy:id='rows' ");
        html.append("height='");
        html.append(firstComponentHeight - yOffset);
        html.append("' ");
        if ((obj instanceof ISupportRowBGColorScript) && (((ISupportRowBGColorScript) obj).getRowBGColorScript() == null || ((ISupportRowBGColorScript) obj).getRowBGColorScript().trim().length() == 0)) {
            html.append("class='even'");
        }
        html.append(">\n");
        html.append(columns);
        html.append("</tr>\n");
        html.append("</tbody></table>\n");
        html.append("</td></tr>\n");
        html.append("<tr valign='bottom'>\n");
        html.append("<td servoy:id='navigator' height='1%'>&nbsp;</td>\n");
        html.append("</tr>\n");
        html.append("</table>\n");
        if (!(obj instanceof Form)) {
            html.append("</div>\n");
        }
        html.append("\n\n");
    } finally {
        css.removeCSSBoundsHandler();
    }
}
Also used : IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) WebForm(com.servoy.j2db.server.headlessclient.WebForm) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) Attribute(javax.swing.text.html.CSS.Attribute) ISupportScrollbars(com.servoy.j2db.persistence.ISupportScrollbars) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportName(com.servoy.j2db.persistence.ISupportName) Bean(com.servoy.j2db.persistence.Bean) Field(com.servoy.j2db.persistence.Field) Portal(com.servoy.j2db.persistence.Portal) ISupportRowBGColorScript(com.servoy.j2db.ui.ISupportRowBGColorScript) IStyleSheet(com.servoy.j2db.util.IStyleSheet) AbstractBase(com.servoy.j2db.persistence.AbstractBase) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point) IFormElement(com.servoy.j2db.persistence.IFormElement) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) IPersist(com.servoy.j2db.persistence.IPersist) Part(com.servoy.j2db.persistence.Part) IStyleRule(com.servoy.j2db.util.IStyleRule) MatteBorder(javax.swing.border.MatteBorder) Border(javax.swing.border.Border) TitledBorder(javax.swing.border.TitledBorder) EmptyBorder(javax.swing.border.EmptyBorder)

Example 14 with IStyleRule

use of com.servoy.j2db.util.IStyleRule 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)

Example 15 with IStyleRule

use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.

the class AbstractFormLayoutProvider method fillPartStyle.

public void fillPartStyle(TextualStyle partStyle, Part part) {
    Pair<IStyleSheet, IStyleRule> pairStyle = ComponentFactory.getStyleForBasicComponent(sp, part, f);
    if (pairStyle != null) {
        addBackgroundImageAttributeIfExists(pairStyle.getRight(), partStyle);
    }
    fillPartBackground(partStyle, part);
    if (part.getPartType() == Part.BODY) {
        // $NON-NLS-1$
        partStyle.setProperty("overflow-x", getCSSScrolling(f.getScrollbars(), true));
        // $NON-NLS-1$
        partStyle.setProperty("overflow-y", getCSSScrolling(f.getScrollbars(), false));
    } else {
        // $NON-NLS-1$ //$NON-NLS-2$
        partStyle.setProperty("overflow", "hidden");
    }
    int spaceUsedOnlyInPrintAbove = 0;
    int spaceUsedOnlyInPrintBelow = 0;
    Iterator<Part> allParts = f.getParts();
    while (allParts.hasNext()) {
        Part otherPart = allParts.next();
        if (Part.rendersOnlyInPrint(otherPart.getPartType())) {
            int otherPartHeight = otherPart.getHeight() - f.getPartStartYPos(otherPart.getID());
            if (part.getPartType() > otherPart.getPartType())
                spaceUsedOnlyInPrintAbove += otherPartHeight;
            if (part.getPartType() < otherPart.getPartType())
                spaceUsedOnlyInPrintBelow += otherPartHeight;
        }
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    partStyle.setProperty("position", "absolute");
    fillPartLayoutCSS(partStyle, part, spaceUsedOnlyInPrintAbove, spaceUsedOnlyInPrintBelow);
    if (pairStyle != null && pairStyle.getLeft() != null && pairStyle.getRight() != null) {
        copyBorderAttributes(pairStyle.getRight(), partStyle);
    }
}
Also used : IStyleSheet(com.servoy.j2db.util.IStyleSheet) Part(com.servoy.j2db.persistence.Part) IStyleRule(com.servoy.j2db.util.IStyleRule)

Aggregations

IStyleRule (com.servoy.j2db.util.IStyleRule)18 IStyleSheet (com.servoy.j2db.util.IStyleSheet)17 Point (java.awt.Point)8 Border (javax.swing.border.Border)7 Part (com.servoy.j2db.persistence.Part)6 Dimension (java.awt.Dimension)6 Insets (java.awt.Insets)6 FormController (com.servoy.j2db.FormController)4 IForm (com.servoy.j2db.IForm)4 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)4 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)4 Color (java.awt.Color)4 TitledBorder (javax.swing.border.TitledBorder)4 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)3 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)3 AbstractBase (com.servoy.j2db.persistence.AbstractBase)3 RepositoryException (com.servoy.j2db.persistence.RepositoryException)3 ISupportRowStyling (com.servoy.j2db.ui.ISupportRowStyling)3 IScriptExecuter (com.servoy.j2db.IScriptExecuter)2 FindState (com.servoy.j2db.dataprocessing.FindState)2