source: osm/applications/editors/josm/plugins/smed2/src/seamap/Renderer.java@ 29175

Last change on this file since 29175 was 29175, checked in by malcolmh, 14 years ago

save

File size: 2.2 KB
Line 
1/* Copyright 2013 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 seamap;
11
12import java.awt.Graphics2D;
13import java.awt.RenderingHints;
14import java.awt.geom.Point2D;
15import java.util.ArrayList;
16import java.util.EnumMap;
17import java.util.HashMap;
18
19import s57.S57att.Att;
20import s57.S57obj.Obj;
21import s57.S57val.ColCOL;
22import s57.S57val.*;
23import s57.S57val;
24import seamap.SeaMap.*;
25import symbols.Symbols;
26import symbols.Symbols.*;
27
28public class Renderer {
29
30 static MapHelper helper;
31 static SeaMap map;
32 static double sScale;
33 static double tScale;
34 static Graphics2D g2;
35
36 public static void reRender(Graphics2D g, int zoom, double factor, SeaMap m, MapHelper h) {
37 g2 = g;
38 helper = h;
39 map = m;
40 sScale = Symbols.symbolScale[zoom]*factor;
41 tScale = Symbols.textScale[zoom]*factor;
42 if (map != null) {
43 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
44 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
45 Rules.MainRules(map, zoom);
46 }
47 }
48
49 public static EnumMap<Att, AttItem> getAtts(Feature feature, Obj obj, int idx) {
50 HashMap<Integer, EnumMap<Att, AttItem>> objs = feature.objs.get(obj);
51 if (objs == null) return null;
52 else return objs.get(idx);
53 }
54
55 public static Object getAttVal(Feature feature, Obj obj, int idx, Att att) {
56 EnumMap<Att, AttItem> atts = getAtts(feature, obj, idx);
57 if (atts == null) return S57val.nullVal(att);
58 else {
59 AttItem item = atts.get(att);
60 if (item == null) return S57val.nullVal(att);
61 return item.val;
62 }
63 }
64
65 public static void symbol(Feature feature, ArrayList<Instr> symbol, Obj obj) {
66 Point2D point = helper.getPoint(map.nodes.get(feature.refs));
67 ArrayList<ColCOL> colours = (ArrayList<ColCOL>) getAttVal(feature, obj, 0, Att.COLOUR);
68 ArrayList<ColPAT> pattern = (ArrayList<ColPAT>) getAttVal(feature, obj, 0, Att.COLPAT);
69 Symbols.drawSymbol(g2, symbol, sScale, point.getX(), point.getY(), null, new Scheme(pattern, colours));
70 }
71
72}
Note: See TracBrowser for help on using the repository browser.