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.Collections;
|
---|
6 | import java.util.Objects;
|
---|
7 |
|
---|
8 | import javax.swing.AbstractAction;
|
---|
9 | import javax.swing.JMenu;
|
---|
10 | import javax.swing.JOptionPane;
|
---|
11 |
|
---|
12 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
13 | import org.openstreetmap.josm.gui.mappaint.StyleSetting.PropertyStyleSetting;
|
---|
14 | import org.openstreetmap.josm.gui.mappaint.loader.MapPaintStyleLoader;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * GUI elements for a {@link PropertyStyleSetting} class.
|
---|
18 | * @since 15731
|
---|
19 | */
|
---|
20 | class PropertyStyleSettingGui<T> implements StyleSettingGui {
|
---|
21 |
|
---|
22 | private final PropertyStyleSetting<T> setting;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Constructs a new {@code BooleanStyleSettingGui}.
|
---|
26 | * @param setting boolean style setting
|
---|
27 | */
|
---|
28 | PropertyStyleSettingGui(PropertyStyleSetting<T> setting) {
|
---|
29 | this.setting = Objects.requireNonNull(setting);
|
---|
30 | }
|
---|
31 |
|
---|
32 | class PropertyStyleSettingAction extends AbstractAction {
|
---|
33 |
|
---|
34 | PropertyStyleSettingAction() {
|
---|
35 | super(setting.label);
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public void actionPerformed(ActionEvent e) {
|
---|
40 | final String initialValue = String.valueOf(setting.getValue());
|
---|
41 | final String userInput = JOptionPane.showInputDialog(setting.label, initialValue);
|
---|
42 | if (userInput != null && !initialValue.equals(userInput)) {
|
---|
43 | setting.setStringValue(userInput);
|
---|
44 | MainApplication.worker.submit(new MapPaintStyleLoader(Collections.singletonList(setting.parentStyle)));
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | public void addMenuEntry(JMenu menu) {
|
---|
51 | menu.add(new PropertyStyleSettingAction());
|
---|
52 | }
|
---|
53 | }
|
---|