Changeset 1772 in josm
- Timestamp:
- 2009-07-12T13:11:06+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r1765 r1772 308 308 Relation relation = (Relation)membershipData.getValueAt(row, 0); 309 309 Main.main.map.relationListDialog.selectRelation(relation); 310 RelationEditor.getEditor(relation, 310 RelationEditor.getEditor( 311 Main.map.mapView.getEditLayer(), 312 relation, 311 313 (Collection<RelationMember>) membershipData.getValueAt(row, 1) ).setVisible(true); 312 314 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r1763 r1772 59 59 if (toEdit == null) 60 60 return; 61 RelationEditor.getEditor(toEdit, null).setVisible(true); 61 RelationEditor.getEditor(Main.map.mapView.getEditLayer(),toEdit, null).setVisible(true); 62 62 } 63 63 }); … … 94 94 public void actionPerformed(ActionEvent e) { 95 95 // call relation editor with null argument to create new relation 96 RelationEditor.getEditor(null, null).setVisible(true); 96 RelationEditor.getEditor(Main.map.mapView.getEditLayer(),null, null).setVisible(true); 97 97 } 98 98 }), GBC.std()); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1770 r1772 53 53 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionCache; 54 54 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionList; 55 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 55 56 import org.openstreetmap.josm.io.OsmApi; 56 57 import org.openstreetmap.josm.io.OsmServerObjectReader; … … 141 142 * @param relation relation to edit, or null to create a new one. 142 143 */ 143 public GenericRelationEditor(Relation relation, Collection<RelationMember> selectedMembers ) 144 public GenericRelationEditor(OsmDataLayer layer, Relation relation, Collection<RelationMember> selectedMembers ) 144 145 { 145 146 // Initalizes ExtendedDialog 146 super(relation, selectedMembers); 147 super(layer, relation, selectedMembers); 148 System.out.println("-- After super constructor"); 149 for (OsmPrimitive primitive : getLayer().data.allNonDeletedPrimitives()) { 150 System.out.println(OsmPrimitiveType.from(primitive) + " " + primitive.id + " incomplete=" + primitive.incomplete); 151 } 152 System.out.println("-------------"); 147 153 acCache = AutoCompletionCache.getCacheForLayer(Main.map.mapView.getEditLayer()); 148 154 acList = new AutoCompletionList(); … … 527 533 } 528 534 } 529 530 535 refreshTables(); 531 536 } … … 565 570 // FIXME: Make it remember dialog size 566 571 return new Dimension(600, 500); 572 } 573 574 /** 575 * Updates the references from members of the cloned relation (see {@see #getClone()) 576 * after an update from the server. 577 * 578 */ 579 protected void updateMemberReferencesInClone() { 580 DataSet ds = getLayer().data; 581 for (RelationMember member : getClone().members) { 582 if (member.member.id == 0) { 583 continue; 584 } 585 OsmPrimitive primitive = ds.getPrimitiveById(member.member.id); 586 if (primitive != null) { 587 StringBuffer sb = new StringBuffer(); 588 sb.append("updating primitive:") 589 .append("type=" + OsmPrimitiveType.from(primitive)) 590 .append(", id=" + primitive.id) 591 .append(", was incomplete=" + member.member.incomplete) 592 .append(", is incomplete=" + primitive.incomplete); 593 System.out.println(sb.toString()); 594 member.member = primitive; 595 } 596 } 567 597 } 568 598 … … 800 830 @Override 801 831 protected void finish() { 832 if (cancelled) return; 833 updateMemberReferencesInClone(); 802 834 refreshTables(); 803 if (cancelled) return;804 835 if (lastException == null) return; 805 836 showLastException(); … … 815 846 DataSet dataSet = reader.parseOsm(); 816 847 if (dataSet != null) { 817 final MergeVisitor visitor = new MergeVisitor(Main.main.map.mapView.getEditLayer() 818 .data, dataSet); 848 for (OsmPrimitive primitive : getLayer().data.allNonDeletedPrimitives()) { 849 System.out.println(OsmPrimitiveType.from(primitive) + " " + primitive.id + " incomplete=" + primitive.incomplete); 850 } 851 System.out.println("-------------"); 852 final MergeVisitor visitor = new MergeVisitor(getLayer().data, dataSet); 819 853 visitor.merge(); 854 for (OsmPrimitive primitive : getLayer().data.allNonDeletedPrimitives()) { 855 System.out.println(OsmPrimitiveType.from(primitive) + " " + primitive.id + " incomplete=" + primitive.incomplete); 856 } 820 857 821 858 // copy the merged layer's data source info 822 859 for (DataSource src : dataSet.dataSources) { 823 Main.map.mapView.getEditLayer().data.dataSources.add(src);824 } 825 Main.map.mapView.getEditLayer().fireDataChange();860 getLayer().data.dataSources.add(src); 861 } 862 getLayer().fireDataChange(); 826 863 827 864 if (visitor.getConflicts().isEmpty()) 828 865 return; 829 final ConflictDialog dlg = Main.map.conflictDialog; 830 dlg.getConflicts().add(visitor.getConflicts()); 866 getLayer().getConflicts().add(visitor.getConflicts()); 831 867 JOptionPane op = new JOptionPane( 832 868 tr("There were {0} conflicts during import.", … … 835 871 ); 836 872 JDialog dialog = op.createDialog(Main.pleaseWaitDlg, tr("Conflicts in data")); 837 dialog.setAlwaysOnTop(true); //<-- this line873 dialog.setAlwaysOnTop(true); 838 874 dialog.setModal(true); 839 875 dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java
r1762 r1772 5 5 import java.awt.event.WindowEvent; 6 6 import java.util.HashMap; 7 import java.util.Iterator; 8 import java.util.Map.Entry; 7 9 8 10 import org.openstreetmap.josm.data.osm.Relation; 11 import org.openstreetmap.josm.gui.layer.Layer; 12 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 13 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 9 14 10 15 /** … … 12 17 * 13 18 */ 14 public class RelationDialogManager extends WindowAdapter { 19 public class RelationDialogManager extends WindowAdapter implements LayerChangeListener { 20 static private class DialogContext { 21 public Relation relation; 22 public OsmDataLayer layer; 15 23 16 private HashMap<Relation, RelationEditor> openDialogs; 24 public DialogContext(OsmDataLayer layer, Relation relation) { 25 this.layer = layer; 26 this.relation = relation; 27 } 28 29 @Override 30 public int hashCode() { 31 final int prime = 31; 32 int result = 1; 33 result = prime * result + ((layer == null) ? 0 : layer.hashCode()); 34 result = prime * result + ((relation == null) ? 0 : relation.hashCode()); 35 return result; 36 } 37 @Override 38 public boolean equals(Object obj) { 39 if (this == obj) 40 return true; 41 if (obj == null) 42 return false; 43 if (getClass() != obj.getClass()) 44 return false; 45 DialogContext other = (DialogContext) obj; 46 if (layer == null) { 47 if (other.layer != null) 48 return false; 49 } else if (!layer.equals(other.layer)) 50 return false; 51 if (relation == null) { 52 if (other.relation != null) 53 return false; 54 } else if (!relation.equals(other.relation)) 55 return false; 56 return true; 57 } 58 59 public boolean matchesLayer(OsmDataLayer layer) { 60 if (layer == null) return false; 61 return this.layer.equals(layer); 62 } 63 } 64 65 private HashMap<DialogContext, RelationEditor> openDialogs; 17 66 18 67 public RelationDialogManager(){ 19 openDialogs = new HashMap< Relation, RelationEditor>();68 openDialogs = new HashMap<DialogContext, RelationEditor>(); 20 69 } 21 70 22 public void register(Relation relation, RelationEditor editor) { 23 openDialogs.put(relation, editor); 71 public void register(OsmDataLayer layer, Relation relation, RelationEditor editor) { 72 DialogContext context = new DialogContext(layer, relation); 73 openDialogs.put(context, editor); 24 74 editor.addWindowListener(this); 25 75 } 26 76 27 public boolean isOpenInEditor(Relation relation) { 28 return openDialogs.keySet().contains(relation); 77 public boolean isOpenInEditor(OsmDataLayer layer, Relation relation) { 78 DialogContext context = new DialogContext(layer, relation); 79 return openDialogs.keySet().contains(context); 29 80 } 30 81 31 public RelationEditor getEditorForRelation(Relation relation) { 32 return openDialogs.get(relation); 82 public RelationEditor getEditorForRelation(OsmDataLayer layer, Relation relation) { 83 DialogContext context = new DialogContext(layer, relation); 84 return openDialogs.get(context); 33 85 } 34 86 … … 36 88 public void windowClosed(WindowEvent e) { 37 89 RelationEditor editor = ((RelationEditor)e.getWindow()); 38 Relation editedRelation= null;39 for ( Relation r: openDialogs.keySet()) {40 if (openDialogs.get( r).equals(editor)) {41 editedRelation = r;90 DialogContext context = null; 91 for (DialogContext c : openDialogs.keySet()) { 92 if (openDialogs.get(c).equals(editor)) { 93 context = c; 42 94 break; 43 95 } 44 96 } 45 if ( editedRelation!= null) {46 openDialogs.remove( editedRelation);97 if (context != null) { 98 openDialogs.remove(context); 47 99 } 48 100 } 101 102 public void layerRemoved(Layer oldLayer) { 103 if (oldLayer == null || ! (oldLayer instanceof OsmDataLayer)) 104 return; 105 OsmDataLayer dataLayer = (OsmDataLayer)oldLayer; 106 107 Iterator<Entry<DialogContext,RelationEditor>> it = openDialogs.entrySet().iterator(); 108 while(it.hasNext()) { 109 Entry<DialogContext,RelationEditor> entry = it.next(); 110 if (entry.getKey().matchesLayer(dataLayer)) { 111 RelationEditor editor = entry.getValue(); 112 it.remove(); 113 editor.setVisible(false); 114 editor.dispose(); 115 } 116 } 117 } 118 119 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 120 // do nothing 121 } 122 123 public void layerAdded(Layer newLayer) { 124 // do nothing 125 } 49 126 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java
r1762 r1772 10 10 11 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 12 14 import org.openstreetmap.josm.data.osm.Relation; 13 15 import org.openstreetmap.josm.data.osm.RelationMember; 14 16 import org.openstreetmap.josm.gui.ExtendedDialog; 17 import org.openstreetmap.josm.gui.layer.Layer; 18 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 15 19 16 20 public abstract class RelationEditor extends ExtendedDialog { … … 27 31 if (relationDialogManager == null) { 28 32 relationDialogManager = new RelationDialogManager(); 33 Layer.listeners.add(relationDialogManager); 29 34 } 30 35 return relationDialogManager; … … 39 44 private Relation relation; 40 45 private Relation clone; 46 47 /** the data layer the relation belongs to */ 48 private OsmDataLayer layer; 41 49 42 50 /** … … 58 66 * @return an instance of RelationEditor suitable for editing that kind of relation 59 67 */ 60 public static RelationEditor getEditor(Relation r, Collection<RelationMember> selectedMembers) { 68 public static RelationEditor getEditor(OsmDataLayer layer, Relation r, Collection<RelationMember> selectedMembers) { 61 69 for (Class<RelationEditor> e : editors) { 62 70 try { … … 65 73 if (canEdit) { 66 74 Constructor<RelationEditor> con = e.getConstructor(Relation.class, Collection.class); 67 RelationEditor editor = con.newInstance(r, selectedMembers); 75 RelationEditor editor = con.newInstance(layer, r, selectedMembers); 68 76 return editor; 69 77 } … … 72 80 } 73 81 } 74 if (getRelationDialogManager().isOpenInEditor(r)) 75 return getRelationDialogManager().getEditorForRelation(r); 82 if (getRelationDialogManager().isOpenInEditor(layer, r)) 83 return getRelationDialogManager().getEditorForRelation(layer, r); 76 84 else { 77 RelationEditor editor = new GenericRelationEditor(r, selectedMembers); 78 getRelationDialogManager().register(r, editor); 85 RelationEditor editor = new GenericRelationEditor(layer, r, selectedMembers); 86 getRelationDialogManager().register(layer, r, editor); 79 87 return editor; 80 88 } 81 89 } 82 90 83 protected RelationEditor(Relation relation, Collection<RelationMember> selectedMembers) 91 protected RelationEditor(OsmDataLayer layer, Relation relation, Collection<RelationMember> selectedMembers) 84 92 { 85 93 // Initalizes ExtendedDialog 86 94 super(Main.parent, 87 95 relation == null 88 ? tr("Create new relation ")96 ? tr("Create new relation in layer ''{0}''", layer.getName()) 89 97 : (relation.id == 0 90 ? tr ("Edit new relation ")91 : tr("Edit relation #{0}", relation.id) 98 ? tr ("Edit new relation in layer ''{0}''", layer.getName()) 99 : tr("Edit relation #{0} in layer ''{1}''", relation.id, layer.getName()) 92 100 ), 93 101 new String[] { tr("Apply Changes"), tr("Cancel")}, 94 102 false 95 103 ); 104 System.out.println("-- in super constructor"); 105 for (OsmPrimitive primitive : layer.data.allNonDeletedPrimitives()) { 106 System.out.println(OsmPrimitiveType.from(primitive) + " " + primitive.id + " incomplete=" + primitive.incomplete); 107 } 108 System.out.println("-------------"); 109 96 110 97 111 this.relation = relation; 112 this.layer = layer; 98 113 99 114 if (relation == null) { … … 113 128 return clone; 114 129 } 130 131 protected OsmDataLayer getLayer() { 132 return layer; 133 } 115 134 } -
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r1646 r1772 123 123 public File getAssociatedFile() { return associatedFile; } 124 124 public void setAssociatedFile(File file) { associatedFile = file; } 125 126 127 /** 128 * Replies the name of the layer 129 * 130 * @return the name of the layer 131 */ 132 public String getName() { 133 return name; 134 } 125 135 } -
trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r1670 r1772 101 101 return null; 102 102 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 103 final DataSet data = OsmReader.parseDataSet(in, null,Main.pleaseWaitDlg);103 final DataSet data = OsmReader.parseDataSet(in,Main.pleaseWaitDlg); 104 104 in.close(); 105 105 activeConnection = null; -
trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java
r1690 r1772 319 319 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 320 320 try { 321 final OsmReader osm = OsmReader.parseDataSetOsm(in, outputDataSet,Main.pleaseWaitDlg);321 final OsmReader osm = OsmReader.parseDataSetOsm(in, Main.pleaseWaitDlg); 322 322 skippedWayIds.addAll(osm.getSkippedWayIds()); 323 323 merge(osm.getDs()); … … 345 345 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 346 346 try { 347 final OsmReader osm = OsmReader.parseDataSetOsm(in, null,Main.pleaseWaitDlg);347 final OsmReader osm = OsmReader.parseDataSetOsm(in,Main.pleaseWaitDlg); 348 348 skippedWayIds.addAll(osm.getSkippedWayIds()); 349 349 merge(osm.getDs()); -
trunk/src/org/openstreetmap/josm/io/OsmImporter.java
r1696 r1772 46 46 47 47 protected void importData(InputStream in, File associatedFile) throws SAXException, IOException { 48 OsmReader osm = OsmReader.parseDataSetOsm(in, null,Main.pleaseWaitDlg);48 OsmReader osm = OsmReader.parseDataSetOsm(in,Main.pleaseWaitDlg); 49 49 DataSet dataSet = osm.getDs(); 50 50 OsmDataLayer layer = new OsmDataLayer(dataSet, associatedFile.getName(), associatedFile); … … 55 55 String notes = osm.getParseNotes(); 56 56 int j = 0; 57 for (int i = 0; i < 5; i++) 57 for (int i = 0; i < 5; i++) { 58 58 j = notes.indexOf('\n', j + 1); 59 } 59 60 j = j >= 0 ? j : notes.length(); 60 61 JOptionPane.showMessageDialog(Main.parent, notes.substring(0, j)); -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r1690 r1772 52 52 53 53 /** 54 * This is used as (readonly) source for finding missing references when not transferred in the55 * file.56 */57 private DataSet references;58 59 /**60 54 * The dataset to add parsed objects to. 61 55 */ … … 88 82 private Map<Long, Node> nodes = new HashMap<Long, Node>(); 89 83 84 85 /** 86 * constructor (for private use only) 87 * 88 * @see #parseDataSet(InputStream, DataSet, PleaseWaitDialog) 89 * @see #parseDataSetOsm(InputStream, DataSet, PleaseWaitDialog) 90 */ 91 private OsmReader() { 92 } 90 93 91 94 private static class OsmPrimitiveData { … … 342 345 if (n != null) 343 346 return n; 344 for (Node node : references.nodes)345 if (node.id == id)346 return node;347 // TODO: This has to be changed to support multiple layers.348 for (Node node : Main.ds.nodes)349 if (node.id == id)350 return new Node(node);351 347 return null; 352 348 } … … 382 378 /** 383 379 * Return the Way object with the given id, or null if it doesn't 384 * exist yet. This method only looks at ways stored in the data set. 380 * exist yet. This method only looks at ways stored in the already parsed 381 * ways. 385 382 * 386 383 * @param id … … 388 385 */ 389 386 private Way findWay(long id) { 390 for (Way w y : Main.ds.ways)391 if (wy.id == id) 392 return wy; 387 for (Way way : ds.ways) 388 if (way.id == id) 389 return way; 393 390 return null; 394 391 } … … 396 393 /** 397 394 * Return the Relation object with the given id, or null if it doesn't 398 * exist yet. This method only looks at relations stored in the data set. 395 * exist yet. This method only looks at relations in the already parsed 396 * relations. 399 397 * 400 398 * @param id … … 403 401 private Relation findRelation(long id) { 404 402 for (Relation e : ds.relations) 405 if (e.id == id)406 return e;407 for (Relation e : Main.ds.relations)408 403 if (e.id == id) 409 404 return e; … … 476 471 * element found there is returned. 477 472 */ 478 public static DataSet parseDataSet(InputStream source, DataSet ref,PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException {479 return parseDataSetOsm(source, ref,pleaseWaitDlg).ds;480 } 481 482 public static OsmReader parseDataSetOsm(InputStream source, DataSet ref,PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException {473 public static DataSet parseDataSet(InputStream source, PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException { 474 return parseDataSetOsm(source, pleaseWaitDlg).ds; 475 } 476 477 public static OsmReader parseDataSetOsm(InputStream source,PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException { 483 478 OsmReader osm = new OsmReader(); 484 osm.references = ref == null ? new DataSet() : ref;485 479 486 480 // phase 1: Parse nodes and read in raw ways -
trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
r1670 r1772 32 32 return null; 33 33 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 34 final DataSet data = OsmReader.parseDataSet(in, null,Main.pleaseWaitDlg);34 final DataSet data = OsmReader.parseDataSet(in, Main.pleaseWaitDlg); 35 35 in.close(); 36 36 activeConnection = null; -
trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java
r1670 r1772 48 48 return null; 49 49 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 50 final OsmReader osm = OsmReader.parseDataSetOsm(in, null,Main.pleaseWaitDlg);50 final OsmReader osm = OsmReader.parseDataSetOsm(in,Main.pleaseWaitDlg); 51 51 final DataSet data = osm.getDs(); 52 52
Note:
See TracChangeset
for help on using the changeset viewer.