Changeset 1599 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-05-19T00:16:01+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/dialogs
- Files:
-
- 2 added
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r1446 r1599 63 63 import org.openstreetmap.josm.gui.MapFrame; 64 64 import org.openstreetmap.josm.gui.SideButton; 65 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 66 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 65 67 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference; 66 68 import org.openstreetmap.josm.gui.tagging.TaggingPreset; … … 294 296 */ 295 297 void membershipEdit(int row) { 296 final RelationEditor editor = new RelationEditor((Relation)membershipData.getValueAt(row, 0), 297 (Collection<RelationMember>) membershipData.getValueAt(row, 1) ); 298 editor.setVisible(true); 298 RelationEditor.getEditor((Relation)membershipData.getValueAt(row, 0), 299 (Collection<RelationMember>) membershipData.getValueAt(row, 1) ).setVisible(true); 299 300 } 300 301 -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r1554 r1599 27 27 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 28 28 import org.openstreetmap.josm.gui.SideButton; 29 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 29 30 import org.openstreetmap.josm.gui.layer.DataChangeListener; 30 31 import org.openstreetmap.josm.gui.layer.Layer; … … 40 41 * We don't have such dialogs for nodes, segments, and ways, because those 41 42 * objects are visible on the map and can be selected there. Relations are not. 42 *43 * @author Frederik Ramm <frederik@remote.org>44 43 */ 45 44 public class RelationListDialog extends ToggleDialog implements LayerChangeListener, DataChangeListener { … … 60 59 if (toEdit == null) 61 60 return; 62 63 new RelationEditor(toEdit).setVisible(true); 61 RelationEditor.getEditor(toEdit, null).setVisible(true); 64 62 } 65 63 }); … … 95 93 public void actionPerformed(ActionEvent e) { 96 94 // call relation editor with null argument to create new relation 97 new RelationEditor(null).setVisible(true);95 RelationEditor.getEditor(null, null).setVisible(true); 98 96 } 99 97 }), GBC.std()); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1566 r1599 1 package org.openstreetmap.josm.gui.dialogs ;1 package org.openstreetmap.josm.gui.dialogs.relation; 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.marktr; … … 11 11 import java.awt.event.KeyEvent; 12 12 import java.io.IOException; 13 import java.text.Collator;14 13 import java.util.ArrayList; 15 14 import java.util.Arrays; 16 15 import java.util.Collection; 17 import java.util.Collections;18 import java.util.Comparator;19 16 import java.util.Map.Entry; 20 17 … … 37 34 import org.openstreetmap.josm.data.osm.DataSet; 38 35 import org.openstreetmap.josm.data.osm.DataSource; 36 import org.openstreetmap.josm.data.osm.Node; 39 37 import org.openstreetmap.josm.data.osm.OsmPrimitive; 40 38 import org.openstreetmap.josm.data.osm.Relation; 41 39 import org.openstreetmap.josm.data.osm.RelationMember; 40 import org.openstreetmap.josm.data.osm.Way; 42 41 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 43 import org.openstreetmap.josm.gui.ExtendedDialog;44 42 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 45 43 import org.openstreetmap.josm.gui.SideButton; 44 import org.openstreetmap.josm.gui.dialogs.ConflictDialog; 46 45 import org.openstreetmap.josm.io.OsmServerObjectReader; 47 46 import org.openstreetmap.josm.tools.GBC; … … 60 59 * 61 60 */ 62 public class RelationEditor extends ExtendedDialog { 63 64 /** 65 * The relation that this editor is working on, and the clone made for 66 * editing. 67 */ 68 private final Relation relation; 69 private final Relation clone; 61 public class GenericRelationEditor extends RelationEditor { 62 70 63 private JLabel status; 71 64 … … 111 104 * @param relation relation to edit, or null to create a new one. 112 105 */ 113 public RelationEditor(Relation relation) 114 { 115 this(relation, null); 116 } 117 118 /** 119 * Creates a new relation editor for the given relation. The relation 120 * will be saved if the user selects "ok" in the editor. 121 * 122 * If no relation is given, will create an editor for a new relation. 123 * 124 * @param relation relation to edit, or null to create a new one. 125 */ 126 public RelationEditor(Relation relation, Collection<RelationMember> selectedMembers ) 106 public GenericRelationEditor(Relation relation, Collection<RelationMember> selectedMembers ) 127 107 { 128 108 // Initalizes ExtendedDialog 129 super(Main.parent, 130 relation == null 131 ? tr("Create new relation") 132 : (relation.id == 0 133 ? tr ("Edit new relation") 134 : tr("Edit relation #{0}", relation.id) 135 ), 136 new String[] { applyChangesText, tr("Cancel")}, 137 false 138 ); 139 140 this.relation = relation; 141 142 if (relation == null) { 143 // create a new relation 144 this.clone = new Relation(); 145 } else { 146 // edit an existing relation 147 this.clone = new Relation(relation); 148 } 109 super(relation, selectedMembers); 149 110 150 111 JPanel bothTables = setupBasicLayout(selectedMembers); … … 195 156 // setting up the member table 196 157 197 memberData.setColumnIdentifiers(new String[]{tr("Role"),tr("Occupied By") });158 memberData.setColumnIdentifiers(new String[]{tr("Role"),tr("Occupied By"), tr("linked")}); 198 159 memberTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 199 160 memberTable.getColumnModel().getColumn(1).setCellRenderer(new OsmPrimitivRenderer()); … … 326 287 */ 327 288 private void applyChanges() { 328 if ( RelationEditor.this.relation == null) {289 if (GenericRelationEditor.this.relation == null) { 329 290 // If the user wanted to create a new relation, but hasn't added any members or 330 291 // tags, don't add an empty relation … … 333 294 Main.main.undoRedo.add(new AddCommand(clone)); 334 295 DataSet.fireSelectionChanged(Main.ds.getSelected()); 335 } else if (! RelationEditor.this.relation.realEqual(clone, true)) {336 Main.main.undoRedo.add(new ChangeCommand( RelationEditor.this.relation, clone));296 } else if (!GenericRelationEditor.this.relation.realEqual(clone, true)) { 297 Main.main.undoRedo.add(new ChangeCommand(GenericRelationEditor.this.relation, clone)); 337 298 DataSet.fireSelectionChanged(Main.ds.getSelected()); 338 299 } … … 366 327 367 328 memberData.setRowCount(0); 368 for (RelationMember em : clone.members) { 369 memberData.addRow(new Object[]{em.role, em.member}); 329 for (int i=0; i<clone.members.size(); i++) { 330 331 // this whole section is aimed at finding out whether the 332 // relation member is "linked" with the next, i.e. whether 333 // (if both are ways) these ways are connected. It should 334 // really produce a much more beautiful output (with a linkage 335 // symbol somehow places betweeen the two member lines!), and 336 // it should cache results, so... FIXME ;-) 337 338 RelationMember em = clone.members.get(i); 339 boolean linked = false; 340 Node n1 = null; 341 Node n2 = null; 342 RelationMember m = em; 343 while (m != null) { 344 if (m.member instanceof Way) { 345 n1 = ((Way) m.member).lastNode(); 346 break; 347 } else if (em.member instanceof Relation) { 348 m = ((Relation)m.member).lastMember(); 349 } else { 350 break; 351 } 352 } 353 if (i<clone.members.size()-1) { 354 m = clone.members.get(i+1); 355 while (m != null) { 356 if (m.member instanceof Way) { 357 n2 = ((Way) (m.member)).firstNode(); 358 break; 359 } else if (em.member instanceof Relation) { 360 m = ((Relation)(m.member)).firstMember(); 361 } else { 362 break; 363 } 364 } 365 } 366 linked = (n1 != null) && n1.equals(n2); 367 368 // end of section to determine linkedness. 369 370 memberData.addRow(new Object[]{em.role, em.member, linked ? tr("yes") : tr("no")}); 370 371 } 371 372 status.setText(tr("Members: {0}", clone.members.size()));
Note:
See TracChangeset
for help on using the changeset viewer.