Author: dsvyatobatsko
Date: 2008-02-05 12:26:40 -0500 (Tue, 05 Feb 2008)
New Revision: 5835
Modified:
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ColorUtils.java
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:
Modified:
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ColorUtils.java
===================================================================
---
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ColorUtils.java 2008-02-05
17:26:36 UTC (rev 5834)
+++
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ColorUtils.java 2008-02-05
17:26:40 UTC (rev 5835)
@@ -29,180 +29,194 @@
*/
public abstract class ColorUtils {
- /**
- * Converts the components of a color, as specified by the default RGB
- * model, to an equivalent set of values for hue, saturation, and
- * lightness that are the three components of the HSL model.
+ /**
+ * Converts the components of a color, as specified by the default RGB
+ * model, to an equivalent set of values for hue, saturation, and lightness
+ * that are the three components of the HSL model.
*
- * @param r the red component of the color
- * @param g the green component of the color
- * @param b the blue component of the color
- * @return an array of three elements containing the hue, saturation,
- * and lightness (in that order), of the color with
- * the indicated red, green, and blue components.
- */
- public static float[] RGBtoHSL(int r, int g, int b) {
- float varR = (r / 255f);
- float varG = (g / 255f);
- float varB = (b / 255f);
+ * @param r
+ * the red component of the color
+ * @param g
+ * the green component of the color
+ * @param b
+ * the blue component of the color
+ * @return an array of three elements containing the hue, saturation, and
+ * lightness (in that order), of the color with the indicated red,
+ * green, and blue components.
+ */
+ public static float[] RGBtoHSL(int r, int g, int b) {
+ float varR = (r / 255f);
+ float varG = (g / 255f);
+ float varB = (b / 255f);
- float varMin = Math.min(varR, Math.min(varG, varB)); //Min value of RGB
- float varMax = Math.max(varR, Math.max(varG, varB)); //Max value of RGB
- float delMax = varMax - varMin; //Delta RGB value
+ float varMin = Math.min(varR, Math.min(varG, varB)); // Min value of RGB
+ float varMax = Math.max(varR, Math.max(varG, varB)); // Max value of RGB
+ float delMax = varMax - varMin; // Delta RGB value
- float h = 0;
- float s = 0;
- float l = (varMax + varMin) / 2;
+ float h = 0;
+ float s = 0;
+ float l = (varMax + varMin) / 2;
- if(delMax == 0 || l == 0) {
- s = 0;
- } else if (l == 1) {
- s = 1;
- } else if(l <= 0.5) {
- s = delMax / (2 * (1 - l));
- } else if(l > 0.5) {
- s = delMax / (2 * l);
- }
+ if (delMax == 0 || l == 0) {
+ s = 0;
+ } else if (l == 1) {
+ s = 1;
+ } else if (l <= 0.5) {
+ s = delMax / (2 * (1 - l));
+ } else if (l > 0.5) {
+ s = delMax / (2 * l);
+ }
- if(delMax == 0) {
- h = 0;
- } else if (varMax == varR && g >= b) {
- h = 60 * (varG - varB) / delMax + 0;
- } else if (varMax == varR && varG < b) {
- h = 60 * (varG - varB) / delMax + 360;
- } else if (varMax == varG) {
- h = 60 * (varB - varR) / delMax + 120;
- } else if (varMax == varB) {
- h = 60 * (varR - varG) / delMax + 240;
- }
+ if (delMax == 0) {
+ h = 0;
+ } else if (varMax == varR && g >= b) {
+ h = 60 * (varG - varB) / delMax + 0;
+ } else if (varMax == varR && varG < b) {
+ h = 60 * (varG - varB) / delMax + 360;
+ } else if (varMax == varG) {
+ h = 60 * (varB - varR) / delMax + 120;
+ } else if (varMax == varB) {
+ h = 60 * (varR - varG) / delMax + 240;
+ }
- return new float[] { h, s, l };
- }
+ return new float[] { h, s, l };
+ }
/**
- * Converts the components of a color, as specified by the HSL
- * model, to an equivalent set of values for the default RGB model.
+ * Converts the components of a color, as specified by the HSL model, to an
+ * equivalent set of values for the default RGB model.
* <p>
* The <code>saturation</code> and <code>lightness</code>
components
- * should be floating-point values between zero and one
- * (numbers in the range 0.0-1.0). The <code>hue</code> component
- * can be any floating-point number. The floor of this number is
- * subtracted from it to create a fraction between 0 and 1. This
- * fractional number is then multiplied by 360 to produce the hue
- * angle in the HSB color model.
- * @param h the hue component of the color
- * @param s the saturation of the color
- * @param l the lightness of the color
- * @return the RGB value of the color with the indicated hue,
- * saturation, and lightness
+ * should be floating-point values between zero and one (numbers in the
+ * range 0.0-1.0). The <code>hue</code> component can be any
+ * floating-point number. The floor of this number is subtracted from it to
+ * create a fraction between 0 and 1. This fractional number is then
+ * multiplied by 360 to produce the hue angle in the HSB color model.
+ *
+ * @param h
+ * the hue component of the color
+ * @param s
+ * the saturation of the color
+ * @param l
+ * the lightness of the color
+ * @return the RGB value of the color with the indicated hue, saturation,
+ * and lightness
*/
- public static Color HSLtoRGB(float h, float s, float l) {
- float q;
- if (l < 0.5) {
- q = l * (1 + s);
- } else {
- q = l + s - (l * s);
- }
+ public static Color HSLtoRGB(float h, float s, float l) {
+ float q;
+ if (l < 0.5) {
+ q = l * (1 + s);
+ } else {
+ q = l + s - (l * s);
+ }
- float p = 2 * l - q;
- float hNorm = h / 360;
+ float p = 2 * l - q;
+ float hNorm = h / 360;
- float tR = hNorm + 1f/3f;
- float tG = hNorm;
- float tB = hNorm - 1f/3f;
+ float tR = hNorm + 1f / 3f;
+ float tG = hNorm;
+ float tB = hNorm - 1f / 3f;
- float r = tC2C(tR, p, q);
- float g = tC2C(tG, p, q);
- float b = tC2C(tB, p, q);
+ float r = tC2C(tR, p, q);
+ float g = tC2C(tG, p, q);
+ float b = tC2C(tB, p, q);
- return new Color(r, g, b);
- }
+ return new Color(r, g, b);
+ }
- private static float tC2C(float tC, float p, float q)
- {
- float retVal;
+ private static float tC2C(float tC, float p, float q) {
+ float retVal;
- if (tC < 0) {
- tC += 1;
+ if (tC < 0) {
+ tC += 1;
}
- if (tC > 1) {
- tC -= 1;
- }
+ if (tC > 1) {
+ tC -= 1;
+ }
- if ((6 * tC) < 1) {
- retVal = (p + (q - p) * 6 * tC);
- } else if ((2 * tC) < 1) {
- retVal = q;
- } else if ((3 * tC) < 2) {
- retVal = (p + (q - p) * 6 * (2f / 3f - tC));
- } else {
- retVal = p;
- }
+ if ((6 * tC) < 1) {
+ retVal = (p + (q - p) * 6 * tC);
+ } else if ((2 * tC) < 1) {
+ retVal = q;
+ } else if ((3 * tC) < 2) {
+ retVal = (p + (q - p) * 6 * (2f / 3f - tC));
+ } else {
+ retVal = p;
+ }
- return retVal;
- }
+ return retVal;
+ }
- /**
- * Increases/decreases brightness of the given color by the specified
<code>difference</code>.
- * <p>
- * The <code>difference</code> values in the range (-1.0, 1.0): 1.0 - the
brightest value;
- * -1.0 - the dimmest value.
- *
- * @param c color to adjust
- * @param difference value to be added to the current brightness
- *
- * @return a new <code>Color</code> instance with increased/decreased
brightness by specified <code>difference</code>
- * @throws IllegalArgumentException if difference is outside of the range -1.0 to 1.0,
inclusive
- */
- public static Color adjustBrightness(Color c, float difference) {
- if (difference < -1.0 || difference > 1.0) {
- throw new IllegalArgumentException("Difference parameter outside of expected
range: " +
- "Difference parameter should be floating-point values between -1 and 1");
- }
+ /**
+ * Increases/decreases brightness of the given color by the specified
+ * <code>difference</code>.
+ * <p>
+ * The <code>difference</code> values in the range (-1.0, 1.0): 1.0 -
the
+ * brightest value; -1.0 - the dimmest value.
+ *
+ * @param c
+ * color to adjust
+ * @param difference
+ * value to be added to the current brightness
+ *
+ * @return a new <code>Color</code> instance with increased/decreased
+ * brightness by specified <code>difference</code>
+ * @throws IllegalArgumentException
+ * if difference is outside of the range -1.0 to 1.0, inclusive
+ */
+ public static Color adjustBrightness(Color c, float difference) {
+ if (difference < -1.0 || difference > 1.0) {
+ throw new IllegalArgumentException("Difference parameter outside of
expected range: "
+ + "Difference parameter should be floating-point values between
-1 and 1");
+ }
- float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
- float brightness = Math.min(1.0f, Math.max(0.0f, hsb[2] + difference));
- return new Color(Color.HSBtoRGB(hsb[0], hsb[1], brightness));
- }
+ float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
+ float brightness = Math.min(1.0f, Math.max(0.0f, hsb[2] + difference));
+ return new Color(Color.HSBtoRGB(hsb[0], hsb[1], brightness));
+ }
- /**
- * Increases/decreases lightness of the given color by the specified
<code>difference</code>.
- * <p>
- * The <code>difference</code> values in the range (-1.0, 1.0): 1.0 - the
lightest value;
- * -1.0 - on the contrary.
- *
- * @param c color to adjust
- * @param difference value to be added to the current lightness
- *
- * @return a new <code>Color</code> instance with increased/decreased
lightness by specified <code>difference</code>
- * @throws IllegalArgumentException if difference is outside of the range -1.0 to 1.0,
inclusive
- */
- public static Color adjustLightness(Color c, float difference) {
- if (difference < -1.0 || difference > 1.0) {
- throw new IllegalArgumentException("Difference parameter outside of expected
range: " +
- "Difference parameter should be floating-point values between -1 and 1");
- }
+ /**
+ * Increases/decreases lightness of the given color by the specified
+ * <code>difference</code>.
+ * <p>
+ * The <code>difference</code> values in the range (-1.0, 1.0): 1.0 -
the
+ * lightest value; -1.0 - on the contrary.
+ *
+ * @param c
+ * color to adjust
+ * @param difference
+ * value to be added to the current lightness
+ *
+ * @return a new <code>Color</code> instance with increased/decreased
+ * lightness by specified <code>difference</code>
+ * @throws IllegalArgumentException
+ * if difference is outside of the range -1.0 to 1.0, inclusive
+ */
+ public static Color adjustLightness(Color c, float difference) {
+ if (difference < -1.0 || difference > 1.0) {
+ throw new IllegalArgumentException("Difference parameter outside of
expected range: "
+ + "Difference parameter should be floating-point values between
-1 and 1");
+ }
- float[] hsl = RGBtoHSL(c.getRed(), c.getGreen(), c.getBlue());
- float lightness = Math.min(1.0f, Math.max(0.0f, hsl[2] + difference));
- return HSLtoRGB(hsl[0], hsl[1], lightness);
- }
+ float[] hsl = RGBtoHSL(c.getRed(), c.getGreen(), c.getBlue());
+ float lightness = Math.min(1.0f, Math.max(0.0f, hsl[2] + difference));
+ return HSLtoRGB(hsl[0], hsl[1], lightness);
+ }
- /**
- * 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
- */
- public static 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;
- }
+ /**
+ * 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
+ */
+ public static 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/ProgressBarAnimatedBg.java
===================================================================
---
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ProgressBarAnimatedBg.java 2008-02-05
17:26:36 UTC (rev 5834)
+++
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ProgressBarAnimatedBg.java 2008-02-05
17:26:40 UTC (rev 5835)
@@ -20,6 +20,9 @@
*/
package org.richfaces.renderkit.html.images;
+import static org.richfaces.renderkit.html.images.ColorUtils.adjustLightness;
+import static org.richfaces.renderkit.html.images.ColorUtils.overwriteAlpha;
+
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
@@ -40,134 +43,115 @@
public class ProgressBarAnimatedBg extends AnimationResource {
- private static int NUMBER_OF_FRAMES = 12;
- private BufferedImage mainStage;
- private Dimension frameSize = new Dimension(24, 48);
+ private static int NUMBER_OF_FRAMES = 12;
- private Color progressbarSpiralColor;
- private Color progressbarBackgroundColor;
- private Color progressbarShadowColor;
+ private BufferedImage mainStage;
- private Color progressbarShadowStartColor;
- private Color progressbarShadowEndColor;
+ private Dimension frameSize = new Dimension(24, 48);
- @Override
- protected Dimension getFrameSize(ResourceContext resourceContext) {
- return frameSize;
- }
+ private Color progressbarBasicColor;
- /**
- * @see Java2Dresource#isCacheable(ResourceContext)
- */
- public boolean isCacheable(ResourceContext ctx) {
- return true;
- }
+ private Color progressbarSpiralColor;
- @Override
- protected int getRepeat() {
- return 0;
- }
-
- @Override
- protected int getNumberOfFrames() {
- return NUMBER_OF_FRAMES;
- }
+ private Color progressbarBackgroundColor;
- @Override
- protected void paint(ResourceContext context, Graphics2D g2d, int frameIndex) {
- if (mainStage == null) {
- 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.fillRect(0, 0, frameSize.width, 7);
- }
+ private Color progressbarShadowStartColor;
- /**
- * Creates a main stage for progress bar background.
- *
- * @param context resource context
- * @return a <code>BufferedImage</code> object
- */
- 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);
- g.setColor(progressbarSpiralColor);
- for (int k : new int[] { -24, 0, 24, 48, 72 }) {
- g.fillPolygon(new int[] { 0, 24, 24, 0 }, new int[] { 24 + k, k,
- 12 + k, 36 + k }, 4);
- }
- g.dispose();
+ private Color progressbarShadowEndColor;
- return retVal;
- }
+ @Override
+ protected Dimension getFrameSize(ResourceContext resourceContext) {
+ return frameSize;
+ }
- /**
- * @see InternetResourceBase#getDataToStore(FacesContext, Object)
- */
- protected Object getDataToStore(FacesContext context, Object data) {
- byte[] retVal = null;
- if (progressbarSpiralColor == null) {
- progressbarSpiralColor = getColorValueParameter(context,
"progressbarSpiralColor");
- }
- if (progressbarBackgroundColor == null) {
- progressbarBackgroundColor = getColorValueParameter(context,
"progressbarBackgroundColor");
- }
- if (progressbarShadowColor == null) {
- progressbarShadowColor = getColorValueParameter(context,
"progressbarShadowColor");
- }
+ /**
+ * @see Java2Dresource#isCacheable(ResourceContext)
+ */
+ public boolean isCacheable(ResourceContext ctx) {
+ return true;
+ }
- retVal = new byte[3 * 3];
- new Zipper2(retVal).addColor(progressbarSpiralColor).addColor(
- progressbarBackgroundColor).addColor(progressbarShadowColor);
+ @Override
+ protected int getRepeat() {
+ return 0;
+ }
- return retVal;
- }
+ @Override
+ protected int getNumberOfFrames() {
+ return NUMBER_OF_FRAMES;
+ }
- /**
- * @see InternetResourceBase#deserializeData(byte[])
- */
- protected Object deserializeData(byte[] objectArray) {
- if (objectArray != null) {
- Zipper2 zipper2 = new Zipper2(objectArray);
- progressbarSpiralColor = zipper2.nextColor();
- progressbarBackgroundColor = zipper2.nextColor();
- progressbarShadowColor = zipper2.nextColor();
- }
+ @Override
+ protected void paint(ResourceContext context, Graphics2D g2d, int frameIndex) {
+ if (mainStage == null) {
+ 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.fillRect(0, 0, frameSize.width, 7);
+ }
- return objectArray;
- }
+ /**
+ * Creates a main stage for progress bar background.
+ *
+ * @param context
+ * resource context
+ * @return a <code>BufferedImage</code> object
+ */
+ private BufferedImage createMainStage(ResourceContext ctx) {
+ progressbarBackgroundColor = progressbarBasicColor;
+ progressbarSpiralColor = adjustLightness(progressbarBasicColor, 0.15f);
+ progressbarShadowStartColor =
overwriteAlpha(adjustLightness(progressbarBasicColor, 0.5f), 0.6f);
+ progressbarShadowEndColor = overwriteAlpha(adjustLightness(progressbarBasicColor,
0.1f), 0.6f);
+ 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);
+ g.setColor(progressbarSpiralColor);
+ for (int k : new int[] { -24, 0, 24, 48, 72 }) {
+ g.fillPolygon(new int[] { 0, 24, 24, 0 }, new int[] { 24 + k, k, 12 + k, 36 +
k }, 4);
+ }
+ g.dispose();
- 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("")) {
- retVal = HtmlColor.decode(color);
- }
- return retVal;
- }
+ 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;
- }
+ /**
+ * @see InternetResourceBase#getDataToStore(FacesContext, Object)
+ */
+ protected Object getDataToStore(FacesContext context, Object data) {
+ byte[] retVal = null;
+ if (progressbarBasicColor == null) {
+ progressbarBasicColor = getColorValueParameter(context,
"selectControlColor");
+ }
+ retVal = new byte[3 * 1];
+ new Zipper2(retVal).addColor(progressbarBasicColor);
+
+ return retVal;
+ }
+
+ /**
+ * @see InternetResourceBase#deserializeData(byte[])
+ */
+ protected Object deserializeData(byte[] objectArray) {
+ if (objectArray != null) {
+ Zipper2 zipper2 = new Zipper2(objectArray);
+ progressbarBasicColor = zipper2.nextColor();
+ }
+
+ return objectArray;
+ }
+
+ 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("")) {
+ retVal = HtmlColor.decode(color);
+ }
+ 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-02-05
17:26:36 UTC (rev 5834)
+++
trunk/sandbox/ui/progressBAR/src/main/java/org/richfaces/renderkit/html/images/ProgressBarBg.java 2008-02-05
17:26:40 UTC (rev 5835)
@@ -20,6 +20,9 @@
*/
package org.richfaces.renderkit.html.images;
+import static org.richfaces.renderkit.html.images.ColorUtils.adjustLightness;
+import static org.richfaces.renderkit.html.images.ColorUtils.overwriteAlpha;
+
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
@@ -40,127 +43,98 @@
public class ProgressBarBg extends Java2Dresource {
- private Dimension dim = new Dimension(24, 48);
+ private Dimension dim = new Dimension(24, 48);
- private Color progressbarSpiralColor;
- private Color progressbarBackgroundColor;
- private Color progressbarShadowColor;
+ private Color progressbarBasicColor;
- private Color progressbarShadowStartColor;
- private Color progressbarShadowEndColor;
+ /**
+ * <P>
+ * No args constructor.
+ * </p>
+ */
+ public ProgressBarBg() {
+ setRenderer(new PngRenderer());
+ setLastModified(new Date(InternetResourceBuilder.getInstance().getStartTime()));
+ }
- /**
- * <P>
- * No args constructor.
- * </p>
- */
- public ProgressBarBg() {
- setRenderer(new PngRenderer());
- setLastModified(new Date(InternetResourceBuilder.getInstance().getStartTime()));
- }
+ /**
+ * @see Java2Dresource#getDimensions(ResourceContext)
+ */
+ protected Dimension getDimensions(ResourceContext resourceContext) {
+ return dim;
+ }
- /**
- * @see Java2Dresource#getDimensions(ResourceContext)
- */
- protected Dimension getDimensions(ResourceContext resourceContext) {
- return dim;
- }
+ /**
+ * @see Java2Dresource#getDimensions(FacesContext, Object)
+ */
+ public Dimension getDimensions(FacesContext facesContext, Object data) {
+ return dim;
+ }
- /**
- * @see Java2Dresource#getDimensions(FacesContext, Object)
- */
- public Dimension getDimensions(FacesContext facesContext, Object data) {
- return dim;
- }
+ /**
+ * @see Java2Dresource#isCacheable(ResourceContext)
+ */
+ public boolean isCacheable(ResourceContext ctx) {
+ return true;
+ }
- /**
- * @see Java2Dresource#isCacheable(ResourceContext)
- */
- public boolean isCacheable(ResourceContext ctx) {
- return true;
- }
+ /**
+ * <P>
+ * Paints fixed progress bar background.
+ * </p>
+ */
+ protected void paint(ResourceContext context, Graphics2D g2d) {
+ Color progressbarBackgroundColor = progressbarBasicColor;
+ Color progressbarSpiralColor = adjustLightness(progressbarBasicColor, 0.15f);
+ Color progressbarShadowStartColor =
overwriteAlpha(adjustLightness(progressbarBasicColor, 0.5f), 0.6f);
+ Color progressbarShadowEndColor =
overwriteAlpha(adjustLightness(progressbarBasicColor, 0.1f), 0.6f);
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
+ g2d.setColor(progressbarBackgroundColor);
+ g2d.fillRect(0, 0, dim.width, dim.height);
+ g2d.setColor(progressbarSpiralColor);
+ for (int k : new int[] { -24, 0, 24 }) {
+ g2d.fillPolygon(new int[] { 0, 24, 24, 0 }, new int[] { 24 + k, k, 12 + k, 36
+ k }, 4);
+ }
- /**
- * <P>
- * Paints fixed progress bar background.
- * </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);
- g2d.setColor(progressbarSpiralColor);
- for (int k : new int[] { -24, 0, 24 }) {
- g2d.fillPolygon(new int[] { 0, 24, 24, 0 }, new int[] { 24 + k,
- k, 12 + k, 36 + k }, 4);
- }
- //paint a shadow in the form of semi-transparent gradient
- g2d.setPaint(new GradientPaint(0, 0, progressbarShadowStartColor, 0, 7,
progressbarShadowEndColor));
- g2d.fillRect(0, 0, dim.width, 7);
- }
+ // paint a shadow in the form of semi-transparent gradient
+ g2d.setPaint(new GradientPaint(0, 0, progressbarShadowStartColor, 0, 7,
progressbarShadowEndColor));
+ 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) {
- progressbarSpiralColor = getColorValueParameter(context,
"progressbarSpiralColor");
- }
- if (progressbarBackgroundColor == null) {
- progressbarBackgroundColor = getColorValueParameter(context,
"progressbarBackgroundColor");
- }
- if (progressbarShadowColor == null) {
- progressbarShadowColor = getColorValueParameter(context,
"progressbarShadowColor");
- }
+ /**
+ * @see InternetResourceBase#getDataToStore(FacesContext, Object)
+ */
+ protected Object getDataToStore(FacesContext context, Object data) {
+ byte[] retVal = null;
+ if (progressbarBasicColor == null) {
+ progressbarBasicColor = getColorValueParameter(context,
"selectControlColor");
+ }
- retVal = new byte[3 * 3];
- new Zipper2(retVal).addColor(progressbarSpiralColor).addColor(
- progressbarBackgroundColor).addColor(progressbarShadowColor);
+ retVal = new byte[3 * 1];
+ new Zipper2(retVal).addColor(progressbarBasicColor);
- return retVal;
- }
+ 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();
- progressbarShadowColor = zipper2.nextColor();
- }
+ /**
+ * @see InternetResourceBase#deserializeData(byte[])
+ */
+ protected Object deserializeData(byte[] objectArray) {
+ if (objectArray != null) {
+ Zipper2 zipper2 = new Zipper2(objectArray);
+ progressbarBasicColor = zipper2.nextColor();
+ }
- return objectArray;
- }
+ return objectArray;
+ }
- 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("")) {
- retVal = HtmlColor.decode(color);
- }
- return retVal;
- }
+ 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("")) {
+ retVal = HtmlColor.decode(color);
+ }
+ 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;
- }
-
}