source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/PropertyStyleSettingGui.java@ 15731

Last change on this file since 15731 was 15731, checked in by simon04, 4 years ago

see #10435, fix #18095 - MapCSS: add settings of type string/double

File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint;
3
4import java.awt.event.ActionEvent;
5import java.util.Collections;
6import java.util.Objects;
7
8import javax.swing.AbstractAction;
9import javax.swing.JMenu;
10import javax.swing.JOptionPane;
11
12import org.openstreetmap.josm.gui.MainApplication;
13import org.openstreetmap.josm.gui.mappaint.StyleSetting.PropertyStyleSetting;
14import org.openstreetmap.josm.gui.mappaint.loader.MapPaintStyleLoader;
15
16/**
17 * GUI elements for a {@link PropertyStyleSetting} class.
18 * @since 15731
19 */
20class 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}
Note: See TracBrowser for help on using the repository browser.