- Timestamp:
- 2019-08-07T21:50:20+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r15287 r15289 25 25 import java.util.Collection; 26 26 import java.util.List; 27 import java.util.Map.Entry; 28 import java.util.stream.Collectors; 27 29 28 30 import javax.swing.AbstractAction; … … 63 65 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; 64 66 import org.openstreetmap.josm.gui.mappaint.StyleSetting; 67 import org.openstreetmap.josm.gui.mappaint.StyleSetting.StyleSettingGroup; 68 import org.openstreetmap.josm.gui.mappaint.StyleSettingGroupGui; 65 69 import org.openstreetmap.josm.gui.mappaint.StyleSettingGuiFactory; 66 70 import org.openstreetmap.josm.gui.mappaint.StyleSource; … … 691 695 add(setMenu); 692 696 693 int sel = tblStyles.getSelectionModel().getLeadSelectionIndex(); 694 StyleSource style = null; 695 if (sel >= 0 && sel < model.getRowCount()) { 696 style = model.getRow(sel); 697 } 697 final int sel = tblStyles.getSelectionModel().getLeadSelectionIndex(); 698 final StyleSource style = sel >= 0 && sel < model.getRowCount() ? model.getRow(sel) : null; 698 699 if (style == null || style.settings.isEmpty()) { 699 700 setMenu.setEnabled(false); 700 701 } else { 701 for (StyleSetting s : style.settings) { 702 // Add settings groups 703 for (Entry<StyleSettingGroup, List<StyleSetting>> e : style.settingGroups.entrySet()) { 704 new StyleSettingGroupGui(e.getKey(), e.getValue()).addMenuEntry(setMenu); 705 } 706 // Add settings not in groups 707 final List<StyleSetting> allStylesInGroups = style.settingGroups.values().stream() 708 .flatMap(l -> l.stream()).collect(Collectors.toList()); 709 for (StyleSetting s : style.settings.stream() 710 .filter(s -> !allStylesInGroups.contains(s)).collect(Collectors.toList())) { 702 711 StyleSettingGuiFactory.getStyleSettingGui(s).addMenuEntry(setMenu); 703 712 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/BooleanStyleSettingGui.java
r15288 r15289 7 7 8 8 import javax.swing.AbstractAction; 9 import javax.swing.Action;10 9 import javax.swing.JCheckBoxMenuItem; 11 10 import javax.swing.JMenu; … … 32 31 } 33 32 33 static class BooleanStyleSettingCheckBoxMenuItem extends JCheckBoxMenuItem { 34 boolean noRepaint = false; 35 36 public 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 public void doClickWithoutRepaint(int pressTime) { 51 noRepaint = true; 52 doClick(pressTime); 53 noRepaint = false; 54 } 55 } 56 34 57 @Override 35 58 public void addMenuEntry(JMenu menu) { 36 final JCheckBoxMenuItem item = new JCheckBoxMenuItem(); 37 Action a = new AbstractAction(setting.label) { 38 @Override 39 public void actionPerformed(ActionEvent e) { 40 setting.setValue(item.isSelected()); 41 MainApplication.worker.submit(new MapPaintStyleLoader(Arrays.asList(setting.parentStyle))); 42 } 43 }; 44 item.setAction(a); 45 item.setSelected((boolean) setting.getValue()); 46 item.setUI(new StayOpenCheckBoxMenuItemUI()); 47 menu.add(item); 59 menu.add(new BooleanStyleSettingCheckBoxMenuItem(setting)); 48 60 } 49 61 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSetting.java
r13800 r15289 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import java.util.Objects; 5 import java.util.Optional; 6 7 import javax.swing.Icon; 8 4 9 import org.openstreetmap.josm.spi.preferences.Config; 10 import org.openstreetmap.josm.tools.ImageProvider; 11 import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; 5 12 import org.openstreetmap.josm.tools.Logging; 6 13 … … 34 41 35 42 /** 43 * Superclass of style settings and groups. 44 * @since 15289 45 */ 46 abstract class LabeledStyleSetting implements Comparable<LabeledStyleSetting> { 47 public final StyleSource parentStyle; 48 public final String label; 49 50 LabeledStyleSetting(StyleSource parentStyle, String label) { 51 this.parentStyle = Objects.requireNonNull(parentStyle); 52 this.label = Objects.requireNonNull(label); 53 } 54 55 @Override 56 public int compareTo(LabeledStyleSetting o) { 57 return label.compareTo(o.label); 58 } 59 } 60 61 /** 62 * A style setting group. 63 * @since 15289 64 */ 65 class StyleSettingGroup extends LabeledStyleSetting { 66 public final String key; 67 public final Icon icon; 68 69 public StyleSettingGroup(StyleSource parentStyle, String label, String key, Icon icon) { 70 super(parentStyle, label); 71 this.key = Objects.requireNonNull(key); 72 this.icon = icon; 73 } 74 75 public static StyleSettingGroup create(Cascade c, StyleSource parentStyle, String key) { 76 String label = c.get("label", null, String.class); 77 if (label == null) { 78 Logging.warn("property 'label' required for boolean style setting"); 79 return null; 80 } 81 Icon icon = Optional.ofNullable(c.get("icon", null, String.class)) 82 .map(s -> ImageProvider.get(s, ImageSizes.MENU)).orElse(null); 83 return new StyleSettingGroup(parentStyle, label, key, icon); 84 } 85 } 86 87 /** 36 88 * A style setting for boolean value (yes / no). 37 89 */ 38 class BooleanStyleSetting implements StyleSetting, Comparable<BooleanStyleSetting> { 39 public final StyleSource parentStyle; 90 class BooleanStyleSetting extends LabeledStyleSetting implements StyleSetting { 40 91 public final String prefKey; 41 public final String label;42 92 public final boolean def; 43 93 44 94 public BooleanStyleSetting(StyleSource parentStyle, String prefKey, String label, boolean def) { 45 this.parentStyle = parentStyle; 46 this.prefKey = prefKey; 47 this.label = label; 95 super(parentStyle, label); 96 this.prefKey = Objects.requireNonNull(prefKey); 48 97 this.def = def; 49 98 } … … 82 131 } 83 132 } 84 85 @Override86 public int compareTo(BooleanStyleSetting o) {87 return label.compareTo(o.label);88 }89 133 } 90 134 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r14273 r15289 15 15 import java.util.Map; 16 16 import java.util.Set; 17 import java.util.TreeMap; 17 18 import java.util.concurrent.CopyOnWriteArrayList; 18 19 import java.util.concurrent.CopyOnWriteArraySet; … … 24 25 import org.openstreetmap.josm.data.preferences.sources.SourceType; 25 26 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 27 import org.openstreetmap.josm.gui.mappaint.StyleSetting.StyleSettingGroup; 26 28 import org.openstreetmap.josm.io.CachedFile; 27 29 import org.openstreetmap.josm.tools.ImageOverlay; … … 65 67 */ 66 68 public Map<String, Object> settingValues = new HashMap<>(); 69 /** 70 * Map of settings per group. 71 */ 72 public final Map<StyleSettingGroup, List<StyleSetting>> settingGroups = new TreeMap<>(); 67 73 68 74 /** -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r14801 r15289 49 49 import org.openstreetmap.josm.gui.mappaint.StyleSetting; 50 50 import org.openstreetmap.josm.gui.mappaint.StyleSetting.BooleanStyleSetting; 51 import org.openstreetmap.josm.gui.mappaint.StyleSetting.StyleSettingGroup; 51 52 import org.openstreetmap.josm.gui.mappaint.StyleSource; 52 53 import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyCondition; … … 502 503 case Selector.BASE_META: 503 504 case Selector.BASE_SETTING: 505 case Selector.BASE_SETTINGS: 504 506 break; 505 507 default: … … 576 578 } 577 579 580 private static void loadSettings(MapCSSRule r, GeneralSelector gs, Environment env) { 581 if (gs.matchesConditions(env)) { 582 env.layer = null; 583 env.layer = gs.getSubpart().getId(env); 584 r.execute(env); 585 } 586 } 587 578 588 private void loadSettings() { 579 589 settings.clear(); 580 590 settingValues.clear(); 591 settingGroups.clear(); 581 592 MultiCascade mc = new MultiCascade(); 593 MultiCascade mcGroups = new MultiCascade(); 582 594 Node n = new Node(); 583 String code = LanguageInfo.getJOSMLocaleCode(); 584 n.put("lang", code); 595 n.put("lang", LanguageInfo.getJOSMLocaleCode()); 585 596 // create a fake environment to read the meta data block 586 597 Environment env = new Environment(n, mc, "default", this); 587 598 Environment envGroups = new Environment(n, mcGroups, "default", this); 599 600 // Parse rules 588 601 for (MapCSSRule r : rules) { 589 602 if (r.selector instanceof GeneralSelector) { 590 603 GeneralSelector gs = (GeneralSelector) r.selector; 591 604 if (Selector.BASE_SETTING.equals(gs.getBase())) { 592 if (!gs.matchesConditions(env)) { 593 continue; 594 } 595 env.layer = null; 596 env.layer = gs.getSubpart().getId(env); 597 r.execute(env); 598 } 599 } 600 } 605 loadSettings(r, gs, env); 606 } else if (Selector.BASE_SETTINGS.equals(gs.getBase())) { 607 loadSettings(r, gs, envGroups); 608 } 609 } 610 } 611 // Load groups 612 for (Entry<String, Cascade> e : mcGroups.getLayers()) { 613 if ("default".equals(e.getKey())) { 614 Logging.warn("settings requires layer identifier e.g. 'settings::settings_group {...}'"); 615 continue; 616 } 617 settingGroups.put(StyleSettingGroup.create(e.getValue(), this, e.getKey()), new ArrayList<>()); 618 } 619 // Load settings 601 620 for (Entry<String, Cascade> e : mc.getLayers()) { 602 621 if ("default".equals(e.getKey())) { … … 610 629 set = BooleanStyleSetting.create(c, this, e.getKey()); 611 630 } else { 612 Logging.warn("Unknown setting type: "+type);631 Logging.warn("Unknown setting type: {0}", type); 613 632 } 614 633 if (set != null) { 615 634 settings.add(set); 616 635 settingValues.put(e.getKey(), set.getValue()); 636 String groupId = c.get("group", null, String.class); 637 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); 640 } 617 641 } 618 642 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r15102 r15289 74 74 /** selector base for artificial bases created to use preferences. */ 75 75 String BASE_SETTING = "setting"; 76 77 /** selector base for grouping settings. */ 78 String BASE_SETTINGS = "settings"; 76 79 77 80 /** … … 703 706 case "canvas": return BASE_CANVAS; 704 707 case "setting": return BASE_SETTING; 708 case "settings": return BASE_SETTINGS; 705 709 default: 706 710 throw new IllegalArgumentException(MessageFormat.format("Unknown MapCSS base selector {0}", base)); … … 779 783 @Override 780 784 public String toString() { 781 return base + (Range.ZERO_TO_INFINITY.equals(range) ? "" : range) + Utils.join("", conds)785 return base + (Range.ZERO_TO_INFINITY.equals(range) ? "" : range) + (conds != null ? Utils.join("", conds) : "") 782 786 + (subpart != null && subpart != Subpart.DEFAULT_SUBPART ? ("::" + subpart) : ""); 783 787 }
Note:
See TracChangeset
for help on using the changeset viewer.