source: osm/applications/editors/josm/plugins/smed2/src/symbols/Symbols.java@ 29082

Last change on this file since 29082 was 29082, checked in by malcolmh, 12 years ago

save

File size: 6.2 KB
Line 
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
10package symbols;
11
12import java.awt.BasicStroke;
13import java.awt.Color;
14import java.awt.Graphics2D;
15import java.awt.Rectangle;
16import java.awt.geom.*;
17import java.util.ArrayList;
18import java.util.EnumMap;
19
20import s57.S57val.*;
21
22public class Symbols {
23
24 public enum Prim {
25 BBOX, STRK, COLR, FILL, LINE, RECT, RRCT, ELPS, EARC, PLIN, PGON, 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 void drawSymbol(Graphics2D g2, ArrayList<Instr> symbol, int zoom, double x, double y, Delta dd, Scheme cs) {
87 int pn = 0;
88 int cn = 0;
89 if (cs != null) {
90 pn = cs.pat.size();
91 cn = cs.col.size() - ((pn != 0) ? pn - 1 : 0);
92 }
93 AffineTransform savetr = g2.getTransform();
94 g2.translate(x, y);
95 g2.scale(symbolScale[zoom], symbolScale[zoom]);
96 for (Instr item : symbol) {
97 switch (item.type) {
98 case BBOX:
99 Rectangle bbox = (Rectangle) item.params;
100 double dx = 0.0;
101 double dy = 0.0;
102 if (dd != null) {
103 switch (dd.h) {
104 case CC:
105 dx = bbox.x + (bbox.width / 2.0);
106 dy = bbox.y - (bbox.height / 2.0);
107 break;
108 case TL:
109 dx = bbox.x;
110 dy = bbox.y;
111 break;
112 case TR:
113 dx = bbox.x + bbox.width;
114 dy = bbox.y;
115 break;
116 case TC:
117 dx = bbox.x + (bbox.width / 2.0);
118 dy = bbox.y;
119 break;
120 case LC:
121 dx = bbox.x;
122 dy = bbox.y - (bbox.height / 2.0);
123 break;
124 case RC:
125 dx = bbox.x + bbox.width;
126 dy = bbox.y - (bbox.height / 2.0);
127 break;
128 case BL:
129 dx = bbox.x;
130 dy = bbox.y - bbox.height;
131 break;
132 case BR:
133 dx = bbox.x + bbox.width;
134 dy = bbox.y - bbox.height;
135 break;
136 case BC:
137 dx = bbox.x + (bbox.width / 2.0);
138 dy = bbox.y - bbox.height;
139 break;
140 }
141 g2.translate(dx, dy);
142 g2.transform(dd.t);
143 }
144 break;
145 case COLR:
146 if ((cs != null) && (cs.col != null)) {
147 for (Instr patch : (ArrayList<Instr>) item.params) {
148 switch (patch.type) {
149 case P1:
150 if (cn > 0) {
151 g2.setPaint(bodyColours.get(cs.col.get(0)));
152 g2.fill((Path2D.Double) patch.params);
153 }
154 break;
155 case P2:
156 if (cn > 0) {
157 if (cn > 1) {
158 g2.setPaint(bodyColours.get(cs.col.get(1)));
159 } else {
160 g2.setPaint(bodyColours.get(cs.col.get(0)));
161 }
162 g2.fill((Path2D.Double) patch.params);
163 }
164 break;
165 case H2:
166 if ((cn > 1) && (cs.pat.get(0) == ColPAT.PAT_HORI)) {
167 g2.setPaint(bodyColours.get(cs.col.get(cs.col.size() - pn)));
168 g2.fill((Path2D.Double) patch.params);
169 }
170 break;
171 case H3:
172 if ((cn == 3) && (cs.pat.get(0) == ColPAT.PAT_HORI)) {
173 g2.setPaint(bodyColours.get(cs.col.get(1)));
174 g2.fill((Path2D.Double) patch.params);
175 }
176 break;
177 case H4:
178 if ((cn == 4) && (cs.pat.get(0) == ColPAT.PAT_HORI)) {
179 g2.setPaint(bodyColours.get(cs.col.get(1)));
180 g2.fill((Path2D.Double) patch.params);
181 }
182 break;
183 case H5:
184 if ((cn == 4) && (cs.pat.get(0) == ColPAT.PAT_HORI)) {
185 g2.setPaint(bodyColours.get(cs.col.get(2)));
186 g2.fill((Path2D.Double) patch.params);
187 }
188 break;
189 case V2:
190 if ((cn > 1) && (cs.pat.get(0) == ColPAT.PAT_VERT)) {
191 g2.setPaint(bodyColours.get(cs.col.get(cs.col.size() - pn)));
192 g2.fill((Path2D.Double) patch.params);
193 }
194 break;
195 }
196 }
197 }
198 break;
199 case STRK:
200 g2.setStroke((BasicStroke) item.params);
201 break;
202 case FILL:
203 g2.setPaint((Color) item.params);
204 break;
205 case LINE:
206 g2.draw((Line2D.Double) item.params);
207 break;
208 case RECT:
209 g2.draw((Rectangle2D.Double) item.params);
210 break;
211 case RRCT:
212 g2.draw((RoundRectangle2D.Double) item.params);
213 break;
214 case ELPS:
215 g2.draw((Ellipse2D.Double) item.params);
216 break;
217 case EARC:
218 g2.draw((Arc2D.Double) item.params);
219 break;
220 case PLIN:
221 g2.draw((Path2D.Double) item.params);
222 break;
223 case PGON:
224 g2.fill((Path2D.Double) item.params);
225 break;
226 case SYMB:
227 drawSymbol(g2, (ArrayList<Instr>) item.params, zoom, 0.0, 0.0, null, null);
228 break;
229 }
230 }
231 g2.setTransform(savetr);
232 }
233}
Note: See TracBrowser for help on using the repository browser.