source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/CheckGroup.java

Last change on this file was 18221, checked in by Don-vip, 3 years ago

fix #21319 - Refactoring of class hierarchy around JosmComboBox / AutoCompComboBox (patch by marcello):

  • Code reuse: JosmComboBox now uses a JosmTextField as editor
  • Code reuse: AutoCompComboBox now uses AutoCompTextField as editor
  • JosmComboBox uses more of the original L&F
  • JosmComboBox lists now expand all the way to the bottom or the top of the screen
  • Variable height items in combobox lists now work, see #19321
  • Autocomplete uses different algorithm, fix #21290
  • editable="false" comboboxes in Presets now work, fix #6157 see #11024 see #18714
  • The user may toggle LTR-RTL script in JosmTextField (menu and ctrl+space)
  • LTR-RTL automatically toggles according to key in AddTag and EditTag dialogs, fix #16163
File size: 1.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging.presets.items;
3
4import java.awt.GridLayout;
5import java.util.LinkedList;
6import java.util.List;
7import java.util.Map;
8
9import javax.swing.JLabel;
10import javax.swing.JPanel;
11
12import org.openstreetmap.josm.data.osm.Tag;
13import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem;
14import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
15import org.openstreetmap.josm.tools.GBC;
16
17/**
18 * A group of {@link Check}s.
19 * @since 6114
20 */
21public 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}
Note: See TracBrowser for help on using the repository browser.