Changeset 1762 in josm
- Timestamp:
- 2009-07-11T09:32:42+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 13 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java
r1706 r1762 44 44 public String apply(String text) { 45 45 Matcher m = startPattern.matcher(text); 46 if (!m.lookingAt()) 46 if (!m.lookingAt()) { 47 47 m = endPattern.matcher(text); 48 } 48 49 49 50 if (m.lookingAt()) { … … 62 63 63 64 private static PrefixSuffixSwitcher[] prefixSuffixSwitchers = 64 65 66 67 68 65 new PrefixSuffixSwitcher[] { 66 new PrefixSuffixSwitcher("left", "right"), 67 new PrefixSuffixSwitcher("forward", "backward"), 68 new PrefixSuffixSwitcher("forwards", "backwards") 69 }; 69 70 70 71 @Override 71 72 public Collection<Command> execute(Way oldway, Way way) throws UserCancelException { 72 73 Map<OsmPrimitive, List<TagCorrection>> tagCorrectionsMap = 73 74 new HashMap<OsmPrimitive, List<TagCorrection>>(); 74 75 75 76 ArrayList<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); … … 86 87 87 88 if (key.equals("oneway")) { 88 if (value.equals("-1")) 89 if (value.equals("-1")) { 89 90 newValue = OsmUtils.trueval; 90 else {91 } else { 91 92 Boolean boolValue = OsmUtils.getOsmBoolean(value); 92 93 if (boolValue != null && boolValue.booleanValue()) { … … 97 98 for (PrefixSuffixSwitcher prefixSuffixSwitcher : prefixSuffixSwitchers) { 98 99 newKey = prefixSuffixSwitcher.apply(key); 99 if (!key.equals(newKey)) 100 if (!key.equals(newKey)) { 100 101 break; 102 } 101 103 } 102 104 } 103 105 104 if (!key.equals(newKey) || !value.equals(newValue)) 106 if (!key.equals(newKey) || !value.equals(newValue)) { 105 107 tagCorrectionsMap.get(primitive).add( 106 108 new TagCorrection(key, value, newKey, newValue)); 109 } 107 110 } 108 111 } 109 112 110 113 Map<OsmPrimitive, List<RoleCorrection>> roleCorrectionMap = 111 114 new HashMap<OsmPrimitive, List<RoleCorrection>>(); 112 115 roleCorrectionMap.put(way, new ArrayList<RoleCorrection>()); 113 116 … … 115 118 int position = 0; 116 119 for (RelationMember member : relation.members) { 117 if (!member.member. realEqual(oldway, true)120 if (!member.member.hasEqualSemanticAttributes(oldway) 118 121 || member.role.length() == 0) { 119 122 position++; … … 131 134 } 132 135 133 if (found) 136 if (found) { 134 137 roleCorrectionMap.get(way).add( 135 138 new RoleCorrection(relation, position, member, newRole)); 139 } 136 140 137 141 position++; -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r1750 r1762 107 107 } 108 108 109 /**110 * @deprecated111 * @see #hasEqualSemanticAttributes(OsmPrimitive)112 * @see #hasEqualTechnicalAttributes(OsmPrimitive)113 */114 @Deprecated115 @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {116 if (osm instanceof Node) {117 if (super.realEqual(osm, semanticOnly)) {118 if ((coor == null) && ((Node)osm).coor == null)119 return true;120 if (coor != null)121 return coor.equals(((Node)osm).coor);122 }123 }124 return false;125 }126 127 109 @Override 128 110 public boolean hasEqualSemanticAttributes(OsmPrimitive other) { -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r1690 r1762 284 284 clearCached(); 285 285 clearErrors(); 286 }287 288 /**289 * Perform an equality compare for all non-volatile fields not only for the id290 * but for the whole object (for conflict resolving)291 * @param semanticOnly if <code>true</code>, modified flag and timestamp are not compared292 *293 * @deprecated294 * @see #hasEqualSemanticAttributes(OsmPrimitive)295 * @see #hasEqualTechnicalAttributes(OsmPrimitive)296 */297 @Deprecated298 public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {299 return id == osm.id300 && incomplete == osm.incomplete301 && deleted == osm.deleted302 && (semanticOnly || (303 modified == osm.modified304 && timestamp == osm.timestamp305 && version == osm.version306 && visible == osm.visible307 && (user == null ? osm.user==null : user==osm.user))308 )309 && (keys == null ? osm.keys==null : keys.equals(osm.keys));310 286 } 311 287 -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r1690 r1762 68 68 // adding members in string increases memory usage a lot and overflows for looped relations 69 69 return "{Relation id="+id+" version="+version+"}"; 70 }71 72 @Deprecated73 @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {74 return osm instanceof Relation ? super.realEqual(osm, semanticOnly) && members.equals(((Relation)osm).members) : false;75 70 } 76 71 -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r1690 r1762 99 99 if (incomplete) return "{Way id="+id+" version="+version+" (incomplete)}"; 100 100 return "{Way id="+id+" version="+version+" nodes="+Arrays.toString(nodes.toArray())+"}"; 101 }102 103 @Deprecated104 @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {105 return osm instanceof Way ? super.realEqual(osm, semanticOnly) && nodes.equals(((Way)osm).nodes) : false;106 101 } 107 102 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1754 r1762 9 9 import java.awt.event.ActionEvent; 10 10 import java.awt.event.ActionListener; 11 import java.awt.event.ComponentAdapter; 12 import java.awt.event.ComponentEvent; 11 13 import java.awt.event.KeyEvent; 14 import java.awt.event.WindowAdapter; 15 import java.awt.event.WindowEvent; 12 16 import java.io.IOException; 13 17 import java.util.ArrayList; 14 18 import java.util.Arrays; 15 19 import java.util.Collection; 16 import java.util.Map.Entry;17 20 18 21 import javax.swing.JLabel; … … 23 26 import javax.swing.JTable; 24 27 import javax.swing.ListSelectionModel; 28 import javax.swing.SwingUtilities; 25 29 import javax.swing.event.ListSelectionEvent; 26 30 import javax.swing.event.ListSelectionListener; … … 44 48 import org.openstreetmap.josm.gui.SideButton; 45 49 import org.openstreetmap.josm.gui.dialogs.ConflictDialog; 50 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionCache; 51 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionList; 46 52 import org.openstreetmap.josm.io.OsmServerObjectReader; 47 53 import org.openstreetmap.josm.io.OsmTransferException; … … 94 100 public class GenericRelationEditor extends RelationEditor { 95 101 102 // We need this twice, so cache result 103 protected final static String applyChangesText = tr("Apply Changes"); 104 96 105 private JLabel status; 97 98 /**99 * The property data.100 */101 private final DefaultTableModel propertyData = new DefaultTableModel() {102 @Override public boolean isCellEditable(int row, int column) {103 return true;104 }105 @Override public Class<?> getColumnClass(int columnIndex) {106 return String.class;107 }108 };109 106 110 107 /** … … 123 120 * The properties and membership lists. 124 121 */ 125 private final JTable propertyTable = new JTable(propertyData);126 122 private final JTable memberTable = new JTable(memberData); 127 123 128 // We need this twice, so cache result 129 protected final static String applyChangesText = tr("Apply Changes"); 124 /** the tag table and its model */ 125 private TagEditorModel tagEditorModel; 126 private TagTable tagTable; 127 private AutoCompletionCache acCache; 128 private AutoCompletionList acList; 129 130 130 131 131 /** … … 141 141 // Initalizes ExtendedDialog 142 142 super(relation, selectedMembers); 143 acCache = AutoCompletionCache.getCacheForLayer(Main.map.mapView.getEditLayer()); 144 acList = new AutoCompletionList(); 143 145 144 146 JPanel bothTables = setupBasicLayout(selectedMembers); 147 if (relation != null) { 148 this.tagEditorModel.initFromPrimitive(relation); 149 } else { 150 tagEditorModel.clear(); 151 } 152 tagEditorModel.ensureOneTag(); 153 addWindowListener( 154 new WindowAdapter() { 155 protected void requestFocusInTopLeftCell() { 156 SwingUtilities.invokeLater(new Runnable(){ 157 public void run() 158 { 159 tagEditorModel.ensureOneTag(); 160 tagTable.requestFocusInCell(0, 0); 161 } 162 }); 163 } 164 @Override public void windowGainedFocus(WindowEvent e) { 165 requestFocusInTopLeftCell(); 166 } 167 @Override 168 public void windowActivated(WindowEvent e) { 169 requestFocusInTopLeftCell(); 170 } 171 @Override 172 public void windowDeiconified(WindowEvent e) { 173 requestFocusInTopLeftCell(); 174 } 175 @Override 176 public void windowOpened(WindowEvent e) { 177 requestFocusInTopLeftCell(); 178 } 179 } 180 ); 145 181 146 182 JTabbedPane tabPane = new JTabbedPane(); … … 165 201 */ 166 202 private JPanel setupBasicLayout(Collection<RelationMember> selectedMembers) { 167 // setting up the properties table 168 propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")}); 169 propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 170 propertyData.addTableModelListener(new TableModelListener() { 171 public void tableChanged(TableModelEvent tme) { 172 if (tme.getType() == TableModelEvent.UPDATE) { 173 int row = tme.getFirstRow(); 174 175 if (!(tme.getColumn() == 0 && row == propertyData.getRowCount() -1)) { 176 clone.entrySet().clear(); 177 for (int i = 0; i < propertyData.getRowCount(); i++) { 178 String key = propertyData.getValueAt(i, 0).toString(); 179 String value = propertyData.getValueAt(i, 1).toString(); 180 if (key.length() > 0 && value.length() > 0) { 181 clone.put(key, value); 182 } 183 } 184 refreshTables(); 185 } 186 } 187 } 188 }); 189 propertyTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); 203 // setting up the tag table 204 // 205 tagEditorModel = new TagEditorModel(); 206 tagTable = new TagTable(tagEditorModel); 207 acCache.initFromJOSMDataset(); 208 TagCellEditor editor = ((TagCellEditor)tagTable.getColumnModel().getColumn(0).getCellEditor()); 209 editor.setAutoCompletionCache(acCache); 210 editor.setAutoCompletionList(acList); 211 editor = ((TagCellEditor)tagTable.getColumnModel().getColumn(1).getCellEditor()); 212 editor.setAutoCompletionCache(acCache); 213 editor.setAutoCompletionList(acList); 214 190 215 191 216 // setting up the member table … … 198 223 if (tme.getType() == TableModelEvent.UPDATE && tme.getColumn() == 0) { 199 224 int row = tme.getFirstRow(); 200 clone.members.get(row).role = memberData.getValueAt(row, 0).toString();225 getClone().members.get(row).role = memberData.getValueAt(row, 0).toString(); 201 226 } 202 227 } … … 230 255 JPanel bothTables = new JPanel(); 231 256 bothTables.setLayout(new GridBagLayout()); 232 bothTables.add(new JLabel(tr("Tags (empty value deletes tag)")), GBC.eol().fill(GBC.HORIZONTAL)); 233 bothTables.add(new JScrollPane(propertyTable), GBC.eop().fill(GBC.BOTH)); 257 bothTables.add(new JLabel(tr("Tags")), GBC.eol().fill(GBC.HORIZONTAL)); 258 final JScrollPane scrollPane = new JScrollPane(tagTable); 259 260 // this adapters ensures that the width of the tag table columns is adjusted 261 // to the width of the scroll pane viewport. Also tried to overwrite 262 // getPreferredViewportSize() in JTable, but did not work. 263 // 264 scrollPane.addComponentListener( 265 new ComponentAdapter() { 266 @Override public void componentResized(ComponentEvent e) { 267 super.componentResized(e); 268 Dimension d = scrollPane.getViewport().getExtentSize(); 269 tagTable.adjustColumnWidth(d.width); 270 } 271 } 272 ); 273 bothTables.add(scrollPane, GBC.eop().fill(GBC.BOTH)); 234 274 bothTables.add(status = new JLabel(tr("Members")), GBC.eol().fill(GBC.HORIZONTAL)); 235 275 // this is not exactly pretty but the four buttons simply don't fit in one line. … … 310 350 mem.role = memberTable.getValueAt(row, 0).toString(); 311 351 mem.member = (OsmPrimitive) memberTable.getValueAt(row, 1); 312 clone.members.remove(mem);352 getClone().members.remove(mem); 313 353 } 314 354 refreshTables(); … … 337 377 // TODO: sort only selected rows 338 378 339 for (i = 1; i < clone.members.size(); ++i)379 for (i = 1; i < getClone().members.size(); ++i) 340 380 { 341 RelationMember m = clone.members.get(i);381 RelationMember m = getClone().members.get(i); 342 382 if (m.member.incomplete) 343 383 // TODO: emit some message that sorting failed … … 373 413 } 374 414 375 for (i = 0; i < clone.members.size(); ++i)415 for (i = 0; i < getClone().members.size(); ++i) 376 416 { 377 RelationMember m = clone.members.get(i);417 RelationMember m = getClone().members.get(i); 378 418 Integer m2 = null; 379 419 Node searchNode = null; … … 410 450 { 411 451 m2 = points.get(searchNode).first(); 412 if (m.member == clone.members.get(m2).member)452 if (m.member == getClone().members.get(m2).member) 413 453 { 414 454 m2 = points.get(searchNode).last(); … … 418 458 catch(java.util.NoSuchElementException e) {} 419 459 420 if ((m2 == null) && ((i+1) < clone.members.size()))460 if ((m2 == null) && ((i+1) < getClone().members.size())) 421 461 { 422 462 // TODO: emit some message that sorting failed … … 429 469 try 430 470 { 431 Way next = (Way) clone.members.get(m2).member;471 Way next = (Way)getClone().members.get(m2).member; 432 472 lastWayStartUsed = searchNode.equals(next.firstNode()); 433 473 } … … 436 476 } 437 477 438 if ((m2 < clone.members.size()) && ((i+1) < clone.members.size()))439 { 440 RelationMember a = clone.members.get(i+1);441 RelationMember b = clone.members.get(m2);478 if ((m2 < getClone().members.size()) && ((i+1) < getClone().members.size())) 479 { 480 RelationMember a = getClone().members.get(i+1); 481 RelationMember b = getClone().members.get(m2); 442 482 443 483 if (m2 != (i+1)) 444 484 { 445 clone.members.set(i+1, b);446 clone.members.set(m2, a);485 getClone().members.set(i+1, b); 486 getClone().members.set(m2, a); 447 487 448 488 try … … 499 539 */ 500 540 private void applyChanges() { 501 if ( GenericRelationEditor.this.relation== null) {541 if (getRelation()== null) { 502 542 // If the user wanted to create a new relation, but hasn't added any members or 503 543 // tags, don't add an empty relation 504 if( clone.members.size() == 0 && !clone.isTagged())544 if(getClone().members.size() == 0 && tagEditorModel.getKeys().isEmpty()) 505 545 return; 506 Main.main.undoRedo.add(new AddCommand(clone)); 546 tagEditorModel.applyToPrimitive(getClone()); 547 Main.main.undoRedo.add(new AddCommand(getClone())); 507 548 DataSet.fireSelectionChanged(Main.ds.getSelected()); 508 } else if (!GenericRelationEditor.this.relation.realEqual(clone, true)) { 509 Main.main.undoRedo.add(new ChangeCommand(GenericRelationEditor.this.relation, clone)); 549 } else if (getRelation().hasEqualSemanticAttributes(getClone())) { 550 tagEditorModel.applyToPrimitive(getClone()); 551 Main.main.undoRedo.add(new ChangeCommand(getRelation(), getClone())); 510 552 DataSet.fireSelectionChanged(Main.ds.getSelected()); 511 553 } … … 532 574 int numLinked = 0; 533 575 534 propertyData.setRowCount(0);535 for (Entry<String, String> e : clone.entrySet()) {536 propertyData.addRow(new Object[]{e.getKey(), e.getValue()});537 }538 propertyData.addRow(new Object[]{"", ""});539 540 576 // re-load membership data 541 577 542 578 memberData.setRowCount(0); 543 for (int i=0; i< clone.members.size(); i++) {579 for (int i=0; i<getClone().members.size(); i++) { 544 580 545 581 // this whole section is aimed at finding out whether the … … 550 586 // it should cache results, so... FIXME ;-) 551 587 552 RelationMember em = clone.members.get(i);588 RelationMember em = getClone().members.get(i); 553 589 WayConnectionType link = WayConnectionType.none; 554 590 RelationMember m = em; … … 562 598 break; 563 599 } else if (m.member instanceof Relation) { 564 if (m.member == this. relation) {600 if (m.member == this.getRelation()) { 565 601 break; 566 602 } … … 572 608 } 573 609 if (way1 != null) { 574 int next = (i+1) % clone.members.size();610 int next = (i+1) % getClone().members.size(); 575 611 while (next != i) { 576 m = clone.members.get(next);577 next = (next + 1) % clone.members.size();612 m = getClone().members.get(next); 613 next = (next + 1) % getClone().members.size(); 578 614 depth = 0; 579 615 while (m != null && depth < 10) { … … 582 618 break; 583 619 } else if (m.member instanceof Relation) { 584 if (m.member == this. relation) {620 if (m.member == this.getRelation()) { 585 621 break; 586 622 } … … 631 667 memberData.addRow(new Object[]{em.role, em.member, link}); 632 668 } 633 status.setText(tr("Members: {0} (linked: {1})", clone.members.size(), numLinked));669 status.setText(tr("Members: {0} (linked: {1})", getClone().members.size(), numLinked)); 634 670 } 635 671 … … 657 693 int[] rows = memberTable.getSelectedRows(); 658 694 if (rows.length > 0) { 659 clone.members.add(rows[0], em);695 getClone().members.add(rows[0], em); 660 696 } else { 661 clone.members.add(em);697 getClone().members.add(em); 662 698 } 663 699 } … … 667 703 private void deleteSelected() { 668 704 for (OsmPrimitive p : Main.ds.getSelected()) { 669 Relation c = new Relation( clone);705 Relation c = new Relation(getClone()); 670 706 for (RelationMember rm : c.members) { 671 707 if (rm.member == p) … … 674 710 mem.role = rm.role; 675 711 mem.member = rm.member; 676 clone.members.remove(mem);712 getClone().members.remove(mem); 677 713 } 678 714 } … … 687 723 // check if user attempted to move anything beyond the boundary of the list 688 724 if (rows[0] + direction < 0) return; 689 if (rows[rows.length-1] + direction >= clone.members.size()) return;690 691 RelationMember m[] = new RelationMember[ clone.members.size()];725 if (rows[rows.length-1] + direction >= getClone().members.size()) return; 726 727 RelationMember m[] = new RelationMember[getClone().members.size()]; 692 728 693 729 // first move all selected rows from the member list into a new array, 694 730 // displaced by the move amount 695 731 for (Integer i: rows) { 696 m[i+direction] = clone.members.get(i);697 clone.members.set(i, null);732 m[i+direction] = getClone().members.get(i); 733 getClone().members.set(i, null); 698 734 } 699 735 … … 701 737 // elements. 702 738 int i = 0; 703 for (RelationMember rm : clone.members) {739 for (RelationMember rm : getClone().members) { 704 740 if (rm != null) { 705 741 while (m[i] != null) { … … 711 747 712 748 // and write the array back into the member list. 713 clone.members.clear();714 clone.members.addAll(Arrays.asList(m));749 getClone().members.clear(); 750 getClone().members.addAll(Arrays.asList(m)); 715 751 refreshTables(); 716 752 ListSelectionModel lsm = memberTable.getSelectionModel(); … … 724 760 private void downloadRelationMembers() { 725 761 boolean download = false; 726 for (RelationMember member : clone.members) {762 for (RelationMember member : getClone().members) { 727 763 if (member.member.incomplete) { 728 764 download = true; … … 731 767 } 732 768 if (download) { 733 OsmServerObjectReader reader = new OsmServerObjectReader( clone.id, OsmPrimitiveType.RELATION, true);769 OsmServerObjectReader reader = new OsmServerObjectReader(getClone().id, OsmPrimitiveType.RELATION, true); 734 770 try { 735 771 DataSet dataSet = reader.parseOsm(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java
r1710 r1762 16 16 public abstract class RelationEditor extends ExtendedDialog { 17 17 18 /** keeps track of open relation editors */ 19 static private RelationDialogManager relationDialogManager; 20 21 /** 22 * Replies the singleton {@see RelationDialogManager} 23 * 24 * @return the singleton {@see RelationDialogManager} 25 */ 26 static public RelationDialogManager getRelationDialogManager() { 27 if (relationDialogManager == null) { 28 relationDialogManager = new RelationDialogManager(); 29 } 30 return relationDialogManager; 31 } 32 18 33 public static ArrayList<Class<RelationEditor>> editors = new ArrayList<Class<RelationEditor>>(); 19 34 … … 22 37 * editing. 23 38 */ 24 pr otectedRelation relation;25 pr otectedRelation clone;39 private Relation relation; 40 private Relation clone; 26 41 27 42 /** … … 57 72 } 58 73 } 59 return new GenericRelationEditor(r, selectedMembers); 74 if (getRelationDialogManager().isOpenInEditor(r)) 75 return getRelationDialogManager().getEditorForRelation(r); 76 else { 77 RelationEditor editor = new GenericRelationEditor(r, selectedMembers); 78 getRelationDialogManager().register(r, editor); 79 return editor; 80 } 60 81 } 61 82 … … 84 105 } 85 106 } 107 108 protected Relation getRelation() { 109 return relation; 110 } 111 112 protected Relation getClone() { 113 return clone; 114 } 86 115 }
Note:
See TracChangeset
for help on using the changeset viewer.