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 | String getId(Environment env);
|
---|
15 |
|
---|
16 | Subpart DEFAULT_SUBPART = new StringSubpart("default");
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Simple static subpart identifier.
|
---|
20 | *
|
---|
21 | * E.g. ::layer_1
|
---|
22 | */
|
---|
23 | class StringSubpart implements Subpart {
|
---|
24 | private final String id;
|
---|
25 |
|
---|
26 | public StringSubpart(String id) {
|
---|
27 | this.id = id;
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public String getId(Environment env) {
|
---|
32 | return id;
|
---|
33 | }
|
---|
34 |
|
---|
35 | @Override
|
---|
36 | public String toString() {
|
---|
37 | return id;
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Subpart identifier given by an expression.
|
---|
43 | *
|
---|
44 | * E.g. ::(concat("layer_", prop("i", "default")))
|
---|
45 | */
|
---|
46 | class ExpressionSubpart implements Subpart {
|
---|
47 | private final Expression id;
|
---|
48 |
|
---|
49 | public ExpressionSubpart(Expression id) {
|
---|
50 | this.id = id;
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | public String getId(Environment env) {
|
---|
55 | return Cascade.convertTo(id.evaluate(env), String.class);
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public String toString() {
|
---|
60 | return String.valueOf(id);
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|