1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
3 |
|
---|
4 | import java.awt.event.ActionEvent;
|
---|
5 | import java.util.Arrays;
|
---|
6 | import java.util.Objects;
|
---|
7 |
|
---|
8 | import javax.swing.AbstractAction;
|
---|
9 | import javax.swing.JCheckBoxMenuItem;
|
---|
10 | import javax.swing.JMenu;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
13 | import org.openstreetmap.josm.gui.mappaint.StyleSetting.BooleanStyleSetting;
|
---|
14 | import org.openstreetmap.josm.gui.mappaint.loader.MapPaintStyleLoader;
|
---|
15 | import org.openstreetmap.josm.gui.util.StayOpenCheckBoxMenuItemUI;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * GUI elements for a {@link BooleanStyleSetting} class.
|
---|
19 | * @since 12831
|
---|
20 | */
|
---|
21 | public class BooleanStyleSettingGui implements StyleSettingGui {
|
---|
22 |
|
---|
23 | final StyleSetting.BooleanStyleSetting setting;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Constructs a new {@code BooleanStyleSettingGui}.
|
---|
27 | * @param setting boolean style setting
|
---|
28 | */
|
---|
29 | public BooleanStyleSettingGui(BooleanStyleSetting setting) {
|
---|
30 | this.setting = Objects.requireNonNull(setting);
|
---|
31 | }
|
---|
32 |
|
---|
33 | static class BooleanStyleSettingCheckBoxMenuItem extends JCheckBoxMenuItem {
|
---|
34 | boolean noRepaint;
|
---|
35 |
|
---|
36 | BooleanStyleSettingCheckBoxMenuItem(BooleanStyleSetting setting) {
|
---|
37 | setAction(new AbstractAction(setting.label) {
|
---|
38 | @Override
|
---|
39 | public void actionPerformed(ActionEvent e) {
|
---|
40 | setting.setValue(isSelected());
|
---|
41 | if (!noRepaint) {
|
---|
42 | MainApplication.worker.submit(new MapPaintStyleLoader(Arrays.asList(setting.parentStyle)));
|
---|
43 | }
|
---|
44 | }
|
---|
45 | });
|
---|
46 | setSelected((boolean) setting.getValue());
|
---|
47 | setUI(new StayOpenCheckBoxMenuItemUI());
|
---|
48 | }
|
---|
49 |
|
---|
50 | void doClickWithoutRepaint(int pressTime) {
|
---|
51 | noRepaint = true;
|
---|
52 | doClick(pressTime);
|
---|
53 | noRepaint = false;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public void addMenuEntry(JMenu menu) {
|
---|
59 | menu.add(new BooleanStyleSettingCheckBoxMenuItem(setting));
|
---|
60 | }
|
---|
61 | }
|
---|