Changeset 15731 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-01-19T17:33:40+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 added
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r15612 r15731 25 25 import java.util.Collection; 26 26 import java.util.List; 27 import java.util.Map.Entry;28 import java.util.stream.Collectors;29 27 30 28 import javax.swing.AbstractAction; … … 63 61 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 64 62 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; 65 import org.openstreetmap.josm.gui.mappaint.StyleSetting;66 import org.openstreetmap.josm.gui.mappaint.StyleSetting.StyleSettingGroup;67 63 import org.openstreetmap.josm.gui.mappaint.StyleSettingGroupGui; 68 import org.openstreetmap.josm.gui.mappaint.StyleSettingGuiFactory;69 64 import org.openstreetmap.josm.gui.mappaint.StyleSource; 70 65 import org.openstreetmap.josm.gui.mappaint.loader.MapPaintStyleLoader; … … 694 689 } else { 695 690 // Add settings groups 696 for (Entry<StyleSettingGroup, List<StyleSetting>> e : style.settingGroups.entrySet()) { 697 new StyleSettingGroupGui(e.getKey(), e.getValue()).addMenuEntry(setMenu); 698 } 691 style.settingGroups.forEach((group, settings) -> new StyleSettingGroupGui(group, settings).addMenuEntry(setMenu)); 699 692 // Add settings not in groups 700 final List<StyleSetting> allStylesInGroups = style.settingGroups.values().stream() 701 .flatMap(List<StyleSetting>::stream).collect(Collectors.toList()); 702 for (StyleSetting s : style.settings.stream() 703 .filter(s -> !allStylesInGroups.contains(s)).collect(Collectors.toList())) { 704 StyleSettingGuiFactory.getStyleSettingGui(s).addMenuEntry(setMenu); 705 } 693 style.settings.stream() 694 .filter(s -> style.settingGroups.values().stream().flatMap(List::stream).noneMatch(s::equals)) 695 .forEach(s -> s.getStyleSettingGui().addMenuEntry(setMenu)); 706 696 } 707 697 -
trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingHelper.java
r14120 r15731 121 121 } 122 122 for (String key : sd.settings.keySet()) { 123 StyleSetting. BooleanStyleSettingmatch = source.settings.stream()124 .filter(s -> s instanceof StyleSetting. BooleanStyleSetting)125 .map(s -> (StyleSetting. BooleanStyleSetting) s)126 .filter(bs -> bs. prefKey.endsWith(":" + key))123 StyleSetting.PropertyStyleSetting<?> match = source.settings.stream() 124 .filter(s -> s instanceof StyleSetting.PropertyStyleSetting) 125 .map(s -> (StyleSetting.PropertyStyleSetting<?>) s) 126 .filter(bs -> bs.getKey().endsWith(":" + key)) 127 127 .findFirst().orElse(null); 128 128 if (match == null) { 129 129 Logging.warn(tr("Style setting not found: ''{0}''", key)); 130 130 } else { 131 boolean value = Boolean.parseBoolean(sd.settings.get(key));131 String value = sd.settings.get(key); 132 132 Logging.trace("setting applied: ''{0}:{1}''", key, value); 133 match.set Value(value);133 match.setStringValue(value); 134 134 } 135 135 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSetting.java
r15293 r15731 7 7 import javax.swing.Icon; 8 8 9 import org.openstreetmap.josm. spi.preferences.Config;9 import org.openstreetmap.josm.data.preferences.AbstractToStringProperty; 10 10 import org.openstreetmap.josm.tools.ImageProvider; 11 11 import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; … … 39 39 */ 40 40 Object getValue(); 41 42 /** 43 * Create a matching {@link StyleSettingGui} instances for a given {@link StyleSetting} object. 44 * @return matching {@code StyleSettingGui} 45 * @throws UnsupportedOperationException when class of {@link StyleSetting} is not supported 46 */ 47 default StyleSettingGui getStyleSettingGui() { 48 throw new UnsupportedOperationException(getClass() + " not supported"); 49 } 41 50 42 51 /** … … 84 93 public final Icon icon; 85 94 86 publicStyleSettingGroup(StyleSource parentStyle, String label, String key, Icon icon) {95 StyleSettingGroup(StyleSource parentStyle, String label, String key, Icon icon) { 87 96 super(parentStyle, label); 88 97 this.key = Objects.requireNonNull(key); … … 100 109 String label = c.get("label", null, String.class); 101 110 if (label == null) { 102 Logging.warn("property 'label' required for boolean style setting");111 Logging.warn("property 'label' required for StyleSettingGroup"); 103 112 return null; 104 113 } … … 109 118 } 110 119 120 class PropertyStyleSetting<T> extends LabeledStyleSetting implements StyleSetting { 121 private final Class<T> type; 122 private final AbstractToStringProperty<T> property; 123 124 PropertyStyleSetting(StyleSource parentStyle, String label, Class<T> type, AbstractToStringProperty<T> property) { 125 super(parentStyle, label); 126 this.type = type; 127 this.property = property; 128 } 129 130 /** 131 * Replies the property key. 132 * @return The property key 133 */ 134 public String getKey() { 135 return property.getKey(); 136 } 137 138 @Override 139 public T getValue() { 140 return property.get(); 141 } 142 143 /** 144 * Sets this property to the specified value. 145 * @param value The new value of this property 146 */ 147 public void setValue(T value) { 148 property.put(value); 149 } 150 151 /** 152 * Sets this property to the specified string value. 153 * @param value The new string value of this property 154 */ 155 public void setStringValue(String value) { 156 setValue(Cascade.convertTo(value, type)); 157 } 158 159 @Override 160 public StyleSettingGui getStyleSettingGui() { 161 return new PropertyStyleSettingGui<>(this); 162 } 163 } 164 111 165 /** 112 166 * A style setting for boolean value (yes / no). 113 167 */ 114 class BooleanStyleSetting extends LabeledStyleSetting implements StyleSetting { 115 public final String prefKey; 116 public final boolean def; 117 118 public BooleanStyleSetting(StyleSource parentStyle, String prefKey, String label, boolean def) { 119 super(parentStyle, label); 120 this.prefKey = Objects.requireNonNull(prefKey); 121 this.def = def; 122 } 123 124 /** 125 * Creates a new {@code BooleanStyleSetting}. 126 * @param c cascade 127 * @param parentStyle parent style source 128 * @param key setting identifier 129 * @return newly created {@code BooleanStyleSetting} 130 */ 131 public static BooleanStyleSetting create(Cascade c, StyleSource parentStyle, String key) { 132 String label = c.get("label", null, String.class); 133 if (label == null) { 134 Logging.warn("property 'label' required for boolean style setting"); 135 return null; 136 } 137 Boolean def = c.get("default", null, Boolean.class); 138 if (def == null) { 139 Logging.warn("property 'default' required for boolean style setting"); 140 return null; 141 } 142 String prefKey = parentStyle.url + ":boolean:" + key; 143 return new BooleanStyleSetting(parentStyle, prefKey, label, def); 168 class BooleanStyleSetting extends PropertyStyleSetting<Boolean> { 169 BooleanStyleSetting(StyleSource parentStyle, String label, AbstractToStringProperty<Boolean> property) { 170 super(parentStyle, label, Boolean.class, property); 144 171 } 145 172 146 173 @Override 147 public Object getValue() { 148 String val = Config.getPref().get(prefKey, null); 149 if (val == null) return def; 150 return Boolean.valueOf(val); 151 } 152 153 public void setValue(Object o) { 154 if (!(o instanceof Boolean)) { 155 throw new IllegalArgumentException(); 156 } 157 boolean b = (Boolean) o; 158 if (b == def) { 159 Config.getPref().put(prefKey, null); 160 } else { 161 Config.getPref().putBoolean(prefKey, b); 162 } 174 public StyleSettingGui getStyleSettingGui() { 175 return new BooleanStyleSettingGui(this); 163 176 } 164 177 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSettingGroupGui.java
r15289 r15731 64 64 // Add individual settings 65 65 for (StyleSetting s : settings) { 66 StyleSettingGuiFactory.getStyleSettingGui(s).addMenuEntry(submenu);66 s.getStyleSettingGui().addMenuEntry(submenu); 67 67 } 68 68 menu.add(submenu); -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r15717 r15731 49 49 import org.openstreetmap.josm.gui.mappaint.StyleKeys; 50 50 import org.openstreetmap.josm.gui.mappaint.StyleSetting; 51 import org.openstreetmap.josm.gui.mappaint.StyleSetting.BooleanStyleSetting;52 51 import org.openstreetmap.josm.gui.mappaint.StyleSetting.StyleSettingGroup; 52 import org.openstreetmap.josm.gui.mappaint.StyleSettingFactory; 53 53 import org.openstreetmap.josm.gui.mappaint.StyleSource; 54 54 import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyCondition; … … 624 624 } 625 625 Cascade c = e.getValue(); 626 String type = c.get("type", null, String.class); 627 StyleSetting set = null; 628 if ("boolean".equals(type)) { 629 set = BooleanStyleSetting.create(c, this, e.getKey()); 630 } else { 631 Logging.warn("Unknown setting type: {0}", type); 632 } 626 StyleSetting set = StyleSettingFactory.create(c, this, e.getKey()); 633 627 if (set != null) { 634 628 settings.add(set); … … 636 630 String groupId = c.get("group", null, String.class); 637 631 if (groupId != null) { 638 settingGroups.get(settingGroups.keySet().stream().filter(g -> g.key.equals(groupId)).findAny() 639 .orElseThrow(() -> new IllegalArgumentException("Unknown settings group: " + groupId))).add(set); 632 final StyleSettingGroup group = settingGroups.keySet().stream() 633 .filter(g -> g.key.equals(groupId)) 634 .findAny() 635 .orElseThrow(() -> new IllegalArgumentException("Unknown settings group: " + groupId)); 636 settingGroups.get(group).add(set); 640 637 } 641 638 }
Note:
See TracChangeset
for help on using the changeset viewer.