Revision: 7648
Author: victormote
Date: 2006-06-16 09:27:10 -0700 (Fri, 16 Jun 2006)
ViewCVS: http://svn.sourceforge.net/foray/?rev=7648&view=rev
Log Message:
-----------
1. Make static values instances of DtColor instead of java.awt.Color.
2. Reduce the DtColor named colors parsed to those listed in the XSL-FO standard. Retain others in a comment.
Modified Paths:
--------------
trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/prop/Border.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/prop/BorderColor.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/prop/Color.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/parse/PropertyParser.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/value/DtColor.java
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/prop/Border.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/prop/Border.java 2006-06-16 15:49:09 UTC (rev 7647)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/prop/Border.java 2006-06-16 16:27:10 UTC (rev 7648)
@@ -35,7 +35,6 @@
import org.axsl.common.Constants;
-import java.awt.Color;
import java.util.StringTokenizer;
/**
@@ -111,10 +110,10 @@
new PropertyKeyword(keyword));
}
// Now check for color keywords
- Color color = DtColor.mapNameToColorRGB(token);
- if (color != null) {
+ DtColor dtColor = DtColor.mapNameToColorRGB(token);
+ if (dtColor != null) {
return new BorderColor(Constants.FOPROP_BORDER_COLOR,
- DtColor.makeColorDT(color));
+ dtColor);
}
// Now try using the standard parse
PropertyValue pv = standardParse(propertyList, token, false, false);
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/prop/BorderColor.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/prop/BorderColor.java 2006-06-16 15:49:09 UTC (rev 7647)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/prop/BorderColor.java 2006-06-16 16:27:10 UTC (rev 7648)
@@ -114,7 +114,7 @@
}
public static Color getValueNoInstance() {
- return DtColor.mapNameToColorRGB("black");
+ return DtColor.mapNameToColorRGB("black").getColor();
}
/**
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/prop/Color.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/prop/Color.java 2006-06-16 15:49:09 UTC (rev 7647)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/prop/Color.java 2006-06-16 16:27:10 UTC (rev 7648)
@@ -60,9 +60,9 @@
public PropertyValue createPropertyValue(PropertyList propertyList,
String value) throws PropertyException {
- java.awt.Color color = DtColor.mapNameToColorRGB(value);
- if (color != null) {
- return DtColor.makeColorDT(color);
+ DtColor dtColor = DtColor.mapNameToColorRGB(value);
+ if (dtColor != null) {
+ return dtColor;
}
PropertyValue pv = checkKeywords(value);
if (pv != null) {
@@ -112,7 +112,7 @@
}
protected static java.awt.Color getDefaultColor() {
- return DtColor.mapNameToColorRGB("black");
+ return DtColor.mapNameToColorRGB("black").getColor();
}
}
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/parse/PropertyParser.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/parse/PropertyParser.java 2006-06-16 15:49:09 UTC (rev 7647)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/parse/PropertyParser.java 2006-06-16 16:27:10 UTC (rev 7648)
@@ -46,7 +46,6 @@
import org.foray.fotree.value.Function;
import org.foray.fotree.value.PropertyValue;
-import java.awt.Color;
import java.util.ArrayList;
import java.util.Stack;
@@ -237,13 +236,11 @@
break;
case TOK_COLORSPEC:
- Color color = null;
- try {
- color = DtColor.parseColorDescription(currentTokenValue);
- } catch (PropertyException e) {
- throw new PropertyException(e.getMessage());
- }
- prop = DtColor.makeColorDT(color);
+ try {
+ prop = DtColor.parseColorDescription(currentTokenValue);
+ } catch (PropertyException e) {
+ throw new PropertyException(e.getMessage());
+ }
break;
case TOK_FUNCTION_LPAR: {
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/value/DtColor.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/value/DtColor.java 2006-06-16 15:49:09 UTC (rev 7647)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/value/DtColor.java 2006-06-16 16:27:10 UTC (rev 7648)
@@ -35,169 +35,61 @@
*/
public class DtColor extends Datatype implements ExprColor {
- /*
- * Keep this list in alphabetical order, to facilitate binary searches.
+ /**
+ * Alphabetical list of named colors supported by XSL-FO.
+ * The list is kept in alphabetical order to facilitate binary searches.
+ * (There are only 16 items now, but that may grow in the future).
+ * The list of these colors is found in XSL-FO 1.0, Section 5.11, in the
+ * description of the "color" datatype.
*/
- static final String[] names = {
- "aliceblue",
- "antiquewhite",
+ private static final String[] names = {
"aqua",
- "aquamarine",
- "azure",
- "beige",
- "bisque",
"black",
- "blanchedalmond",
"blue",
- "blueviolet",
- "brown",
- "burlywood",
- "cadetblue",
- "chartreuse",
- "chocolate",
- "coral",
- "cornflowerblue",
- "cornsilk",
- "crimson",
- "cyan",
- "darkblue",
- "darkcyan",
- "darkgoldenrod",
- "darkgray",
- "darkgreen",
- "darkgrey",
- "darkkhaki",
- "darkmagenta",
- "darkolivegreen",
- "darkorange",
- "darkorchid",
- "darkred",
- "darksalmon",
- "darkseagreen",
- "darkslateblue",
- "darkslategray",
- "darkslategrey",
- "darkturquoise",
- "darkviolet",
- "deeppink",
- "deepskyblue",
- "dimgray",
- "dimgrey",
- "dodgerblue",
- "firebrick",
- "floralwhite",
- "forestgreen",
"fuchsia",
- "gainsboro",
- "ghostwhite",
- "gold",
- "goldenrod",
"gray",
"green",
- "greenyellow",
- "grey",
- "honeydew",
- "hotpink",
- "indianred",
- "indigo",
- "ivory",
- "khaki",
- "lavender",
- "lavenderblush",
- "lawngreen",
- "lemonchiffon",
- "lightblue",
- "lightcoral",
- "lightcyan",
- "lightgoldenrodyellow",
- "lightgray",
- "lightgreen",
- "lightgrey",
- "lightpink",
- "lightsalmon",
- "lightseagreen",
- "lightskyblue",
- "lightslategray",
- "lightslategrey",
- "lightsteelblue",
- "lightyellow",
"lime",
- "limegreen",
- "linen",
- "magenta",
"maroon",
- "mediumaquamarine",
- "mediumblue",
- "mediumorchid",
- "mediumpurple",
- "mediumseagreen",
- "mediumslateblue",
- "mediumspringgreen",
- "mediumturquoise",
- "mediumvioletred",
- "midnightblue",
- "mintcream",
- "mistyrose",
- "moccasin",
- "navajowhite",
"navy",
- "oldlace",
"olive",
- "olivedrab",
- "orange",
- "orangered",
- "orchid",
- "palegoldenrod",
- "palegreen",
- "paleturquoise",
- "palevioletred",
- "papayawhip",
- "peachpuff",
- "peru",
- "pink",
- "plum",
- "powderblue",
"purple",
"red",
- "rosybrown",
- "royalblue",
- "saddlebrown",
- "salmon",
- "sandybrown",
- "seagreen",
- "seashell",
- "sienna",
"silver",
- "skyblue",
- "slateblue",
- "slategray",
- "slategrey",
- "snow",
- "springgreen",
- "steelblue",
- "tan",
"teal",
- "thistle",
- "tomato",
- "turquoise",
- "violet",
- "wheat",
"white",
- "whitesmoke",
"yellow",
- "yellowgreen"
-};
+ };
- /*
+ /**
* Keep this list in the same order as the name list above (i.e.
* alphabetical, to facilitate binary searches.
- *
- * Don't know where these values and names came from. However, the 16
- * named colors defined in the CSS-1 (Cascading Style Sheets) standard are
- * defined and match the values in that standard. XSL 1.0 uses the same
- * 16 named colors.
*/
- static final Color[] vals = {
+ private static final DtColor[] vals = {
+ makeColorDT(new Color(0, 255, 255)), // aqua
+ makeColorDT(new Color(0, 0, 0)), // black
+ makeColorDT(new Color(0, 0, 255)), // blue
+ makeColorDT(new Color(255, 0, 255)), // fuchsia
+ makeColorDT(new Color(128, 128, 128)), // gray
+ makeColorDT(new Color(0, 255, 0)), // green
+ makeColorDT(new Color(0, 255, 0)), // lime
+ makeColorDT(new Color(128, 0, 0)), // maroon
+ makeColorDT(new Color(0, 0, 128)), // navy
+ makeColorDT(new Color(128, 128, 0)), // olive
+ makeColorDT(new Color(128, 0, 128)), // purple
+ makeColorDT(new Color(255, 0, 0)), // red
+ makeColorDT(new Color(192, 192, 192)), // silver
+ makeColorDT(new Color(0, 128, 128)), // teal
+ makeColorDT(new Color(255, 255, 255)), // white
+ makeColorDT(new Color(255, 255, 0)), // yellow
+ };
+
+ /*
+ * Here are the RGB values for a bunch of other colors, listed in
+ * alphabetical order, that are not supported by XSL-FO. They are retained
+ * here for reference purposes only, and in case these named colors are
+ * added to the standard in the future. We do not know the source of these
+ * color definitions.
new Color(240, 248, 255), // aliceblue
new Color(250, 235, 215), // antiquewhite
new Color(0, 255, 255), // aqua
@@ -345,7 +237,7 @@
new Color(245, 245, 245), // whitesmoke
new Color(255, 255, 0), // yellow
new Color(154, 205, 50) // yellowgreen
- };
+ */
public static final Color COLOR_RGB_TRANSPARENT = new Color(255, 255, 255,
0);
@@ -375,28 +267,18 @@
* Factory method which converts a named color into a ColorDT instance.
* @param input The named color (for example, "blue" or "teal") to be
* converted.
- * @return A ColorDT instance, or null if input is not valid.
+ * @return A ColorDT instance, or null if input is not a defined XSL-FO
+ * named color.
*/
public static DtColor makeColorDT(String input) {
- /*
- * Note: This scheme is not strictly
- * conformant to the XSL-FO 1.0 Standard, which lists only 16 named
- * colors, the same that are in CSS. The list used in our search has
- * many more than that. Not sure whether this is a bonus or a problem
- * with regard to standardization.
- */
- Color color = mapNameToColorRGB(input);
- if (color != null) {
- return new DtColor(color);
- }
- return null;
+ return mapNameToColorRGB(input);
}
public static DtColor makeColorDT(Color color) {
return new DtColor(color);
}
- public static Color mapNameToColorRGB(String colorName) {
+ public static DtColor mapNameToColorRGB(String colorName) {
// Do a binary search to find the name in the names list.
int index = Arrays.binarySearch(names, colorName);
if (index < 0 || index >= names.length) {
@@ -410,7 +292,7 @@
* set the colour given a particular String specifying either a
* colour name or #RGB or #RRGGBB
*/
- public static Color parseColorDescription(String value)
+ public static DtColor parseColorDescription(String value)
throws PropertyException {
float red = 0;
float green = 0;
@@ -507,7 +389,7 @@
blue = 0;
alpha = 1;
} else {
- Color foundColor = mapNameToColorRGB(value.toLowerCase());
+ DtColor foundColor = mapNameToColorRGB(value.toLowerCase());
if (foundColor == null) {
red = 0;
green = 0;
@@ -515,13 +397,11 @@
throw new PropertyException("Unknown colour name: "
+ value);
}
- red = foundColor.getRed();
- green = foundColor.getGreen();
- blue = foundColor.getBlue();
+ return foundColor;
}
}
Color newColor = new Color(red, green, blue, alpha);
- return newColor;
+ return new DtColor(newColor);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|