Author: nbelaevski
Date: 2008-04-22 13:21:16 -0400 (Tue, 22 Apr 2008)
New Revision: 8078
Added:
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/GradientAlignment.java
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/ResourceElement.java
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java
trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java
Log:
baseSkin skin parameter handling implemented
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/ResourceElement.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/ResourceElement.java 2008-04-22
16:58:34 UTC (rev 8077)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/ResourceElement.java 2008-04-22
17:21:16 UTC (rev 8078)
@@ -40,6 +40,22 @@
public class ResourceElement extends ElementBase {
private Map attrs = new HashMap();
+
+ private Map<String, Object> createParameterMap(TemplateContext context) {
+ //usefullness of lazy evaluation here is doubtful for me - nick
+ Map<String, Object> result = new HashMap<String, Object>();
+
+ for (Object object : getChildren()) {
+ if (object instanceof AttributeElement) {
+ AttributeElement attribute = (AttributeElement) object;
+
+ result.put(attribute.getName(), attribute.getValue(context));
+ }
+ }
+
+ return result;
+ }
+
/* (non-Javadoc)
* @see java.util.Map#put(java.lang.Object, java.lang.Object)
*/
@@ -60,7 +76,12 @@
public void encodeBegin(TemplateContext context) throws IOException {
InternetResource resource = findResource(context);
if(null !=resource){
- resource.encodeBegin(context.getFacesContext(),context.getComponent(),attrs);
+ Object dataParameter = context.getComponent();
+ if (dataParameter == null) {
+ dataParameter = createParameterMap(context);
+ }
+
+ resource.encodeBegin(context.getFacesContext(), dataParameter, attrs);
}
}
@@ -70,7 +91,12 @@
public void encodeEnd(TemplateContext context) throws IOException {
InternetResource resource = findResource(context);
if(null !=resource){
- resource.encodeEnd(context.getFacesContext(),context.getComponent());
+ Object dataParameter = context.getComponent();
+ if (dataParameter == null) {
+ dataParameter = createParameterMap(context);
+ }
+
+ resource.encodeEnd(context.getFacesContext(), dataParameter);
}
}
@@ -80,7 +106,12 @@
public String getString(TemplateContext context) throws FacesException {
InternetResource resource = findResource(context);
if(null !=resource){
- return resource.getUri(context.getFacesContext(),context.getComponent());
+ Object dataParameter = context.getComponent();
+ if (dataParameter == null) {
+ dataParameter = createParameterMap(context);
+ }
+
+ return resource.getUri(context.getFacesContext(), dataParameter);
}
return "";
}
Modified:
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2008-04-22
16:58:34 UTC (rev 8077)
+++
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2008-04-22
17:21:16 UTC (rev 8078)
@@ -26,9 +26,11 @@
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.util.Date;
+import java.util.Map;
import javax.faces.context.FacesContext;
@@ -38,6 +40,7 @@
import org.ajax4jsf.resource.ResourceContext;
import org.ajax4jsf.util.HtmlColor;
import org.ajax4jsf.util.Zipper2;
+import org.richfaces.renderkit.html.images.GradientAlignment;
import org.richfaces.renderkit.html.images.GradientType;
import org.richfaces.renderkit.html.images.GradientType.BiColor;
import org.richfaces.skin.Skin;
@@ -50,48 +53,48 @@
*/
public class BaseGradient extends Java2Dresource {
- private int width;
- private int height;
- private int gradientHeight;
- private String baseColor;
- private String gradientColor;
+ private int width;
+ private int height;
+ private int gradientHeight;
+ private String baseColor;
+ private String gradientColor;
private boolean horizontal = false;
-
- public BaseGradient(int width, int height, int gradientHeight) {
- super();
- this.width = width;
- this.height = height;
- this.gradientHeight = gradientHeight;
- setRenderer(new PngRenderer());
- setLastModified(new Date(InternetResourceBuilder.getInstance().getStartTime()));
- }
+ public BaseGradient(int width, int height, int gradientHeight) {
+ super();
+ this.width = width;
+ this.height = height;
+ this.gradientHeight = gradientHeight;
- public BaseGradient(int width, int height, int gradientHeight, String baseColor, String
gradientColor) {
- this(width, height, gradientHeight);
- this.baseColor = baseColor;
- this.gradientColor = gradientColor;
- }
+ setRenderer(new PngRenderer());
+ setLastModified(new Date(InternetResourceBuilder.getInstance().getStartTime()));
+ }
- public BaseGradient(int width, int height) {
- this(width, height, height);
- }
+ public BaseGradient(int width, int height, int gradientHeight, String baseColor,
String gradientColor) {
+ this(width, height, gradientHeight);
+ this.baseColor = baseColor;
+ this.gradientColor = gradientColor;
+ }
- public BaseGradient(int width, int height, String baseColor, String gradientColor) {
- this(width, height, height);
- this.baseColor = baseColor;
- this.gradientColor = gradientColor;
- }
+ public BaseGradient(int width, int height) {
+ this(width, height, height);
+ }
- public BaseGradient() {
- this(30, 50, 20);
- }
-
- public BaseGradient(String baseColor, String gradientColor) {
- this(30, 50, 20);
- this.baseColor = baseColor;
- this.gradientColor = gradientColor;
- }
+ public BaseGradient(int width, int height, String baseColor, String gradientColor) {
+ this(width, height, height);
+ this.baseColor = baseColor;
+ this.gradientColor = gradientColor;
+ }
+
+ public BaseGradient() {
+ this(30, 50, 20);
+ }
+
+ public BaseGradient(String baseColor, String gradientColor) {
+ this(30, 50, 20);
+ this.baseColor = baseColor;
+ this.gradientColor = gradientColor;
+ }
public BaseGradient(int width, int height, int gradientHeight, boolean horizontal) {
this(width, height, gradientHeight);
@@ -129,202 +132,279 @@
this.horizontal = horizontal;
}
- public Dimension getDimensions(FacesContext facesContext, Object data) {
- return new Dimension(width, height);
+ public Dimension getDimensions(FacesContext facesContext, Object data) {
+ return new Dimension(width, height);
+ }
+
+ protected Dimension getDimensions(ResourceContext resourceContext) {
+ return getDimensions(null, restoreData(resourceContext));
+ }
+
+ private void drawRectangle(Graphics2D g2d, Rectangle2D rect, BiColor biColor, boolean
useTop) {
+ if (biColor != null) {
+ Color color = useTop ? biColor.getTopColor() : biColor.getBottomColor();
+ g2d.setColor(color);
+ g2d.fill(rect);
}
+ }
- protected Dimension getDimensions(ResourceContext resourceContext) {
- return getDimensions(null, restoreData(resourceContext));
+ private void drawGradient(Graphics2D g2d, Rectangle2D rectangle, BiColor colors, int
height) {
+ if (colors != null) {
+ GradientPaint gragient = new GradientPaint(0, 0, colors.getTopColor(), 0, height,
colors.getBottomColor());
+ g2d.setPaint(gragient);
+ g2d.fill(rectangle);
}
-
- private void drawGradient(Graphics2D g2d, Rectangle2D rectangle, BiColor colors, int
height, boolean horizontal) {
- if (colors != null) {
- GradientPaint gragient;
+ }
+
+ protected void paint(ResourceContext resourceContext, Graphics2D g2d) {
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
+ g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
+
+ g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
+ g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+ g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
+
+ Data dataToStore = (Data) restoreData(resourceContext);
+ if (dataToStore != null) {
+ Integer headerBackgroundColor = dataToStore.getHeaderBackgroundColor();
+ Integer headerGradientColor = dataToStore.getHeaderGradientColor();
+
+ if (headerBackgroundColor != null && headerGradientColor != null) {
+ Color baseColor = new Color(headerBackgroundColor.intValue());
+ Color alternateColor = new Color(headerGradientColor.intValue());
+ BiColor biColor = new GradientType.BiColor(baseColor, alternateColor);
+
+ GradientType type = dataToStore.getGradientType();
+ BiColor firstLayer = type.getFirstLayerColors(biColor);
+ BiColor secondLayer = type.getSecondLayerColors(biColor);
+
+ Dimension dim = getDimensions(resourceContext);
+
if (horizontal) {
- gragient = new GradientPaint(0, 0, colors.getTopColor(), height, 0,
colors.getBottomColor());
- } else {
- gragient = new GradientPaint(0, 0, colors.getTopColor(), 0, height,
colors.getBottomColor());
+ //x -> y, y -> x
+ g2d.transform(new AffineTransform(0, 1, 1, 0, 0, 0));
+ dim.setSize(dim.height, dim.width);
}
+
+ Rectangle2D rect =
+ new Rectangle2D.Float(
+ 0,
+ 0,
+ dim.width,
+ dim.height);
- g2d.setPaint(gragient);
- g2d.fill(rectangle);
- }
- }
+ GradientAlignment gradientAlignment = dataToStore.getGradientAlignment();
+ int topRectangleHeight = gradientAlignment.getTopRectangleHeight(dim.height,
gradientHeight);
+ int bottomRectangleHeight = gradientAlignment.getBottomRectangleHeight(dim.height,
gradientHeight);
- protected void paint(ResourceContext resourceContext, Graphics2D g2d) {
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
- g2d.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
+ rect = new Rectangle2D.Float(
+ 0,
+ 0,
+ dim.width,
+ topRectangleHeight);
- g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
- g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
- g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY);
+ drawRectangle(g2d, rect, firstLayer, true);
+ drawRectangle(g2d, rect, secondLayer, true);
- Data dataToStore = (Data) restoreData(resourceContext);
- if (dataToStore != null) {
- Integer headerBackgroundColor = dataToStore.getHeaderBackgroundColor();
- Integer headerGradientColor = dataToStore.getHeaderGradientColor();
+ rect = new Rectangle2D.Float(
+ 0,
+ dim.height - bottomRectangleHeight,
+ dim.width,
+ dim.height);
- if (headerBackgroundColor != null && headerGradientColor != null) {
- Color baseColor = new Color(headerBackgroundColor.intValue());
- Color alternateColor = new Color(headerGradientColor.intValue());
- BiColor biColor = new GradientType.BiColor(baseColor, alternateColor);
+ drawRectangle(g2d, rect, firstLayer, false);
+ drawRectangle(g2d, rect, secondLayer, false);
- GradientType type = dataToStore.getGradientType();
- BiColor firstLayer = type.getFirstLayerColors(biColor);
- BiColor secondLayer = type.getSecondLayerColors(biColor);
+ g2d.transform(AffineTransform.getTranslateInstance(0, topRectangleHeight));
- Dimension dim = getDimensions(resourceContext);
- Rectangle2D rect =
- new Rectangle2D.Float(
- 0,
- 0,
- dim.width,
- dim.height);
+ rect = new Rectangle2D.Float(
+ 0,
+ 0,
+ dim.width,
+ dim.height);
- drawGradient(g2d, rect, firstLayer, gradientHeight, horizontal);
- drawGradient(g2d, rect, secondLayer, gradientHeight / 2, horizontal);
- }
+ drawGradient(g2d, rect, firstLayer, gradientHeight);
+ drawGradient(g2d, rect, secondLayer, gradientHeight / 2);
}
}
+ }
- protected void restoreData(Data data, Zipper2 zipper2) {
- if (zipper2.hasMore()) {
- data.setHeaderBackgroundColor(Integer.valueOf(zipper2.nextIntColor()));
- data.setHeaderGradientColor(Integer.valueOf(zipper2.nextIntColor()));
- data.setGradientType(GradientType.values()[zipper2.nextByte()]);
- }
+ protected void restoreData(Data data, Zipper2 zipper2) {
+ if (zipper2.hasMore()) {
+ data.setHeaderBackgroundColor(Integer.valueOf(zipper2.nextIntColor()));
+ data.setHeaderGradientColor(Integer.valueOf(zipper2.nextIntColor()));
+ data.setGradientType(GradientType.values()[zipper2.nextByte()]);
+ data.setGradientAlignment(GradientAlignment.values()[zipper2.nextByte()]);
}
-
- protected Object deserializeData(byte[] objectArray) {
- Data data = createData();
- if (objectArray != null) {
- Zipper2 zipper2 = new Zipper2(objectArray);
- restoreData(data, zipper2);
- }
+ }
- return data;
+ protected Object deserializeData(byte[] objectArray) {
+ Data data = createData();
+ if (objectArray != null) {
+ Zipper2 zipper2 = new Zipper2(objectArray);
+ restoreData(data, zipper2);
}
-
- protected Data createData() {
- return new Data();
+
+ return data;
+ }
+
+ protected Data createData() {
+ return new Data();
+ }
+
+ private Integer decodeColor(String value) {
+ if (value !=null && value.length() != 0) {
+ return Integer.valueOf(HtmlColor.decode(value).getRGB());
+ } else {
+ return null;
}
-
- private void saveData(FacesContext context, Data data, String baseColor, String
gradientColor) {
- Integer headerBackgroundColor = getColorValueParameter(context, baseColor, false);
- Integer headerGradientColor = getColorValueParameter(context, gradientColor,
false);
+ }
- if (!(headerBackgroundColor == null && headerGradientColor == null)) {
- if (headerBackgroundColor == null) {
- headerBackgroundColor = getColorValueParameter(context, baseColor, true);
- }
+ private void saveData(FacesContext context, Data data, String baseColor, String
gradientColor, Object parameterData) {
+ Integer baseIntColor = null;
+ Integer headerIntColor = null;
+ String gradientTypeString = null;
+ String alignmentString = null;
- if (headerGradientColor == null) {
- headerGradientColor = getColorValueParameter(context, gradientColor, true);
- }
- }
+ if (parameterData instanceof Map<?, ?>) {
+ Map<?, ?> map = (Map<?, ?>) parameterData;
- data.setHeaderBackgroundColor(headerBackgroundColor);
- data.setHeaderGradientColor(headerGradientColor);
- data.setGradientType(GradientType.getBySkinParameter(getValueParameter(context,
Skin.gradientType)));
+ gradientTypeString = (String) map.get(Skin.gradientType);
+ alignmentString = (String) map.get("valign");
+ baseIntColor = decodeColor((String) map.get("baseColor"));
+ headerIntColor = decodeColor((String) map.get("gradientColor"));
}
-
- protected void saveData(FacesContext context, Data data) {
- if (baseColor == null) {
- saveData(context, data, Skin.headerBackgroundColor, "headerGradientColor");
- } else {
- saveData(context, data, baseColor, gradientColor);
- }
+
+ if (baseIntColor == null) {
+ baseIntColor = getColorValueParameter(context, baseColor, false);
}
-
- protected Object getDataToStore(FacesContext context, Object data) {
- Data dataObject = createData();
- saveData(context, dataObject);
-
- return dataObject.toByteArray();
+
+ if (headerIntColor == null) {
+ headerIntColor = getColorValueParameter(context, gradientColor, false);
}
-
- public boolean isCacheable() {
- return true;
- }
-
- protected String getValueParameter(FacesContext context, String name) {
- SkinFactory skinFactory = SkinFactory.getInstance();
+ if (!(baseIntColor == null && headerIntColor == null)) {
+ if (baseIntColor == null) {
+ baseIntColor = getColorValueParameter(context, baseColor, true);
+ }
- Skin skin = skinFactory.getSkin(context);
- String value = (String) skin.getParameter(context, name);
-
- if (value == null || value.length() == 0) {
- skin = skinFactory.getDefaultSkin(context);
- value = (String) skin.getParameter(context, name);
+ if (headerIntColor == null) {
+ headerIntColor = getColorValueParameter(context, gradientColor, true);
}
-
- return value;
}
- protected Integer getColorValueParameter(FacesContext context, String name, boolean
useDefault) {
- Skin skin;
- if (useDefault) {
- skin = SkinFactory.getInstance().getDefaultSkin(context);
- } else {
- skin = SkinFactory.getInstance().getSkin(context);
- }
-
- String tmp = (String) skin.getParameter(context,name);
- if (tmp!=null && tmp.length() != 0) {
- return new Integer(HtmlColor.decode(tmp).getRGB());
- } else {
- return null;
- }
+ data.setHeaderBackgroundColor(baseIntColor);
+ data.setHeaderGradientColor(headerIntColor);
+
+ if (gradientTypeString == null || gradientTypeString.length() == 0) {
+ gradientTypeString = getValueParameter(context, Skin.gradientType);
}
- protected static class Data implements Serializable {
- public Data() {
- }
+ data.setGradientType(GradientType.getBySkinParameter(gradientTypeString));
+ data.setGradientAlignment(GradientAlignment.getByParameter(alignmentString));
+ }
- /**
- *
- */
- private static final long serialVersionUID = 1732700513743861250L;
- private Integer headerBackgroundColor;
- private Integer headerGradientColor;
- private GradientType gradientType;
-
- public byte[] toByteArray() {
- if (headerBackgroundColor != null && headerGradientColor != null &&
gradientType != null) {
- byte[] ret = new byte[7];
- new
Zipper2(ret).addColor(headerBackgroundColor.intValue()).addColor(headerGradientColor.intValue()).
- addByte((byte) gradientType.ordinal());
- return ret;
- } else {
- return null;
- }
- }
+ protected void saveData(FacesContext context, Data data, Object parameterData) {
+ if (baseColor == null) {
+ saveData(context, data, Skin.headerBackgroundColor, "headerGradientColor",
parameterData);
+ } else {
+ saveData(context, data, baseColor, gradientColor, parameterData);
+ }
+ }
- public Integer getHeaderBackgroundColor() {
- return headerBackgroundColor;
- }
+ protected Object getDataToStore(FacesContext context, Object data) {
+ Data dataObject = createData();
+ saveData(context, dataObject, data);
- public void setHeaderBackgroundColor(Integer headerBackgroundColor) {
- this.headerBackgroundColor = headerBackgroundColor;
- }
+ return dataObject.toByteArray();
+ }
- public Integer getHeaderGradientColor() {
- return headerGradientColor;
- }
+ public boolean isCacheable() {
+ return true;
+ }
- public void setHeaderGradientColor(Integer headerGradientColor) {
- this.headerGradientColor = headerGradientColor;
- }
- public GradientType getGradientType() {
- return gradientType;
- }
+ protected String getValueParameter(FacesContext context, String name) {
+ SkinFactory skinFactory = SkinFactory.getInstance();
- public void setGradientType(GradientType gradientType) {
- this.gradientType = gradientType;
- }
-
+ Skin skin = skinFactory.getSkin(context);
+ String value = (String) skin.getParameter(context, name);
+
+ if (value == null || value.length() == 0) {
+ skin = skinFactory.getDefaultSkin(context);
+ value = (String) skin.getParameter(context, name);
}
+ return value;
+ }
+
+ protected Integer getColorValueParameter(FacesContext context, String name, boolean
useDefault) {
+ Skin skin;
+ if (useDefault) {
+ skin = SkinFactory.getInstance().getDefaultSkin(context);
+ } else {
+ skin = SkinFactory.getInstance().getSkin(context);
+ }
+
+ return decodeColor((String) skin.getParameter(context,name));
+ }
+
+ protected static class Data implements Serializable {
+ public Data() {
+ }
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1732700513743861250L;
+ private Integer headerBackgroundColor;
+ private Integer headerGradientColor;
+ private GradientType gradientType;
+ private GradientAlignment gradientAlignment;
+
+ public byte[] toByteArray() {
+ if (headerBackgroundColor != null && headerGradientColor != null &&
gradientType != null) {
+ byte[] ret = new byte[8];
+ new
Zipper2(ret).addColor(headerBackgroundColor.intValue()).addColor(headerGradientColor.intValue()).
+ addByte((byte) gradientType.ordinal()).addByte((byte) gradientAlignment.ordinal());
+ return ret;
+ } else {
+ return null;
+ }
+ }
+
+ public Integer getHeaderBackgroundColor() {
+ return headerBackgroundColor;
+ }
+
+ public void setHeaderBackgroundColor(Integer headerBackgroundColor) {
+ this.headerBackgroundColor = headerBackgroundColor;
+ }
+
+ public Integer getHeaderGradientColor() {
+ return headerGradientColor;
+ }
+
+ public void setHeaderGradientColor(Integer headerGradientColor) {
+ this.headerGradientColor = headerGradientColor;
+ }
+
+ public GradientType getGradientType() {
+ return gradientType;
+ }
+
+ public void setGradientType(GradientType gradientType) {
+ this.gradientType = gradientType;
+ }
+
+ public GradientAlignment getGradientAlignment() {
+ return gradientAlignment;
+ }
+
+ public void setGradientAlignment(GradientAlignment gradientAlignment) {
+ this.gradientAlignment = gradientAlignment;
+ }
+
+ }
+
}
Modified:
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java 2008-04-22
16:58:34 UTC (rev 8077)
+++
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java 2008-04-22
17:21:16 UTC (rev 8078)
@@ -87,8 +87,8 @@
}
@Override
- protected void saveData(FacesContext context,
org.richfaces.renderkit.html.BaseGradient.Data data) {
- super.saveData(context, data);
+ protected void saveData(FacesContext context,
org.richfaces.renderkit.html.BaseGradient.Data data, Object parameterData) {
+ super.saveData(context, data, parameterData);
((Data) data).setHeight(getHeight(context));
}
@@ -125,13 +125,5 @@
this.height = height;
}
- public GradientType getGradientType() {
- return GradientType.PLAIN;
- }
-
- public void setGradientType(GradientType gradientType) {
- //does nothing
- }
-
};
}
Added:
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/GradientAlignment.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/GradientAlignment.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/GradientAlignment.java 2008-04-22
17:21:16 UTC (rev 8078)
@@ -0,0 +1,83 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.renderkit.html.images;
+
+
+
+/**
+ * Created 22.04.2008
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public enum GradientAlignment {
+ TOP {
+ @Override
+ public int getBottomRectangleHeight(int imageHeight, int gradientHeight) {
+ return imageHeight - gradientHeight;
+ }
+
+ @Override
+ public int getTopRectangleHeight(int imageHeight, int gradientHeight) {
+ return 0;
+ }
+ },
+
+ CENTER {
+ @Override
+ public int getBottomRectangleHeight(int imageHeight, int gradientHeight) {
+ return (imageHeight - gradientHeight) / 2;
+ }
+
+ @Override
+ public int getTopRectangleHeight(int imageHeight, int gradientHeight) {
+ return getBottomRectangleHeight(imageHeight, gradientHeight);
+ }
+ },
+
+ BOTTOM {
+ @Override
+ public int getBottomRectangleHeight(int imageHeight, int gradientHeight) {
+ return 0;
+ }
+
+ @Override
+ public int getTopRectangleHeight(int imageHeight, int gradientHeight) {
+ return imageHeight - gradientHeight;
+ }
+ };
+
+ public static final GradientAlignment getByParameter(String string) {
+ if (string == null || string.length() == 0) {
+ return TOP;
+ }
+
+ return GradientAlignment.valueOf(string.toUpperCase());
+ }
+
+ public abstract int getTopRectangleHeight(int imageHeight, int gradientHeight);
+
+ public abstract int getBottomRectangleHeight(int imageHeight, int gradientHeight);
+
+
+
+}
Modified: trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java 2008-04-22
16:58:34 UTC (rev 8077)
+++ trunk/framework/impl/src/main/java/org/richfaces/skin/SkinFactoryImpl.java 2008-04-22
17:21:16 UTC (rev 8078)
@@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import java.util.Map.Entry;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
@@ -248,6 +249,38 @@
}
}
+ private void processProperties(Map<Object, Object> properties) {
+ // replace all EL-expressions by prepared ValueBinding ?
+ ApplicationFactory factory = (ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY);
+ Application app = factory.getApplication();
+
+ for (Entry<Object, Object> entry : properties.entrySet()) {
+ String propertyName = (String) entry.getKey();
+ Object propertyObject = entry.getValue();
+ if (propertyObject instanceof String) {
+ String property = (String) propertyObject;
+ int count = 0;
+ while (property.startsWith("&")) {
+ property = (String) properties.get(property.substring(1));
+ if (null == property) {
+ throw new FacesException(Messages.getMessage(
+ Messages.SKIN_ILLEGAL_REFERENCE, propertyName));
+ }
+ if (count++ > 1000) {
+ throw new FacesException(Messages.getMessage(
+ Messages.SKIN_CYCLIC_REFERENCE, propertyName));
+ }
+ }
+ if (ELUtils.isValueReference(property)) {
+ entry.setValue(app.createValueBinding(property));
+ } else {
+ entry.setValue(property);
+ }
+ }
+ }
+ }
+
/**
* Factory method for build skin from properties files. for given skin name,
* search in classpath all resources with name 'name'.skin.properties and
@@ -264,8 +297,37 @@
*/
protected Skin buildSkin(String name, Properties defaultProperties)
throws SkinNotFoundException {
- Map skinParams = loadProperties(name, defaultProperties, SKINS_PATHS);
- return new SkinImpl(skinParams);
+
+ String baseSkinName = name;
+ int counter = 0;
+
+ Map<Object, Object> result = new HashMap<Object, Object>();
+ do {
+ Map<Object, Object> skinParams = loadProperties(baseSkinName, SKINS_PATHS);
+ for (Entry<Object, Object> entry : skinParams.entrySet()) {
+ Object key = entry.getKey();
+ if (!result.containsKey(key)) {
+ result.put(key, entry.getValue());
+ }
+ }
+
+ baseSkinName = (String) skinParams.get(Skin.baseSkin);
+
+ if (counter++ > 1000) {
+ throw new IllegalStateException("Cyclic base skin!");
+ }
+
+ } while (baseSkinName != null);
+
+ for (Entry<Object, Object> entry : defaultProperties.entrySet()) {
+ if (!result.containsKey(entry.getKey())) {
+ result.put(entry.getKey(), entry.getValue());
+ }
+ }
+
+ processProperties(result);
+
+ return new SkinImpl(result);
}
/**
@@ -276,12 +338,11 @@
* @throws FacesException
* @throws ReferenceSyntaxException
*/
- protected Map loadProperties(String name, Properties defaultProperties,
- String[] paths) throws SkinNotFoundException, FacesException,
+ protected Map loadProperties(String name, String[] paths) throws SkinNotFoundException,
FacesException,
ReferenceSyntaxException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
// Get properties for concrete skin.
- Properties skinProperties = new Properties(defaultProperties);
+ Properties skinProperties = new Properties();
int loadedPropertiesCount = 0;
for (int i = 0; i < paths.length; i++) {
try {
@@ -320,38 +381,7 @@
throw new SkinNotFoundException(Messages.getMessage(
Messages.SKIN_NOT_FOUND_ERROR, name));
}
- // replace all EL-expressions by prepared ValueBinding ?
- ApplicationFactory factory = (ApplicationFactory) FactoryFinder
- .getFactory(FactoryFinder.APPLICATION_FACTORY);
- Application app = factory.getApplication();
- Map skinParams = new HashMap();
- for (Enumeration e = skinProperties.propertyNames(); e
- .hasMoreElements();) {
- String propertyName = (String) e.nextElement();
- String property = skinProperties.getProperty(propertyName);
- if (null != property) {
- int count = 0;
- while (property.startsWith("&")) {
- property = skinProperties
- .getProperty(property.substring(1));
- if (null == property) {
- throw new FacesException(Messages.getMessage(
- Messages.SKIN_ILLEGAL_REFERENCE, propertyName));
- }
- if (count++ > 1000) {
- throw new FacesException(Messages.getMessage(
- Messages.SKIN_CYCLIC_REFERENCE, propertyName));
- }
- }
- if (ELUtils.isValueReference(property)) {
- skinParams.put(propertyName, app
- .createValueBinding(property));
- } else {
- skinParams.put(propertyName, property);
- }
- }
- }
- return skinParams;
+ return skinProperties;
}
}