01: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
02: // Released under the terms of the GNU General Public License version 2 or later.
03:
04: package fat;
05:
06: import fit.*;
07:
08: public class Color extends PrimitiveFixture {
09:
10: Parse actualRow;
11:
12: public void doRows(Parse rows) {
13: actualRow = Table.table.parts;
14: if (rows.size() != actualRow.size())
15: throw new RuntimeException("wrong size table");
16: super .doRows(rows);
17: }
18:
19: public void doRow(Parse row) {
20: super .doRow(row);
21: actualRow = actualRow.more;
22: }
23:
24: public void doCell(Parse cell, int columnNumber) {
25: check(cell, color(actualRow.parts.at(columnNumber)));
26: }
27:
28: String color(Parse cell) {
29: String b = extract(cell.tag, "bgcolor=\"", "white");
30: String f = extract(cell.body, "<font color=", "black");
31: return f.equals("black") ? b : f + "/" + b;
32: }
33:
34: String extract(String text, String pattern, String defaultColor) {
35: int index = text.indexOf(pattern);
36: if (index < 0)
37: return defaultColor;
38: index += pattern.length();
39: return decode(text.substring(index, index + 7));
40: }
41:
42: String decode(String code) {
43: return code.equals(Fixture.red) ? "red" : code
44: .equals(Fixture.green) ? "green" : code
45: .equals(Fixture.yellow) ? "yellow" : code
46: .equals(Fixture.gray) ? "gray"
47: : code.equals("#808080") ? "gray" : code;
48: }
49:
50: }
|