- Timestamp:
- 2013-04-02T00:55:56+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/relation/AbstractRelationAction.java
r5799 r5821 7 7 import javax.swing.AbstractAction; 8 8 9 import org.openstreetmap.josm.actions.OsmPrimitiveAction; 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 11 import org.openstreetmap.josm.data.osm.Relation; 12 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 10 13 11 14 /** … … 14 17 * @since 5793 15 18 */ 16 public abstract class AbstractRelationAction extends AbstractAction {19 public abstract class AbstractRelationAction extends AbstractAction implements OsmPrimitiveAction { 17 20 protected Collection<Relation> relations = Collections.<Relation>emptySet(); 18 21 19 /** 20 * Specifies the working set of relations. 21 * @param relations The new working set of relations. Can be null or empty 22 protected static final Collection<Relation> getRelations(Collection<? extends OsmPrimitive> primitives) { 23 if (primitives == null || primitives.isEmpty()) { 24 return Collections.<Relation>emptySet(); 25 } else { 26 return new SubclassFilteredCollection<OsmPrimitive, Relation>( 27 primitives, OsmPrimitive.relationPredicate); 28 } 29 } 30 31 /* (non-Javadoc) 32 * @see org.openstreetmap.josm.actions.relation.RelationAction#setPrimitives 22 33 */ 23 public void setRelations(Collection<Relation> relations) { 24 if (relations==null) { 25 this.relations = Collections.<Relation>emptySet(); 26 } else { 27 this.relations = relations; 28 } 34 @Override 35 public void setPrimitives(Collection<? extends OsmPrimitive> primitives) { 36 this.relations = getRelations(primitives); 29 37 updateEnabledState(); 30 38 } -
trunk/src/org/openstreetmap/josm/actions/relation/DownloadMembersAction.java
r5799 r5821 6 6 7 7 import java.awt.event.ActionEvent; 8 import java.util.Collection; 8 9 9 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 import org.openstreetmap.josm.data.osm.Relation; 10 13 import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask; 11 14 import org.openstreetmap.josm.tools.ImageProvider; 15 import org.openstreetmap.josm.tools.Predicate; 16 import org.openstreetmap.josm.tools.Utils; 12 17 13 18 /** 14 19 * The action for downloading members of relations 15 20 * @since 5793 16 21 */ 17 22 public class DownloadMembersAction extends AbstractRelationAction { … … 32 37 Main.worker.submit(new DownloadRelationTask(relations, Main.map.mapView.getEditLayer())); 33 38 } 39 40 @Override 41 public void setPrimitives(Collection<? extends OsmPrimitive> primitives) { 42 // selected non-new relations 43 this.relations = Utils.filter(getRelations(primitives), new Predicate<Relation>(){ 44 @Override public boolean evaluate(Relation r) { 45 return !r.isNew(); 46 }}); 47 updateEnabledState(); 48 } 34 49 } -
trunk/src/org/openstreetmap/josm/actions/relation/DownloadSelectedIncompleteMembersAction.java
r5799 r5821 14 14 import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask; 15 15 import org.openstreetmap.josm.tools.ImageProvider; 16 import org.openstreetmap.josm.tools.Predicate; 17 import org.openstreetmap.josm.tools.Utils; 16 18 17 19 /** … … 51 53 Main.map.mapView.getEditLayer())); 52 54 } 55 56 @Override 57 public void setPrimitives(Collection<? extends OsmPrimitive> primitives) { 58 // selected relations with incomplete members 59 this.relations = Utils.filter(getRelations(primitives), new Predicate<Relation>(){ 60 @Override public boolean evaluate(Relation r) { 61 return !r.isNew() && r.hasIncompleteMembers(); 62 }}); 63 updateEnabledState(); 64 } 53 65 } -
trunk/src/org/openstreetmap/josm/actions/relation/DuplicateRelationAction.java
r5799 r5821 17 17 */ 18 18 public class DuplicateRelationAction extends AbstractRelationAction { 19 20 /** 21 * Constructs a new {@code DuplicateRelationAction}. 22 */ 19 23 public DuplicateRelationAction() { 20 24 putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window")); -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r5799 r5821 16 16 import java.util.Collections; 17 17 import java.util.HashSet; 18 import java.util.Iterator;19 18 import java.util.List; 20 19 import java.util.Set; … … 22 21 import javax.swing.AbstractAction; 23 22 import javax.swing.AbstractListModel; 24 import javax.swing.Action;25 23 import javax.swing.DefaultListSelectionModel; 26 24 import javax.swing.JComponent; 27 25 import javax.swing.JList; 28 import javax.swing.JMenuItem;29 26 import javax.swing.JPanel; 30 27 import javax.swing.JPopupMenu; … … 39 36 import javax.swing.event.ListSelectionEvent; 40 37 import javax.swing.event.ListSelectionListener; 41 import javax.swing.event.PopupMenuListener;42 38 43 39 import org.openstreetmap.josm.Main; … … 69 65 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 70 66 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 67 import org.openstreetmap.josm.gui.PopupMenuHandler; 71 68 import org.openstreetmap.josm.gui.SideButton; 72 69 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; … … 95 92 private final NewAction newAction; 96 93 97 /** the popup menu */ 98 private final RelationDialogPopupMenu popupMenu; 94 /** the popup menu and its handler */ 95 private final JPopupMenu popupMenu = new JPopupMenu(); 96 private final PopupMenuHandler popupMenuHandler = new PopupMenuHandler(popupMenu); 99 97 100 98 private final JTextField filter; … … 109 107 private final DownloadMembersAction downloadMembersAction = new DownloadMembersAction(); 110 108 private final DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction(); 111 private final SelectMembersAction selectMem ebersAction = new SelectMembersAction(false);109 private final SelectMembersAction selectMembersAction = new SelectMembersAction(false); 112 110 private final SelectMembersAction addMembersToSelectionAction = new SelectMembersAction(true); 113 111 private final SelectRelationAction selectRelationAction = new SelectRelationAction(false); 114 112 private final SelectRelationAction addRelationToSelectionAction = new SelectRelationAction(true); 115 /** add all selected primitives to the given re altions */113 /** add all selected primitives to the given relations */ 116 114 private final AddSelectionToRelations addSelectionToRelations = new AddSelectionToRelations(); 117 115 … … 154 152 } 155 153 }); 154 155 // Setup popup menu handler 156 setupPopupMenuHandler(); 156 157 157 158 JPanel pane = new JPanel(new BorderLayout()); … … 175 176 InputMapUtils.addEnterAction(displaylist, selectRelationAction); 176 177 177 popupMenu = new RelationDialogPopupMenu();178 179 178 // Edit relation on Ctrl-Enter 180 179 displaylist.getActionMap().put("edit", editAction); … … 186 185 // inform all actions about list of relations they need 187 186 private void updateActionsRelationLists() { 188 List<Relation> rels; 189 rels = model.getSelectedNonNewRelations(); 190 downloadMembersAction.setRelations(rels); 191 192 rels = model.getSelectedRelationsWithIncompleteMembers(); 193 downloadSelectedIncompleteMembersAction.setRelations(rels); 194 195 rels = model.getSelectedRelations(); 196 editAction.setRelations(rels); 197 deleteRelationsAction.setRelations(rels); 198 addSelectionToRelations.setRelations(rels); 199 selectMemebersAction.setRelations(rels); 200 addMembersToSelectionAction.setRelations(rels); 201 selectRelationAction.setRelations(rels); 202 addRelationToSelectionAction.setRelations(rels); 203 duplicateAction.setRelations(rels); 187 popupMenuHandler.setPrimitives(model.getSelectedRelations()); 204 188 } 205 189 … … 509 493 } 510 494 } 511 512 /**513 * Replies the list of selected relations with incomplete members514 *515 * @return the list of selected relations with incomplete members516 */517 public List<Relation> getSelectedRelationsWithIncompleteMembers() {518 List<Relation> ret = getSelectedNonNewRelations();519 Iterator<Relation> it = ret.iterator();520 while(it.hasNext()) {521 Relation r = it.next();522 if (!r.hasIncompleteMembers()) {523 it.remove();524 }525 }526 return ret;527 }528 495 529 496 private void updateFilteredRelations() { … … 569 536 570 537 /** 571 * Replies the list of selected, non-new relations. Empty list,572 * if there are no selected, non-new relations.573 *574 * @return the list of selected, non-new relations.575 */576 public List<Relation> getSelectedNonNewRelations() {577 ArrayList<Relation> ret = new ArrayList<Relation>();578 for (int i=0; i<getSize();i++) {579 if (!selectionModel.isSelectedIndex(i)) {580 continue;581 }582 if (getVisibleRelation(i).isNew()) {583 continue;584 }585 ret.add(getVisibleRelation(i));586 }587 return ret;588 }589 590 /**591 538 * Replies the list of selected relations. Empty list, 592 539 * if there are no selected relations. … … 656 603 } 657 604 658 class RelationDialogPopupMenu extends JPopupMenu { 659 660 public RelationDialogPopupMenu() { 661 // -- download members action 662 add(downloadMembersAction); 663 664 // -- download incomplete members action 665 add(downloadSelectedIncompleteMembersAction); 666 667 addSeparator(); 668 669 // -- select members action 670 add(selectMemebersAction); 671 add(addMembersToSelectionAction); 672 673 // -- select action 674 add(selectRelationAction); 675 add(addRelationToSelectionAction); 676 677 addSeparator(); 678 679 add(addSelectionToRelations); 680 } 681 } 682 605 private final void setupPopupMenuHandler() { 606 607 // -- download members action 608 popupMenuHandler.addAction(downloadMembersAction); 609 610 // -- download incomplete members action 611 popupMenuHandler.addAction(downloadSelectedIncompleteMembersAction); 612 613 popupMenuHandler.addSeparator(); 614 615 // -- select members action 616 popupMenuHandler.addAction(selectMembersAction); 617 popupMenuHandler.addAction(addMembersToSelectionAction); 618 619 // -- select action 620 popupMenuHandler.addAction(selectRelationAction); 621 popupMenuHandler.addAction(addRelationToSelectionAction); 622 623 popupMenuHandler.addSeparator(); 624 625 popupMenuHandler.addAction(addSelectionToRelations); 626 } 627 683 628 /* ---------------------------------------------------------------------------------- */ 684 /* Methods that can be called from plugins 629 /* Methods that can be called from plugins */ 685 630 /* ---------------------------------------------------------------------------------- */ 686 631 687 public void addPopupMenuSeparator() { 688 popupMenu.addSeparator(); 689 } 690 691 public JMenuItem addPopupMenuAction(Action a) { 692 return popupMenu.add(a); 693 } 694 695 public void addPopupMenuListener(PopupMenuListener l) { 696 popupMenu.addPopupMenuListener(l); 697 } 698 699 public void removePopupMenuListener(PopupMenuListener l) { 700 popupMenu.addPopupMenuListener(l); 632 /** 633 * Replies the popup menu handler. 634 * @return The popup menu handler 635 */ 636 public PopupMenuHandler getPopupMenuHandler() { 637 return popupMenuHandler; 701 638 } 702 639 -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r5806 r5821 24 24 import javax.swing.AbstractAction; 25 25 import javax.swing.AbstractListModel; 26 import javax.swing.Action;27 26 import javax.swing.DefaultListSelectionModel; 28 27 import javax.swing.JList; … … 35 34 import javax.swing.event.ListSelectionEvent; 36 35 import javax.swing.event.ListSelectionListener; 37 import javax.swing.event.PopupMenuListener;38 36 39 37 import org.openstreetmap.josm.Main; … … 67 65 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener; 68 66 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 67 import org.openstreetmap.josm.gui.PopupMenuHandler; 69 68 import org.openstreetmap.josm.gui.SideButton; 70 69 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 92 91 private DownloadSelectedIncompleteMembersAction actDownloadSelectedIncompleteMembers; 93 92 94 private SelectionPopup popupMenu; 93 /** the popup menu and its handler */ 94 private final ListPopupMenu popupMenu; 95 private final PopupMenuHandler popupMenuHandler; 95 96 96 97 /** … … 148 149 actDownloadSelectedIncompleteMembers = new DownloadSelectedIncompleteMembersAction(); 149 150 151 popupMenu = new ListPopupMenu(lstPrimitives); 152 popupMenuHandler = setupPopupMenuHandler(); 153 150 154 lstPrimitives.addListSelectionListener(new ListSelectionListener() { 151 155 @Override 152 156 public void valueChanged(ListSelectionEvent e) { 153 157 actZoomToListSelection.valueChanged(e); 154 List<Relation> rels; 155 rels = model.getSelectedRelationsWithIncompleteMembers(); 156 actDownloadSelectedIncompleteMembers.setRelations(rels); 157 rels = OsmPrimitive.getFilteredList(model.getSelected(), Relation.class); 158 actSetRelationSelection.setRelations(rels); 159 actEditRelationSelection.setRelations(rels); 158 popupMenuHandler.setPrimitives(model.getSelected()); 160 159 } 161 160 }); … … 164 163 lstPrimitives.addMouseListener(new DblClickHandler()); 165 164 166 popupMenu = new SelectionPopup(lstPrimitives);167 165 InputMapUtils.addEnterAction(lstPrimitives, actZoomToListSelection); 168 166 } … … 221 219 } 222 220 223 /** 224 * The popup menu for the selection list 225 */ 226 class SelectionPopup extends ListPopupMenu { 227 public SelectionPopup(JList list) { 228 super(list); 229 add(actZoomToJOSMSelection); 230 add(actZoomToListSelection); 231 addSeparator(); 232 add(actSetRelationSelection); 233 add(actEditRelationSelection); 234 addSeparator(); 235 add(actDownloadSelectedIncompleteMembers); 236 } 237 } 238 239 public void addPopupMenuSeparator() { 240 popupMenu.addSeparator(); 241 } 242 243 public JMenuItem addPopupMenuAction(Action a) { 244 return popupMenu.add(a); 245 } 246 247 public void addPopupMenuListener(PopupMenuListener l) { 248 popupMenu.addPopupMenuListener(l); 249 } 250 251 public void removePopupMenuListener(PopupMenuListener l) { 252 popupMenu.addPopupMenuListener(l); 221 private final PopupMenuHandler setupPopupMenuHandler() { 222 PopupMenuHandler handler = new PopupMenuHandler(popupMenu); 223 handler.addAction(actZoomToJOSMSelection); 224 handler.addAction(actZoomToListSelection); 225 handler.addSeparator(); 226 handler.addAction(actSetRelationSelection); 227 handler.addAction(actEditRelationSelection); 228 handler.addSeparator(); 229 handler.addAction(actDownloadSelectedIncompleteMembers); 230 return handler; 231 } 232 233 /** 234 * Replies the popup menu handler. 235 * @return The popup menu handler 236 */ 237 public PopupMenuHandler getPopupMenuHandler() { 238 return popupMenuHandler; 253 239 } 254 240 … … 596 582 } 597 583 setSelected(sel); 598 }599 600 /**601 * Replies the list of selected relations with incomplete members602 *603 * @return the list of selected relations with incomplete members604 */605 public List<Relation> getSelectedRelationsWithIncompleteMembers() {606 List<Relation> ret = new LinkedList<Relation>();607 for(int i=0; i<getSize(); i++) {608 if (!selectionModel.isSelectedIndex(i)) {609 continue;610 }611 OsmPrimitive p = selection.get(i);612 if (! (p instanceof Relation)) {613 continue;614 }615 if (p.isNew()) {616 continue;617 }618 Relation r = (Relation)p;619 if (r.hasIncompleteMembers()) {620 ret.add(r);621 }622 }623 return ret;624 584 } 625 585 -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r5800 r5821 32 32 33 33 import javax.swing.AbstractAction; 34 import javax.swing.Action;35 34 import javax.swing.JComponent; 36 35 import javax.swing.JLabel; 37 import javax.swing.JMenuItem;38 36 import javax.swing.JPanel; 39 37 import javax.swing.JPopupMenu; … … 44 42 import javax.swing.event.ListSelectionEvent; 45 43 import javax.swing.event.ListSelectionListener; 46 import javax.swing.event.PopupMenuListener;47 44 import javax.swing.table.DefaultTableCellRenderer; 48 45 import javax.swing.table.DefaultTableModel; … … 77 74 import org.openstreetmap.josm.gui.MapFrame; 78 75 import org.openstreetmap.josm.gui.MapView; 76 import org.openstreetmap.josm.gui.PopupMenuHandler; 79 77 import org.openstreetmap.josm.gui.SideButton; 80 78 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; … … 111 109 */ 112 110 public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener, MapView.EditLayerChangeListener, DataSetListenerAdapter.Listener { 113 // hook for roadsigns plugin to display a small 114 // button in the upper right corner of this dialog 111 112 /** 113 * hook for roadsigns plugin to display a small button in the upper right corner of this dialog 114 */ 115 115 public static final JPanel pluginHook = new JPanel(); 116 116 … … 134 134 private final JTable membershipTable = new JTable(membershipData); 135 135 136 private JPopupMenu propertyMenu; 137 private JPopupMenu membershipMenu; 136 // Popup menus 137 private final JPopupMenu propertyMenu = new JPopupMenu(); 138 private final JPopupMenu membershipMenu = new JPopupMenu(); 139 140 // Popup menu handlers 141 private final PopupMenuHandler propertyMenuHandler = new PopupMenuHandler(propertyMenu); 142 private final PopupMenuHandler membershipMenuHandler = new PopupMenuHandler(membershipMenu); 138 143 139 144 private final Map<String, Map<String, Integer>> valueCount = new TreeMap<String, Map<String, Integer>>(); … … 202 207 /** 203 208 * Create a new PropertiesDialog 209 * @param mapFrame The parent map fram 204 210 */ 205 211 public PropertiesDialog(MapFrame mapFrame) { … … 370 376 private void setupMembershipMenu() { 371 377 // setting up the membership table 372 membershipMenu = new JPopupMenu(); 373 membershipMenu.add(addRelationToSelectionAction); 374 membershipMenu.add(selectRelationAction); 375 membershipMenu.add(addMembersToSelectionAction); 376 membershipMenu.add(downloadSelectedIncompleteMembersAction); 378 membershipMenuHandler.addAction(addRelationToSelectionAction); 379 membershipMenuHandler.addAction(selectRelationAction); 380 membershipMenuHandler.addAction(addMembersToSelectionAction); 381 membershipMenuHandler.addAction(downloadSelectedIncompleteMembersAction); 377 382 membershipMenu.addSeparator(); 378 383 membershipMenu.add(helpAction); … … 389 394 idx = new int[]{row}; 390 395 } 391 List<Relation> rels = new ArrayList<Relation>(10);396 List<Relation> rels = new ArrayList<Relation>(); 392 397 for (int i: idx) { 393 398 Relation r = (Relation) (membershipData.getValueAt(i, 0)); 394 399 rels.add(r); 395 400 } 396 selectRelationAction.setRelations(rels); 397 addRelationToSelectionAction.setRelations(rels); 398 addMembersToSelectionAction.setRelations(rels); 399 downloadSelectedIncompleteMembersAction.setRelations(rels); 401 membershipMenuHandler.setPrimitives(rels); 400 402 membershipMenu.show(membershipTable, p.x, p.y-3); 401 403 } … … 407 409 */ 408 410 private void setupPropertiesMenu() { 409 propertyMenu = new JPopupMenu();410 411 propertyMenu.add(pasteValueAction); 411 412 propertyMenu.add(copyValueAction); … … 695 696 696 697 // <editor-fold defaultstate="collapsed" desc="Methods that are called by plugins to extend fuctionalty "> 697 public void addPropertyPopupMenuSeparator() { 698 propertyMenu.addSeparator(); 699 } 700 701 public JMenuItem addPropertyPopupMenuAction(Action a) { 702 return propertyMenu.add(a); 703 } 704 705 public void addPropertyPopupMenuListener(PopupMenuListener l) { 706 propertyMenu.addPopupMenuListener(l); 707 } 708 709 public void removePropertyPopupMenuListener(PopupMenuListener l) { 710 propertyMenu.addPopupMenuListener(l); 698 699 /** 700 * Replies the property popup menu handler. 701 * @return The property popup menu handler 702 */ 703 public PopupMenuHandler getPropertyPopupMenuHandler() { 704 return propertyMenuHandler; 711 705 } 712 706 … … 721 715 } 722 716 723 public void addMembershipPopupMenuSeparator() { 724 membershipMenu.addSeparator(); 725 } 726 727 public JMenuItem addMembershipPopupMenuAction(Action a) { 728 return membershipMenu.add(a); 729 } 730 731 public void addMembershipPopupMenuListener(PopupMenuListener l) { 732 membershipMenu.addPopupMenuListener(l); 733 } 734 735 public void removeMembershipPopupMenuListener(PopupMenuListener l) { 736 membershipMenu.addPopupMenuListener(l); 717 /** 718 * Replies the membership popup menu handler. 719 * @return The membership popup menu handler 720 */ 721 public PopupMenuHandler getMembershipPopupMenuHandler() { 722 return membershipMenuHandler; 737 723 } 738 724
Note:
See TracChangeset
for help on using the changeset viewer.