You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by je...@apache.org on 2010/07/12 09:56:00 UTC
svn commit: r963203 - in /xmlgraphics/batik/branches/svgcolor12: ./
sources/org/apache/batik/bridge/ sources/org/apache/batik/bridge/svg12/
sources/org/apache/batik/css/engine/value/svg/
sources/org/apache/batik/css/engine/value/svg12/ sources/org/apac...
Author: jeremias
Date: Mon Jul 12 07:56:00 2010
New Revision: 963203
URL: http://svn.apache.org/viewvc?rev=963203&view=rev
Log:
Initial upload of SVG Color 1.2 support (work in progress).
Added:
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/CIELabColor.java (with props)
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/DeviceColor.java (with props)
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/ICCNamedColor.java (with props)
Modified:
xmlgraphics/batik/branches/svgcolor12/ (props changed)
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/CSSUtilities.java
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/PaintServer.java
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/SVGColorProfileElementBridge.java
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/SVGImageElementBridge.java
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/svg12/SVGSolidColorElementBridge.java
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg/ICCColor.java
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg/SVGColorManager.java
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/color/NamedProfileCache.java
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/renderable/ProfileRable.java
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/rendered/ProfileRed.java
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/spi/ImageTagRegistry.java
xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/util/SoftReferenceCache.java
Propchange: xmlgraphics/batik/branches/svgcolor12/
------------------------------------------------------------------------------
svn:mergeinfo = /xmlgraphics/batik/branches/foreignObject:658527-658531
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/CSSUtilities.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/CSSUtilities.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/CSSUtilities.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/CSSUtilities.java Mon Jul 12 07:56:00 2010
@@ -31,7 +31,6 @@ import org.apache.batik.css.engine.CSSSt
import org.apache.batik.css.engine.SVGCSSEngine;
import org.apache.batik.css.engine.value.ListValue;
import org.apache.batik.css.engine.value.Value;
-import org.apache.batik.css.engine.value.svg.ICCColor;
import org.apache.batik.dom.svg.SVGOMDocument;
import org.apache.batik.ext.awt.MultipleGradientPaint;
import org.apache.batik.ext.awt.image.renderable.ClipRable;
@@ -815,7 +814,7 @@ public abstract class CSSUtilities
return PaintServer.convertColor(v, 1);
} else {
return PaintServer.convertRGBICCColor
- (e, v.item(0), (ICCColor)v.item(1), 1, ctx);
+ (e, v.item(0), v.item(1), 1, ctx);
}
}
@@ -838,7 +837,7 @@ public abstract class CSSUtilities
return PaintServer.convertColor(v, f);
} else {
return PaintServer.convertRGBICCColor
- (e, v.item(0), (ICCColor)v.item(1), f, ctx);
+ (e, v.item(0), v.item(1), f, ctx);
}
}
@@ -864,7 +863,7 @@ public abstract class CSSUtilities
return PaintServer.convertColor(v, opacity);
} else {
return PaintServer.convertRGBICCColor
- (e, v.item(0), (ICCColor)v.item(1), opacity, ctx);
+ (e, v.item(0), v.item(1), opacity, ctx);
}
}
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/PaintServer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/PaintServer.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/PaintServer.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/PaintServer.java Mon Jul 12 07:56:00 2010
@@ -23,11 +23,15 @@ import java.awt.Color;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.Stroke;
+import java.awt.color.ICC_Profile;
+import java.io.IOException;
import org.apache.batik.css.engine.SVGCSSEngine;
import org.apache.batik.css.engine.value.Value;
import org.apache.batik.css.engine.value.svg.ICCColor;
-import org.apache.batik.ext.awt.color.ICCColorSpaceExt;
+import org.apache.batik.css.engine.value.svg12.CIELabColor;
+import org.apache.batik.css.engine.value.svg12.DeviceColor;
+import org.apache.batik.css.engine.value.svg12.ICCNamedColor;
import org.apache.batik.gvt.CompositeShapePainter;
import org.apache.batik.gvt.FillShapePainter;
import org.apache.batik.gvt.GraphicsNode;
@@ -38,6 +42,16 @@ import org.apache.batik.gvt.ShapePainter
import org.apache.batik.gvt.StrokeShapePainter;
import org.apache.batik.util.CSSConstants;
import org.apache.batik.util.SVGConstants;
+
+import org.apache.xmlgraphics.java2d.color.CIELabColorSpace;
+import org.apache.xmlgraphics.java2d.color.ColorSpaces;
+import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives;
+import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace;
+import org.apache.xmlgraphics.java2d.color.ICCColorSpaceExt;
+import org.apache.xmlgraphics.java2d.color.NamedColorSpace;
+import org.apache.xmlgraphics.java2d.color.profile.NamedColorProfile;
+import org.apache.xmlgraphics.java2d.color.profile.NamedColorProfileParser;
+
import org.w3c.dom.Element;
import org.w3c.dom.css.CSSPrimitiveValue;
import org.w3c.dom.css.CSSValue;
@@ -271,7 +285,7 @@ public abstract class PaintServer
switch (v.getPrimitiveType()) {
case CSSPrimitiveValue.CSS_RGBCOLOR:
return convertRGBICCColor(paintedElement, v,
- (ICCColor)paintDef.item(1),
+ paintDef.item(1),
opacity, ctx);
case CSSPrimitiveValue.CSS_URI: {
@@ -290,7 +304,7 @@ public abstract class PaintServer
return convertColor(v, opacity);
} else {
return convertRGBICCColor(paintedElement, v,
- (ICCColor)paintDef.item(2),
+ paintDef.item(2),
opacity, ctx);
}
default:
@@ -376,12 +390,20 @@ public abstract class PaintServer
*/
public static Color convertRGBICCColor(Element paintedElement,
Value colorDef,
- ICCColor iccColor,
+ Value iccColor,
float opacity,
BridgeContext ctx) {
Color color = null;
- if (iccColor != null){
- color = convertICCColor(paintedElement, iccColor, opacity, ctx);
+ if (iccColor != null) {
+ if (iccColor instanceof ICCColor) {
+ color = convertICCColor(paintedElement, (ICCColor)iccColor, opacity, ctx);
+ } else if (iccColor instanceof ICCNamedColor) {
+ color = convertICCNamedColor(paintedElement, (ICCNamedColor)iccColor, opacity, ctx);
+ } else if (iccColor instanceof CIELabColor) {
+ color = convertCIELabColor(paintedElement, (CIELabColor)iccColor, opacity, ctx);
+ } else if (iccColor instanceof DeviceColor) {
+ color = convertDeviceColor(paintedElement, colorDef, (DeviceColor)iccColor, opacity, ctx);
+ }
}
if (color == null){
color = convertColor(colorDef, opacity);
@@ -402,7 +424,7 @@ public abstract class PaintServer
public static Color convertICCColor(Element e,
ICCColor c,
float opacity,
- BridgeContext ctx){
+ BridgeContext ctx) {
// Get ICC Profile's name
String iccProfileName = c.getColorProfile();
if (iccProfileName == null){
@@ -434,10 +456,137 @@ public abstract class PaintServer
// Convert values to RGB
float[] rgb = profileCS.intendedToRGB(colorValue);
+ //TODO Preserve original ICC color value!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
return new Color(rgb[0], rgb[1], rgb[2], opacity);
}
/**
+ * Returns a Color object that corresponds to the input Paint's
+ * ICC named color value or null if the related color profile could not
+ * be used or loaded for any reason.
+ *
+ * @param e the element using the color
+ * @param c the ICC named color definition
+ * @param opacity the opacity
+ * @param ctx the bridge context to use
+ */
+ public static Color convertICCNamedColor(Element e,
+ ICCNamedColor c,
+ float opacity,
+ BridgeContext ctx) {
+ // Get ICC Profile's name
+ String iccProfileName = c.getColorProfile();
+ if (iccProfileName == null){
+ return null;
+ }
+ // Ask the bridge to map the ICC profile name to an ICC_Profile object
+ SVGColorProfileElementBridge profileBridge
+ = (SVGColorProfileElementBridge)
+ ctx.getBridge(SVG_NAMESPACE_URI, SVG_COLOR_PROFILE_TAG);
+ if (profileBridge == null){
+ return null; // no bridge for color profile
+ }
+
+ ICCColorSpaceExt profileCS
+ = profileBridge.createICCColorSpaceExt(ctx, e, iccProfileName);
+ if (profileCS == null){
+ return null; // no profile
+ }
+ ICC_Profile iccProfile = profileCS.getProfile();
+
+ String iccProfileSrc = null; //TODO Fill me!
+
+ if (NamedColorProfileParser.isNamedColorProfile(iccProfile)) {
+ NamedColorProfileParser parser = new NamedColorProfileParser();
+ NamedColorProfile ncp;
+ try {
+ ncp = parser.parseProfile(iccProfile, iccProfileName, iccProfileSrc);
+ } catch (IOException ioe) {
+ return null;
+ }
+ NamedColorSpace ncs = ncp.getNamedColor(c.getColorName());
+ if (ncs != null) {
+ Color specColor
+ = new ColorWithAlternatives(ncs, new float[] {1.0f}, opacity, null);
+ return specColor;
+ } else {
+ /*
+ log.warn("Color '" + colorName
+ + "' does not exist in named color profile: " + iccProfileSrc);
+ */
+ //parsedColor = sRGB;
+ return null;
+ }
+ } else {
+ //log.warn("ICC profile is no named color profile: " + iccProfileSrc);
+ //parsedColor = sRGB;
+ }
+
+ // Convert values to RGB
+ //float[] rgb = profileCS.intendedToRGB(colorValue);
+ //TODO Preserve original ICC color value!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ //return new Color(rgb[0], rgb[1], rgb[2], opacity);
+ return null;
+ }
+
+ /**
+ * Returns a Color object that corresponds to the input Paint's
+ * CIE Lab color value.
+ *
+ * @param e the element using the color
+ * @param c the CIE Lab color definition
+ * @param opacity the opacity
+ * @param ctx the bridge context to use
+ */
+ public static Color convertCIELabColor(Element e,
+ CIELabColor c,
+ float opacity,
+ BridgeContext ctx) {
+ //We're assuming here that SVG Color 1.2 means to use D50 as white point for CIE Lab
+ CIELabColorSpace cs = ColorSpaces.getCIELabColorSpaceD50();
+ float[] lab = c.getColorValues();
+ Color specColor = cs.toColor(lab[0], lab[1], lab[2], opacity);
+ return specColor;
+ }
+
+ /**
+ * Returns a Color object that corresponds to the input Paint's
+ * device-specific color value.
+ *
+ * @param e the element using the color
+ * @param srgb the sRGB fallback color
+ * @param c the device-specific color definition
+ * @param opacity the opacity
+ * @param ctx the bridge context to use
+ */
+ public static Color convertDeviceColor(Element e,
+ Value srgb,
+ DeviceColor c,
+ float opacity,
+ BridgeContext ctx) {
+ int r = resolveColorComponent(srgb.getRed());
+ int g = resolveColorComponent(srgb.getGreen());
+ int b = resolveColorComponent(srgb.getBlue());
+ if (c.isNChannel()) {
+ return convertColor(srgb, opacity); //NYI
+ } else {
+ if (c.getNumberOfColors() == 4) {
+ DeviceCMYKColorSpace cmykCs = ColorSpaces.getDeviceCMYKColorSpace();
+ float[] comps = new float[4];
+ for (int i = 0; i < 4; i++) {
+ comps[i] = c.getColor(i);
+ }
+ Color cmyk = new ColorWithAlternatives(cmykCs, comps, opacity, null);
+ Color specColor = new ColorWithAlternatives(r, g, b, Math.round(opacity * 255f),
+ new Color[] {cmyk});
+ return specColor;
+ } else {
+ return convertColor(srgb, opacity); //NYI
+ }
+ }
+ }
+
+ /**
* Converts the given Value and opacity to a Color object.
* @param c The CSS color to convert.
* @param opacity The opacity value (0 <= o <= 1).
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/SVGColorProfileElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/SVGColorProfileElementBridge.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/SVGColorProfileElementBridge.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/SVGColorProfileElementBridge.java Mon Jul 12 07:56:00 2010
@@ -23,10 +23,11 @@ import java.io.IOException;
import org.apache.batik.dom.AbstractNode;
import org.apache.batik.dom.util.XLinkSupport;
-import org.apache.batik.ext.awt.color.ICCColorSpaceExt;
import org.apache.batik.ext.awt.color.NamedProfileCache;
import org.apache.batik.util.ParsedURL;
+import org.apache.xmlgraphics.java2d.color.ICCColorSpaceExt;
+
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -128,7 +129,7 @@ public class SVGColorProfileElementBridg
// Extract the rendering intent from profile element
int intent = convertIntent(profile, ctx);
- cs = new ICCColorSpaceExt(p, intent);
+ cs = new ICCColorSpaceExt(p, intent, href, iccProfileName);
// Add profile to cache
cache.put(iccProfileName.toLowerCase(), cs);
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/SVGImageElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/SVGImageElementBridge.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/SVGImageElementBridge.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/SVGImageElementBridge.java Mon Jul 12 07:56:00 2010
@@ -42,7 +42,6 @@ import org.apache.batik.dom.svg.LiveAttr
import org.apache.batik.dom.svg.SVGOMAnimatedPreserveAspectRatio;
import org.apache.batik.dom.svg.SVGOMDocument;
import org.apache.batik.dom.svg.SVGOMElement;
-import org.apache.batik.ext.awt.color.ICCColorSpaceExt;
import org.apache.batik.ext.awt.image.renderable.ClipRable8Bit;
import org.apache.batik.ext.awt.image.renderable.Filter;
import org.apache.batik.ext.awt.image.spi.BrokenLinkProvider;
@@ -58,6 +57,8 @@ import org.apache.batik.util.MimeTypeCon
import org.apache.batik.util.ParsedURL;
import org.apache.batik.util.XMLConstants;
+import org.apache.xmlgraphics.java2d.color.ICCColorSpaceExt;
+
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.events.DocumentEvent;
@@ -968,7 +969,7 @@ public class SVGImageElementBridge exten
colorSpace = new ICCColorSpaceExt
(ICC_Profile.getInstance(ColorSpace.CS_sRGB),
- ICCColorSpaceExt.AUTO);
+ ICCColorSpaceExt.AUTO, "sRGB", null);
} else if (!CSS_AUTO_VALUE.equalsIgnoreCase(colorProfileProperty)
&& !"".equalsIgnoreCase(colorProfileProperty)){
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/svg12/SVGSolidColorElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/svg12/SVGSolidColorElementBridge.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/svg12/SVGSolidColorElementBridge.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/bridge/svg12/SVGSolidColorElementBridge.java Mon Jul 12 07:56:00 2010
@@ -34,7 +34,6 @@ import org.apache.batik.css.engine.CSSEn
import org.apache.batik.css.engine.CSSStylableElement;
import org.apache.batik.css.engine.StyleMap;
import org.apache.batik.css.engine.value.Value;
-import org.apache.batik.css.engine.value.svg.ICCColor;
import org.apache.batik.dom.svg.SVGOMDocument;
import org.apache.batik.dom.util.XLinkSupport;
import org.apache.batik.gvt.GraphicsNode;
@@ -156,7 +155,7 @@ public class SVGSolidColorElementBridge
} else {
return PaintServer.convertRGBICCColor
(paintElement, colorDef.item(0),
- (ICCColor)colorDef.item(1),
+ colorDef.item(1),
opacity, ctx);
}
}
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg/ICCColor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg/ICCColor.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg/ICCColor.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg/ICCColor.java Mon Jul 12 07:56:00 2010
@@ -30,6 +30,8 @@ import org.w3c.dom.css.CSSValue;
*/
public class ICCColor extends AbstractValue {
+ public static final String ICC_COLOR_FUNCTION = "icc-color";
+
/**
* The color profile.
*/
@@ -86,7 +88,7 @@ public class ICCColor extends AbstractVa
*/
public String getCssText() {
StringBuffer sb = new StringBuffer( count * 8 );
- sb.append("icc-color(");
+ sb.append(ICC_COLOR_FUNCTION).append('(');
sb.append(colorProfile);
for (int i = 0; i < count; i++) {
sb.append(", ");
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg/SVGColorManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg/SVGColorManager.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg/SVGColorManager.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg/SVGColorManager.java Mon Jul 12 07:56:00 2010
@@ -24,6 +24,9 @@ import org.apache.batik.css.engine.Style
import org.apache.batik.css.engine.value.ListValue;
import org.apache.batik.css.engine.value.Value;
import org.apache.batik.css.engine.value.ValueManager;
+import org.apache.batik.css.engine.value.svg12.CIELabColor;
+import org.apache.batik.css.engine.value.svg12.DeviceColor;
+import org.apache.batik.css.engine.value.svg12.ICCNamedColor;
import org.apache.batik.util.CSSConstants;
import org.apache.batik.util.SVGTypes;
@@ -100,7 +103,7 @@ public class SVGColorManager extends Col
return property;
}
-
+
/**
* Implements {@link
* org.apache.batik.css.engine.value.ValueManager#getDefaultValue()}.
@@ -108,7 +111,7 @@ public class SVGColorManager extends Col
public Value getDefaultValue() {
return defaultValue;
}
-
+
/**
* Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
*/
@@ -125,36 +128,127 @@ public class SVGColorManager extends Col
if (lu == null) {
return v;
}
- if (lu.getLexicalUnitType() != LexicalUnit.SAC_FUNCTION ||
- !lu.getFunctionName().equalsIgnoreCase("icc-color")) {
- throw createInvalidLexicalUnitDOMException
- (lu.getLexicalUnitType());
- }
- lu = lu.getParameters();
- if (lu.getLexicalUnitType() != LexicalUnit.SAC_IDENT) {
+
+ if (lu.getLexicalUnitType() != LexicalUnit.SAC_FUNCTION) {
throw createInvalidLexicalUnitDOMException
(lu.getLexicalUnitType());
}
+
ListValue result = new ListValue(' ');
result.append(v);
+ String functionName = lu.getFunctionName();
+ if (functionName.equalsIgnoreCase(ICCColor.ICC_COLOR_FUNCTION)) {
+ result.append(createICCColorValue(lu, v));
+ } else if (functionName.equalsIgnoreCase(ICCNamedColor.ICC_NAMED_COLOR_FUNCTION)) {
+ result.append(createICCNamedColorValue(lu, v));
+ } else if (functionName.equalsIgnoreCase(CIELabColor.CIE_LAB_COLOR_FUNCTION)) {
+ result.append(createCIELabColorValue(lu, v));
+ } else if (functionName.equalsIgnoreCase(DeviceColor.DEVICE_CMYK_COLOR_FUNCTION)) {
+ result.append(createDeviceColorValue(lu, v, 4));
+ } else if (functionName.equalsIgnoreCase(DeviceColor.DEVICE_RGB_COLOR_FUNCTION)) {
+ result.append(createDeviceColorValue(lu, v, 3));
+ } else if (functionName.equalsIgnoreCase(DeviceColor.DEVICE_GRAY_COLOR_FUNCTION)) {
+ result.append(createDeviceColorValue(lu, v, 1));
+ } else if (functionName.equalsIgnoreCase(DeviceColor.DEVICE_CMYK_COLOR_FUNCTION)) {
+ result.append(createDeviceColorValue(lu, v, 0));
+ } else {
+ throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType());
+ }
+ return result;
+ }
+
+ private Value createICCColorValue(LexicalUnit lu, Value v) {
+ lu = lu.getParameters();
+ expectIdent(lu);
+
ICCColor icc = new ICCColor(lu.getStringValue());
- result.append(icc);
lu = lu.getNextLexicalUnit();
while (lu != null) {
- if (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) {
- throw createInvalidLexicalUnitDOMException
- (lu.getLexicalUnitType());
- }
+ expectComma(lu);
lu = lu.getNextLexicalUnit();
- if (lu == null) {
- throw createInvalidLexicalUnitDOMException((short)-1);
- }
icc.append(getColorValue(lu));
lu = lu.getNextLexicalUnit();
}
- return result;
+ return icc;
+ }
+
+ private Value createICCNamedColorValue(LexicalUnit lu, Value v) {
+ lu = lu.getParameters();
+ expectIdent(lu);
+ String profileName = lu.getStringValue();
+
+ lu = lu.getNextLexicalUnit();
+ expectComma(lu);
+ lu = lu.getNextLexicalUnit();
+ expectIdent(lu);
+ String colorName = lu.getStringValue();
+
+ ICCNamedColor icc = new ICCNamedColor(profileName, colorName);
+
+ lu = lu.getNextLexicalUnit();
+ return icc;
+ }
+
+ private Value createCIELabColorValue(LexicalUnit lu, Value v) {
+ lu = lu.getParameters();
+ float l = getColorValue(lu);
+ lu = lu.getNextLexicalUnit();
+ expectComma(lu);
+ lu = lu.getNextLexicalUnit();
+ float a = getColorValue(lu);
+ lu = lu.getNextLexicalUnit();
+ expectComma(lu);
+ lu = lu.getNextLexicalUnit();
+ float b = getColorValue(lu);
+
+ CIELabColor icc = new CIELabColor(l, a, b);
+
+ lu = lu.getNextLexicalUnit();
+ return icc;
+ }
+
+ private Value createDeviceColorValue(LexicalUnit lu, Value v, int expectedComponents) {
+ lu = lu.getParameters();
+
+ boolean nChannel = (expectedComponents <= 0);
+ DeviceColor col = new DeviceColor(nChannel);
+
+ col.append(getColorValue(lu));
+ LexicalUnit lastUnit = lu;
+ lu = lu.getNextLexicalUnit();
+ while (lu != null) {
+ expectComma(lu);
+ lu = lu.getNextLexicalUnit();
+ col.append(getColorValue(lu));
+ lastUnit = lu;
+ lu = lu.getNextLexicalUnit();
+ }
+ if (!nChannel && expectedComponents != col.getNumberOfColors()) {
+ throw createInvalidLexicalUnitDOMException(lastUnit.getLexicalUnitType());
+ }
+ return col;
+ }
+
+ private void expectIdent(LexicalUnit lu) {
+ if (lu.getLexicalUnitType() != LexicalUnit.SAC_IDENT) {
+ throw createInvalidLexicalUnitDOMException
+ (lu.getLexicalUnitType());
+ }
+ }
+
+ private void expectComma(LexicalUnit lu) {
+ if (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) {
+ throw createInvalidLexicalUnitDOMException
+ (lu.getLexicalUnitType());
+ }
+ }
+
+ private void expectNonNull(LexicalUnit lu) {
+ if (lu == null) {
+ throw createInvalidLexicalUnitDOMException((short)-1);
+ }
}
/**
@@ -192,6 +286,7 @@ public class SVGColorManager extends Col
* Creates a float value usable as a component of an RGBColor.
*/
protected float getColorValue(LexicalUnit lu) {
+ expectNonNull(lu);
switch (lu.getLexicalUnitType()) {
case LexicalUnit.SAC_INTEGER:
return lu.getIntegerValue();
Added: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/CIELabColor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/CIELabColor.java?rev=963203&view=auto
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/CIELabColor.java (added)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/CIELabColor.java Mon Jul 12 07:56:00 2010
@@ -0,0 +1,108 @@
+/*
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+package org.apache.batik.css.engine.value.svg12;
+
+import org.apache.batik.css.engine.value.AbstractValue;
+
+import org.apache.xmlgraphics.java2d.color.ColorSpaces;
+
+import org.w3c.dom.css.CSSValue;
+
+/**
+ * This class represents an CIE L*a*b* color value.
+ *
+ * @version $Id$
+ */
+public class CIELabColor extends AbstractValue {
+
+ public static final String CIE_LAB_COLOR_FUNCTION = "cielab";
+
+ /** The three color values (L*a*b*). */
+ protected float[] values = new float[3];
+
+ /** The white point, initialized to D65. */
+ protected float[] whitepoint = ColorSpaces.getCIELabColorSpaceD65().getWhitePoint();
+
+ /**
+ * Creates a new ICCColor.
+ * @param l the L* value
+ * @param a the a* value
+ * @param b the b* value
+ * @param whitepoint the white point in CIE XYZ coordinates
+ */
+ public CIELabColor(float l, float a, float b, float[] whitepoint) {
+ values[0] = l;
+ values[1] = a;
+ values[2] = b;
+ if (whitepoint != null) {
+ System.arraycopy(whitepoint, 0, this.whitepoint, 0, this.whitepoint.length);
+ }
+ }
+
+ /**
+ * Creates a new ICCColor.
+ */
+ public CIELabColor(float l, float a, float b) {
+ this(l, a, b, null);
+ }
+
+ /**
+ * Returns the color values.
+ * @return the color values
+ */
+ public float[] getColorValues() {
+ float[] copy = new float[3];
+ System.arraycopy(this.values, 0, copy, 0, copy.length);
+ return copy;
+ }
+
+ /**
+ * Returns the white point in CIE XYZ coordinates.
+ * @return the white point in CIE XYZ coordinates
+ */
+ public float[] getWhitePoint() {
+ float[] copy = new float[3];
+ System.arraycopy(this.whitepoint, 0, copy, 0, copy.length);
+ return copy;
+ }
+
+ /**
+ * Implements {@link
+ * org.apache.batik.css.engine.value.Value#getCssValueType()}.
+ */
+ public short getCssValueType() {
+ return CSSValue.CSS_CUSTOM;
+ }
+
+ /**
+ * A string representation of the current value.
+ */
+ public String getCssText() {
+ StringBuffer sb = new StringBuffer(CIE_LAB_COLOR_FUNCTION);
+ sb.append('(');
+ sb.append(values[0]);
+ sb.append(", ");
+ sb.append(values[1]);
+ sb.append(", ");
+ sb.append(values[2]);
+ sb.append( ')' );
+ return sb.toString();
+ }
+
+}
Propchange: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/CIELabColor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/CIELabColor.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/DeviceColor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/DeviceColor.java?rev=963203&view=auto
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/DeviceColor.java (added)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/DeviceColor.java Mon Jul 12 07:56:00 2010
@@ -0,0 +1,131 @@
+/*
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+package org.apache.batik.css.engine.value.svg12;
+
+import org.apache.batik.css.engine.value.AbstractValue;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.css.CSSValue;
+
+/**
+ * This class represents an device-specific color value.
+ *
+ * @version $Id$
+ */
+public class DeviceColor extends AbstractValue {
+
+ public static final String DEVICE_GRAY_COLOR_FUNCTION = "device-gray";
+ public static final String DEVICE_RGB_COLOR_FUNCTION = "device-rgb";
+ public static final String DEVICE_CMYK_COLOR_FUNCTION = "device-cmyk";
+ public static final String DEVICE_NCHANNEL_COLOR_FUNCTION = "device-nchannel";
+
+ protected boolean nChannel;
+
+ /**
+ * The color count.
+ */
+ protected int count;
+
+ /**
+ * The colors.
+ */
+ protected float[] colors = new float[5];
+
+ /**
+ * Creates a new DeviceColor.
+ * @param nChannel true for a device-nchannel() color, false for Gray, RGB and CMYK
+ */
+ public DeviceColor(boolean nChannel) {
+ this.nChannel = nChannel;
+ }
+
+ /**
+ * Implements {@link
+ * org.apache.batik.css.engine.value.Value#getCssValueType()}.
+ */
+ public short getCssValueType() {
+ return CSSValue.CSS_CUSTOM;
+ }
+
+ /**
+ * Indicates whether this color uses an N-Channel color space.
+ * @return true if N-Channel is used
+ */
+ public boolean isNChannel() {
+ return this.nChannel;
+ }
+
+ /**
+ * Returns the number of colors.
+ */
+ public int getNumberOfColors() throws DOMException {
+ return count;
+ }
+
+ /**
+ * Returns the color at the given index.
+ */
+ public float getColor(int i) throws DOMException {
+ return colors[i];
+ }
+
+ /**
+ * A string representation of the current value.
+ */
+ public String getCssText() {
+ StringBuffer sb = new StringBuffer( count * 8 );
+ switch (count) {
+ case 1:
+ sb.append(DEVICE_GRAY_COLOR_FUNCTION);
+ break;
+ case 3:
+ sb.append(DEVICE_RGB_COLOR_FUNCTION);
+ break;
+ case 4:
+ sb.append(DEVICE_CMYK_COLOR_FUNCTION);
+ break;
+ default:
+ if (nChannel) {
+ sb.append(DEVICE_NCHANNEL_COLOR_FUNCTION);
+ } else {
+ throw new IllegalStateException("Invalid number of components encountered");
+ }
+ }
+ sb.append('(');
+ for (int i = 0; i < count; i++) {
+ if (i > 0) {
+ sb.append(", ");
+ }
+ sb.append(colors[i]);
+ }
+ sb.append( ')' );
+ return sb.toString();
+ }
+
+ /**
+ * Appends a color to the list.
+ */
+ public void append(float c) {
+ if (count == colors.length) {
+ float[] t = new float[count * 2];
+ System.arraycopy( colors, 0, t, 0, count );
+ colors = t;
+ }
+ colors[count++] = c;
+ }
+}
Propchange: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/DeviceColor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/DeviceColor.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/ICCNamedColor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/ICCNamedColor.java?rev=963203&view=auto
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/ICCNamedColor.java (added)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/ICCNamedColor.java Mon Jul 12 07:56:00 2010
@@ -0,0 +1,87 @@
+/*
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ */
+package org.apache.batik.css.engine.value.svg12;
+
+import org.apache.batik.css.engine.value.AbstractValue;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.css.CSSValue;
+
+/**
+ * This class represents an ICC named color value.
+ *
+ * @version $Id$
+ */
+public class ICCNamedColor extends AbstractValue {
+
+ public static final String ICC_NAMED_COLOR_FUNCTION = "icc-named-color";
+
+ /**
+ * The color profile.
+ */
+ protected String colorProfile;
+
+ /**
+ * The color name.
+ */
+ protected String colorName;
+
+ /**
+ * Creates a new ICCColor.
+ */
+ public ICCNamedColor(String profileName, String colorName) {
+ this.colorProfile = profileName;
+ this.colorName = colorName;
+ }
+
+ /**
+ * Implements {@link
+ * org.apache.batik.css.engine.value.Value#getCssValueType()}.
+ */
+ public short getCssValueType() {
+ return CSSValue.CSS_CUSTOM;
+ }
+
+ /**
+ * Returns the color name.
+ */
+ public String getColorProfile() throws DOMException {
+ return colorProfile;
+ }
+
+ /**
+ * Returns the color name
+ */
+ public String getColorName() throws DOMException {
+ return colorName;
+ }
+
+ /**
+ * A string representation of the current value.
+ */
+ public String getCssText() {
+ StringBuffer sb = new StringBuffer(ICC_NAMED_COLOR_FUNCTION);
+ sb.append('(');
+ sb.append(colorProfile);
+ sb.append(", ");
+ sb.append(colorName);
+ sb.append( ')' );
+ return sb.toString();
+ }
+
+}
Propchange: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/ICCNamedColor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/css/engine/value/svg12/ICCNamedColor.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/color/ICCColorSpaceExt.java Mon Jul 12 07:56:00 2010
@@ -30,6 +30,7 @@ import java.awt.color.ICC_Profile;
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
* @version $Id$
+ * @deprecated use the version from XML Graphics Commons instead
*/
public class ICCColorSpaceExt extends ICC_ColorSpace {
public static final int PERCEPTUAL = 0;
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/color/NamedProfileCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/color/NamedProfileCache.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/color/NamedProfileCache.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/color/NamedProfileCache.java Mon Jul 12 07:56:00 2010
@@ -21,9 +21,11 @@ package org.apache.batik.ext.awt.color;
import org.apache.batik.util.SoftReferenceCache;
+import org.apache.xmlgraphics.java2d.color.ICCColorSpaceExt;
+
/**
* This class manages a cache of soft references to named profiles that
- * we have already loaded.
+ * we have already loaded.
*
* @author <a href="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
* @version $Id$
@@ -37,7 +39,9 @@ public class NamedProfileCache extends S
/**
* Let people create there own caches.
*/
- public NamedProfileCache() { }
+ public NamedProfileCache() {
+ super(true);
+ }
/**
* Check if <tt>request(profileName)</tt> will return with a ICCColorSpaceExt
@@ -45,7 +49,7 @@ public class NamedProfileCache extends S
* that this will return true but between this call and the call
* to request the soft-reference will be cleared. So it
* is still possible for request to return NULL, just much less
- * likely (you can always call 'clear' in that case).
+ * likely (you can always call 'clear' in that case).
*/
public synchronized boolean isPresent(String profileName) {
return super.isPresentImpl(profileName);
@@ -64,7 +68,9 @@ public class NamedProfileCache extends S
/**
* If this returns null then you are now 'on the hook'.
* to put the ICCColorSpaceExt associated with String into the
- * cache. */
+ * cache.
+ * @param the profile name
+ */
public synchronized ICCColorSpaceExt request(String profileName) {
return (ICCColorSpaceExt)super.requestImpl(profileName);
}
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/renderable/ProfileRable.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/renderable/ProfileRable.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/renderable/ProfileRable.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/renderable/ProfileRable.java Mon Jul 12 07:56:00 2010
@@ -21,11 +21,12 @@ package org.apache.batik.ext.awt.image.r
import java.awt.image.RenderedImage;
import java.awt.image.renderable.RenderContext;
-import org.apache.batik.ext.awt.color.ICCColorSpaceExt;
import org.apache.batik.ext.awt.image.GraphicsUtil;
import org.apache.batik.ext.awt.image.rendered.CachableRed;
import org.apache.batik.ext.awt.image.rendered.ProfileRed;
+import org.apache.xmlgraphics.java2d.color.ICCColorSpaceExt;
+
/**
* Implements the interface expected from a color matrix
* operation
@@ -34,7 +35,7 @@ import org.apache.batik.ext.awt.image.re
* @version $Id$
*/
public class ProfileRable extends AbstractRable{
-
+
private ICCColorSpaceExt colorSpace;
/**
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/rendered/ProfileRed.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/rendered/ProfileRed.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/rendered/ProfileRed.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/rendered/ProfileRed.java Mon Jul 12 07:56:00 2010
@@ -35,8 +35,7 @@ import java.awt.image.Raster;
import java.awt.image.RenderedImage;
import java.awt.image.WritableRaster;
-import org.apache.batik.ext.awt.color.ICCColorSpaceExt;
-
+import org.apache.xmlgraphics.java2d.color.ICCColorSpaceExt;
/**
* This implementation of rendered image forces a color profile
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/spi/ImageTagRegistry.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/spi/ImageTagRegistry.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/spi/ImageTagRegistry.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/ext/awt/image/spi/ImageTagRegistry.java Mon Jul 12 07:56:00 2010
@@ -28,13 +28,14 @@ import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
-import org.apache.batik.ext.awt.color.ICCColorSpaceExt;
import org.apache.batik.ext.awt.image.URLImageCache;
import org.apache.batik.ext.awt.image.renderable.Filter;
import org.apache.batik.ext.awt.image.renderable.ProfileRable;
import org.apache.batik.util.ParsedURL;
import org.apache.batik.util.Service;
+import org.apache.xmlgraphics.java2d.color.ICCColorSpaceExt;
+
/**
* This class handles the registered Image tag handlers. These are
* instances of RegistryEntry in this package.
Modified: xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/util/SoftReferenceCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/util/SoftReferenceCache.java?rev=963203&r1=963202&r2=963203&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/util/SoftReferenceCache.java (original)
+++ xmlgraphics/batik/branches/svgcolor12/sources/org/apache/batik/util/SoftReferenceCache.java Mon Jul 12 07:56:00 2010
@@ -53,10 +53,23 @@ public class SoftReferenceCache {
*/
protected final Map map = new HashMap();
+ private final boolean synchronous;
+
/**
* Let people create their own caches.
*/
- protected SoftReferenceCache() { }
+ protected SoftReferenceCache() {
+ this(false);
+ }
+
+ /**
+ * Constructs a soft reference cache.
+ * @param synchronous true to enable synchronous mode, false to enable waiting on requestImpl()
+ * until another thread adds the missing object
+ */
+ protected SoftReferenceCache(boolean synchronous) {
+ this.synchronous = synchronous;
+ }
/**
* Let people flush the cache (remove any cached data). Pending
@@ -126,6 +139,9 @@ public class SoftReferenceCache {
Object o = map.get(key);
while(o == null) {
+ if (synchronous) {
+ return null; //Noone will add the value asynchronously, so don't wait()
+ }
try {
// When something is cleared or put we will be notified.
wait();