Author: nbelaevski
Date: 2010-07-22 12:25:19 -0400 (Thu, 22 Jul 2010)
New Revision: 18200
Removed:
root/core/trunk/impl/src/main/java/org/richfaces/resource/AnimatedTestResource.java
root/core/trunk/impl/src/main/java/org/richfaces/resource/TestResource2.java
Modified:
root/core/trunk/api/src/main/java/org/richfaces/skin/Skin.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/StandardButtonBgImage.java
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/StandardButtonPressedBgImage.java
root/core/trunk/impl/src/main/java/org/richfaces/skin/AbstractSkin.java
root/core/trunk/impl/src/main/java/org/richfaces/skin/SkinBean.java
Log:
Added getIntegerParameter() method into Skin
Dynamic resources code updated
Unit test failure fixed
Modified: root/core/trunk/api/src/main/java/org/richfaces/skin/Skin.java
===================================================================
--- root/core/trunk/api/src/main/java/org/richfaces/skin/Skin.java 2010-07-22 16:06:49 UTC
(rev 18199)
+++ root/core/trunk/api/src/main/java/org/richfaces/skin/Skin.java 2010-07-22 16:25:19 UTC
(rev 18200)
@@ -304,6 +304,10 @@
*/
public Integer getColorParameter(FacesContext context, String name, Object
defaultValue);
+ public Integer getIntegerParameter(FacesContext context, String name);
+
+ public Integer getIntegerParameter(FacesContext context, String name, Object
defaultValue);
+
/**
* @param name
* @return
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2010-07-22
16:06:49 UTC (rev 18199)
+++
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2010-07-22
16:25:19 UTC (rev 18200)
@@ -31,22 +31,26 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
+import java.util.Date;
+import java.util.Map;
import javax.faces.context.FacesContext;
-import org.ajax4jsf.resource.Java2Dresource;
import org.richfaces.renderkit.html.images.GradientType;
import org.richfaces.renderkit.html.images.GradientType.BiColor;
import org.richfaces.resource.DynamicResource;
import org.richfaces.resource.ImageType;
+import org.richfaces.resource.Java2DUserResource;
+import org.richfaces.resource.StateHolderResource;
import org.richfaces.skin.Skin;
+import org.richfaces.skin.SkinFactory;
/**
* @author Nick Belaevski - nbelaevski(a)exadel.com
* created 02.02.2007
*/
@DynamicResource
-public class BaseGradient extends Java2Dresource {
+public class BaseGradient implements Java2DUserResource, StateHolderResource {
protected Integer headerBackgroundColor;
protected Integer headerGradientColor;
@@ -61,7 +65,6 @@
public BaseGradient(int width, int height, int gradientHeight, String baseColor,
String gradientColor,
boolean horizontal) {
- super(ImageType.PNG);
this.width = width;
this.height = height;
this.gradientHeight = gradientHeight;
@@ -118,34 +121,14 @@
private void initialize() {
FacesContext context = FacesContext.getCurrentInstance();
+ Skin skin = SkinFactory.getInstance(context).getSkin(context);
+
+ this.headerBackgroundColor = skin.getColorParameter(context, baseColor);
+ this.headerGradientColor = skin.getColorParameter(context, gradientColor);
- Integer baseIntColor = null;
- Integer headerIntColor = null;
String gradientTypeString = null;
-
- if (baseIntColor == null) {
- baseIntColor = getColorValueParameter(context, baseColor, false);
- }
-
- if (headerIntColor == null) {
- headerIntColor = getColorValueParameter(context, gradientColor, false);
- }
-
- if (!(baseIntColor == null && headerIntColor == null)) {
- if (baseIntColor == null) {
- baseIntColor = getColorValueParameter(context, baseColor, true);
- }
-
- if (headerIntColor == null) {
- headerIntColor = getColorValueParameter(context, gradientColor, true);
- }
- }
-
- this.headerBackgroundColor = baseIntColor;
- this.headerGradientColor = headerIntColor;
-
if (gradientTypeString == null || gradientTypeString.length() == 0) {
- gradientTypeString = getValueParameter(context, Skin.GRADIENT_TYPE);
+ gradientTypeString = (String) skin.getParameter(context,
Skin.GRADIENT_TYPE);
}
this.gradientType = GradientType.getByParameter(gradientTypeString);
@@ -199,10 +182,7 @@
}
}
- @Override
- protected void paint(Graphics2D graphics2d, Dimension dimension) {
- super.paint(graphics2d, dimension);
-
+ public void paint(Graphics2D graphics2d, Dimension dimension) {
graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics2d.setRenderingHint(RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE);
@@ -257,19 +237,31 @@
}
public void readState(FacesContext context, DataInput dataInput) throws IOException
{
- super.readState(context, dataInput);
this.headerBackgroundColor = dataInput.readInt();
this.headerGradientColor = dataInput.readInt();
this.gradientType = GradientType.values()[dataInput.readByte()];
}
- @Override
public void writeState(FacesContext context, DataOutput dataOutput) throws
IOException {
- super.writeState(context, dataOutput);
-
dataOutput.writeInt(this.headerBackgroundColor);
dataOutput.writeInt(this.headerGradientColor);
dataOutput.writeByte((byte) this.gradientType.ordinal());
}
+ public Map<String, String> getResponseHeaders() {
+ return null;
+ }
+
+ public Date getLastModified() {
+ return null;
+ }
+
+ public ImageType getImageType() {
+ return ImageType.PNG;
+ }
+
+ public boolean isTransient() {
+ return false;
+ }
+
}
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java 2010-07-22
16:06:49 UTC (rev 18199)
+++
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/BaseControlBackgroundImage.java 2010-07-22
16:25:19 UTC (rev 18200)
@@ -29,6 +29,7 @@
import org.richfaces.renderkit.html.BaseGradient;
import org.richfaces.skin.Skin;
+import org.richfaces.skin.SkinFactory;
/**
* Created 23.02.2008
@@ -39,8 +40,7 @@
public abstract class BaseControlBackgroundImage extends BaseGradient {
- //TODO - lazy initialize?
- private Integer height = getHeight(FacesContext.getCurrentInstance(),
Skin.GENERAL_SIZE_FONT);
+ private Integer height = null;
public BaseControlBackgroundImage(String baseColor, String gradientColor, int width)
{
super(width, -1, baseColor, gradientColor);
@@ -56,6 +56,8 @@
DataOutput stream) throws IOException {
super.writeState(context, stream);
+ this.height = getHeight(context, Skin.GENERAL_SIZE_FONT);
+
stream.writeInt(this.height);
}
@@ -69,4 +71,9 @@
this.gradientType = GradientType.PLAIN;
}
+ public Integer getHeight(FacesContext context, String parameterName) {
+ Skin skin = SkinFactory.getInstance(context).getSkin(context);
+ return skin.getIntegerParameter(context, parameterName);
+ }
+
}
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/StandardButtonBgImage.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/StandardButtonBgImage.java 2010-07-22
16:06:49 UTC (rev 18199)
+++
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/StandardButtonBgImage.java 2010-07-22
16:25:19 UTC (rev 18200)
@@ -21,16 +21,16 @@
package org.richfaces.renderkit.html.images;
+import javax.faces.context.FacesContext;
+
import org.richfaces.skin.Skin;
-import javax.faces.context.FacesContext;
-
public class StandardButtonBgImage extends BaseControlBackgroundImage {
public StandardButtonBgImage() {
super(Skin.ADDITIONAL_BACKGROUND_COLOR, "trimColor", 9);
}
protected Integer getHeight(FacesContext context) {
- return (int) (1.7 * super.getHeight(context, Skin.BUTTON_SIZE_FONT));
+ return (int) (1.7 * getHeight(context, Skin.BUTTON_SIZE_FONT));
}
}
Modified:
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/StandardButtonPressedBgImage.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/StandardButtonPressedBgImage.java 2010-07-22
16:06:49 UTC (rev 18199)
+++
root/core/trunk/impl/src/main/java/org/richfaces/renderkit/html/images/StandardButtonPressedBgImage.java 2010-07-22
16:25:19 UTC (rev 18200)
@@ -21,16 +21,16 @@
package org.richfaces.renderkit.html.images;
+import javax.faces.context.FacesContext;
+
import org.richfaces.skin.Skin;
-import javax.faces.context.FacesContext;
-
public class StandardButtonPressedBgImage extends BaseControlBackgroundImage {
public StandardButtonPressedBgImage() {
super("trimColor", Skin.ADDITIONAL_BACKGROUND_COLOR, 9);
}
protected Integer getHeight(FacesContext context) {
- return (int) (1.7 * super.getHeight(context, Skin.BUTTON_SIZE_FONT));
+ return (int) (1.7 * getHeight(context, Skin.BUTTON_SIZE_FONT));
}
}
Deleted:
root/core/trunk/impl/src/main/java/org/richfaces/resource/AnimatedTestResource.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/AnimatedTestResource.java 2010-07-22
16:06:49 UTC (rev 18199)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/AnimatedTestResource.java 2010-07-22
16:25:19 UTC (rev 18200)
@@ -1,168 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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.resource;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.GradientPaint;
-import java.awt.Graphics2D;
-import java.awt.GraphicsEnvironment;
-import java.awt.color.ColorSpace;
-import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-
-import javax.imageio.IIOImage;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageTypeSpecifier;
-import javax.imageio.ImageWriteParam;
-import javax.imageio.ImageWriter;
-import javax.imageio.metadata.IIOMetadata;
-import javax.imageio.metadata.IIOMetadataNode;
-import javax.imageio.stream.ImageOutputStream;
-
-import org.w3c.dom.Node;
-
-public class AnimatedTestResource extends TestResource2 {
- private static final int DELAY_TIME = 50;
- private static final int FRAMES_COUNT = 10;
-
- private static ImageWriter getImageWriter() {
- ImageWriter result = null;
- Iterator<ImageWriter> imageWriters =
ImageIO.getImageWritersByFormatName("gif");
-
- while (imageWriters.hasNext() && (result == null)) {
- ImageWriter imageWriter = imageWriters.next();
-
- if (imageWriter.canWriteSequence()) {
- result = imageWriter;
- }
- }
-
- return result;
- }
-
- private static Node getOrCreateChild(Node root, String name) {
- Node result = null;
-
- for (Node node = root.getFirstChild(); (node != null) && (result ==
null); node = node.getNextSibling()) {
- if (name.equals(node.getNodeName())) {
- result = node;
- }
- }
-
- if (result == null) {
- result = new IIOMetadataNode(name);
- root.appendChild(result);
- }
-
- return result;
- }
-
- @Override
- public String getContentType() {
- return "image/gif";
- }
-
- @Override
- public InputStream getInputStream() throws IOException {
- GraphicsEnvironment environment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
- Dimension dimension = getDimension();
- BufferedImage image = new BufferedImage(dimension.width, dimension.height,
ColorSpace.TYPE_RGB);
- Graphics2D g2d = environment.createGraphics(image);
- ImageWriter sequenceCapableImageWriter = getImageWriter();
-
- if (sequenceCapableImageWriter == null) {
- throw new IllegalStateException("No sequence-capable image writers
exit");
- }
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ImageOutputStream imageOutputStream = null;
-
- try {
- imageOutputStream = ImageIO.createImageOutputStream(baos);
- sequenceCapableImageWriter.setOutput(imageOutputStream);
-
- ImageWriteParam defaultImageWriteParam =
sequenceCapableImageWriter.getDefaultWriteParam();
- ImageTypeSpecifier imageTypeSpecifier =
ImageTypeSpecifier.createFromBufferedImageType(image.getType());
- IIOMetadata imageMetaData =
sequenceCapableImageWriter.getDefaultImageMetadata(imageTypeSpecifier,
- defaultImageWriteParam);
- String metaFormatName = imageMetaData.getNativeMetadataFormatName();
- Node root = imageMetaData.getAsTree(metaFormatName);
- IIOMetadataNode graphicsControlExtensionNode = (IIOMetadataNode)
getOrCreateChild(root,
- "GraphicControlExtension");
-
- //
http://java.sun.com/javase/6/docs/api/javax/imageio/metadata/doc-files/gi...
- graphicsControlExtensionNode.setAttribute("disposalMethod",
"none");
- graphicsControlExtensionNode.setAttribute("userInputFlag",
"FALSE");
- graphicsControlExtensionNode.setAttribute("transparentColorFlag",
"FALSE");
- graphicsControlExtensionNode.setAttribute("delayTime",
Integer.toString(DELAY_TIME));
- graphicsControlExtensionNode.setAttribute("transparentColorIndex",
"0");
-
- boolean loopContinuously = false;
- Node applicationExtensionsNode = getOrCreateChild(root,
"ApplicationExtensions");
- IIOMetadataNode netscapeExtension = new
IIOMetadataNode("ApplicationExtension");
-
- netscapeExtension.setAttribute("applicationID",
"NETSCAPE");
- netscapeExtension.setAttribute("authenticationCode",
"2.0");
-
- byte numLoops = (byte) (loopContinuously ? 0x0 : 0x1);
-
- netscapeExtension.setUserObject(new byte[]{0x1, numLoops, 0x0});
- applicationExtensionsNode.appendChild(netscapeExtension);
- imageMetaData.setFromTree(metaFormatName, root);
- sequenceCapableImageWriter.prepareWriteSequence(null);
-
- for (int i = 1; i <= FRAMES_COUNT; i++) {
- g2d.setPaint(new GradientPaint(0, i * dimension.height / FRAMES_COUNT,
Color.WHITE, 0,
- dimension.height, getColor()));
- g2d.fillRect(0, 0, dimension.width, dimension.height);
- sequenceCapableImageWriter.writeToSequence(new IIOImage(image, null,
imageMetaData),
- defaultImageWriteParam);
- }
-
- sequenceCapableImageWriter.endWriteSequence();
- } catch (IOException e) {
-
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- if (imageOutputStream != null) {
- try {
- imageOutputStream.close();
- } catch (IOException e) {
-
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- g2d.dispose();
- sequenceCapableImageWriter.dispose();
- }
-
- return new ByteArrayInputStream(baos.toByteArray());
- }
-}
Deleted: root/core/trunk/impl/src/main/java/org/richfaces/resource/TestResource2.java
===================================================================
---
root/core/trunk/impl/src/main/java/org/richfaces/resource/TestResource2.java 2010-07-22
16:06:49 UTC (rev 18199)
+++
root/core/trunk/impl/src/main/java/org/richfaces/resource/TestResource2.java 2010-07-22
16:25:19 UTC (rev 18200)
@@ -1,105 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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.resource;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.GradientPaint;
-import java.awt.Graphics2D;
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.resource.Java2Dresource;
-import org.ajax4jsf.util.HtmlColor;
-import org.richfaces.VersionBean;
-import org.richfaces.skin.Skin;
-import org.richfaces.skin.SkinFactory;
-
-@DynamicResource
-public class TestResource2 extends Java2Dresource implements VersionedResource {
-
- private static final int MASK_FOR_COLOR_WITHOUT_ALPHA_CHANNEL = 0x00FFFFFF;
-
- private Color color;
-
- private Dimension dimension = new Dimension(20, 150);
-
- public TestResource2() {
- super(ImageType.PNG);
- FacesContext context = FacesContext.getCurrentInstance();
- Skin skin = SkinFactory.getInstance().getSkin(context);
- Object parameter = skin.getParameter(context, Skin.HEADER_GRADIENT_COLOR);
- this.color = HtmlColor.decode(parameter.toString());
- }
-
- @Override
- protected void paint(Graphics2D graphics2d, Dimension dim) {
- super.paint(graphics2d, dim);
-
- graphics2d.setPaint(new GradientPaint(0, 0, Color.WHITE, dim.width, dim.height,
color));
- graphics2d.fillRect(0, 0, dim.width, dim.height);
- }
-
- @Override
- public void readState(FacesContext context, DataInput stream) throws IOException {
- super.readState(context, stream);
- this.color = new Color(stream.readInt());
- }
-
- @Override
- public void writeState(FacesContext context, DataOutput stream) throws IOException {
- super.writeState(context, stream);
- stream.writeInt(this.color.getRGB());
- }
-
- @Override
- public String getEntityTag(FacesContext context) {
- return ResourceUtils.formatWeakTag(getColorWitoutAlphaChanel());
- }
-
- private String getColorWitoutAlphaChanel() {
- return Integer.toHexString(color.getRGB() &
MASK_FOR_COLOR_WITHOUT_ALPHA_CHANNEL);
- }
-
- public String getVersion() {
- return VersionBean.VERSION.getResourceVersion();
- }
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.resource.Java2Dresource#getDimension()
- */
- @Override
- public Dimension getDimension() {
- return dimension;
- }
-
- public Color getColor() {
- return color;
- }
-
- public void setColor(Color color) {
- this.color = color;
- }
-}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/skin/AbstractSkin.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/skin/AbstractSkin.java 2010-07-22
16:06:49 UTC (rev 18199)
+++ root/core/trunk/impl/src/main/java/org/richfaces/skin/AbstractSkin.java 2010-07-22
16:25:19 UTC (rev 18200)
@@ -26,6 +26,7 @@
import javax.faces.context.FacesContext;
import org.ajax4jsf.util.HtmlColor;
+import org.ajax4jsf.util.HtmlDimensions;
/**
* @author Nick Belaevski
@@ -48,6 +49,19 @@
}
}
+ protected Integer decodeInteger(Object value) {
+ if (value instanceof Number) {
+ return Integer.valueOf(((Number) value).intValue());
+ } else {
+ String stringValue = (String) value;
+ if (stringValue != null && stringValue.length() != 0) {
+ return (int) HtmlDimensions.decode(stringValue).doubleValue();
+ } else {
+ return null;
+ }
+ }
+ }
+
public Integer getColorParameter(FacesContext context, String name) {
return decodeColor(getParameter(context, name));
}
@@ -56,4 +70,11 @@
return decodeColor(getParameter(context, name, defaultValue));
}
+ public Integer getIntegerParameter(FacesContext context, String name) {
+ return decodeInteger(getParameter(context, name));
+ }
+
+ public Integer getIntegerParameter(FacesContext context, String name, Object
defaultValue) {
+ return decodeInteger(getParameter(context, name, defaultValue));
+ }
}
Modified: root/core/trunk/impl/src/main/java/org/richfaces/skin/SkinBean.java
===================================================================
--- root/core/trunk/impl/src/main/java/org/richfaces/skin/SkinBean.java 2010-07-22
16:06:49 UTC (rev 18199)
+++ root/core/trunk/impl/src/main/java/org/richfaces/skin/SkinBean.java 2010-07-22
16:25:19 UTC (rev 18200)
@@ -149,4 +149,18 @@
public Integer getColorParameter(FacesContext context, String name, Object
defaultValue) {
return getSkin().getColorParameter(context, name, defaultValue);
}
+
+ /* (non-Javadoc)
+ * @see org.richfaces.skin.Skin#getIntegerParameter(javax.faces.context.FacesContext,
java.lang.String)
+ */
+ public Integer getIntegerParameter(FacesContext context, String name) {
+ return getSkin().getIntegerParameter(context, name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.skin.Skin#getIntegerParameter(javax.faces.context.FacesContext,
java.lang.String, java.lang.Object)
+ */
+ public Integer getIntegerParameter(FacesContext context, String name, Object
defaultValue) {
+ return getSkin().getIntegerParameter(context, name, defaultValue);
+ }
}