1 | /* Copyright 2012 Malcolm Herring
|
---|
2 | *
|
---|
3 | * This is free software: you can redistribute it and/or modify
|
---|
4 | * it under the terms of the GNU General Public License as published by
|
---|
5 | * the Free Software Foundation, version 3 of the License.
|
---|
6 | *
|
---|
7 | * For a copy of the GNU General Public License, see <http://www.gnu.org/licenses/>.
|
---|
8 | */
|
---|
9 |
|
---|
10 | package symbols;
|
---|
11 |
|
---|
12 | import java.awt.BasicStroke;
|
---|
13 | import java.awt.Color;
|
---|
14 | import java.awt.Graphics2D;
|
---|
15 | import java.awt.Rectangle;
|
---|
16 | import java.awt.geom.*;
|
---|
17 | import java.util.ArrayList;
|
---|
18 | import java.util.EnumMap;
|
---|
19 |
|
---|
20 | import s57.S57val.*;
|
---|
21 |
|
---|
22 | public class Symbols {
|
---|
23 |
|
---|
24 | public enum Prim {
|
---|
25 | BBOX, STRK, COLR, FILL, LINE, RECT, RRCT, ELPS, EARC, PLIN, PGON, RSHP, TEXT, SYMB, P1, P2, H2, H3, H4, H5, V2, D2, D3, D4, B2, S2, S3, S4, C2, X2
|
---|
26 | }
|
---|
27 |
|
---|
28 | public enum Handle {
|
---|
29 | CC, TL, TR, TC, LC, RC, BL, BR, BC
|
---|
30 | }
|
---|
31 |
|
---|
32 | public static final double symbolScale[] = { 256.0, 128.0, 64.0, 32.0, 16.0, 8.0, 4.0, 2.0, 1.0, 0.61, 0.372, 0.227, 0.138,
|
---|
33 | 0.0843, 0.0514, 0.0313, 0.0191, 0.0117, 0.007, 0.138 };
|
---|
34 |
|
---|
35 | public static final double textScale[] = { 256.0, 128.0, 64.0, 32.0, 16.0, 8.0, 4.0, 2.0, 1.0, 0.5556, 0.3086, 0.1714, 0.0953,
|
---|
36 | 0.0529, 0.0294, 0.0163, 0.0091, 0.0050, 0.0028, 0.0163 };
|
---|
37 |
|
---|
38 | private static final EnumMap<ColCOL, Color> bodyColours = new EnumMap<ColCOL, Color>(ColCOL.class);
|
---|
39 | static {
|
---|
40 | bodyColours.put(ColCOL.COL_UNK, new Color(0, true));
|
---|
41 | bodyColours.put(ColCOL.COL_WHT, new Color(0xffffff));
|
---|
42 | bodyColours.put(ColCOL.COL_BLK, new Color(0x000000));
|
---|
43 | bodyColours.put(ColCOL.COL_RED, new Color(0xd40000));
|
---|
44 | bodyColours.put(ColCOL.COL_GRN, new Color(0x00d400));
|
---|
45 | bodyColours.put(ColCOL.COL_BLU, Color.blue);
|
---|
46 | bodyColours.put(ColCOL.COL_YEL, new Color(0xffd400));
|
---|
47 | bodyColours.put(ColCOL.COL_GRY, Color.gray);
|
---|
48 | bodyColours.put(ColCOL.COL_BRN, new Color(0x8b4513));
|
---|
49 | bodyColours.put(ColCOL.COL_AMB, new Color(0xfbf00f));
|
---|
50 | bodyColours.put(ColCOL.COL_VIO, new Color(0xee82ee));
|
---|
51 | bodyColours.put(ColCOL.COL_ORG, Color.orange);
|
---|
52 | bodyColours.put(ColCOL.COL_MAG, new Color(0xf000f0));
|
---|
53 | bodyColours.put(ColCOL.COL_PNK, Color.pink);
|
---|
54 | }
|
---|
55 |
|
---|
56 | public static class Instr {
|
---|
57 | Prim type;
|
---|
58 | Object params;
|
---|
59 |
|
---|
60 | Instr(Prim itype, Object iparams) {
|
---|
61 | type = itype;
|
---|
62 | params = iparams;
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | public static class Delta {
|
---|
67 | Handle h;
|
---|
68 | AffineTransform t;
|
---|
69 |
|
---|
70 | public Delta(Handle ih, AffineTransform it) {
|
---|
71 | h = ih;
|
---|
72 | t = it;
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | public static class Scheme {
|
---|
77 | ArrayList<ColPAT> pat;
|
---|
78 | ArrayList<ColCOL> col;
|
---|
79 |
|
---|
80 | public Scheme(ArrayList<ColPAT> ipat, ArrayList<ColCOL> icol) {
|
---|
81 | pat = ipat;
|
---|
82 | col = icol;
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | public static class Symbol {
|
---|
87 | ArrayList<Instr> instr;
|
---|
88 | double scale;
|
---|
89 | double x;
|
---|
90 | double y;
|
---|
91 | Delta delta;
|
---|
92 | Scheme scheme;
|
---|
93 |
|
---|
94 | public Symbol(ArrayList<Instr> iinstr, double iscale, double ix, double iy, Delta idelta, Scheme ischeme) {
|
---|
95 | instr = iinstr;
|
---|
96 | scale = iscale;
|
---|
97 | x = ix;
|
---|
98 | y = iy;
|
---|
99 | delta = idelta;
|
---|
100 | scheme = ischeme;
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | public static void drawSymbol(Graphics2D g2, ArrayList<Instr> symbol, double scale, double x, double y, Delta dd, Scheme cs) {
|
---|
105 | int pn = 0;
|
---|
106 | int cn = 0;
|
---|
107 | if (cs != null) {
|
---|
108 | pn = cs.pat.size();
|
---|
109 | cn = cs.col.size() - ((pn != 0) ? pn - 1 : 0);
|
---|
110 | }
|
---|
111 | AffineTransform savetr = g2.getTransform();
|
---|
112 | g2.translate(x, y);
|
---|
113 | g2.scale(scale, scale);
|
---|
114 | for (Instr item : symbol) {
|
---|
115 | switch (item.type) {
|
---|
116 | case BBOX:
|
---|
117 | Rectangle bbox = (Rectangle) item.params;
|
---|
118 | double dx = 0.0;
|
---|
119 | double dy = 0.0;
|
---|
120 | if (dd != null) {
|
---|
121 | switch (dd.h) {
|
---|
122 | case CC:
|
---|
123 | dx = bbox.x + (bbox.width / 2.0);
|
---|
124 | dy = bbox.y - (bbox.height / 2.0);
|
---|
125 | break;
|
---|
126 | case TL:
|
---|
127 | dx = bbox.x;
|
---|
128 | dy = bbox.y;
|
---|
129 | break;
|
---|
130 | case TR:
|
---|
131 | dx = bbox.x + bbox.width;
|
---|
132 | dy = bbox.y;
|
---|
133 | break;
|
---|
134 | case TC:
|
---|
135 | dx = bbox.x + (bbox.width / 2.0);
|
---|
136 | dy = bbox.y;
|
---|
137 | break;
|
---|
138 | case LC:
|
---|
139 | dx = bbox.x;
|
---|
140 | dy = bbox.y - (bbox.height / 2.0);
|
---|
141 | break;
|
---|
142 | case RC:
|
---|
143 | dx = bbox.x + bbox.width;
|
---|
144 | dy = bbox.y - (bbox.height / 2.0);
|
---|
145 | break;
|
---|
146 | case BL:
|
---|
147 | dx = bbox.x;
|
---|
148 | dy = bbox.y - bbox.height;
|
---|
149 | break;
|
---|
150 | case BR:
|
---|
151 | dx = bbox.x + bbox.width;
|
---|
152 | dy = bbox.y - bbox.height;
|
---|
153 | break;
|
---|
154 | case BC:
|
---|
155 | dx = bbox.x + (bbox.width / 2.0);
|
---|
156 | dy = bbox.y - bbox.height;
|
---|
157 | break;
|
---|
158 | }
|
---|
159 | g2.translate(dx, dy);
|
---|
160 | g2.transform(dd.t);
|
---|
161 | }
|
---|
162 | break;
|
---|
163 | case COLR:
|
---|
164 | if ((cs != null) && (cs.col != null)) {
|
---|
165 | for (Instr patch : (ArrayList<Instr>) item.params) {
|
---|
166 | switch (patch.type) {
|
---|
167 | case P1:
|
---|
168 | if (cn > 0) {
|
---|
169 | g2.setPaint(bodyColours.get(cs.col.get(0)));
|
---|
170 | g2.fill((Path2D.Double) patch.params);
|
---|
171 | }
|
---|
172 | break;
|
---|
173 | case P2:
|
---|
174 | if (cn > 0) {
|
---|
175 | if (cn > 1) {
|
---|
176 | g2.setPaint(bodyColours.get(cs.col.get(1)));
|
---|
177 | } else {
|
---|
178 | g2.setPaint(bodyColours.get(cs.col.get(0)));
|
---|
179 | }
|
---|
180 | g2.fill((Path2D.Double) patch.params);
|
---|
181 | }
|
---|
182 | break;
|
---|
183 | case H2:
|
---|
184 | if ((cn > 1) && (cs.pat.get(0) == ColPAT.PAT_HORI)) {
|
---|
185 | g2.setPaint(bodyColours.get(cs.col.get(cs.col.size() - pn)));
|
---|
186 | g2.fill((Path2D.Double) patch.params);
|
---|
187 | }
|
---|
188 | break;
|
---|
189 | case H3:
|
---|
190 | if ((cn == 3) && (cs.pat.get(0) == ColPAT.PAT_HORI)) {
|
---|
191 | g2.setPaint(bodyColours.get(cs.col.get(1)));
|
---|
192 | g2.fill((Path2D.Double) patch.params);
|
---|
193 | }
|
---|
194 | break;
|
---|
195 | case H4:
|
---|
196 | if ((cn == 4) && (cs.pat.get(0) == ColPAT.PAT_HORI)) {
|
---|
197 | g2.setPaint(bodyColours.get(cs.col.get(1)));
|
---|
198 | g2.fill((Path2D.Double) patch.params);
|
---|
199 | }
|
---|
200 | break;
|
---|
201 | case H5:
|
---|
202 | if ((cn == 4) && (cs.pat.get(0) == ColPAT.PAT_HORI)) {
|
---|
203 | g2.setPaint(bodyColours.get(cs.col.get(2)));
|
---|
204 | g2.fill((Path2D.Double) patch.params);
|
---|
205 | }
|
---|
206 | break;
|
---|
207 | case V2:
|
---|
208 | if ((cn > 1) && (cs.pat.get(0) == ColPAT.PAT_VERT)) {
|
---|
209 | g2.setPaint(bodyColours.get(cs.col.get(cs.col.size() - pn)));
|
---|
210 | g2.fill((Path2D.Double) patch.params);
|
---|
211 | }
|
---|
212 | break;
|
---|
213 | }
|
---|
214 | }
|
---|
215 | }
|
---|
216 | break;
|
---|
217 | case STRK:
|
---|
218 | g2.setStroke((BasicStroke) item.params);
|
---|
219 | break;
|
---|
220 | case FILL:
|
---|
221 | g2.setPaint((Color) item.params);
|
---|
222 | break;
|
---|
223 | case LINE:
|
---|
224 | g2.draw((Line2D.Double) item.params);
|
---|
225 | break;
|
---|
226 | case RECT:
|
---|
227 | g2.draw((Rectangle2D.Double) item.params);
|
---|
228 | break;
|
---|
229 | case RRCT:
|
---|
230 | g2.draw((RoundRectangle2D.Double) item.params);
|
---|
231 | break;
|
---|
232 | case ELPS:
|
---|
233 | g2.draw((Ellipse2D.Double) item.params);
|
---|
234 | break;
|
---|
235 | case EARC:
|
---|
236 | g2.draw((Arc2D.Double) item.params);
|
---|
237 | break;
|
---|
238 | case PLIN:
|
---|
239 | g2.draw((Path2D.Double) item.params);
|
---|
240 | break;
|
---|
241 | case PGON:
|
---|
242 | g2.fill((Path2D.Double) item.params);
|
---|
243 | break;
|
---|
244 | case RSHP:
|
---|
245 | g2.fill((RectangularShape) item.params);
|
---|
246 | break;
|
---|
247 | case SYMB:
|
---|
248 | Symbol s = (Symbol) item.params;
|
---|
249 | drawSymbol(g2, s.instr, s.scale, s.x, s.y, s.delta, s.scheme);
|
---|
250 | break;
|
---|
251 | case TEXT:
|
---|
252 | break;
|
---|
253 | }
|
---|
254 | }
|
---|
255 | g2.setTransform(savetr);
|
---|
256 | }
|
---|
257 | }
|
---|