Author: nbelaevski
Date: 2008-04-24 09:08:04 -0400 (Thu, 24 Apr 2008)
New Revision: 8119
Added:
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java
Modified:
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/GradientAlignment.java
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/GradientType.java
Log:
CustomizeableGradient added
Customization removed from BaseGradient
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-24
12:37:10 UTC (rev 8118)
+++
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/BaseGradient.java 2008-04-24
13:08:04 UTC (rev 8119)
@@ -21,7 +21,6 @@
package org.richfaces.renderkit.html;
-import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
@@ -30,7 +29,6 @@
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.util.Date;
-import java.util.Map;
import javax.faces.context.FacesContext;
@@ -40,7 +38,6 @@
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;
@@ -60,20 +57,25 @@
private String gradientColor;
private boolean horizontal = false;
- public BaseGradient(int width, int height, int gradientHeight) {
+ public BaseGradient(int width, int height, int gradientHeight, String baseColor,
String gradientColor, boolean horizontal) {
super();
this.width = width;
this.height = height;
this.gradientHeight = gradientHeight;
+ this.baseColor = baseColor != null ? baseColor : Skin.headerBackgroundColor;
+ this.gradientColor = gradientColor != null ? gradientColor :
Skin.headerGradientColor;
+ this.horizontal = horizontal;
setRenderer(new PngRenderer());
setLastModified(new Date(InternetResourceBuilder.getInstance().getStartTime()));
}
+
+ public BaseGradient(int width, int height, int gradientHeight) {
+ this(width, height, gradientHeight, null, null, false);
+ }
public BaseGradient(int width, int height, int gradientHeight, String baseColor,
String gradientColor) {
- this(width, height, gradientHeight);
- this.baseColor = baseColor;
- this.gradientColor = gradientColor;
+ this(width, height, gradientHeight, baseColor, gradientColor, false);
}
public BaseGradient(int width, int height) {
@@ -81,9 +83,7 @@
}
public BaseGradient(int width, int height, String baseColor, String gradientColor) {
- this(width, height, height);
- this.baseColor = baseColor;
- this.gradientColor = gradientColor;
+ this(width, height, height, baseColor, gradientColor);
}
public BaseGradient() {
@@ -91,45 +91,27 @@
}
public BaseGradient(String baseColor, String gradientColor) {
- this(30, 50, 20);
- this.baseColor = baseColor;
- this.gradientColor = gradientColor;
+ this(30, 50, 20, baseColor, gradientColor);
}
public BaseGradient(int width, int height, int gradientHeight, boolean horizontal) {
- this(width, height, gradientHeight);
- this.horizontal = horizontal;
+ this(width, height, gradientHeight, null, null, horizontal);
}
- public BaseGradient(int width, int height, int gradientHeight, String baseColor,
String gradientColor, boolean horizontal) {
- this(width, height, gradientHeight);
- this.baseColor = baseColor;
- this.gradientColor = gradientColor;
- this.horizontal = horizontal;
- }
-
public BaseGradient(int width, int height, boolean horizontal) {
- this(width, height, horizontal?width:height);
- this.horizontal = horizontal;
+ this(width, height, horizontal ? width : height, null, null, horizontal);
}
public BaseGradient(int width, int height, String baseColor, String gradientColor,
boolean horizontal) {
- this(width, height, horizontal?width:height);
- this.baseColor = baseColor;
- this.gradientColor = gradientColor;
- this.horizontal = horizontal;
+ this(width, height, horizontal ? width : height, baseColor, gradientColor,
horizontal);
}
public BaseGradient(boolean horizontal) {
- this(30, 50, 20);
- this.horizontal = horizontal;
+ this(30, 50, 20, null, null, horizontal);
}
public BaseGradient(String baseColor, String gradientColor, boolean horizontal) {
- this(30, 50, 20);
- this.baseColor = baseColor;
- this.gradientColor = gradientColor;
- this.horizontal = horizontal;
+ this(30, 50, 20, baseColor, gradientColor, horizontal);
}
public Dimension getDimensions(FacesContext facesContext, Object data) {
@@ -140,14 +122,6 @@
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);
- }
- }
-
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());
@@ -170,9 +144,7 @@
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);
+ BiColor biColor = new GradientType.BiColor(headerBackgroundColor,
headerGradientColor);
GradientType type = dataToStore.getGradientType();
BiColor firstLayer = type.getFirstLayerColors(biColor);
@@ -186,43 +158,12 @@
dim.setSize(dim.height, dim.width);
}
- Rectangle2D rect =
- new Rectangle2D.Float(
- 0,
- 0,
- dim.width,
- dim.height);
-
- GradientAlignment gradientAlignment = dataToStore.getGradientAlignment();
- int topRectangleHeight = gradientAlignment.getTopRectangleHeight(dim.height,
gradientHeight);
- int bottomRectangleHeight = gradientAlignment.getBottomRectangleHeight(dim.height,
gradientHeight);
-
- rect = new Rectangle2D.Float(
+ Rectangle2D rect = new Rectangle2D.Float(
0,
0,
dim.width,
- topRectangleHeight);
-
- drawRectangle(g2d, rect, firstLayer, true);
- drawRectangle(g2d, rect, secondLayer, true);
-
- rect = new Rectangle2D.Float(
- 0,
- dim.height - bottomRectangleHeight,
- dim.width,
dim.height);
- drawRectangle(g2d, rect, firstLayer, false);
- drawRectangle(g2d, rect, secondLayer, false);
-
- g2d.transform(AffineTransform.getTranslateInstance(0, topRectangleHeight));
-
- rect = new Rectangle2D.Float(
- 0,
- 0,
- dim.width,
- dim.height);
-
drawGradient(g2d, rect, firstLayer, gradientHeight);
rect = new Rectangle2D.Float(
@@ -241,7 +182,6 @@
data.setHeaderBackgroundColor(Integer.valueOf(zipper2.nextIntColor()));
data.setHeaderGradientColor(Integer.valueOf(zipper2.nextIntColor()));
data.setGradientType(GradientType.values()[zipper2.nextByte()]);
- data.setGradientAlignment(GradientAlignment.values()[zipper2.nextByte()]);
}
}
@@ -267,21 +207,11 @@
}
}
- private void saveData(FacesContext context, Data data, String baseColor, String
gradientColor, Object parameterData) {
+ protected void saveData(FacesContext context, Data data, Object parameterData) {
Integer baseIntColor = null;
Integer headerIntColor = null;
String gradientTypeString = null;
- String alignmentString = null;
- if (parameterData instanceof Map<?, ?>) {
- Map<?, ?> map = (Map<?, ?>) parameterData;
-
- gradientTypeString = (String) map.get(Skin.gradientType);
- alignmentString = (String) map.get("valign");
- baseIntColor = decodeColor((String) map.get("baseColor"));
- headerIntColor = decodeColor((String) map.get("gradientColor"));
- }
-
if (baseIntColor == null) {
baseIntColor = getColorValueParameter(context, baseColor, false);
}
@@ -308,17 +238,8 @@
}
data.setGradientType(GradientType.getBySkinParameter(gradientTypeString));
- data.setGradientAlignment(GradientAlignment.getByParameter(alignmentString));
}
- 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);
- }
- }
-
protected Object getDataToStore(FacesContext context, Object data) {
Data dataObject = createData();
saveData(context, dataObject, data);
@@ -367,13 +288,12 @@
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];
+ byte[] ret = new byte[7];
new
Zipper2(ret).addColor(headerBackgroundColor.intValue()).addColor(headerGradientColor.intValue()).
- addByte((byte) gradientType.ordinal()).addByte((byte) gradientAlignment.ordinal());
+ addByte((byte) gradientType.ordinal());
return ret;
} else {
return null;
@@ -404,14 +324,6 @@
this.gradientType = gradientType;
}
- public GradientAlignment getGradientAlignment() {
- return gradientAlignment;
- }
-
- public void setGradientAlignment(GradientAlignment gradientAlignment) {
- this.gradientAlignment = gradientAlignment;
- }
-
}
}
Added:
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/CustomizeableGradient.java 2008-04-24
13:08:04 UTC (rev 8119)
@@ -0,0 +1,327 @@
+/**
+ * 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;
+
+import java.awt.Color;
+import java.awt.Dimension;
+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;
+
+import org.ajax4jsf.resource.InternetResourceBuilder;
+import org.ajax4jsf.resource.Java2Dresource;
+import org.ajax4jsf.resource.PngRenderer;
+import org.ajax4jsf.resource.ResourceContext;
+import org.ajax4jsf.util.HtmlColor;
+import org.ajax4jsf.util.HtmlDimensions;
+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;
+import org.richfaces.skin.SkinFactory;
+
+/**
+ * @author Nick Belaevski - nbelaevski(a)exadel.com
+ * created 02.02.2007
+ *
+ */
+public class CustomizeableGradient extends Java2Dresource {
+
+ private Dimension dimension = new Dimension(20, 500);
+
+ public CustomizeableGradient() {
+ super();
+
+ setRenderer(new PngRenderer());
+ setLastModified(new Date(InternetResourceBuilder.getInstance().getStartTime()));
+ }
+
+ public Dimension getDimensions(FacesContext facesContext, Object data) {
+ return dimension;
+ }
+
+ protected Dimension getDimensions(ResourceContext resourceContext) {
+ return dimension;
+ }
+
+ 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);
+ }
+ }
+
+ 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);
+ }
+ }
+
+ 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) {
+ BiColor biColor = new GradientType.BiColor(dataToStore.getGradientColor(),
dataToStore.getBaseColor());
+
+ GradientType type = dataToStore.getGradientType();
+ BiColor firstLayer = type.getFirstLayerColors(biColor);
+ BiColor secondLayer = type.getSecondLayerColors(biColor);
+
+ Dimension dim = getDimensions(resourceContext);
+ int gradientHeight = dataToStore.getGradientHeight();
+
+ Rectangle2D rect =
+ new Rectangle2D.Float(
+ 0,
+ 0,
+ dim.width,
+ dim.height);
+
+ GradientAlignment gradientAlignment = dataToStore.getGradientAlignment();
+ int topRectangleHeight = gradientAlignment.getTopRectangleHeight(dim.height,
gradientHeight);
+ int bottomRectangleHeight = gradientAlignment.getBottomRectangleHeight(dim.height,
gradientHeight);
+
+ rect = new Rectangle2D.Float(
+ 0,
+ 0,
+ dim.width,
+ topRectangleHeight);
+
+ drawRectangle(g2d, rect, firstLayer, true);
+ drawRectangle(g2d, rect, secondLayer, true);
+
+ rect = new Rectangle2D.Float(
+ 0,
+ dim.height - bottomRectangleHeight,
+ dim.width,
+ dim.height);
+
+ drawRectangle(g2d, rect, firstLayer, false);
+ drawRectangle(g2d, rect, secondLayer, false);
+
+ g2d.transform(AffineTransform.getTranslateInstance(0, topRectangleHeight));
+
+ rect = new Rectangle2D.Float(
+ 0,
+ 0,
+ dim.width,
+ dim.height);
+
+ drawGradient(g2d, rect, firstLayer, gradientHeight);
+
+ rect = new Rectangle2D.Float(
+ 0,
+ 0,
+ dim.width,
+ gradientHeight / 2);
+
+ drawGradient(g2d, rect, secondLayer, gradientHeight / 2);
+ }
+ }
+
+ protected Object deserializeData(byte[] objectArray) {
+ Data data = new Data();
+ if (objectArray != null) {
+ Zipper2 zipper2 = new Zipper2(objectArray);
+
+ data.setGradientType(GradientType.values()[zipper2.nextByte()]);
+ data.setGradientAlignment(GradientAlignment.values()[zipper2.nextByte()]);
+ data.setGradientHeight(zipper2.nextInt());
+ data.setBaseColor(Integer.valueOf(zipper2.nextIntColor()));
+
+ if (zipper2.hasMore()) {
+ data.setGradientColor(Integer.valueOf(zipper2.nextIntColor()));
+ } else {
+ data.setGradientColor(data.getBaseColor());
+ }
+ }
+
+ return data;
+ }
+
+ private Integer decodeColor(String value) {
+ if (value !=null && value.length() != 0) {
+ return Integer.valueOf(HtmlColor.decode(value).getRGB());
+ } else {
+ return null;
+ }
+ }
+
+ private Integer decodeHeight(String value) {
+ if (value !=null && value.length() != 0) {
+ return HtmlDimensions.decode(value).intValue();
+ } else {
+ return null;
+ }
+ }
+
+ protected Object getDataToStore(FacesContext context, Object parameterData) {
+ Data data = new Data();
+
+ Integer baseIntColor = null;
+ Integer gradientIntColor = null;
+ Integer gradientHeight = null;
+
+ String gradientTypeString = null;
+ String alignmentString = null;
+
+ if (parameterData instanceof Map<?, ?>) {
+ Map<?, ?> map = (Map<?, ?>) parameterData;
+
+ gradientTypeString = (String) map.get(Skin.gradientType);
+ alignmentString = (String) map.get("valign");
+ baseIntColor = decodeColor((String) map.get("baseColor"));
+ gradientIntColor = decodeColor((String) map.get("gradientColor"));
+ gradientHeight = decodeHeight((String) map.get("gradientHeight"));
+ }
+
+ data.setBaseColor(baseIntColor);
+ if (gradientIntColor != null) {
+ data.setGradientColor(gradientIntColor);
+ } else {
+ data.setGradientColor(baseIntColor);
+ }
+
+ if (gradientHeight == null) {
+ gradientHeight = 22;
+ }
+ data.setGradientHeight(gradientHeight);
+
+ if (gradientTypeString == null || gradientTypeString.length() == 0) {
+ gradientTypeString = getValueParameter(context, Skin.gradientType);
+ }
+
+ data.setGradientType(GradientType.getBySkinParameter(gradientTypeString));
+ data.setGradientAlignment(GradientAlignment.getByParameter(alignmentString));
+
+ return data.toByteArray();
+ }
+
+ public boolean isCacheable() {
+ return true;
+ }
+
+ protected String getValueParameter(FacesContext context, String name) {
+ SkinFactory skinFactory = SkinFactory.getInstance();
+
+ 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 static class Data implements Serializable {
+ public Data() {
+ }
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1732700513743861250L;
+ private Integer gradientColor;
+ private Integer baseColor;
+ private Integer gradientHeight;
+
+ private GradientType gradientType;
+ private GradientAlignment gradientAlignment;
+
+ public byte[] toByteArray() {
+ if (baseColor != null && gradientColor != null && gradientHeight !=
null && gradientAlignment != null && gradientType != null) {
+ byte[] ret = new byte[12];
+ new Zipper2(ret)
+ .addByte((byte) gradientType.ordinal())
+ .addByte((byte) gradientAlignment.ordinal())
+ .addInt(gradientHeight.intValue())
+ .addColor(baseColor.intValue())
+ .addColor(gradientColor.intValue());
+
+ return ret;
+ } else {
+ return null;
+ }
+ }
+
+ public Integer getGradientColor() {
+ return gradientColor;
+ }
+
+ public void setGradientColor(Integer headerBackgroundColor) {
+ this.gradientColor = headerBackgroundColor;
+ }
+
+ public Integer getBaseColor() {
+ return baseColor;
+ }
+
+ public void setBaseColor(Integer headerGradientColor) {
+ this.baseColor = 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;
+ }
+
+ public Integer getGradientHeight() {
+ return gradientHeight;
+ }
+
+ public void setGradientHeight(Integer gradientHeight) {
+ this.gradientHeight = gradientHeight;
+ }
+
+ }
+
+}
Modified:
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 2008-04-24
12:37:10 UTC (rev 8118)
+++
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/GradientAlignment.java 2008-04-24
13:08:04 UTC (rev 8119)
@@ -21,6 +21,7 @@
package org.richfaces.renderkit.html.images;
+import static java.lang.Math.max;
/**
@@ -33,7 +34,7 @@
TOP {
@Override
public int getBottomRectangleHeight(int imageHeight, int gradientHeight) {
- return imageHeight - gradientHeight;
+ return max(imageHeight - gradientHeight, 0);
}
@Override
@@ -45,7 +46,7 @@
CENTER {
@Override
public int getBottomRectangleHeight(int imageHeight, int gradientHeight) {
- return (imageHeight - gradientHeight) / 2;
+ return max((imageHeight - gradientHeight) / 2, 0);
}
@Override
@@ -62,7 +63,7 @@
@Override
public int getTopRectangleHeight(int imageHeight, int gradientHeight) {
- return imageHeight - gradientHeight;
+ return max(imageHeight - gradientHeight, 0);
}
};
Modified:
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/GradientType.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/GradientType.java 2008-04-24
12:37:10 UTC (rev 8118)
+++
trunk/framework/impl/src/main/java/org/richfaces/renderkit/html/images/GradientType.java 2008-04-24
13:08:04 UTC (rev 8119)
@@ -17,32 +17,28 @@
@Override
public BiColor getFirstLayerColors(BiColor biColor) {
-// Color topColor = biColor.getTopColor();
-//
-// float[] hsb = Color.RGBtoHSB(topColor.getRed(), topColor.getGreen(),
topColor.getBlue(), null);
-//
-// hsb[2] = 0.2f * hsb[2] + 80; //(hsb[2] * 2) / 10 + 80;
-// hsb[1] = 0.5f * hsb[1];
-//
-// Color bottomColor = new Color(Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]));
-//
-// return new BiColor(topColor, bottomColor);
-
Color bottomColor = biColor.getBottomColor();
-
- float[] hsb = Color.RGBtoHSB(bottomColor.getRed(), bottomColor.getGreen(),
bottomColor.getBlue(), null);
+ if (bottomColor != null) {
+ float[] hsb = Color.RGBtoHSB(bottomColor.getRed(), bottomColor.getGreen(),
bottomColor.getBlue(), null);
- hsb[2] = 0.2f * hsb[2] + 0.80f; //(hsb[2] * 2) / 10 + 80;
- hsb[1] = 0.5f * hsb[1];
+ hsb[2] = 0.2f * hsb[2] + 0.80f; //(hsb[2] * 2) / 10 + 80;
+ hsb[1] = 0.5f * hsb[1];
- Color topColor = new Color(Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]));
-
- return new BiColor(bottomColor, topColor);
+ Color topColor = new Color(Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]));
+
+ return new BiColor(bottomColor, topColor);
+ } else {
+ return null;
+ }
}
@Override
public BiColor getSecondLayerColors(BiColor biColor) {
- return WHITE;
+ if (biColor.getBottomColor() != null) {
+ return WHITE;
+ } else {
+ return null;
+ }
}
},
@@ -52,20 +48,27 @@
@Override
public BiColor getFirstLayerColors(BiColor biColor) {
Color bottomColor = biColor.getBottomColor();
+ if (bottomColor != null) {
+ float[] hsb = Color.RGBtoHSB(bottomColor.getRed(), bottomColor.getGreen(),
bottomColor.getBlue(), null);
- float[] hsb = Color.RGBtoHSB(bottomColor.getRed(), bottomColor.getGreen(),
bottomColor.getBlue(), null);
+ hsb[2] = 0.25f * hsb[2] + 0.75f; //(100 - hsb[2]) * 0.75f + hsb[2];
+ hsb[1] = 0.75f * hsb[1];
- hsb[2] = 0.25f * hsb[2] + 0.75f; //(100 - hsb[2]) * 0.75f + hsb[2];
- hsb[1] = 0.75f * hsb[1];
+ Color topColor = new Color(Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]));
- Color topColor = new Color(Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]));
-
- return new BiColor(topColor, bottomColor);
+ return new BiColor(topColor, bottomColor);
+ } else {
+ return null;
+ }
}
@Override
public BiColor getSecondLayerColors(BiColor biColor) {
- return WHITE;
+ if (biColor.getBottomColor() != null) {
+ return WHITE;
+ } else {
+ return null;
+ }
}
},
@@ -74,7 +77,11 @@
@Override
public BiColor getFirstLayerColors(BiColor biColor) {
- return biColor;
+ if (biColor.getBottomColor() != null && biColor.getTopColor() != null) {
+ return biColor;
+ } else {
+ return null;
+ }
}
@Override
@@ -105,14 +112,17 @@
public BiColor(Color topColor, Color bottomColor) {
super();
- if (topColor == null || bottomColor == null) {
- throw new NullPointerException("Color is null!");
- }
-
this.topColor = topColor;
this.bottomColor = bottomColor;
}
+ public BiColor(Integer topColor, Integer bottomColor) {
+ super();
+
+ this.topColor = topColor != null ? new Color(topColor.intValue()) : null;
+ this.bottomColor = bottomColor != null ? new Color(bottomColor.intValue()) : null;
+ }
+
public Color getTopColor() {
return topColor;
}