- Timestamp:
- 2008-12-11T23:52:36+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationEditor.java
r999 r1113 14 14 import java.beans.PropertyChangeListener; 15 15 import java.io.IOException; 16 import java.lang.reflect.Array; 16 17 import java.text.Collator; 17 18 import java.util.ArrayList; 19 import java.util.Arrays; 18 20 import java.util.Collection; 19 21 import java.util.Collections; … … 21 23 import java.util.Map.Entry; 22 24 25 import javax.swing.BoxLayout; 23 26 import javax.swing.JButton; 24 27 import javax.swing.JFrame; … … 70 73 private JLabel status; 71 74 75 /** 76 * True if the relation is ordered (API 0.6). False for API 0.5. 77 */ 78 boolean ordered; 79 72 80 /** 73 81 * The property data. … … 100 108 private final JTable memberTable = new JTable(memberData); 101 109 110 // =================== FIXME FIXME FIXME ===================== 111 // As soon as API 0.5 is dead, drop all the collation stuff from here ... 112 102 113 /** 103 114 * Collator for sorting the roles and entries of the member table. … … 164 175 }; 165 176 177 // =================== FIXME FIXME FIXME ===================== 178 // ... until here, and also get rid of the "Collections.sort..." below. 179 166 180 /** 167 181 * Creates a new relation editor for the given relation. The relation … … 192 206 this.relation = relation; 193 207 208 ordered = Main.pref.get("osm-server.version", "0.5").equals("0.6"); 209 194 210 if (relation == null) { 195 211 // create a new relation … … 198 214 // edit an existing relation 199 215 this.clone = new Relation(relation); 200 Collections.sort(this.clone.members, memberComparator);216 if (!ordered) Collections.sort(this.clone.members, memberComparator); 201 217 } 202 218 … … 278 294 memberTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); 279 295 280 281 296 // combine both tables and wrap them in a scrollPane 282 297 JPanel bothTables = new JPanel(); … … 285 300 bothTables.add(new JScrollPane(propertyTable), GBC.eop().fill(GBC.BOTH)); 286 301 bothTables.add(status = new JLabel(tr("Members")), GBC.eol().fill(GBC.HORIZONTAL)); 287 bothTables.add(new JScrollPane(memberTable), GBC.eol().fill(GBC.BOTH)); 288 302 if (ordered) { 303 JPanel upDownPanel = new JPanel(); 304 upDownPanel.setLayout(new BoxLayout(upDownPanel, BoxLayout.Y_AXIS)); 305 306 307 308 upDownPanel.add(createButton(null, "moveup", tr("Move the currently selected member(s) up"), 309 KeyEvent.VK_U, new ActionListener() { 310 public void actionPerformed(ActionEvent e) { 311 moveMembers(-1); 312 } 313 })); 314 upDownPanel.add(createButton(null, "movedown", tr("Move the currently selected member(s) down"), 315 KeyEvent.VK_N, new ActionListener() { 316 public void actionPerformed(ActionEvent e) { 317 moveMembers(1); 318 } 319 })); 320 321 322 bothTables.add(new JScrollPane(memberTable), GBC.std().fill(GBC.BOTH)); 323 bothTables.add(upDownPanel, GBC.eol().fill(GBC.VERTICAL)); 324 } else { 325 bothTables.add(new JScrollPane(memberTable), GBC.eol().fill(GBC.BOTH)); 326 } 327 289 328 JPanel buttonPanel = new JPanel(new GridLayout(1,3)); 290 329 … … 297 336 298 337 buttonPanel.add(createButton(marktr("Delete Selected"),"deleteselected", 299 tr("Delete all currently selected objects from rel eation"), KeyEvent.VK_R, new ActionListener() {338 tr("Delete all currently selected objects from relation"), KeyEvent.VK_R, new ActionListener() { 300 339 public void actionPerformed(ActionEvent e) { 301 340 deleteSelected(); … … 406 445 for (OsmPrimitive p : Main.ds.getSelected()) { 407 446 boolean skip = false; 408 for (RelationMember rm : clone.members) { 409 if (rm.member == p || p == relation) 410 { 411 skip = true; 412 break; 413 } 414 } 415 if(!skip) 447 // ordered relations may have the same member multiple times. 448 // TODO: visual indication of the fact that one is there more than once? 449 if (!ordered) 450 { 451 for (RelationMember rm : clone.members) { 452 if (rm.member == p || p == relation) 453 { 454 skip = true; 455 break; 456 } 457 } 458 } 459 if (!skip) 416 460 { 417 461 RelationMember em = new RelationMember(); 418 462 em.member = p; 419 463 em.role = ""; 420 clone.members.add(em); 464 // when working with ordered relations, we make an effort to 465 // add the element before the first selected member. 466 int[] rows = memberTable.getSelectedRows(); 467 if (ordered && rows.length > 0) { 468 clone.members.add(rows[0], em); 469 } else { 470 clone.members.add(em); 471 } 421 472 } 422 473 } … … 438 489 } 439 490 refreshTables(); 491 } 492 493 private void moveMembers(int direction) { 494 int[] rows = memberTable.getSelectedRows(); 495 if (rows.length == 0) return; 496 497 // check if user attempted to move anything beyond the boundary of the list 498 if (rows[0] + direction < 0) return; 499 if (rows[rows.length-1] + direction >= clone.members.size()) return; 500 501 RelationMember m[] = new RelationMember[clone.members.size()]; 502 503 // first move all selected rows from the member list into a new array, 504 // displaced by the move amount 505 for (Integer i: rows) { 506 m[i+direction] = clone.members.get(i); 507 clone.members.set(i, null); 508 } 509 510 // now fill the empty spots in the destination array with the remaining 511 // elements. 512 int i = 0; 513 for (RelationMember rm : clone.members) { 514 if (rm != null) { 515 while (m[i] != null) i++; 516 m[i++] = rm; 517 } 518 } 519 520 // and write the array back into the member list. 521 clone.members.clear(); 522 clone.members.addAll(Arrays.asList(m)); 523 refreshTables(); 524 ListSelectionModel lsm = memberTable.getSelectionModel(); 525 lsm.setValueIsAdjusting(true); 526 for (Integer j: rows) { 527 lsm.addSelectionInterval(j + direction, j + direction); 528 } 529 lsm.setValueIsAdjusting(false); 440 530 } 441 531
Note:
See TracChangeset
for help on using the changeset viewer.