- Timestamp:
- 2015-12-05T15:38:14+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/dialogs/properties
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r9078 r9086 172 172 * This sub-object is responsible for all adding and editing of tags 173 173 */ 174 private final transient TagEditHelper editHelper = new TagEditHelper(tag Data, valueCount);174 private final transient TagEditHelper editHelper = new TagEditHelper(tagTable, tagData, valueCount); 175 175 176 176 private final transient DataSetListenerAdapter dataChangedAdapter = new DataSetListenerAdapter(this); … … 561 561 } 562 562 563 private int find Row(TableModel model, Object value) {563 private int findViewRow(JTable table, TableModel model, Object value) { 564 564 for (int i = 0; i < model.getRowCount(); i++) { 565 565 if (model.getValueAt(i, 0).equals(value)) 566 return i;566 return table.convertRowIndexToView(i); 567 567 } 568 568 return -1; … … 639 639 selectedTag = editHelper.getChangedKey(); // select last added or last edited key by default 640 640 if (selectedTag == null && tagTable.getSelectedRowCount() == 1) { 641 selectedTag = (String) tagData.getValueAt(tagTable.getSelectedRow(), 0);641 selectedTag = editHelper.getDataKey(tagTable.getSelectedRow()); 642 642 } 643 643 if (membershipTable.getSelectedRowCount() == 1) { … … 737 737 738 738 int selectedIndex; 739 if (selectedTag != null && (selectedIndex = find Row(tagData, selectedTag)) != -1) {739 if (selectedTag != null && (selectedIndex = findViewRow(tagTable, tagData, selectedTag)) != -1) { 740 740 tagTable.changeSelection(selectedIndex, 0, false, false); 741 } else if (selectedRelation != null && (selectedIndex = find Row(membershipData, selectedRelation)) != -1) {741 } else if (selectedRelation != null && (selectedIndex = findViewRow(membershipTable, membershipData, selectedRelation)) != -1) { 742 742 membershipTable.changeSelection(selectedIndex, 0, false, false); 743 743 } else if (hasTags) { … … 791 791 * @return The current selected tag 792 792 */ 793 @SuppressWarnings("unchecked")794 793 public Tag getSelectedProperty() { 795 794 int row = tagTable.getSelectedRow(); 796 795 if (row == -1) return null; 797 Map<String, Integer> map = (TreeMap<String, Integer>) tagData.getValueAt(row, 1);796 Map<String, Integer> map = editHelper.getDataValues(row); 798 797 return new Tag( 799 tagData.getValueAt(row, 0).toString(),798 editHelper.getDataKey(row), 800 799 map.size() > 1 ? "" : map.keySet().iterator().next()); 801 800 } … … 952 951 int nextKeyIndex = rows[0]; 953 952 for (int row : rows) { 954 String key = tagData.getValueAt(row, 0).toString();953 String key = editHelper.getDataKey(row); 955 954 if (row == nextKeyIndex + 1) { 956 955 nextKeyIndex = row; // no gap yet … … 970 969 nextKeyIndex++; 971 970 } 972 nextKey = (String) tagData.getValueAt(nextKeyIndex, 0);971 nextKey = editHelper.getDataKey(nextKeyIndex); 973 972 } 974 973 … … 978 977 membershipTable.clearSelection(); 979 978 if (nextKey != null) { 980 tagTable.changeSelection(find Row(tagData, nextKey), 0, false, false);979 tagTable.changeSelection(findViewRow(tagTable, tagData, nextKey), 0, false, false); 981 980 } 982 981 } … … 1010 1009 tagTable.clearSelection(); 1011 1010 if (nextRelation != null) { 1012 membershipTable.changeSelection(find Row(membershipData, nextRelation), 0, false, false);1011 membershipTable.changeSelection(findViewRow(membershipTable, membershipData, nextRelation), 0, false, false); 1013 1012 } 1014 1013 } … … 1115 1114 if (tagTable.getSelectedRowCount() == 1) { 1116 1115 row = tagTable.getSelectedRow(); 1117 String key = Utils.encodeUrl(tagData.getValueAt(row, 0).toString()); 1118 @SuppressWarnings("unchecked") 1119 Map<String, Integer> m = (Map<String, Integer>) tagData.getValueAt(row, 1); 1116 String key = Utils.encodeUrl(editHelper.getDataKey(row)); 1117 Map<String, Integer> m = editHelper.getDataValues(row); 1120 1118 String val = Utils.encodeUrl(m.entrySet().iterator().next().getKey()); 1121 1119 … … 1206 1204 1207 1205 @Override 1208 @SuppressWarnings("unchecked")1209 1206 public void actionPerformed(ActionEvent e) { 1210 1207 final String url; 1211 1208 if (tagTable.getSelectedRowCount() == 1) { 1212 1209 final int row = tagTable.getSelectedRow(); 1213 final String key = Utils.encodeUrl( tagData.getValueAt(row, 0).toString());1214 Map<String, Integer> values = (Map<String, Integer>) tagData.getValueAt(row, 1);1210 final String key = Utils.encodeUrl(editHelper.getDataKey(row)); 1211 Map<String, Integer> values = editHelper.getDataValues(row); 1215 1212 if (values.size() == 1) { 1216 1213 url = TAGINFO_URL_PROP.get() + "tags/" + key /* do not URL encode key, otherwise addr:street does not work */ … … 1239 1236 if (tagTable.getSelectedRowCount() != 1) 1240 1237 return; 1241 String key = tagData.getValueAt(tagTable.getSelectedRow(), 0).toString();1238 String key = editHelper.getDataKey(tagTable.getSelectedRow()); 1242 1239 Collection<OsmPrimitive> sel = Main.main.getInProgressSelection(); 1243 1240 String clipboard = Utils.getClipboardContent(); … … 1260 1257 1261 1258 for (int row: rows) { 1262 String key = tagData.getValueAt(row, 0).toString();1259 String key = editHelper.getDataKey(row); 1263 1260 if (sel.isEmpty()) 1264 1261 return; … … 1342 1339 if (tagTable.getSelectedRowCount() != 1) 1343 1340 return; 1344 String key = tagData.getValueAt(tagTable.getSelectedRow(), 0).toString();1341 String key = editHelper.getDataKey(tagTable.getSelectedRow()); 1345 1342 Collection<OsmPrimitive> sel = Main.main.getInProgressSelection(); 1346 1343 if (sel.isEmpty()) -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r9084 r9086 53 53 import javax.swing.JPanel; 54 54 import javax.swing.JPopupMenu; 55 import javax.swing.JTable; 55 56 import javax.swing.KeyStroke; 56 57 import javax.swing.ListCellRenderer; … … 86 87 */ 87 88 class TagEditHelper { 89 private final JTable tagTable; 88 90 private final DefaultTableModel tagData; 89 91 private final Map<String, Map<String, Integer>> valueCount; … … 116 118 }; 117 119 118 TagEditHelper(DefaultTableModel propertyData, Map<String, Map<String, Integer>> valueCount) { 120 TagEditHelper(JTable tagTable, DefaultTableModel propertyData, Map<String, Map<String, Integer>> valueCount) { 121 this.tagTable = tagTable; 119 122 this.tagData = propertyData; 120 123 this.valueCount = valueCount; 124 } 125 126 public final String getDataKey(int viewRow) { 127 return tagData.getValueAt(tagTable.convertRowIndexToModel(viewRow), 0).toString(); 128 } 129 130 @SuppressWarnings("unchecked") 131 public final Map<String, Integer> getDataValues(int viewRow) { 132 return (Map<String, Integer>) tagData.getValueAt(tagTable.convertRowIndexToModel(viewRow), 1); 121 133 } 122 134 … … 152 164 if (sel == null || sel.isEmpty()) return; 153 165 154 String key = tagData.getValueAt(row, 0).toString();166 String key = getDataKey(row); 155 167 objKey = key; 156 168 157 @SuppressWarnings("unchecked") 158 final EditTagDialog editDialog = new EditTagDialog(key, 159 (Map<String, Integer>) tagData.getValueAt(row, 1), focusOnKey); 169 final EditTagDialog editDialog = new EditTagDialog(key, getDataValues(row), focusOnKey); 160 170 editDialog.showDialog(); 161 171 if (editDialog.getValue() != 1) return; … … 567 577 } 568 578 for (int i = 0; i < tagData.getRowCount(); ++i) { 569 if (item.getValue().equals( tagData.getValueAt(i, 0))) {579 if (item.getValue().equals(getDataKey(i))) { 570 580 if (itemToSelect == item) { 571 581 itemToSelect = null; … … 831 841 // performing this action leads to autocomplete to the next key (see #7671 comments) 832 842 for (int j = 0; j < tagData.getRowCount(); ++j) { 833 if (t.getKey().equals( tagData.getValueAt(j, 0))) {843 if (t.getKey().equals(getDataKey(j))) { 834 844 action.setEnabled(false); 835 845 break;
Note:
See TracChangeset
for help on using the changeset viewer.