Changeset 1927 in josm
- Timestamp:
- 2009-08-08T10:53:46+02:00 (15 years ago)
- Location:
- trunk
- Files:
-
- 7 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1925 r1927 334 334 editor.setAutoCompletionList(acList); 335 335 336 SelectionSynchronizer synchronizer = new SelectionSynchronizer();337 memberTable.getSelectionModel().addListSelectionListener(synchronizer);338 DataSet.selListeners.add(synchronizer);339 336 memberTable.addMouseListener(new MemberTableDblClickAdapter()); 340 337 memberTableModel.addMemberModelListener(memberTable); … … 489 486 gc.weightx = 0.0; 490 487 gc.weighty = 0.0; 488 489 // ----- 490 gc.gridy = 0; 491 491 MoveUpAction moveUpAction = new MoveUpAction(); 492 492 memberTableModel.getSelectionModel().addListSelectionListener(moveUpAction); … … 511 511 pnl.add(new JButton(removeSelectedAction), gc); 512 512 513 513 514 // ------ 514 515 gc.gridy = 4; 516 SelectPrimitivesForSelectedMembersAction selectAction = new SelectPrimitivesForSelectedMembersAction(); 517 memberTable.getSelectionModel().addListSelectionListener(selectAction); 518 pnl.add(new JButton(selectAction), gc); 519 520 // ------ 521 gc.gridy = 5; 515 522 SortAction sortAction = new SortAction(); 516 523 pnl.add(new JButton(sortAction), gc); … … 518 525 // ------ 519 526 // just grab the remaining space 520 gc.gridy = 5;527 gc.gridy = 6; 521 528 gc.weighty = 1.0; 522 529 gc.fill = GridBagConstraints.BOTH; … … 550 557 // ----- 551 558 gc.gridy = 1; 559 SelectedMembersForSelectionAction selectMembersForSelectionAction = new SelectedMembersForSelectionAction(); 560 selectionTableModel.addTableModelListener(selectMembersForSelectionAction); 561 memberTableModel.addTableModelListener(selectMembersForSelectionAction); 562 pnl.add(new JButton(selectMembersForSelectionAction), gc); 563 564 // ----- 565 gc.gridy = 2; 552 566 RemoveSelectedAction removeSelectedAction = new RemoveSelectedAction(); 553 567 selectionTableModel.addTableModelListener(removeSelectedAction); … … 556 570 // ------ 557 571 // just grab the remaining space 558 gc.gridy = 2;572 gc.gridy = 3; 559 573 gc.weighty = 1.0; 560 574 gc.fill = GridBagConstraints.BOTH; … … 562 576 563 577 // ----- 564 gc.gridy = 3;578 gc.gridy = 4; 565 579 gc.weighty = 0.0; 566 580 AddSelectedAtStartAction addSelectionAction = new AddSelectedAtStartAction(); … … 569 583 570 584 // ----- 571 gc.gridy = 4;585 gc.gridy = 5; 572 586 AddSelectedBeforeSelection addSelectedBeforeSelectionAction = new AddSelectedBeforeSelection(); 573 587 selectionTableModel.addTableModelListener(addSelectedBeforeSelectionAction); … … 576 590 577 591 // ----- 578 gc.gridy = 5;592 gc.gridy = 6; 579 593 AddSelectedAfterSelection addSelectedAfterSelectionAction = new AddSelectedAfterSelection(); 580 594 selectionTableModel.addTableModelListener(addSelectedAfterSelectionAction); … … 887 901 public RemoveSelectedAction() { 888 902 putValue(SHORT_DESCRIPTION, tr("Remove all members referring to one of the selected primitives")); 889 putValue(SMALL_ICON, ImageProvider.get("dialogs ", "removeselected"));903 putValue(SMALL_ICON, ImageProvider.get("dialogs/relation", "deletemembers")); 890 904 // putValue(NAME, tr("Remove Selected")); 891 905 Shortcut.registerShortcut("relationeditor:removeselected", tr("Relation Editor: Remove Selected"), … … 912 926 913 927 public void tableChanged(TableModelEvent e) { 928 updateEnabledState(); 929 } 930 } 931 932 /** 933 * Selects members in the relation editor which refer to primitives in the current 934 * selection of the context layer. 935 * 936 */ 937 class SelectedMembersForSelectionAction extends AbstractAction implements TableModelListener { 938 public SelectedMembersForSelectionAction() { 939 putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to primitives in the current selection")); 940 putValue(SMALL_ICON, ImageProvider.get("dialogs/relation", "selectmembers")); 941 updateEnabledState(); 942 } 943 944 protected void updateEnabledState() { 945 boolean enabled = selectionTableModel.getRowCount() > 0 946 && !memberTableModel.getChildPrimitives(getLayer().data.getSelected()).isEmpty(); 947 948 if (enabled) { 949 putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to {0} primitives in the current selection",memberTableModel.getChildPrimitives(getLayer().data.getSelected()).size())); 950 } else { 951 putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to primitives in the current selection")); 952 } 953 setEnabled(enabled); 954 } 955 956 public void actionPerformed(ActionEvent e) { 957 memberTableModel.selectMembersReferringTo(getLayer().data.getSelected()); 958 } 959 960 public void tableChanged(TableModelEvent e) { 961 updateEnabledState(); 962 963 } 964 } 965 966 /** 967 * Selects primitives in the layer this editor belongs to. The selected primitives are 968 * equal to the set of primitives the currently selected relation members refer to. 969 * 970 */ 971 class SelectPrimitivesForSelectedMembersAction extends AbstractAction implements ListSelectionListener { 972 public SelectPrimitivesForSelectedMembersAction() { 973 putValue(SHORT_DESCRIPTION, tr("Select primitives for selected relation members")); 974 putValue(SMALL_ICON, ImageProvider.get("dialogs/relation", "selectprimitives")); 975 updateEnabledState(); 976 } 977 978 protected void updateEnabledState() { 979 setEnabled(memberTable.getSelectedRowCount() > 0); 980 } 981 982 public void actionPerformed(ActionEvent e) { 983 getLayer().data.setSelected(memberTableModel.getSelectedChildPrimitives()); 984 DataSet.fireSelectionChanged(getLayer().data.getSelected()); 985 } 986 987 public void valueChanged(ListSelectionEvent e) { 914 988 updateEnabledState(); 915 989 } … … 1444 1518 if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { 1445 1519 new EditAction().run(); 1446 }1447 }1448 }1449 1450 /**1451 * Updates the selection in the current data set with the selected referers in1452 * in the member table.1453 */1454 class SelectionSynchronizer implements ListSelectionListener, SelectionChangedListener{1455 public void valueChanged(ListSelectionEvent e) {1456 // as long as the model is computing the final selection it emits selection1457 // change events with getValueIsAdjusting() true. Ignore these events, only1458 // handle the final selection update. Otherwise, infinite loops of property1459 // change events occur.1460 //1461 if (e.getValueIsAdjusting())1462 return;1463 1464 // Avoid infinite loop. Only update the selection if it is not in sync with what1465 // is already selected. Avoids infinite loops of property change events.1466 //1467 if (!memberTableModel.selectionsAreInSync()) {1468 getLayer().data.setSelected(memberTableModel.getSelectedReferers());1469 }1470 }1471 1472 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {1473 // ignore selection change events if they happen for a dataset in another1474 // layer1475 if (!memberTableModel.isActiveLayer()) return;1476 if (!memberTableModel.selectionsAreInSync()) {1477 memberTableModel.selectMembersReferringTo(newSelection);1478 1520 } 1479 1521 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r1926 r1927 376 376 * @return the set of selected referers 377 377 */ 378 public Set<OsmPrimitive> getSelected Referers() {378 public Set<OsmPrimitive> getSelectedChildPrimitives() { 379 379 HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>(); 380 380 for (RelationMember m: getSelectedMembers()) { … … 385 385 386 386 /** 387 * Replies the set of selected referers. Never null, but may be empty. 388 * 389 * @return the set of selected referers 390 */ 391 public Set<OsmPrimitive> getChildPrimitives(Collection<? extends OsmPrimitive> referenceSet) { 392 HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>(); 393 if (referenceSet == null) return null; 394 for (RelationMember m: members) { 395 if (referenceSet.contains(m.member)) { 396 ret.add(m.member); 397 } 398 } 399 return ret; 400 } 401 402 403 /** 387 404 * Replies true, if the selected {@see OsmPrimitive}s in the layer belonging 388 405 * to this model are in sync with the selected referers in this model. … … 391 408 */ 392 409 public boolean selectionsAreInSync() { 393 HashSet<OsmPrimitive> s1 = new HashSet<OsmPrimitive>(getSelected Referers());410 HashSet<OsmPrimitive> s1 = new HashSet<OsmPrimitive>(getSelectedChildPrimitives()); 394 411 if (s1.size() != layer.data.getSelected().size()) return false; 395 412 s1.removeAll(layer.data.getSelected());
Note:
See TracChangeset
for help on using the changeset viewer.