Changeset 3289 in josm
- Timestamp:
- 2010-06-01T09:09:39+02:00 (15 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/defaultpresets.xml
r3279 r3289 48 48 value_off: the value to set when unchecked (default is 'no') 49 49 50 role: type to specify possible roles in relations 51 key: the role name used in relation 52 text: fixed label to display 53 requisite: "optional" or "required" (default is optional) 54 count: how often can the role occur (if not given unlimited number is assumed) 55 type: the data types - way,node,relation,closedway (separated by comma) 56 50 57 For external files the <annotations> should have following elements: 51 58 - author the author of the preset … … 3179 3186 </group> <!-- Landuse --> 3180 3187 </group> 3181 <!-- FIXME: element role not yet supported! -->3182 3188 <group name="Relations" icon="presets/relations.png"> 3183 3189 <item name="Multipolygon" icon="presets/empty.png" type="relation"> … … 3193 3199 <role key="outer" text="outer segment" requisite="required" type="way" /> 3194 3200 <role key="inner" text="inner segment" requisite="optional" type="way" /> 3201 </roles> 3202 </item> 3203 <item name="Boundary" icon="presets/empty.png" type="relation"> 3204 <link href="http://wiki.openstreetmap.org/wiki/Relation:boundary" 3205 de.href="http://wiki.openstreetmap.org/wiki/DE:Relation:boundary" 3206 es.href="http://wiki.openstreetmap.org/wiki/ES:Relation:boundary" 3207 fr.href="http://wiki.openstreetmap.org/wiki/FR:Relation:boundary" /> 3208 <label text="Edit Boundary" /> 3209 <key key="type" value="boundary" /> 3210 <text key="name" text="Name" default="" delete_if_empty="true" /> 3211 <optional> 3212 <combo key="boundary" text="Boundary type" values="administrative,national,civil,political" default="" delete_if_empty="true" /> 3213 <combo key="admin_level" text="Administrative level" values="1,2,3,4,5,6,7,8,9,10" default="" delete_if_empty="true" /> 3214 </optional> 3215 <roles> 3216 <role key="outer" text="outer segment" requisite="required" type="way" /> 3217 <role key="inner" text="inner segment" requisite="optional" type="way" /> 3218 <role key="subarea" text="Sub area" requisite="optional" type="relation" /> 3219 <role key="admin_centre" text="Administration centre" requisite="optional" type="node" /> 3195 3220 </roles> 3196 3221 </item> -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r3225 r3289 310 310 } 311 311 ); 312 tfRole.setText(Main.pref.get("relation.editor.generic.lastrole", "")); 312 313 p3.add(tfRole); 313 314 SetRoleAction setRoleAction = new SetRoleAction(); … … 1167 1168 1168 1169 public void run() { 1170 Main.pref.put("relation.editor.generic.lastrole", tfRole.getText()); 1169 1171 if (getRelation() == null) { 1170 1172 applyNewRelation(); -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r3279 r3289 486 486 } 487 487 488 public static class Role { 489 public List<String> types; 490 public String key; 491 public String text; 492 public String text_context; 493 public String locale_text; 494 495 public boolean required=false; 496 public long count = 0; 497 498 public void setType(String types) throws SAXException { 499 this.types = TaggingPreset.getType(types); 500 } 501 502 public void setRequisite(String str) throws SAXException { 503 if("required".equals(str)) 504 required = true; 505 else if(!"optional".equals(str)) 506 throw new SAXException(tr("Unknown requisite: {0}", str)); 507 } 508 509 /* return either argument, the highest possible value or the lowest 510 allowed value */ 511 public long getValidCount(long c) 512 { 513 if(count > 0 && !required) 514 return c != 0 ? count : 0; 515 else if(count > 0) 516 return count; 517 else if(!required) 518 return c != 0 ? c : 0; 519 else 520 return c != 0 ? c : 1; 521 } 522 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 523 String cstring; 524 if(count > 0 && !required) 525 cstring = "0,"+String.valueOf(count); 526 else if(count > 0) 527 cstring = String.valueOf(count); 528 else if(!required) 529 cstring = "0-..."; 530 else 531 cstring = "1-..."; 532 if(locale_text == null) { 533 if (text != null) { 534 if(text_context != null) { 535 locale_text = trc(text_context, text); 536 } else { 537 locale_text = tr(text); 538 } 539 } 540 } 541 p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0)); 542 p.add(new JLabel(key), GBC.std().insets(0,0,10,0)); 543 p.add(new JLabel(cstring), types == null ? GBC.eol() : GBC.std().insets(0,0,10,0)); 544 if(types != null){ 545 JPanel pp = new JPanel(); 546 for(String t : types) 547 pp.add(new JLabel(ImageProvider.get("Mf_" + t))); 548 p.add(pp, GBC.eol()); 549 } 550 return true; 551 } 552 } 553 554 public static class Roles extends Item { 555 public List<Role> roles = new LinkedList<Role>(); 556 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 557 p.add(new JLabel(" "), GBC.eol()); // space 558 if(roles.size() > 0) 559 { 560 JPanel proles = new JPanel(new GridBagLayout()); 561 proles.add(new JLabel(tr("Available roles")), GBC.std().insets(0,0,10,0)); 562 proles.add(new JLabel(tr("role")), GBC.std().insets(0,0,10,0)); 563 proles.add(new JLabel(tr("count")), GBC.std().insets(0,0,10,0)); 564 proles.add(new JLabel(tr("elements")), GBC.eol()); 565 for (Role i : roles) 566 i.addToPanel(proles, sel); 567 p.add(proles, GBC.eol()); 568 } 569 return false; 570 } 571 @Override public void addCommands(Collection<OsmPrimitive> sel, List<Command> cmds) {} 572 } 573 488 574 public static class Optional extends Item { 489 575 // TODO: Draw a box around optional stuff … … 581 667 */ 582 668 private static Collection<String> allowedtypes = Arrays.asList(new String[] 583 {marktr("way"), marktr("node"), marktr("relation"), marktr("closedway")}); 584 public void setType(String types) throws SAXException { 585 this.types = Arrays.asList(types.split(",")); 586 for (String type : this.types) { 669 {marktr("way"), marktr("node"), marktr("relation"), marktr("closedway")}); 670 671 static public List<String> getType(String types) throws SAXException { 672 List<String> t = Arrays.asList(types.split(",")); 673 for (String type : t) { 587 674 if(!allowedtypes.contains(type)) 588 675 throw new SAXException(tr("Unknown type: {0}", type)); 589 676 } 677 return t; 678 } 679 680 public void setType(String types) throws SAXException { 681 this.types = getType(types); 590 682 } 591 683 … … 598 690 parser.map("link", Link.class); 599 691 parser.mapOnStart("optional", Optional.class); 692 parser.mapOnStart("roles", Roles.class); 693 parser.map("role", Role.class); 600 694 parser.map("check", Check.class); 601 695 parser.map("combo", Combo.class); … … 605 699 LinkedList<TaggingPreset> all = new LinkedList<TaggingPreset>(); 606 700 TaggingPresetMenu lastmenu = null; 701 Roles lastrole = null; 607 702 parser.start(in); 608 703 while(parser.hasNext()) { … … 621 716 622 717 } 718 lastrole = null; 623 719 } else if (o instanceof TaggingPresetSeparator) { 624 720 TaggingPresetSeparator tp = (TaggingPresetSeparator) o; 625 721 tp.group = lastmenu; 626 722 all.add(tp); 723 lastrole = null; 627 724 } else if (o instanceof TaggingPreset) { 628 725 TaggingPreset tp = (TaggingPreset) o; … … 631 728 all.add(tp); 632 729 Main.toolbar.register(tp); 730 lastrole = null; 633 731 } else { 634 if(all.size() != 0) 635 all.getLast().data.add((Item)o); 732 if(all.size() != 0) { 733 if(o instanceof Roles) { 734 all.getLast().data.add((Item)o); 735 lastrole = (Roles) o; 736 } 737 else if(o instanceof Role) { 738 if(lastrole == null) 739 throw new SAXException(tr("Preset role element without parent")); 740 lastrole.roles.add((Role) o); 741 } 742 else { 743 all.getLast().data.add((Item)o); 744 lastrole = null; 745 } 746 } 636 747 else 637 748 throw new SAXException(tr("Preset sub element without parent")); -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java
r3214 r3289 75 75 * use getRoleCache() accessor 76 76 */ 77 protected Set<String> roleCache; 77 protected Set<String> roleCache; 78 /** 79 * the same as roleCache but for the preset roles 80 * can be accessed directly 81 */ 82 protected static Set<String> presetRoleCache = new HashSet<String>(); 78 83 79 84 public AutoCompletionManager(DataSet ds) { … … 179 184 presetTagCache.put(tt.key, tt.default_); 180 185 } 186 } else if (item instanceof TaggingPreset.Roles) { 187 TaggingPreset.Roles r = (TaggingPreset.Roles) item; 188 for (TaggingPreset.Role i : r.roles) { 189 if (i.key != null) 190 presetRoleCache.add(i.key); 191 } 181 192 } 182 193 } … … 228 239 */ 229 240 public void populateWithMemberRoles(AutoCompletionList list) { 241 list.add(presetRoleCache, AutoCompletionItemPritority.IS_IN_STANDARD); 230 242 list.add(getRoleCache(), AutoCompletionItemPritority.IS_IN_DATASET); 231 243 }
Note:
See TracChangeset
for help on using the changeset viewer.