| 1 |
|
| 2 |
package org.freehep.graphicsio.cgm; |
| 3 |
|
| 4 |
import java.awt.Color; |
| 5 |
import java.awt.geom.Point2D; |
| 6 |
import java.io.IOException; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public class CellArray extends CGMTag { |
| 17 |
|
| 18 |
public final static int RUN_LENGTH = 0; |
| 19 |
|
| 20 |
public final static int PACKED = 1; |
| 21 |
|
| 22 |
private Point2D p, q, r; |
| 23 |
|
| 24 |
private Color[][] colorArray; |
| 25 |
|
| 26 |
private int precision; |
| 27 |
|
| 28 |
private int mode; |
| 29 |
|
| 30 |
public CellArray() { |
| 31 |
super(4, 9, 1); |
| 32 |
} |
| 33 |
|
| 34 |
private CellArray(Point2D p, Point2D q, Point2D r, Color[][] colorArray, |
| 35 |
int precision, int mode) { |
| 36 |
this(); |
| 37 |
this.p = p; |
| 38 |
this.q = q; |
| 39 |
this.r = r; |
| 40 |
this.colorArray = colorArray; |
| 41 |
this.precision = precision; |
| 42 |
this.mode = mode; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public CellArray(Point2D p, Point2D q, Point2D r, Color[][] colorArray) { |
| 49 |
this(p, q, r, colorArray, 8, PACKED); |
| 50 |
} |
| 51 |
|
| 52 |
public void write(int tagID, CGMOutputStream cgm) throws IOException { |
| 53 |
cgm.writePoint(p); |
| 54 |
cgm.writePoint(q); |
| 55 |
cgm.writePoint(r); |
| 56 |
cgm.writeInteger(colorArray[0].length); |
| 57 |
cgm.writeInteger(colorArray.length); |
| 58 |
cgm.writeInteger(precision); |
| 59 |
cgm.writeEnumerate(mode); |
| 60 |
cgm.pushBuffer(); |
| 61 |
for (int i = 0; i < colorArray.length; i++) { |
| 62 |
wordAlign(cgm); |
| 63 |
for (int j = 0; j < colorArray[0].length; j++) { |
| 64 |
cgm.writeColor(colorArray[i][j]); |
| 65 |
} |
| 66 |
} |
| 67 |
cgm.popBuffer(); |
| 68 |
cgm.append(); |
| 69 |
} |
| 70 |
|
| 71 |
private void wordAlign(CGMOutputStream cgm) throws IOException { |
| 72 |
int align = 2; |
| 73 |
int pad = (align - (cgm.getBufferLength() % align)) % align; |
| 74 |
for (int i = 0; i < pad; i++) { |
| 75 |
cgm.write(0); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
public void write(int tagID, CGMWriter cgm) throws IOException { |
| 80 |
cgm.println("CELLARRAY"); |
| 81 |
cgm.indent(); |
| 82 |
cgm.writePoint(p); |
| 83 |
cgm.println(","); |
| 84 |
cgm.writePoint(q); |
| 85 |
cgm.println(","); |
| 86 |
cgm.writePoint(r); |
| 87 |
cgm.println(","); |
| 88 |
cgm.writeInteger(colorArray[0].length); |
| 89 |
cgm.println(","); |
| 90 |
cgm.writeInteger(colorArray.length); |
| 91 |
cgm.println(","); |
| 92 |
cgm.writeInteger(precision); |
| 93 |
cgm.println(","); |
| 94 |
for (int i = 0; i < colorArray.length; i++) { |
| 95 |
cgm.print("("); |
| 96 |
int widthMinus1 = colorArray[0].length - 1; |
| 97 |
for (int j = 0; j < widthMinus1; j++) { |
| 98 |
cgm.writeColor(colorArray[i][j]); |
| 99 |
cgm.print(", "); |
| 100 |
} |
| 101 |
cgm.writeColor(colorArray[i][widthMinus1]); |
| 102 |
if (i == colorArray.length - 1) { |
| 103 |
cgm.print(")"); |
| 104 |
} else { |
| 105 |
cgm.println(") ,"); |
| 106 |
} |
| 107 |
} |
| 108 |
cgm.outdent(); |
| 109 |
} |
| 110 |
} |