1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint.mapcss;
|
---|
3 |
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.gui.mappaint.Environment;
|
---|
7 | import org.openstreetmap.josm.tools.Utils;
|
---|
8 |
|
---|
9 | public class MapCSSRule {
|
---|
10 |
|
---|
11 | public Selector selector;
|
---|
12 | public Declaration declaration;
|
---|
13 |
|
---|
14 | public static class Declaration {
|
---|
15 | public List<Instruction> instructions;
|
---|
16 | // usedId is an optimized way to make sure that
|
---|
17 | // each declaration is only applied once for each primitive,
|
---|
18 | // even if multiple of the comma separated selectors in the
|
---|
19 | // rule match.
|
---|
20 | public int usedId;
|
---|
21 |
|
---|
22 | public Declaration(List<Instruction> instructions) {
|
---|
23 | this.instructions = instructions;
|
---|
24 | usedId = 0;
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
28 | public MapCSSRule(Selector selector, Declaration declaration) {
|
---|
29 | this.selector = selector;
|
---|
30 | this.declaration = declaration;
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * <p>Executes the instructions against the environment {@code env}</p>
|
---|
35 | *
|
---|
36 | * @param env the environment
|
---|
37 | */
|
---|
38 | public void execute(Environment env) {
|
---|
39 | for (Instruction i : declaration.instructions) {
|
---|
40 | i.execute(env);
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Override
|
---|
45 | public String toString() {
|
---|
46 | return selector + " {\n " + Utils.join("\n ", declaration.instructions) + "\n}";
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|