Changeset 5793 in josm
- Timestamp:
- 2013-03-22T19:53:11+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r5744 r5793 31 31 import javax.swing.JMenuItem; 32 32 import javax.swing.JPanel; 33 import javax.swing.JPopupMenu; 33 34 import javax.swing.JScrollPane; 34 35 import javax.swing.JTextField; … … 44 45 45 46 import org.openstreetmap.josm.Main; 47 import org.openstreetmap.josm.actions.relation.DownloadMembersAction; 48 import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction; 49 import org.openstreetmap.josm.actions.relation.EditRelationAction; 50 import org.openstreetmap.josm.actions.relation.SelectMembersAction; 51 import org.openstreetmap.josm.actions.relation.SelectRelationAction; 46 52 import org.openstreetmap.josm.actions.search.SearchCompiler; 47 53 import org.openstreetmap.josm.command.Command; … … 51 57 import org.openstreetmap.josm.data.osm.OsmPrimitive; 52 58 import org.openstreetmap.josm.data.osm.Relation; 53 import org.openstreetmap.josm.data.osm.RelationMember;54 59 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 55 60 import org.openstreetmap.josm.data.osm.event.DataChangedEvent; … … 68 73 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 69 74 import org.openstreetmap.josm.gui.SideButton; 70 import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;71 import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;72 75 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 73 76 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; … … 76 79 import org.openstreetmap.josm.gui.util.GuiHelper; 77 80 import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField; 78 import org.openstreetmap.josm.gui.widgets.ListPopupMenu;79 81 import org.openstreetmap.josm.tools.ImageProvider; 80 82 import org.openstreetmap.josm.tools.InputMapUtils; … … 96 98 private final RelationListModel model; 97 99 98 /** the edit action */99 private final EditAction editAction;100 100 /** the delete action */ 101 101 private final DeleteAction deleteAction; 102 102 private final NewAction newAction; 103 103 private final AddToRelation addToRelation; 104 private final DuplicateAction duplicateAction; 105 104 106 /** the popup menu */ 105 107 private final RelationDialogPopupMenu popupMenu; … … 107 109 private final JTextField filter; 108 110 111 // Actions 112 /** the edit action */ 113 private final EditRelationAction editAction; 114 private final DownloadMembersAction downloadMembersAction = new DownloadMembersAction(); 115 private final DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction(); 116 private final SelectMembersAction selectMemebersAction = new SelectMembersAction(false); 117 private final SelectMembersAction addMembersToSelectionAction = new SelectMembersAction(true); 118 private final SelectRelationAction selectRelationAction = new SelectRelationAction(false); 119 private final SelectRelationAction addRelationToSelectionAction = new SelectRelationAction(true); 120 109 121 /** 110 122 * constructor … … 139 151 // the edit action 140 152 // 141 editAction = new EditAction(); 142 displaylist.addListSelectionListener(editAction); 143 153 editAction = new EditRelationAction(); 154 144 155 // the duplicate action 145 156 // 146 DuplicateAction duplicateAction = new DuplicateAction(); 147 displaylist.addListSelectionListener(duplicateAction); 148 157 duplicateAction = new DuplicateAction(); 158 149 159 // the delete action 150 160 // 151 161 deleteAction = new DeleteAction(); 152 displaylist.addListSelectionListener(deleteAction); 153 154 // the select action 162 163 // Add to realaion action 155 164 // 156 SelectAction selectAction = new SelectAction(false); 157 displaylist.addListSelectionListener(selectAction); 158 159 filter = new DisableShortcutsOnFocusGainedTextField(); 160 filter.setToolTipText(tr("Relation list filter")); 161 filter.getDocument().addDocumentListener(new DocumentListener() { 162 163 private void setFilter() { 164 try { 165 filter.setBackground(UIManager.getColor("TextField.background")); 166 filter.setToolTipText(tr("Relation list filter")); 167 model.setFilter(SearchCompiler.compile(filter.getText(), false, false)); 168 } catch (SearchCompiler.ParseError ex) { 169 filter.setBackground(new Color(255, 224, 224)); 170 filter.setToolTipText(ex.getMessage()); 171 model.setFilter(new SearchCompiler.Always()); 172 } 173 } 174 165 addToRelation = new AddToRelation(); 166 167 filter = setupFilter(); 168 169 displaylist.addListSelectionListener(new ListSelectionListener() { 175 170 @Override 176 public void insertUpdate(DocumentEvent e) { 177 setFilter(); 178 } 179 180 @Override 181 public void removeUpdate(DocumentEvent e) { 182 setFilter(); 183 } 184 185 @Override 186 public void changedUpdate(DocumentEvent e) { 187 setFilter(); 171 public void valueChanged(ListSelectionEvent e) { 172 duplicateAction.valueChanged(e); 173 deleteAction.valueChanged(e); 174 addToRelation.valueChanged(e); 175 176 List<Relation> rels; 177 rels = model.getSelectedNonNewRelations(); 178 downloadMembersAction.setRelations(rels); 179 180 rels = model.getSelectedRelationsWithIncompleteMembers(); 181 downloadSelectedIncompleteMembersAction.setRelations(rels); 182 183 rels = model.getSelectedRelations(); 184 selectMemebersAction.setRelations(rels); 185 addMembersToSelectionAction.setRelations(rels); 186 selectRelationAction.setRelations(rels); 187 addRelationToSelectionAction.setRelations(rels); 188 188 } 189 189 }); 190 190 191 191 JPanel pane = new JPanel(new BorderLayout()); 192 192 pane.add(filter, BorderLayout.NORTH); … … 197 197 new SideButton(duplicateAction, false), 198 198 new SideButton(deleteAction, false), 199 new SideButton(select Action, false)199 new SideButton(selectRelationAction, false) 200 200 })); 201 201 … … 207 207 208 208 // Select relation on Ctrl-Enter 209 InputMapUtils.addEnterAction(displaylist, selectAction); 210 211 addToRelation = new AddToRelation(); 212 popupMenu = new RelationDialogPopupMenu(displaylist); 209 InputMapUtils.addEnterAction(displaylist, selectRelationAction); 210 211 popupMenu = new RelationDialogPopupMenu(); 213 212 214 213 // Edit relation on Ctrl-Enter … … 216 215 displaylist.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK), "edit"); 217 216 } 218 217 219 218 @Override public void showNotify() { 220 219 MapView.addLayerChangeListener(newAction); … … 254 253 255 254 /** 256 * Adds a selection listener to the relation list.257 *258 * @param listener the listener to add259 */260 public void addListSelectionListener(ListSelectionListener listener) {261 displaylist.addListSelectionListener(listener);262 }263 264 /**265 * Removes a selection listener from the relation list.266 *267 * @param listener the listener to remove268 */269 public void removeListSelectionListener(ListSelectionListener listener) {270 displaylist.removeListSelectionListener(listener);271 }272 273 /**274 255 * @return The selected relation in the list 275 256 */ … … 306 287 } 307 288 289 private JTextField setupFilter() { 290 final JTextField f = new DisableShortcutsOnFocusGainedTextField(); 291 f.setToolTipText(tr("Relation list filter")); 292 f.getDocument().addDocumentListener(new DocumentListener() { 293 294 private void setFilter() { 295 try { 296 f.setBackground(UIManager.getColor("TextField.background")); 297 f.setToolTipText(tr("Relation list filter")); 298 model.setFilter(SearchCompiler.compile(filter.getText(), false, false)); 299 } catch (SearchCompiler.ParseError ex) { 300 f.setBackground(new Color(255, 224, 224)); 301 f.setToolTipText(ex.getMessage()); 302 model.setFilter(new SearchCompiler.Always()); 303 } 304 } 305 306 @Override 307 public void insertUpdate(DocumentEvent e) { 308 setFilter(); 309 } 310 311 @Override 312 public void removeUpdate(DocumentEvent e) { 313 setFilter(); 314 } 315 316 @Override 317 public void changedUpdate(DocumentEvent e) { 318 setFilter(); 319 } 320 }); 321 return f; 322 } 323 308 324 class MouseEventHandler extends MouseAdapter { 309 325 protected void setCurrentRelationAsSelection() { … … 312 328 313 329 protected void editCurrentRelation() { 314 new EditAction().launchEditor(getSelected());330 EditRelationAction.launchEditor(getSelected()); 315 331 } 316 332 … … 349 365 } 350 366 } 351 352 /** 353 * The edit action 354 * 355 */ 356 class EditAction extends AbstractAction implements ListSelectionListener{ 357 public EditAction() { 358 putValue(SHORT_DESCRIPTION,tr( "Open an editor for the selected relation")); 359 putValue(NAME, tr("Edit")); 360 putValue(SMALL_ICON, ImageProvider.get("dialogs", "edit")); 361 setEnabled(false); 362 } 363 protected Collection<RelationMember> getMembersForCurrentSelection(Relation r) { 364 Collection<RelationMember> members = new HashSet<RelationMember>(); 365 Collection<OsmPrimitive> selection = Main.map.mapView.getEditLayer().data.getSelected(); 366 for (RelationMember member: r.getMembers()) { 367 if (selection.contains(member.getMember())) { 368 members.add(member); 369 } 370 } 371 return members; 372 } 373 374 public void launchEditor(Relation toEdit) { 375 if (toEdit == null) 376 return; 377 RelationEditor.getEditor(Main.map.mapView.getEditLayer(),toEdit, getMembersForCurrentSelection(toEdit)).setVisible(true); 378 } 379 380 public void actionPerformed(ActionEvent e) { 381 if (!isEnabled()) 382 return; 383 launchEditor(getSelected()); 384 } 385 386 public void valueChanged(ListSelectionEvent e) { 387 setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length == 1); 388 } 389 } 390 367 391 368 /** 392 369 * The delete action … … 498 475 protected void updateEnabledState() { 499 476 setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length == 1); 500 }501 502 public void valueChanged(ListSelectionEvent e) {503 updateEnabledState();504 }505 }506 507 /**508 * Sets the current selection to the list of relations selected in this dialog509 *510 */511 class SelectAction extends AbstractAction implements ListSelectionListener{512 boolean add;513 public SelectAction(boolean add) {514 putValue(SHORT_DESCRIPTION, add ? tr("Add the selected relations to the current selection")515 : tr("Set the current selection to the list of selected relations"));516 putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));517 putValue(NAME, add ? tr("Select relation (add)") : tr("Select relation"));518 this.add = add;519 updateEnabledState();520 }521 522 public void actionPerformed(ActionEvent e) {523 if (!isEnabled()) return;524 int [] idx = displaylist.getSelectedIndices();525 if (idx == null || idx.length == 0) return;526 ArrayList<OsmPrimitive> selection = new ArrayList<OsmPrimitive>(idx.length);527 for (int i: idx) {528 selection.add(model.getVisibleRelation(i));529 }530 if(add) {531 Main.map.mapView.getEditLayer().data.addSelected(selection);532 } else {533 Main.map.mapView.getEditLayer().data.setSelected(selection);534 }535 }536 537 protected void updateEnabledState() {538 setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length > 0);539 }540 541 public void valueChanged(ListSelectionEvent e) {542 updateEnabledState();543 }544 }545 546 /**547 * Sets the current selection to the list of relations selected in this dialog548 *549 */550 class SelectMembersAction extends AbstractAction implements ListSelectionListener{551 boolean add;552 public SelectMembersAction(boolean add) {553 putValue(SHORT_DESCRIPTION,add ? tr("Add the members of all selected relations to current selection")554 : tr("Select the members of all selected relations"));555 putValue(SMALL_ICON, ImageProvider.get("selectall"));556 putValue(NAME, add ? tr("Select members (add)") : tr("Select members"));557 this.add = add;558 updateEnabledState();559 }560 561 public void actionPerformed(ActionEvent e) {562 if (!isEnabled()) return;563 List<Relation> relations = model.getSelectedRelations();564 HashSet<OsmPrimitive> members = new HashSet<OsmPrimitive>();565 for(Relation r: relations) {566 members.addAll(r.getMemberPrimitives());567 }568 if(add) {569 Main.map.mapView.getEditLayer().data.addSelected(members);570 } else {571 Main.map.mapView.getEditLayer().data.setSelected(members);572 }573 }574 575 protected void updateEnabledState() {576 setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length > 0);577 }578 579 public void valueChanged(ListSelectionEvent e) {580 updateEnabledState();581 }582 }583 584 /**585 * The action for downloading members of all selected relations586 *587 */588 class DownloadMembersAction extends AbstractAction implements ListSelectionListener{589 590 public DownloadMembersAction() {591 putValue(SHORT_DESCRIPTION,tr("Download all members of the selected relations"));592 putValue(NAME, tr("Download members"));593 putValue(SMALL_ICON, ImageProvider.get("dialogs", "downloadincomplete"));594 putValue("help", ht("/Dialog/RelationList#DownloadMembers"));595 updateEnabledState();596 }597 598 protected void updateEnabledState() {599 setEnabled(! model.getSelectedNonNewRelations().isEmpty());600 }601 602 public void valueChanged(ListSelectionEvent e) {603 updateEnabledState();604 }605 606 public void actionPerformed(ActionEvent e) {607 List<Relation> relations = model.getSelectedNonNewRelations();608 if (relations.isEmpty())609 return;610 Main.worker.submit(new DownloadRelationTask(611 model.getSelectedNonNewRelations(),612 Main.map.mapView.getEditLayer())613 );614 }615 }616 617 /**618 * Action for downloading incomplete members of selected relations619 *620 */621 class DownloadSelectedIncompleteMembersAction extends AbstractAction implements ListSelectionListener{622 public DownloadSelectedIncompleteMembersAction() {623 putValue(SHORT_DESCRIPTION, tr("Download incomplete members of selected relations"));624 putValue(SMALL_ICON, ImageProvider.get("dialogs/relation", "downloadincompleteselected"));625 putValue(NAME, tr("Download incomplete members"));626 updateEnabledState();627 }628 629 public Set<OsmPrimitive> buildSetOfIncompleteMembers(List<Relation> rels) {630 Set<OsmPrimitive> ret = new HashSet<OsmPrimitive>();631 for(Relation r: rels) {632 ret.addAll(r.getIncompleteMembers());633 }634 return ret;635 }636 637 public void actionPerformed(ActionEvent e) {638 if (!isEnabled())639 return;640 List<Relation> rels = model.getSelectedRelationsWithIncompleteMembers();641 if (rels.isEmpty()) return;642 Main.worker.submit(new DownloadRelationMemberTask(643 rels,644 buildSetOfIncompleteMembers(rels),645 Main.map.mapView.getEditLayer()646 ));647 }648 649 protected void updateEnabledState() {650 setEnabled(!model.getSelectedRelationsWithIncompleteMembers().isEmpty());651 477 } 652 478 … … 955 781 } 956 782 957 class RelationDialogPopupMenu extends ListPopupMenu { 958 959 public RelationDialogPopupMenu(JList list) { 960 super(list); 961 783 class RelationDialogPopupMenu extends JPopupMenu { 784 785 public RelationDialogPopupMenu() { 962 786 // -- download members action 963 add( new DownloadMembersAction());787 add(downloadMembersAction); 964 788 965 789 // -- download incomplete members action 966 add( new DownloadSelectedIncompleteMembersAction());790 add(downloadSelectedIncompleteMembersAction); 967 791 968 792 addSeparator(); 969 793 970 794 // -- select members action 971 add( new SelectMembersAction(false));972 add( new SelectMembersAction(true));795 add(selectMemebersAction); 796 add(addMembersToSelectionAction); 973 797 974 798 // -- select action 975 add( new SelectAction(false));976 add( new SelectAction(true));799 add(selectRelationAction); 800 add(addRelationToSelectionAction); 977 801 978 802 addSeparator(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r5716 r5793 39 39 import org.openstreetmap.josm.Main; 40 40 import org.openstreetmap.josm.actions.AutoScaleAction; 41 import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction; 42 import org.openstreetmap.josm.actions.relation.EditRelationAction; 43 import org.openstreetmap.josm.actions.relation.SelectInRelationListAction; 41 44 import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting; 42 45 import org.openstreetmap.josm.data.SelectionChangedListener; … … 46 49 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 47 50 import org.openstreetmap.josm.data.osm.Relation; 48 import org.openstreetmap.josm.data.osm.RelationMember;49 51 import org.openstreetmap.josm.data.osm.Way; 50 52 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; … … 66 68 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 67 69 import org.openstreetmap.josm.gui.SideButton; 68 import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;69 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;70 70 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 71 71 import org.openstreetmap.josm.gui.widgets.ListPopupMenu; … … 88 88 private ZoomToJOSMSelectionAction actZoomToJOSMSelection; 89 89 private ZoomToListSelection actZoomToListSelection; 90 private Se tRelationSelection actSetRelationSelection;91 private EditRelation Selection actEditRelationSelection;90 private SelectInRelationListAction actSetRelationSelection; 91 private EditRelationAction actEditRelationSelection; 92 92 private DownloadSelectedIncompleteMembersAction actDownloadSelectedIncompleteMembers; 93 93 … … 142 142 143 143 actZoomToListSelection = new ZoomToListSelection(); 144 actSetRelationSelection = new Se tRelationSelection();145 actEditRelationSelection = new EditRelation Selection();144 actSetRelationSelection = new SelectInRelationListAction(); 145 actEditRelationSelection = new EditRelationAction(); 146 146 actDownloadSelectedIncompleteMembers = new DownloadSelectedIncompleteMembersAction(); 147 147 148 lstPrimitives.addListSelectionListener(new ListSelectionListener() { 149 @Override 150 public void valueChanged(ListSelectionEvent e) { 151 actZoomToListSelection.valueChanged(e); 152 List<Relation> rels; 153 rels = model.getSelectedRelationsWithIncompleteMembers(); 154 actDownloadSelectedIncompleteMembers.setRelations(rels); 155 rels = OsmPrimitive.getFilteredList(model.getSelected(), Relation.class); 156 actSetRelationSelection.setRelations(rels); 157 actEditRelationSelection.setRelations(rels); 158 } 159 }); 160 148 161 lstPrimitives.addMouseListener(new SelectionPopupMenuLauncher()); 149 162 lstPrimitives.addMouseListener(new DblClickHandler()); … … 250 263 } 251 264 265 @Override 252 266 public void contentsChanged(ListDataEvent e) { 253 267 updateTitle(); 254 268 } 255 269 270 @Override 256 271 public void intervalAdded(ListDataEvent e) { 257 272 updateTitle(); 258 273 } 259 274 275 @Override 260 276 public void intervalRemoved(ListDataEvent e) { 261 277 updateTitle(); … … 274 290 } 275 291 292 @Override 276 293 public void actionPerformed(ActionEvent e) { 277 294 if (!isEnabled()) return; … … 283 300 } 284 301 302 @Override 285 303 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 286 304 updateEnabledState(); … … 329 347 } 330 348 349 @Override 331 350 public void actionPerformed(ActionEvent e) { 332 351 AutoScaleAction.autoScale("selection"); … … 337 356 } 338 357 358 @Override 339 359 public void contentsChanged(ListDataEvent e) { 340 360 updateEnabledState(); 341 361 } 342 362 363 @Override 343 364 public void intervalAdded(ListDataEvent e) { 344 365 updateEnabledState(); 345 366 } 346 367 368 @Override 347 369 public void intervalRemoved(ListDataEvent e) { 348 370 updateEnabledState(); … … 363 385 } 364 386 387 @Override 365 388 public void actionPerformed(ActionEvent e) { 366 389 BoundingXYVisitor box = new BoundingXYVisitor(); … … 378 401 } 379 402 380 public void valueChanged(ListSelectionEvent e) { 381 updateEnabledState(); 382 } 383 } 384 385 /** 386 * The action for setting and editing a relation in relation list dialog 387 * 388 */ 389 class EditRelationSelection extends SetRelationSelection { 390 public EditRelationSelection() { 391 putValue(NAME, tr("Call editor for relation")); 392 putValue(SHORT_DESCRIPTION, tr("Call relation editor for selected relation")); 393 putValue(SMALL_ICON, ImageProvider.get("dialogs", "edit")); 394 updateEnabledState(); 395 } 396 397 @Override 398 public void actionPerformed(ActionEvent e) { 399 Relation relation = (Relation)model.getSelected().toArray()[0]; 400 Collection<RelationMember> members = new HashSet<RelationMember>(); 401 Collection<OsmPrimitive> selection = model.getAllElements(); 402 for (RelationMember member: relation.getMembers()) { 403 if (selection.contains(member.getMember())) { 404 members.add(member); 405 } 406 } 407 Main.map.relationListDialog.selectRelation(relation); 408 RelationEditor.getEditor(Main.map.mapView.getEditLayer(), relation, 409 members).setVisible(true); 410 } 411 } 412 413 /** 414 * The action for setting a relation in relation list dialog 415 * 416 */ 417 class SetRelationSelection extends AbstractAction implements ListSelectionListener{ 418 public SetRelationSelection() { 419 putValue(NAME, tr("Select in relation list")); 420 putValue(SHORT_DESCRIPTION, tr("Select relation in relation list.")); 421 putValue(SMALL_ICON, ImageProvider.get("dialogs", "selectionlist")); 422 updateEnabledState(); 423 } 424 425 public void actionPerformed(ActionEvent e) { 426 Relation relation = (Relation)model.getSelected().toArray()[0]; 427 Main.map.relationListDialog.selectRelation(relation); 428 } 429 430 public void updateEnabledState() { 431 Object[] sel = model.getSelected().toArray(); 432 setEnabled(sel.length == 1 && sel[0] instanceof Relation); 433 } 434 403 @Override 435 404 public void valueChanged(ListSelectionEvent e) { 436 405 updateEnabledState(); … … 663 632 /* interface EditLayerChangeListener */ 664 633 /* ------------------------------------------------------------------------ */ 634 @Override 665 635 public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) { 666 636 if (newLayer == null) { … … 676 646 /* interface SelectionChangeListener */ 677 647 /* ------------------------------------------------------------------------ */ 648 @Override 678 649 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 679 650 setJOSMSelection(newSelection); … … 683 654 /* interface DataSetListener */ 684 655 /* ------------------------------------------------------------------------ */ 656 @Override 685 657 public void dataChanged(DataChangedEvent event) { 686 658 // refresh the whole list … … 688 660 } 689 661 662 @Override 690 663 public void nodeMoved(NodeMovedEvent event) { 691 664 // may influence the display name of primitives, update the data … … 693 666 } 694 667 668 @Override 695 669 public void otherDatasetChange(AbstractDatasetChangedEvent event) { 696 670 // may influence the display name of primitives, update the data … … 698 672 } 699 673 674 @Override 700 675 public void relationMembersChanged(RelationMembersChangedEvent event) { 701 676 // may influence the display name of primitives, update the data … … 703 678 } 704 679 680 @Override 705 681 public void tagsChanged(TagsChangedEvent event) { 706 682 // may influence the display name of primitives, update the data … … 708 684 } 709 685 686 @Override 710 687 public void wayNodesChanged(WayNodesChangedEvent event) { 711 688 // may influence the display name of primitives, update the data … … 713 690 } 714 691 692 @Override 715 693 public void primitivesAdded(PrimitivesAddedEvent event) {/* ignored - handled by SelectionChangeListener */} 694 @Override 716 695 public void primitivesRemoved(PrimitivesRemovedEvent event) {/* ignored - handled by SelectionChangeListener*/} 717 696 } … … 731 710 } 732 711 712 @Override 733 713 public void actionPerformed(ActionEvent e) { 734 714 org.openstreetmap.josm.actions.search.SearchAction.searchWithoutHistory(s); … … 811 791 } 812 792 793 @Override 813 794 public void actionPerformed(ActionEvent e) { 814 795 Main.main.getCurrentDataSet().setSelected(sel); … … 832 813 add(new SelectionMenuItem(sel)); 833 814 } 834 }835 }836 837 /**838 * Action for downloading incomplete members of selected relations839 *840 */841 class DownloadSelectedIncompleteMembersAction extends AbstractAction implements ListSelectionListener {842 public DownloadSelectedIncompleteMembersAction() {843 putValue(SHORT_DESCRIPTION, tr("Download incomplete members of selected relations"));844 putValue(SMALL_ICON, ImageProvider.get("dialogs/relation", "downloadincompleteselected"));845 putValue(NAME, tr("Download incomplete members"));846 updateEnabledState();847 }848 849 public Set<OsmPrimitive> buildSetOfIncompleteMembers(List<Relation> rels) {850 Set<OsmPrimitive> ret = new HashSet<OsmPrimitive>();851 for(Relation r: rels) {852 ret.addAll(r.getIncompleteMembers());853 }854 return ret;855 }856 857 public void actionPerformed(ActionEvent e) {858 if (!isEnabled())859 return;860 List<Relation> rels = model.getSelectedRelationsWithIncompleteMembers();861 if (rels.isEmpty()) return;862 Main.worker.submit(new DownloadRelationMemberTask(863 rels,864 buildSetOfIncompleteMembers(rels),865 Main.map.mapView.getEditLayer()866 ));867 }868 869 protected void updateEnabledState() {870 setEnabled(!model.getSelectedRelationsWithIncompleteMembers().isEmpty());871 }872 873 public void valueChanged(ListSelectionEvent e) {874 updateEnabledState();875 815 } 876 816 } … … 897 837 } 898 838 839 @Override 899 840 public int compare(OsmPrimitive a, OsmPrimitive b) { 900 841 if (a.getType().equals(b.getType())) -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r5789 r5793 53 53 import org.openstreetmap.josm.Main; 54 54 import org.openstreetmap.josm.actions.JosmAction; 55 import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction; 56 import org.openstreetmap.josm.actions.relation.SelectMembersAction; 57 import org.openstreetmap.josm.actions.relation.SelectRelationAction; 55 58 import org.openstreetmap.josm.actions.search.SearchAction.SearchMode; 56 59 import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting; … … 181 184 private final JosmAction[] josmActions = new JosmAction[]{addAction, editAction, deleteAction}; 182 185 186 // relation actions 187 private final DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction(); 188 private final SelectRelationAction addRelationToSelectionAction = new SelectRelationAction(true); 189 private final SelectMembersAction addMembersToSelectionAction = new SelectMembersAction(true); 190 private final SelectRelationAction selectRelationAction = new SelectRelationAction(false); 191 183 192 @Override 184 193 public void showNotify() { … … 379 388 // setting up the membership table 380 389 membershipMenu = new JPopupMenu(); 381 membershipMenu.add( new SelectRelationAction(true));382 membershipMenu.add( new SelectRelationAction(false));383 membershipMenu.add( new SelectRelationMembersAction());384 membershipMenu.add( new DownloadIncompleteMembersAction());390 membershipMenu.add(addRelationToSelectionAction); 391 membershipMenu.add(selectRelationAction); 392 membershipMenu.add(addMembersToSelectionAction); 393 membershipMenu.add(downloadSelectedIncompleteMembersAction); 385 394 membershipMenu.addSeparator(); 386 395 membershipMenu.add(helpAction); 387 396 388 397 membershipData.setColumnIdentifiers(new String[]{tr("Member Of"),tr("Role"),tr("Position")}); 389 membershipTable.setSelectionMode(ListSelectionModel. SINGLE_SELECTION);398 membershipTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 390 399 membershipTable.addMouseListener(new PopupMenuLauncher() { 391 400 @Override … … 393 402 Point p = evt.getPoint(); 394 403 int row = membershipTable.rowAtPoint(p); 395 if (row > -1) { 396 membershipTable.changeSelection(row, 0, false, false); 397 Relation relation = (Relation)membershipData.getValueAt(row, 0); 398 for (Component c : membershipMenu.getComponents()) { 399 if (c instanceof JMenuItem) { 400 Action action = ((JMenuItem) c).getAction(); 401 if (action instanceof RelationRelated) { 402 ((RelationRelated)action).setRelation(relation); 403 } 404 } 404 membershipTable.changeSelection(row, 0, false, false); 405 int idx[] = membershipTable.getSelectedRows(); 406 List<Relation> rels = new ArrayList<Relation>(10); 407 if (idx!=null) { 408 for (int i: idx) { 409 Relation r = (Relation) (membershipData.getValueAt(i, 0)); 410 rels.add(r); 405 411 } 406 membershipMenu.show(membershipTable, p.x, p.y-3); 407 } 412 } 413 selectRelationAction.setRelations(rels); 414 addMembersToSelectionAction.setRelations(rels); 415 addMembersToSelectionAction.setRelations(rels); 416 downloadSelectedIncompleteMembersAction.setRelations(rels); 417 membershipMenu.show(membershipTable, p.x, p.y-3); 408 418 } 409 419 }); … … 1044 1054 } 1045 1055 1046 public static interface RelationRelated {1047 public Relation getRelation();1048 public void setRelation(Relation relation);1049 }1050 1051 static abstract class AbstractRelationAction extends AbstractAction implements RelationRelated {1052 protected Relation relation;1053 public Relation getRelation() {1054 return this.relation;1055 }1056 public void setRelation(Relation relation) {1057 this.relation = relation;1058 }1059 }1060 1061 static class SelectRelationAction extends AbstractRelationAction {1062 boolean selectionmode;1063 public SelectRelationAction(boolean select) {1064 selectionmode = select;1065 if(select) {1066 putValue(NAME, tr("Select relation"));1067 putValue(SHORT_DESCRIPTION, tr("Select relation in main selection."));1068 putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));1069 } else {1070 putValue(NAME, tr("Select in relation list"));1071 putValue(SHORT_DESCRIPTION, tr("Select relation in relation list."));1072 putValue(SMALL_ICON, ImageProvider.get("dialogs", "relationlist"));1073 }1074 }1075 1076 public void actionPerformed(ActionEvent e) {1077 if(selectionmode) {1078 Main.map.mapView.getEditLayer().data.setSelected(relation);1079 } else {1080 Main.map.relationListDialog.selectRelation(relation);1081 Main.map.relationListDialog.unfurlDialog();1082 }1083 }1084 }1085 1086 1087 /**1088 * Sets the current selection to the members of selected relation1089 *1090 */1091 class SelectRelationMembersAction extends AbstractRelationAction {1092 public SelectRelationMembersAction() {1093 putValue(SHORT_DESCRIPTION,tr("Select the members of selected relation"));1094 putValue(SMALL_ICON, ImageProvider.get("selectall"));1095 putValue(NAME, tr("Select members"));1096 }1097 1098 public void actionPerformed(ActionEvent e) {1099 HashSet<OsmPrimitive> members = new HashSet<OsmPrimitive>();1100 members.addAll(relation.getMemberPrimitives());1101 Main.map.mapView.getEditLayer().data.setSelected(members);1102 }1103 1104 }1105 1106 /**1107 * Action for downloading incomplete members of selected relation1108 *1109 */1110 class DownloadIncompleteMembersAction extends AbstractRelationAction {1111 public DownloadIncompleteMembersAction() {1112 putValue(SHORT_DESCRIPTION, tr("Download incomplete members of selected relations"));1113 putValue(SMALL_ICON, ImageProvider.get("dialogs/relation", "downloadincompleteselected"));1114 putValue(NAME, tr("Download incomplete members"));1115 }1116 1117 public Set<OsmPrimitive> buildSetOfIncompleteMembers(Relation r) {1118 Set<OsmPrimitive> ret = new HashSet<OsmPrimitive>();1119 ret.addAll(r.getIncompleteMembers());1120 return ret;1121 }1122 1123 public void actionPerformed(ActionEvent e) {1124 if (!relation.hasIncompleteMembers()) return;1125 ArrayList<Relation> rels = new ArrayList<Relation>();1126 rels.add(relation);1127 Main.worker.submit(new DownloadRelationMemberTask(1128 rels,1129 buildSetOfIncompleteMembers(relation),1130 Main.map.mapView.getEditLayer()1131 ));1132 }1133 }1134 1135 1056 class PasteValueAction extends AbstractAction { 1136 1057 public PasteValueAction() {
Note:
See TracChangeset
for help on using the changeset viewer.