source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/BooleanStyleSettingGui.java@ 17318

Last change on this file since 17318 was 15293, checked in by Don-vip, 5 years ago

sonar

File size: 2.0 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.Arrays;
6import java.util.Objects;
7
8import javax.swing.AbstractAction;
9import javax.swing.JCheckBoxMenuItem;
10import javax.swing.JMenu;
11
12import org.openstreetmap.josm.gui.MainApplication;
13import org.openstreetmap.josm.gui.mappaint.StyleSetting.BooleanStyleSetting;
14import org.openstreetmap.josm.gui.mappaint.loader.MapPaintStyleLoader;
15import org.openstreetmap.josm.gui.util.StayOpenCheckBoxMenuItemUI;
16
17/**
18 * GUI elements for a {@link BooleanStyleSetting} class.
19 * @since 12831
20 */
21public 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}
Note: See TracBrowser for help on using the repository browser.