Changeset 7450 in josm
- Timestamp:
- 2014-08-28T09:57:36+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r7185 r7450 35 35 import javax.swing.JFileChooser; 36 36 import javax.swing.JLabel; 37 import javax.swing.JMenu; 37 38 import javax.swing.JPanel; 38 39 import javax.swing.JPopupMenu; … … 66 67 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 67 68 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; 69 import org.openstreetmap.josm.gui.mappaint.StyleSetting; 68 70 import org.openstreetmap.josm.gui.mappaint.StyleSource; 69 71 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; … … 667 669 add(reloadAction); 668 670 add(new SaveAsAction()); 671 672 JMenu setMenu = new JMenu(tr("Style settings")); 673 setMenu.setIcon(ImageProvider.overlay(ImageProvider.get("preference"), 674 ImageProvider.get("dialogs/mappaint/pencil.png"), 675 ImageProvider.OverlayPosition.SOUTHEAST)); 676 add(setMenu); 677 678 int sel = tblStyles.getSelectionModel().getLeadSelectionIndex(); 679 StyleSource style = null; 680 if (sel >= 0 && sel < model.getRowCount()) { 681 style = model.getRow(sel); 682 } 683 if (style == null || style.settings.isEmpty()) { 684 setMenu.setEnabled(false); 685 } else { 686 for (StyleSetting s : style.settings) { 687 s.addMenuEntry(setMenu); 688 } 689 } 690 669 691 addSeparator(); 670 692 add(new InfoAction()); -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r7248 r7450 11 11 import java.util.Collection; 12 12 import java.util.Collections; 13 import java.util.HashMap; 13 14 import java.util.List; 15 import java.util.Map; 14 16 15 17 import javax.swing.ImageIcon; … … 41 43 42 44 public String icon; 45 46 /** 47 * List of settings for user customization. 48 */ 49 public final List<StyleSetting> settings = new ArrayList<>(); 50 /** 51 * Values of the settings for efficient lookup. 52 */ 53 public Map<String, Object> settingValues = new HashMap<>(); 43 54 44 55 public StyleSource(String url, String name, String title) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r7246 r7450 18 18 import java.util.Collections; 19 19 import java.util.List; 20 import java.util.Objects;21 20 import java.util.regex.Matcher; 22 21 import java.util.regex.Pattern; … … 645 644 /** 646 645 * Get the number of tags for the current primitive. 647 * @param env 646 * @param env the environment 648 647 * @return number of tags 649 648 */ 650 649 public static int number_of_tags(Environment env) { 651 650 return env.osm.getNumKeys(); 651 } 652 653 /** 654 * Get value of a setting. 655 * @param env the environment 656 * @param key setting key (given as layer identifier, e.g. setting::mykey {...}) 657 * @return the value of the setting (calculated when the style is loaded) 658 */ 659 public static Object setting(Environment env, String key) { 660 return env.source.settingValues.get(key); 652 661 } 653 662 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r7448 r7450 35 35 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 36 36 import org.openstreetmap.josm.gui.mappaint.Range; 37 import org.openstreetmap.josm.gui.mappaint.StyleSetting; 38 import org.openstreetmap.josm.gui.mappaint.StyleSetting.BooleanStyleSetting; 37 39 import org.openstreetmap.josm.gui.mappaint.StyleSource; 38 40 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.SimpleKeyValueCondition; … … 70 72 private String css = null; 71 73 private ZipFile zipFile; 72 74 73 75 /** 74 76 * This lock prevents concurrent execution of {@link MapCSSRuleIndex#clear() } / … … 224 226 loadMeta(); 225 227 loadCanvas(); 228 loadSettings(); 226 229 } finally { 227 230 closeSourceInputStream(in); … … 276 279 break; 277 280 case "meta": 281 case "setting": 278 282 break; 279 283 default: … … 352 356 } 353 357 } 358 359 private void loadSettings() { 360 settings.clear(); 361 settingValues.clear(); 362 MultiCascade mc = new MultiCascade(); 363 Node n = new Node(); 364 String code = LanguageInfo.getJOSMLocaleCode(); 365 n.put("lang", code); 366 // create a fake environment to read the meta data block 367 Environment env = new Environment(n, mc, "default", this); 368 369 for (MapCSSRule r : rules) { 370 if ((r.selector instanceof GeneralSelector)) { 371 GeneralSelector gs = (GeneralSelector) r.selector; 372 if (gs.getBase().equals("setting")) { 373 if (!gs.matchesConditions(env)) { 374 continue; 375 } 376 env.layer = gs.getSubpart(); 377 r.execute(env); 378 } 379 } 380 } 381 for (Entry<String, Cascade> e : mc.getLayers()) { 382 if ("default".equals(e.getKey())) { 383 Main.warn("setting requires layer identifier e.g. 'setting::my_setting {...}'"); 384 continue; 385 } 386 Cascade c = e.getValue(); 387 String type = c.get("type", null, String.class); 388 StyleSetting set = null; 389 if ("boolean".equals(type)) { 390 set = BooleanStyleSetting.create(c, this, e.getKey()); 391 } else { 392 Main.warn("Unkown setting type: "+type); 393 } 394 if (set != null) { 395 settings.add(set); 396 settingValues.put(e.getKey(), set.getValue()); 397 } 398 } 399 } 354 400 355 401 private Cascade constructSpecial(String type) {
Note:
See TracChangeset
for help on using the changeset viewer.