1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint.mapcss;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.gui.mappaint.Cascade;
|
---|
5 | import org.openstreetmap.josm.gui.mappaint.Environment;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * A subpart identifies different rendering layers (<code>::subpart</code> syntax).
|
---|
9 | * @since 8086 (creation)
|
---|
10 | * @since 10600 (functional interface)
|
---|
11 | */
|
---|
12 | @FunctionalInterface
|
---|
13 | public interface Subpart {
|
---|
14 | /**
|
---|
15 | * Gets the ID of the suppart
|
---|
16 | * @param env The environment to get it from
|
---|
17 | * @return The id
|
---|
18 | */
|
---|
19 | String getId(Environment env);
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * The default subpart for normal rules
|
---|
23 | */
|
---|
24 | Subpart DEFAULT_SUBPART = new StringSubpart("default");
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Simple static subpart identifier.
|
---|
28 | *
|
---|
29 | * E.g. ::layer_1
|
---|
30 | */
|
---|
31 | class StringSubpart implements Subpart {
|
---|
32 | private final String id;
|
---|
33 |
|
---|
34 | public StringSubpart(String id) {
|
---|
35 | this.id = id;
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public String getId(Environment env) {
|
---|
40 | return id;
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | public String toString() {
|
---|
45 | return id;
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Subpart identifier given by an expression.
|
---|
51 | *
|
---|
52 | * E.g. ::(concat("layer_", prop("i", "default")))
|
---|
53 | */
|
---|
54 | class ExpressionSubpart implements Subpart {
|
---|
55 | private final Expression id;
|
---|
56 |
|
---|
57 | public ExpressionSubpart(Expression id) {
|
---|
58 | this.id = id;
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | public String getId(Environment env) {
|
---|
63 | return Cascade.convertTo(id.evaluate(env), String.class);
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Override
|
---|
67 | public String toString() {
|
---|
68 | return String.valueOf(id);
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|