1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
3 |
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.Collections;
|
---|
6 | import java.util.HashMap;
|
---|
7 | import java.util.Iterator;
|
---|
8 | import java.util.LinkedList;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.data.osm.Node;
|
---|
13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
14 | import org.openstreetmap.josm.data.osm.OsmUtils;
|
---|
15 | import org.openstreetmap.josm.data.osm.Way;
|
---|
16 |
|
---|
17 | public class ElemStyles
|
---|
18 | {
|
---|
19 | HashMap<String, StyleSource> styleSet;
|
---|
20 | public ElemStyles()
|
---|
21 | {
|
---|
22 | styleSet = new HashMap<String, StyleSource>();
|
---|
23 | }
|
---|
24 |
|
---|
25 | public void add(String name, Rule r, Collection<Rule> rules, LineElemStyle style)
|
---|
26 | {
|
---|
27 | if(rules != null)
|
---|
28 | {
|
---|
29 | style.rules = rules;
|
---|
30 | getStyleSet(name, true).linesList.add(style);
|
---|
31 | }
|
---|
32 | else
|
---|
33 | {
|
---|
34 | String key = r.getKey();
|
---|
35 | style.code = key;
|
---|
36 | getStyleSet(name, true).lines.put(key, style);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public void addModifier(String name, Rule r, Collection<Rule> rules, LineElemStyle style)
|
---|
41 | {
|
---|
42 | if(rules != null)
|
---|
43 | {
|
---|
44 | style.rules = rules;
|
---|
45 | getStyleSet(name, true).modifiersList.add(style);
|
---|
46 | }
|
---|
47 | else
|
---|
48 | {
|
---|
49 | String key = r.getKey();
|
---|
50 | style.code = key;
|
---|
51 | getStyleSet(name, true).modifiers.put(key, style);
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | public void add(String name, Rule r, Collection<Rule> rules, AreaElemStyle style)
|
---|
56 | {
|
---|
57 | if(rules != null)
|
---|
58 | {
|
---|
59 | style.rules = rules;
|
---|
60 | getStyleSet(name, true).areasList.add(style);
|
---|
61 | }
|
---|
62 | else
|
---|
63 | {
|
---|
64 | String key = r.getKey();
|
---|
65 | style.code = key;
|
---|
66 | getStyleSet(name, true).areas.put(key, style);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | public void add(String name, Rule r, Collection<Rule> rules, IconElemStyle style)
|
---|
71 | {
|
---|
72 | if(rules != null)
|
---|
73 | {
|
---|
74 | style.rules = rules;
|
---|
75 | getStyleSet(name, true).iconsList.add(style);
|
---|
76 | }
|
---|
77 | else
|
---|
78 | {
|
---|
79 | String key = r.getKey();
|
---|
80 | style.code = key;
|
---|
81 | getStyleSet(name, true).icons.put(key, style);
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | private StyleSource getStyleSet(String name, boolean create)
|
---|
86 | {
|
---|
87 | if(name == null) {
|
---|
88 | name = Main.pref.get("mappaint.style", "standard");
|
---|
89 | }
|
---|
90 |
|
---|
91 | StyleSource s = styleSet.get(name);
|
---|
92 | if(create && s == null)
|
---|
93 | {
|
---|
94 | s = new StyleSource();
|
---|
95 | styleSet.put(name, s);
|
---|
96 | }
|
---|
97 | return s;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /* called from class users, never return null */
|
---|
101 | public StyleSource getStyleSet()
|
---|
102 | {
|
---|
103 | return getStyleSet(null, true);
|
---|
104 | }
|
---|
105 |
|
---|
106 | public Collection<String> getStyleNames()
|
---|
107 | {
|
---|
108 | return styleSet.keySet();
|
---|
109 | }
|
---|
110 | }
|
---|