Changeset 5614 in josm for trunk/src/org
- Timestamp:
- 2012-12-06T22:54:00+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
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.