use of com.servoy.j2db.util.IStyleSheet 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;
}
use of com.servoy.j2db.util.IStyleSheet 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);
}
}
use of com.servoy.j2db.util.IStyleSheet in project servoy-client by Servoy.
the class ComponentFactory method getStyleForBasicComponentInternal.
private static Pair<IStyleSheet, IStyleRule> getStyleForBasicComponentInternal(IServiceProvider sp, AbstractBase bc, Form form, Set<Integer> visited) {
if (bc == null || sp == null)
return null;
// Protection agains cycle in form inheritance hierarchy.
if (!visited.add(new Integer(form.getID())))
return null;
Style repos_style = getStyleForForm(sp, form);
Pair<IStyleSheet, IStyleRule> pair = null;
if (repos_style != null) {
IStyleSheet ss = getCSSStyle(sp, repos_style);
String lookupName = getLookupName(bc);
if (lookupName != null) {
String formLookup = "";
ISupportChilds parent = bc.getParent();
if (parent instanceof Form) {
String styleClass = ((Form) parent).getStyleClass();
if (styleClass != null && styleClass.length() != 0) {
formLookup = "form." + styleClass;
} else {
formLookup = "form";
}
} else if (parent instanceof Portal) {
String styleClass = ((Portal) parent).getStyleClass();
if (styleClass != null && styleClass.length() != 0) {
formLookup = "portal." + styleClass;
} else {
formLookup = "portal";
}
parent = ((Portal) parent).getParent();
if (parent instanceof Form) {
styleClass = ((Form) parent).getStyleClass();
if (styleClass != null && styleClass.length() != 0) {
formLookup = "form." + styleClass + ' ' + formLookup;
} else {
formLookup = "form " + formLookup;
}
}
}
IStyleRule s = null;
String styleClass = (bc instanceof BaseComponent) ? ((BaseComponent) bc).getStyleClass() : null;
if (bc instanceof Part) {
styleClass = ((Part) bc).getStyleClass();
}
if (lookupName.equals("check") || lookupName.equals("combobox") || "radio".equals(lookupName)) {
if (styleClass != null && styleClass.length() != 0) {
lookupName += '.' + styleClass;
}
lookupName = formLookup + ' ' + lookupName;
s = ss.getCSSRule(lookupName);
if (s.getAttributeCount() > 0)
return new Pair<IStyleSheet, IStyleRule>(ss, s);
else
lookupName = "field";
}
if (styleClass != null && styleClass.length() != 0) {
lookupName += '.' + styleClass;
}
lookupName = formLookup + ' ' + lookupName;
s = ss.getCSSRule(lookupName);
pair = new Pair<IStyleSheet, IStyleRule>(ss, s);
// see BoxPainter for getBorder/getInsets/getLength examples
}
}
if ((pair == null || pair.getRight() == null || (pair.getRight()).getAttributeCount() == 0)) {
if (sp.getFlattenedSolution() != null) {
List<Form> formHierarchy = sp.getFlattenedSolution().getFormHierarchy(form);
for (int i = 1; i < formHierarchy.size(); i++) {
pair = getStyleForBasicComponentInternal(sp, bc, formHierarchy.get(i), visited);
if (pair != null && pair.getRight() != null && (pair.getRight()).getAttributeCount() != 0) {
break;
}
}
}
}
return pair;
}
use of com.servoy.j2db.util.IStyleSheet in project servoy-client by Servoy.
the class ComponentFactory method applyBasicComponentProperties.
public static void applyBasicComponentProperties(IApplication application, IComponent c, BaseComponent bc, Pair<IStyleSheet, IStyleRule> styleInfo) {
// flag for border set by style config
boolean isBorderStyle = false;
// by default it is not transparent
c.setOpaque(true);
// apply any style
if (styleInfo != null) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
if (s.hasAttribute(CSS.Attribute.COLOR.toString())) {
Color cfg = ss.getForeground(s);
if (cfg != null)
c.setForeground(cfg);
}
Object sbackground_color = s.getValue(CSS.Attribute.BACKGROUND_COLOR.toString());
if (sbackground_color != null) {
if (IStyleSheet.COLOR_TRANSPARENT.equals(sbackground_color.toString())) {
c.setOpaque(false);
} else {
Color cbg = ss.getBackground(s);
if (cbg != null)
c.setBackground(cbg);
}
}
// else c.setOpaque(false); // no background-color means transparent
if (ss.hasFont(s)) {
Font f = ss.getFont(s);
if (f != null)
c.setFont(f);
}
if (ss.hasBorder(s)) {
Border b = ss.getBorder(s);
if (b != null) {
c.setBorder(b);
isBorderStyle = true;
}
}
if (ss.hasMargin(s)) {
Insets i = ss.getMargin(s);
if (i != null && c instanceof IButton)
((IButton) c).setMargin(i);
}
}
}
// We intentionally leave the location setting to DataRenderers, since thats the context and might substract part heights from location!
java.awt.Dimension dim = bc.getSize();
if (dim != null)
c.setSize(bc.getSize());
javax.swing.border.Border border = ComponentFactoryHelper.createBorder(bc.getBorderType());
if ((c instanceof JCheckBox || /* DataCheckBox */
c instanceof JRadioButton) && (border != null || isBorderStyle)) {
((AbstractButton) c).setBorderPainted(true);
if (c instanceof JCheckBox) {
((JCheckBox) c).setBorderPaintedFlat(false);
}
}
if (border != null) {
if (border instanceof TitledBorder && Utils.isAppleMacOS()) {
// apple bug.. i have to set the font again (as new!!)
TitledBorder tb = (TitledBorder) border;
Font f = tb.getTitleFont();
if (f != null) {
tb.setTitleFont(new Font(f.getName(), f.getStyle(), f.getSize()));
}
c.setBorder(border);
} else {
c.setBorder(border);
}
}
// if (c instanceof IDelegate)
// {
// c = (JComponent)((IDelegate)c).getDelegate();
// }
String fontString = bc.getFontType();
if (fontString != null) {
Font f = PersistHelper.createFont(fontString);
if (f != null)
c.setFont(f);
}
java.awt.Color bg = bc.getBackground();
if (bg != null)
c.setBackground(bg);
java.awt.Color fg = bc.getForeground();
if (fg != null)
c.setForeground(fg);
String name = bc.getName();
if (name != null)
c.setName(name);
// only use component property value if it is "checked" to be transparent
if (bc.getTransparent())
c.setOpaque(false);
c.setComponentEnabled(bc.getEnabled());
c.setComponentVisible(bc.getVisible());
if (Utils.isSwingClient(application.getApplicationType())) {
// special code for smart client LAFs, like BizLaf
String delegateStyleClassNamePropertyKey = application.getSettings().getProperty("servoy.smartclient.componentStyleClassDelegatePropertyKey");
if (delegateStyleClassNamePropertyKey != null && c instanceof JComponent) {
if (c instanceof IScriptableProvider && ((IScriptableProvider) c).getScriptObject() instanceof IRuntimeComponent) {
// special case since putClientProperty can delegate properties but cannot be overridden we relay on the scripting equivalent
((IRuntimeComponent) ((IScriptableProvider) c).getScriptObject()).putClientProperty(delegateStyleClassNamePropertyKey, bc.getStyleClass());
} else {
((JComponent) c).putClientProperty(delegateStyleClassNamePropertyKey, bc.getStyleClass());
}
}
}
}
use of com.servoy.j2db.util.IStyleSheet in project servoy-client by Servoy.
the class ComponentFactory method getCSSStyle.
public static IStyleSheet getCSSStyle(IServiceProvider sp, Style s) {
if (s == null)
return null;
Map<Style, IStyleSheet> parsedStylesMap;
if (sp != null && Boolean.TRUE.equals(s.getRuntimeProperty(MODIFIED_BY_CLIENT))) {
// style changed by client, cache parsed style per client.
parsedStylesMap = (ConcurrentMap<Style, IStyleSheet>) sp.getRuntimeProperties().get(PARSED_STYLES);
if (parsedStylesMap == null) {
parsedStylesMap = new ConcurrentHashMap<Style, IStyleSheet>();
sp.getRuntimeProperties().put(PARSED_STYLES, parsedStylesMap);
}
} else {
// static style, cache globally.
parsedStylesMap = parsedStyles;
}
IStyleSheet ss = parsedStylesMap.get(s);
if (ss == null) {
ss = new ServoyStyleSheet(s.getCSSText(), s.getName());
parsedStylesMap.put(s, ss);
}
return ss;
}
Aggregations