Changeset 7556 in josm
- Timestamp:
- 2014-09-18T02:23:15+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r7432 r7556 163 163 } 164 164 165 @Override public void accept(Visitor visitor) { 165 @Override 166 public void accept(Visitor visitor) { 166 167 visitor.visit(this); 167 168 } 168 169 169 @Override public void accept(PrimitiveVisitor visitor) { 170 @Override 171 public void accept(PrimitiveVisitor visitor) { 170 172 visitor.visit(this); 171 173 } … … 223 225 } 224 226 225 @Override public void cloneFrom(OsmPrimitive osm) { 227 @Override 228 public void cloneFrom(OsmPrimitive osm) { 226 229 boolean locked = writeLock(); 227 230 try { … … 234 237 } 235 238 236 @Override public void load(PrimitiveData data) { 239 @Override 240 public void load(PrimitiveData data) { 237 241 boolean locked = writeLock(); 238 242 try { … … 548 552 return false; 549 553 } 554 555 /** 556 * Returns the set of roles used in this relation. 557 * @return the set of roles used in this relation. Can be empty but never null 558 * @since 7556 559 */ 560 public Set<String> getMemberRoles() { 561 Set<String> result = new HashSet<>(); 562 for (RelationMember rm : members) { 563 String role = rm.getRole(); 564 if (!role.isEmpty()) { 565 result.add(role); 566 } 567 } 568 return result; 569 } 550 570 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r7546 r7556 92 92 /** 93 93 * This dialog is for editing relations. 94 * 94 * @since 343 95 95 */ 96 96 public class GenericRelationEditor extends RelationEditor { … … 172 172 tagEditorPanel.getModel().ensureOneTag(); 173 173 174 JSplitPane pane = buildSplitPane( );174 JSplitPane pane = buildSplitPane(relation); 175 175 pane.setPreferredSize(new Dimension(100, 100)); 176 176 … … 293 293 */ 294 294 protected JPanel buildMemberEditorPanel() { 295 final JPanel pnl = new JPanel(); 296 pnl.setLayout(new GridBagLayout()); 295 final JPanel pnl = new JPanel(new GridBagLayout()); 297 296 // setting up the member table 298 memberTable = new MemberTable(getLayer(), memberTableModel);297 memberTable = new MemberTable(getLayer(), getRelation(), memberTableModel); 299 298 memberTable.addMouseListener(new MemberTableDblClickAdapter()); 300 299 memberTableModel.addMemberModelListener(memberTable); … … 350 349 if (list != null) { 351 350 list.clear(); 352 getLayer().data.getAutoCompletionManager().populateWithMemberRoles(list );351 getLayer().data.getAutoCompletionManager().populateWithMemberRoles(list, getRelation()); 353 352 } 354 353 } … … 454 453 * @return the split panel 455 454 */ 456 protected JSplitPane buildSplitPane( ) {455 protected JSplitPane buildSplitPane(Relation relation) { 457 456 final JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); 458 457 pane.setTopComponent(buildTagEditorPanel()); … … 1603 1602 1604 1603 /** 1605 * Creates a new relation with a copy of the current editor state 1606 * 1604 * Creates a new relation with a copy of the current editor state. 1607 1605 */ 1608 1606 class DuplicateRelationAction extends AbstractAction { … … 1626 1624 1627 1625 /** 1628 * Action for editing the currently selected relation 1629 * 1630 * 1626 * Action for editing the currently selected relation. 1631 1627 */ 1632 1628 class EditAction extends AbstractAction implements ListSelectionListener { … … 1736 1732 } 1737 1733 } 1738 1739 1734 } 1740 1735 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberRoleCellEditor.java
r6246 r7556 10 10 11 11 import org.openstreetmap.josm.data.osm.DataSet; 12 import org.openstreetmap.josm.data.osm.Relation; 12 13 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; 13 14 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; … … 15 16 public class MemberRoleCellEditor extends AbstractCellEditor implements TableCellEditor { 16 17 private AutoCompletingTextField editor = null; 17 private DataSet ds; 18 private final DataSet ds; 19 private final Relation relation; 18 20 19 21 /** user input is matched against this list of auto completion items */ … … 21 23 22 24 /** 23 * constructor 25 * Constructs a new {@code MemberRoleCellEditor}. 26 * @param ds the data set. Must not be null 27 * @param relation the relation. Can be null 24 28 */ 25 public MemberRoleCellEditor(DataSet ds ) {29 public MemberRoleCellEditor(DataSet ds, Relation relation) { 26 30 this.ds = ds; 31 this.relation = relation; 27 32 editor = new AutoCompletingTextField(); 28 33 editor.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); … … 31 36 } 32 37 33 /**34 * replies the table cell editor35 */36 38 @Override 37 39 public Component getTableCellEditorComponent(JTable table, … … 41 43 editor.setText(role); 42 44 autoCompletionList.clear(); 43 ds.getAutoCompletionManager().populateWithMemberRoles(autoCompletionList );45 ds.getAutoCompletionManager().populateWithMemberRoles(autoCompletionList, relation); 44 46 return editor; 45 47 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTable.java
r7005 r7556 29 29 import org.openstreetmap.josm.actions.ZoomToAction; 30 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; 31 import org.openstreetmap.josm.data.osm.Relation; 31 32 import org.openstreetmap.josm.data.osm.RelationMember; 32 33 import org.openstreetmap.josm.data.osm.Way; … … 50 51 * constructor for relation member table 51 52 * 52 * @param layer the data layer of the relation 53 * @param layer the data layer of the relation. Must not be null 54 * @param relation the relation. Can be null 53 55 * @param model the table model 54 56 */ 55 public MemberTable(OsmDataLayer layer, MemberTableModel model) {56 super(model, new MemberTableColumnModel(layer.data ), model.getSelectionModel());57 public MemberTable(OsmDataLayer layer, Relation relation, MemberTableModel model) { 58 super(model, new MemberTableColumnModel(layer.data, relation), model.getSelectionModel()); 57 59 setLayer(layer); 58 60 model.addMemberModelListener(this); … … 157 159 * <li>it jumps over cells in the first column</li> <li>it automatically add a new empty row 158 160 * when the user leaves the last cell in the table</li></ul> 159 *160 *161 161 */ 162 162 class SelectNextColumnCellAction extends AbstractAction { … … 191 191 * Action to be run when the user navigates to the previous cell in the table, for instance by 192 192 * pressing Shift-TAB 193 *194 193 */ 195 194 private class SelectPreviousColumnCellAction extends AbstractAction { -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableColumnModel.java
r6296 r7556 8 8 9 9 import org.openstreetmap.josm.data.osm.DataSet; 10 import org.openstreetmap.josm.data.osm.Relation; 10 11 11 12 public class MemberTableColumnModel extends DefaultTableColumnModel { 12 13 13 public MemberTableColumnModel(DataSet ds) { 14 /** 15 * Constructs a new {@code MemberTableColumnModel}. 16 * @param ds the data set. Must not be null 17 * @param relation the relation. Can be null 18 */ 19 public MemberTableColumnModel(DataSet ds, Relation relation) { 14 20 TableColumn col = null; 15 21 … … 20 26 col.setPreferredWidth(100); 21 27 col.setCellRenderer(new MemberTableRoleCellRenderer()); 22 col.setCellEditor(new MemberRoleCellEditor(ds ));28 col.setCellEditor(new MemberRoleCellEditor(ds, relation)); 23 29 addColumn(col); 24 30 -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java
r7005 r7556 29 29 import org.openstreetmap.josm.gui.tagging.TaggingPresetItem; 30 30 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems; 31 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.Role; 32 import org.openstreetmap.josm.tools.CheckParameterUtil; 31 33 import org.openstreetmap.josm.tools.MultiMap; 34 import org.openstreetmap.josm.tools.Utils; 32 35 33 36 /** … … 210 213 211 214 /** 212 * Populates the an{@link AutoCompletionList} with the currently cached215 * Populates the {@link AutoCompletionList} with the currently cached 213 216 * member roles. 214 217 * … … 218 221 list.add(presetRoleCache, AutoCompletionItemPriority.IS_IN_STANDARD); 219 222 list.add(getRoleCache(), AutoCompletionItemPriority.IS_IN_DATASET); 223 } 224 225 /** 226 * Populates the {@link AutoCompletionList} with the roles used in this relation 227 * plus the ones defined in its applicable presets, if any. If the relation type is unknown, 228 * then all the roles known globally will be added, as in {@link #populateWithMemberRoles(AutoCompletionList)}. 229 * 230 * @param list the list to populate 231 * @param r the relation to get roles from 232 * @throws IllegalArgumentException if list is null 233 * @since 7556 234 */ 235 public void populateWithMemberRoles(AutoCompletionList list, Relation r) { 236 CheckParameterUtil.ensureParameterNotNull(list, "list"); 237 Collection<TaggingPreset> presets = r != null ? TaggingPreset.getMatchingPresets(null, r.getKeys(), false) : null; 238 if (r != null && presets != null && !presets.isEmpty()) { 239 for (TaggingPreset tp : presets) { 240 if (tp.roles != null) { 241 list.add(Utils.transform(tp.roles.roles, new Utils.Function<Role, String>() { 242 public String apply(Role x) { 243 return x.key; 244 } 245 }), AutoCompletionItemPriority.IS_IN_STANDARD); 246 } 247 } 248 list.add(r.getMemberRoles(), AutoCompletionItemPriority.IS_IN_DATASET); 249 } else { 250 populateWithMemberRoles(list); 251 } 220 252 } 221 253 -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r7473 r7556 625 625 return new AbstractList<B>() { 626 626 627 628 627 @Override 629 628 public int size() { … … 635 634 return f.apply(l.get(index)); 636 635 } 637 638 639 636 }; 640 637 }
Note:
See TracChangeset
for help on using the changeset viewer.