1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.tagging.presets.items;
|
---|
3 |
|
---|
4 | import java.awt.GridLayout;
|
---|
5 | import java.util.LinkedList;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Map;
|
---|
8 |
|
---|
9 | import javax.swing.JLabel;
|
---|
10 | import javax.swing.JPanel;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.data.osm.Tag;
|
---|
13 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem;
|
---|
14 | import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
|
---|
15 | import org.openstreetmap.josm.tools.GBC;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * A group of {@link Check}s.
|
---|
19 | * @since 6114
|
---|
20 | */
|
---|
21 | public class CheckGroup extends TaggingPresetItem {
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Number of columns (positive integer)
|
---|
25 | */
|
---|
26 | public short columns = 1; // NOSONAR
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * List of checkboxes
|
---|
30 | */
|
---|
31 | public final List<Check> checks = new LinkedList<>();
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
|
---|
35 | int rows = (int) Math.ceil(checks.size() / ((double) columns));
|
---|
36 | JPanel panel = new JPanel(new GridLayout(rows, columns));
|
---|
37 |
|
---|
38 | int i = 0;
|
---|
39 | for (Check check : checks) {
|
---|
40 | check.addToPanel(panel, support);
|
---|
41 | i++;
|
---|
42 | }
|
---|
43 | for (; i < rows * columns; i++) {
|
---|
44 | // fill remaining cells, see #20792
|
---|
45 | panel.add(new JLabel());
|
---|
46 | }
|
---|
47 |
|
---|
48 | panel.applyComponentOrientation(support.getDefaultComponentOrientation());
|
---|
49 | p.add(panel, GBC.eol());
|
---|
50 | return false;
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | public void addCommands(List<Tag> changedTags) {
|
---|
55 | for (Check check : checks) {
|
---|
56 | check.addCommands(changedTags);
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Override
|
---|
61 | public Boolean matches(Map<String, String> tags) {
|
---|
62 | for (Check check : checks) {
|
---|
63 | if (Boolean.TRUE.equals(check.matches(tags))) {
|
---|
64 | return Boolean.TRUE;
|
---|
65 | }
|
---|
66 | }
|
---|
67 | return null;
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public String toString() {
|
---|
72 | return "CheckGroup [columns=" + columns + ']';
|
---|
73 | }
|
---|
74 | }
|
---|