| 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 |
|
|---|
| 10 | package seamap;
|
|---|
| 11 |
|
|---|
| 12 | import java.awt.Graphics2D;
|
|---|
| 13 | import java.awt.RenderingHints;
|
|---|
| 14 | import java.awt.geom.Point2D;
|
|---|
| 15 | import java.util.ArrayList;
|
|---|
| 16 | import java.util.EnumMap;
|
|---|
| 17 | import java.util.HashMap;
|
|---|
| 18 |
|
|---|
| 19 | import s57.S57att.Att;
|
|---|
| 20 | import s57.S57obj.Obj;
|
|---|
| 21 | import s57.S57val.ColCOL;
|
|---|
| 22 | import s57.S57val.*;
|
|---|
| 23 | import s57.S57val;
|
|---|
| 24 | import seamap.SeaMap.*;
|
|---|
| 25 | import symbols.Symbols;
|
|---|
| 26 | import symbols.Symbols.*;
|
|---|
| 27 |
|
|---|
| 28 | public 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 | }
|
|---|