Changeset 5614 in josm
- Timestamp:
- 2012-12-06T22:54:00+01:00 (12 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/defaultpresets.xml
r5611 r5614 89 89 count: how often can the role occur (if not given unlimited number is assumed) 90 90 type: the data types - way,node,relation,closedway (separated by comma) 91 member_expression: an expression (cf. search dialog) for objects of this role 91 92 92 93 presets: For external files <presets> should have following attributes: … … 2426 2427 <roles> 2427 2428 <role key="" text="route segment" requisite="required" type="way" /> 2428 <role key="stop" text="stop position" requisite="optional" type="node" />2429 <role key="stop_exit_only" text="stop position (exit only)" requisite="optional" type="node" />2430 <role key="stop_entry_only" text="stop position (entry only)" requisite="optional" type="node" />2431 <role key="platform" text="platform" requisite="optional" type="node,way,closedway" />2432 <role key="platform_exit_only" text="platform (exit only)" requisite="optional" type="node,way,closedway" />2433 <role key="platform_entry_only" text="platform (entry only)" requisite="optional" type="node,way,closedway" />2429 <role key="stop" text="stop position" requisite="optional" type="node" member_expression="public_transport=stop_position" /> 2430 <role key="stop_exit_only" text="stop position (exit only)" requisite="optional" type="node" member_expression="public_transport=stop_position" /> 2431 <role key="stop_entry_only" text="stop position (entry only)" requisite="optional" type="node" member_expression="public_transport=stop_position" /> 2432 <role key="platform" text="platform" requisite="optional" type="node,way,closedway" member_expression="public_transport=platform" /> 2433 <role key="platform_exit_only" text="platform (exit only)" requisite="optional" type="node,way,closedway" member_expression="public_transport=platform" /> 2434 <role key="platform_entry_only" text="platform (entry only)" requisite="optional" type="node,way,closedway" member_expression="public_transport=platform" /> 2434 2435 </roles> 2435 2436 </item> … … 2447 2448 </optional> 2448 2449 <roles> 2449 <role key="" text="route variant/direction (at least 2)" requisite="required" type="relation" /> <!-- FIXME: at least 2 members are required -->2450 <role key="" text="route variant/direction (at least 2)" requisite="required" type="relation" member_expression="type=route"/> <!-- FIXME: at least 2 members are required --> 2450 2451 </roles> 2451 2452 </item> … … 2464 2465 </optional> 2465 2466 <roles> 2466 <role key="stop" text="Stop Position" requisite="optional" type="node" />2467 <role key="platform" text="Platform" requisite="optional" type="node,way,closedway" />2468 <role key="" text="Station or amenities" requisite="optional" type="node,way,closedway" />2467 <role key="stop" text="Stop Position" requisite="optional" type="node" member_expression="public_transport=stop_position"/> 2468 <role key="platform" text="Platform" requisite="optional" type="node,way,closedway" member_expression="public_transport=platform"/> 2469 <role key="" text="Station or amenities" requisite="optional" type="node,way,closedway" member_expression="amenity|public_transport=station"/> 2469 2470 </roles> 2470 2471 </item> … … 5906 5907 <text key="name" text="Street name" /> 5907 5908 <roles> 5908 <role key="street" text="street" requisite="required" type="way" />5909 <role key="house" text="house" requisite="required" type="node,way,closedway,relation" />5909 <role key="street" text="street" requisite="required" type="way" member_expression="highway "addr:street"" /> 5910 <role key="house" text="house" requisite="required" type="node,way,closedway,relation" member_expression=""addr:housenumber"" /> 5910 5911 </roles> 5911 5912 </item> … … 5963 5964 </optional> 5964 5965 <roles> 5965 <role key="" text="waterways (no riverbank)" requisite="optional" type="way" />5966 <role key="main_stream" text="waterways (no riverbank)" requisite="optional" type="way" />5967 <role key="side_stream" text="branch waterways (no riverbank)" requisite="optional" type="way" />5966 <role key="" text="waterways (no riverbank)" requisite="optional" type="way" member_expression="waterway -waterway:riverbank" /> 5967 <role key="main_stream" text="waterways (no riverbank)" requisite="optional" type="way" member_expression="waterway -waterway:riverbank" /> 5968 <role key="side_stream" text="branch waterways (no riverbank)" requisite="optional" type="way" member_expression="waterway -waterway:riverbank"/> 5968 5969 <role key="spring" text="spring of waterway" requisite="optional" type="node" /> 5969 5970 </roles> -
trunk/data/tagging-preset.xsd
r5585 r5614 57 57 <element name="optional" type="tns:optional" minOccurs="0" /> 58 58 </choice> 59 <element name="roles" type="tns:roles" minOccurs="0" />59 <element name="roles" type="tns:roles" minOccurs="0" maxOccurs="1" /> 60 60 </sequence> 61 61 <attribute name="name" type="string" use="required" /> … … 232 232 <attribute name="type" type="string" /> 233 233 <attribute name="count" type="integer" /> 234 <attribute name="member_expression" type="string" /> 234 235 </complexType> 235 236 -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PresetListPanel.java
r5170 r5614 21 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 22 import org.openstreetmap.josm.data.osm.Tag; 23 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;24 23 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 25 24 import org.openstreetmap.josm.gui.tagging.TaggingPreset.PresetType; … … 86 85 } 87 86 88 for (TaggingPreset t : TaggingPresetPreference.taggingPresets) { 89 if (!t.matches(types, tags, true)) { 90 continue; 91 } 92 87 for (TaggingPreset t : TaggingPreset.getMatchingPresets(types, tags, true)) { 93 88 JLabel lbl = new JLabel(t.getName() + " …"); 94 89 lbl.setIcon((Icon) t.getValue(Action.SMALL_ICON)); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r5605 r5614 62 62 import org.openstreetmap.josm.gui.SideButton; 63 63 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 64 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel; 64 65 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel.PresetHandler; 65 66 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; … … 115 116 WindowGeometry.centerInWindow(Main.parent, new Dimension(700, 650))); 116 117 117 // init the various models 118 // 119 memberTableModel = new MemberTableModel(getLayer()); 120 memberTableModel.register(); 121 selectionTableModel = new SelectionTableModel(getLayer()); 122 selectionTableModel.register(); 123 referrerModel = new ReferringRelationsBrowserModel(relation); 124 125 tagEditorPanel = new TagEditorPanel(new PresetHandler() { 118 final PresetHandler presetHandler = new PresetHandler() { 126 119 127 120 @Override … … 136 129 return Collections.<OsmPrimitive>singletonList(relation); 137 130 } 138 }); 131 }; 132 133 // init the various models 134 // 135 memberTableModel = new MemberTableModel(getLayer(), presetHandler); 136 memberTableModel.register(); 137 selectionTableModel = new SelectionTableModel(getLayer()); 138 selectionTableModel.register(); 139 referrerModel = new ReferringRelationsBrowserModel(relation); 140 141 tagEditorPanel = new TagEditorPanel(presetHandler); 139 142 140 143 // populate the models -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r5603 r5614 13 13 import java.util.Collections; 14 14 import java.util.Comparator; 15 import java.util.EnumSet; 15 16 import java.util.HashMap; 16 17 import java.util.HashSet; … … 46 47 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 47 48 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 49 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel; 48 50 import org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction; 49 51 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 52 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 50 53 import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTableModel; 51 54 … … 59 62 60 63 private DefaultListSelectionModel listSelectionModel; 61 private CopyOnWriteArrayList<IMemberModelListener> listeners; 62 private OsmDataLayer layer; 64 private final CopyOnWriteArrayList<IMemberModelListener> listeners; 65 private final OsmDataLayer layer; 66 private final PresetListPanel.PresetHandler presetHandler; 63 67 64 68 private final int UNCONNECTED = Integer.MIN_VALUE; … … 73 77 * constructor 74 78 */ 75 public MemberTableModel(OsmDataLayer layer ) {79 public MemberTableModel(OsmDataLayer layer, PresetListPanel.PresetHandler presetHandler) { 76 80 members = new ArrayList<RelationMember>(); 77 81 listeners = new CopyOnWriteArrayList<IMemberModelListener>(); 78 82 this.layer = layer; 83 this.presetHandler = presetHandler; 79 84 addTableModelListener(this); 80 85 } … … 395 400 396 401 private void addMembersAtIndex(List<? extends OsmPrimitive> primitives, int index) { 402 final Collection<TaggingPreset> presets = TaggingPreset.getMatchingPresets(EnumSet.of(TaggingPreset.PresetType.RELATION), presetHandler.getSelection().iterator().next().getKeys(), false); 397 403 if (primitives == null) 398 404 return; 399 405 int idx = index; 400 406 for (OsmPrimitive primitive : primitives) { 401 RelationMember member = new RelationMember("", primitive); 407 final String role = presets.isEmpty() ? null : presets.iterator().next().suggestRoleForOsmPrimitive(primitive); 408 RelationMember member = new RelationMember(role == null ? "" : role, primitive); 402 409 members.add(idx++, member); 403 410 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r5606 r5614 67 67 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 68 68 import org.openstreetmap.josm.gui.preferences.SourceEntry; 69 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference; 69 70 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference.PresetPrefHelper; 70 71 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; … … 76 77 import org.openstreetmap.josm.tools.GBC; 77 78 import org.openstreetmap.josm.tools.ImageProvider; 79 import org.openstreetmap.josm.tools.Predicate; 78 80 import org.openstreetmap.josm.tools.UrlLabel; 79 81 import org.openstreetmap.josm.tools.Utils; … … 1094 1096 public String text_context; 1095 1097 public String locale_text; 1098 public Match memberExpression; 1096 1099 1097 1100 public boolean required = false; … … 1107 1110 } else if(!"optional".equals(str)) 1108 1111 throw new SAXException(tr("Unknown requisite: {0}", str)); 1112 } 1113 1114 public void setMember_expression(String member_expression) throws SAXException { 1115 try { 1116 this.memberExpression = SearchCompiler.compile(member_expression, true, true); 1117 } catch (SearchCompiler.ParseError ex) { 1118 throw new SAXException(tr("Illegal member expression: {0}", ex.getMessage()), ex); 1119 } 1109 1120 } 1110 1121 … … 1158 1169 public static class Roles extends Item { 1159 1170 1160 public List<Role> roles = new LinkedList<Role>();1171 public final List<Role> roles = new LinkedList<Role>(); 1161 1172 1162 1173 @Override … … 1241 1252 public EnumSet<PresetType> types; 1242 1253 public List<Item> data = new LinkedList<Item>(); 1254 public Roles roles; 1243 1255 public TemplateEntry nameTemplate; 1244 1256 public Match nameTemplateFilter; … … 1428 1440 if (o instanceof Roles) { 1429 1441 all.getLast().data.add((Item) o); 1442 if (all.getLast().roles != null) { 1443 throw new SAXException(tr("Roles cannot appear more than once")); 1444 } 1445 all.getLast().roles = (Roles) o; 1430 1446 lastrole = (Roles) o; 1431 1447 } else if (o instanceof Role) { … … 1572 1588 } 1573 1589 1590 public String suggestRoleForOsmPrimitive(OsmPrimitive osm) { 1591 if (roles == null) { 1592 return null; 1593 } 1594 for (Role i : roles.roles) { 1595 if (i.memberExpression != null && i.memberExpression.match(osm)) { 1596 return i.key; 1597 } 1598 } 1599 return null; 1600 } 1601 1574 1602 public void actionPerformed(ActionEvent e) { 1575 1603 if (Main.main == null) return; … … 1590 1618 r.put(t.getKey(), t.getValue()); 1591 1619 } 1592 for(OsmPrimitive osm : Main.main.getCurrentDataSet().getSelected()) { 1593 RelationMember rm = new RelationMember("", osm); 1620 for (OsmPrimitive osm : Main.main.getCurrentDataSet().getSelected()) { 1621 String role = suggestRoleForOsmPrimitive(osm); 1622 RelationMember rm = new RelationMember(role == null ? "" : role, osm); 1594 1623 r.addMember(rm); 1595 1624 members.add(rm); … … 1773 1802 return atLeastOnePositiveMatch; 1774 1803 } 1804 1805 public static Collection<TaggingPreset> getMatchingPresets(final Collection<PresetType> t, final Map<String, String> tags, final boolean onlyShowable) { 1806 return Utils.filter(TaggingPresetPreference.taggingPresets, new Predicate<TaggingPreset>() { 1807 @Override 1808 public boolean evaluate(TaggingPreset object) { 1809 return object.matches(t, tags, onlyShowable); 1810 } 1811 }); 1812 } 1775 1813 }
Note:
See TracChangeset
for help on using the changeset viewer.