Author: dsvyatobatsko
Date: 2008-01-16 08:39:28 -0500 (Wed, 16 Jan 2008)
New Revision: 5412
Modified:
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ProgressBarAnimatedBg.java
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ProgressBarBg.java
Log:
adjusted animated gif generation for progressbar in accordance with the given mockup
Modified:
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ProgressBarAnimatedBg.java
===================================================================
---
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ProgressBarAnimatedBg.java 2008-01-16
13:31:05 UTC (rev 5411)
+++
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ProgressBarAnimatedBg.java 2008-01-16
13:39:28 UTC (rev 5412)
@@ -20,7 +20,6 @@
*/
package org.richfaces.renderkit.html.images;
-import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
@@ -31,6 +30,8 @@
import javax.faces.context.FacesContext;
import org.ajax4jsf.resource.AnimationResource;
+import org.ajax4jsf.resource.ImageRenderer;
+import org.ajax4jsf.resource.InternetResourceBase;
import org.ajax4jsf.resource.Java2Dresource;
import org.ajax4jsf.resource.ResourceContext;
import org.ajax4jsf.util.HtmlColor;
@@ -45,6 +46,8 @@
private Color progressbarSpiralColor;
private Color progressbarBackgroundColor;
+ private Color progressbarShadowColor;
+
private Color progressbarShadowStartColor;
private Color progressbarShadowEndColor;
@@ -73,24 +76,26 @@
@Override
protected void paint(ResourceContext context, Graphics2D g2d, int frameIndex) {
if (mainStage == null) {
- mainStage = createMainStage();
+ mainStage = createMainStage(context);
}
BufferedImage frame = mainStage.getSubimage(0, 48 - frameIndex * 4, frameSize.width,
frameSize.height);
g2d.drawImage(frame, null, null);
// paint a shadow in the form of semi-transparent gradient
g2d.setPaint(new GradientPaint(0, 0, progressbarShadowStartColor, 0, 7,
progressbarShadowEndColor));
- g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
g2d.fillRect(0, 0, frameSize.width, 7);
}
/**
* Creates a main stage for progress bar background.
*
+ * @param context resource context
* @return a <code>BufferedImage</code> object
*/
- private BufferedImage createMainStage() {
- BufferedImage retVal = new BufferedImage(frameSize.width,
- frameSize.height * 2, BufferedImage.TYPE_INT_ARGB);
+ private BufferedImage createMainStage(ResourceContext ctx) {
+ progressbarSpiralColor = overwriteAlpha(progressbarSpiralColor, 0.38f);
+ progressbarShadowStartColor = overwriteAlpha(progressbarShadowColor, 0.6f);
+ progressbarShadowEndColor = overwriteAlpha(progressbarShadowColor, 0.2f);
+ BufferedImage retVal = ((ImageRenderer) getRenderer(ctx)).createImage(frameSize.width,
frameSize.height * 2);
Graphics g = retVal.getGraphics();
g.setColor(progressbarBackgroundColor);
g.fillRect(0, 0, frameSize.width, frameSize.height * 2);
@@ -104,6 +109,9 @@
return retVal;
}
+ /**
+ * @see InternetResourceBase#getDataToStore(FacesContext, Object)
+ */
protected Object getDataToStore(FacesContext context, Object data) {
byte[] retVal = null;
if (progressbarSpiralColor == null) {
@@ -112,35 +120,32 @@
if (progressbarBackgroundColor == null) {
progressbarBackgroundColor = getColorValueParameter(context,
"progressbarBackgroundColor");
}
- if (progressbarShadowStartColor == null) {
- progressbarShadowStartColor = getColorValueParameter(context,
"progressbarShadowStartColor");
+ if (progressbarShadowColor == null) {
+ progressbarShadowColor = getColorValueParameter(context,
"progressbarShadowColor");
}
- if (progressbarShadowEndColor == null) {
- progressbarShadowEndColor = getColorValueParameter(context,
"progressbarShadowEndColor");
- }
- retVal = new byte[3 * 4];
+ retVal = new byte[3 * 3];
new Zipper2(retVal).addColor(progressbarSpiralColor).addColor(
- progressbarBackgroundColor).addColor(
- progressbarShadowStartColor)
- .addColor(progressbarShadowEndColor);
+ progressbarBackgroundColor).addColor(progressbarShadowColor);
return retVal;
}
+ /**
+ * @see InternetResourceBase#deserializeData(byte[])
+ */
protected Object deserializeData(byte[] objectArray) {
if (objectArray != null) {
Zipper2 zipper2 = new Zipper2(objectArray);
progressbarSpiralColor = zipper2.nextColor();
progressbarBackgroundColor = zipper2.nextColor();
- progressbarShadowStartColor = zipper2.nextColor();
- progressbarShadowEndColor = zipper2.nextColor();
+ progressbarShadowColor = zipper2.nextColor();
}
return objectArray;
}
- private Color getColorValueParameter(FacesContext context, String name) {
+ private Color getColorValueParameter(FacesContext context, String name) {
Color retVal = null;
String color = (String)
SkinFactory.getInstance().getSkin(context).getParameter(context, name);
if (color != null && !color.trim().equals("")) {
@@ -149,4 +154,20 @@
return retVal;
}
+ /**
+ * Overwrites alpha value for given color.
+ *
+ * @param c color to overwrite
+ * @param alpha a new value of alpha
+ * @return a new <code>Color</code> object with a new specified alpha value
+ */
+ private Color overwriteAlpha(Color c, float alpha) {
+ Color retVal = c;
+ if (c != null) {
+ retVal = new Color(c.getRed(), c.getGreen(), c.getBlue(),
+ (int) (alpha * 255 + 0.5));
+ }
+ return retVal;
+ }
+
}
Modified:
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ProgressBarBg.java
===================================================================
---
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ProgressBarBg.java 2008-01-16
13:31:05 UTC (rev 5411)
+++
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ProgressBarBg.java 2008-01-16
13:39:28 UTC (rev 5412)
@@ -20,7 +20,6 @@
*/
package org.richfaces.renderkit.html.images;
-import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
@@ -30,6 +29,7 @@
import javax.faces.context.FacesContext;
+import org.ajax4jsf.resource.InternetResourceBase;
import org.ajax4jsf.resource.InternetResourceBuilder;
import org.ajax4jsf.resource.Java2Dresource;
import org.ajax4jsf.resource.PngRenderer;
@@ -44,6 +44,8 @@
private Color progressbarSpiralColor;
private Color progressbarBackgroundColor;
+ private Color progressbarShadowColor;
+
private Color progressbarShadowStartColor;
private Color progressbarShadowEndColor;
@@ -84,6 +86,9 @@
* </p>
*/
protected void paint(ResourceContext context, Graphics2D g2d) {
+ progressbarSpiralColor = overwriteAlpha(progressbarSpiralColor, 0.38f);
+ progressbarShadowStartColor = overwriteAlpha(progressbarShadowColor, 0.6f);
+ progressbarShadowEndColor = overwriteAlpha(progressbarShadowColor, 0.2f);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(progressbarBackgroundColor);
g2d.fillRect(0, 0, dim.width, dim.height);
@@ -94,10 +99,12 @@
}
//paint a shadow in the form of semi-transparent gradient
g2d.setPaint(new GradientPaint(0, 0, progressbarShadowStartColor, 0, 7,
progressbarShadowEndColor));
- g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
g2d.fillRect(0, 0, dim.width, 7);
}
+ /**
+ * @see InternetResourceBase#getDataToStore(FacesContext, Object)
+ */
protected Object getDataToStore(FacesContext context, Object data) {
byte[] retVal = null;
if (progressbarSpiralColor == null) {
@@ -106,29 +113,26 @@
if (progressbarBackgroundColor == null) {
progressbarBackgroundColor = getColorValueParameter(context,
"progressbarBackgroundColor");
}
- if (progressbarShadowStartColor == null) {
- progressbarShadowStartColor = getColorValueParameter(context,
"progressbarShadowStartColor");
+ if (progressbarShadowColor == null) {
+ progressbarShadowColor = getColorValueParameter(context,
"progressbarShadowColor");
}
- if (progressbarShadowEndColor == null) {
- progressbarShadowEndColor = getColorValueParameter(context,
"progressbarShadowEndColor");
- }
- retVal = new byte[3 * 4];
+ retVal = new byte[3 * 3];
new Zipper2(retVal).addColor(progressbarSpiralColor).addColor(
- progressbarBackgroundColor).addColor(
- progressbarShadowStartColor)
- .addColor(progressbarShadowEndColor);
+ progressbarBackgroundColor).addColor(progressbarShadowColor);
return retVal;
}
+ /**
+ * @see InternetResourceBase#deserializeData(byte[])
+ */
protected Object deserializeData(byte[] objectArray) {
if (objectArray != null) {
Zipper2 zipper2 = new Zipper2(objectArray);
progressbarSpiralColor = zipper2.nextColor();
progressbarBackgroundColor = zipper2.nextColor();
- progressbarShadowStartColor = zipper2.nextColor();
- progressbarShadowEndColor = zipper2.nextColor();
+ progressbarShadowColor = zipper2.nextColor();
}
return objectArray;
@@ -143,4 +147,20 @@
return retVal;
}
+ /**
+ * Overwrites alpha value for given color.
+ *
+ * @param c color to overwrite
+ * @param alpha a new value of alpha
+ * @return a new <code>Color</code> object with a new specified alpha value
+ */
+ private Color overwriteAlpha(Color c, float alpha) {
+ Color retVal = c;
+ if (c != null) {
+ retVal = new Color(c.getRed(), c.getGreen(), c.getBlue(),
+ (int) (alpha * 255 + 0.5));
+ }
+ return retVal;
+ }
+
}