1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
3 |
|
---|
4 | import java.util.Collection;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
7 | import org.openstreetmap.josm.data.osm.OsmUtils;
|
---|
8 | import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
|
---|
9 | import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
|
---|
10 | import org.openstreetmap.josm.gui.mappaint.xml.XmlCondition;
|
---|
11 |
|
---|
12 | abstract public class ElemStyle {
|
---|
13 | // zoom range to display the feature
|
---|
14 | public long minScale;
|
---|
15 | public long maxScale;
|
---|
16 |
|
---|
17 | public int priority;
|
---|
18 | public String code;
|
---|
19 | Collection<XmlCondition> conditions = null;
|
---|
20 |
|
---|
21 | @Override
|
---|
22 | public boolean equals(Object o) {
|
---|
23 | return (o instanceof ElemStyle) && (((ElemStyle) o).getCode().equals(getCode()));
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public int hashCode() {
|
---|
28 | return getClass().hashCode();
|
---|
29 | }
|
---|
30 |
|
---|
31 | public String getCode() {
|
---|
32 | if (code == null) {
|
---|
33 | code = "";
|
---|
34 | if (conditions != null) {
|
---|
35 | for (XmlCondition c: conditions) {
|
---|
36 | code += c.toCode();
|
---|
37 | }
|
---|
38 | }
|
---|
39 | }
|
---|
40 | return code;
|
---|
41 | }
|
---|
42 | public boolean check(OsmPrimitive primitive)
|
---|
43 | {
|
---|
44 | if(conditions == null)
|
---|
45 | return true;
|
---|
46 | for(XmlCondition c : conditions)
|
---|
47 | {
|
---|
48 | String k = primitive.get(c.key);
|
---|
49 | String bv = OsmUtils.getNamedOsmBoolean(c.boolValue);
|
---|
50 | if(k == null || (c.value != null && !k.equals(c.value))
|
---|
51 | || (bv != null && !bv.equals(OsmUtils.getNamedOsmBoolean(k))))
|
---|
52 | return false;
|
---|
53 | }
|
---|
54 | return true;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public abstract void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member);
|
---|
58 | }
|
---|