Ticket #7846: 7846_refactor.patch
File 7846_refactor.patch, 38.7 KB (added by , 12 years ago) |
---|
-
core/src/org/openstreetmap/josm/actions/data/NodeAction.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.actions.data; 3 4 import java.util.Collection; 5 6 import javax.swing.Action; 7 8 import org.openstreetmap.josm.data.osm.Node; 9 10 /** 11 * Interface used to enable/disable all node-related actions, even those registered by plugins. 12 * @since 5805 13 */ 14 public interface NodeAction extends Action { 15 16 /** 17 * Specifies the working set of nodes. 18 * @param nodes The new working set of nodes. Can be null or empty 19 */ 20 public abstract void setNodes(Collection<Node> nodes); 21 } -
core/src/org/openstreetmap/josm/actions/data/RelationAction.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.actions.data; 3 4 import java.util.Collection; 5 6 import javax.swing.Action; 7 8 import org.openstreetmap.josm.data.osm.Relation; 9 10 /** 11 * Interface used to enable/disable all relation-related actions, even those registered by plugins. 12 * @since 5805 13 */ 14 public interface RelationAction extends Action { 15 16 /** 17 * Specifies the working set of relations. 18 * @param relations The new working set of relations. Can be null or empty 19 */ 20 public abstract void setRelations(Collection<Relation> relations); 21 } -
core/src/org/openstreetmap/josm/actions/data/WayAction.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.actions.data; 3 4 import java.util.Collection; 5 6 import javax.swing.Action; 7 8 import org.openstreetmap.josm.data.osm.Way; 9 10 /** 11 * Interface used to enable/disable all way-related actions, even those registered by plugins. 12 * @since 5805 13 */ 14 public interface WayAction extends Action { 15 16 /** 17 * Specifies the working set of ways. 18 * @param ways The new working set of ways. Can be null or empty 19 */ 20 public abstract void setWays(Collection<Way> ways); 21 } -
core/src/org/openstreetmap/josm/actions/relation/AbstractRelationAction.java
6 6 7 7 import javax.swing.AbstractAction; 8 8 9 import org.openstreetmap.josm.actions.data.RelationAction; 9 10 import org.openstreetmap.josm.data.osm.Relation; 10 11 11 12 /** … … 13 14 * to be disabled is the collection is empty 14 15 * @since 5793 15 16 */ 16 public abstract class AbstractRelationAction extends AbstractAction {17 public abstract class AbstractRelationAction extends AbstractAction implements RelationAction { 17 18 protected Collection<Relation> relations = Collections.<Relation>emptySet(); 18 19 19 /** 20 * Specifies the working set of relations. 21 * @param relations The new working set of relations. Can be null or empty 20 /* (non-Javadoc) 21 * @see org.openstreetmap.josm.actions.relation.RelationAction#setRelations(java.util.Collection) 22 22 */ 23 @Override 23 24 public void setRelations(Collection<Relation> relations) { 24 25 if (relations==null) { 25 26 this.relations = Collections.<Relation>emptySet(); -
core/src/org/openstreetmap/josm/actions/relation/DuplicateRelationAction.java
16 16 * @since 5799 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")); 21 25 putValue(SMALL_ICON, ImageProvider.get("duplicate")); -
core/src/org/openstreetmap/josm/gui/DataActionPopupMenuHandler.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui; 3 4 import java.util.Collection; 5 import java.util.Collections; 6 import java.util.HashSet; 7 import java.util.Set; 8 9 import javax.swing.Action; 10 import javax.swing.JMenuItem; 11 import javax.swing.JPopupMenu; 12 import javax.swing.MenuElement; 13 import javax.swing.event.PopupMenuListener; 14 15 import org.openstreetmap.josm.actions.data.NodeAction; 16 import org.openstreetmap.josm.actions.data.RelationAction; 17 import org.openstreetmap.josm.actions.data.WayAction; 18 import org.openstreetmap.josm.actions.relation.DownloadMembersAction; 19 import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction; 20 import org.openstreetmap.josm.actions.relation.EditRelationAction; 21 import org.openstreetmap.josm.actions.relation.SelectInRelationListAction; 22 import org.openstreetmap.josm.actions.relation.SelectMembersAction; 23 import org.openstreetmap.josm.actions.relation.SelectRelationAction; 24 import org.openstreetmap.josm.data.osm.Node; 25 import org.openstreetmap.josm.data.osm.Relation; 26 import org.openstreetmap.josm.data.osm.Way; 27 28 /** 29 * Handler to ease management of osm primitives related actions in all different popup menus. 30 * @since 5805 31 */ 32 public class DataActionPopupMenuHandler { 33 34 // Pre-defined relation actions 35 private SelectRelationAction selectRelationAction; 36 private SelectRelationAction addRelationToSelectionAction; 37 private SelectMembersAction selectMembersAction; 38 private SelectMembersAction addMembersToSelectionAction; 39 private SelectInRelationListAction selectInRelationListAction; 40 private EditRelationAction editRelationAction; 41 private DownloadMembersAction downloadMembersAction; 42 private DownloadSelectedIncompleteMembersAction downloadIncompleteMembersAction; 43 44 // Set of enabled node, way and relation actions 45 private final Set<NodeAction> nodeActions = new HashSet<NodeAction>(); 46 private final Set<WayAction> wayActions = new HashSet<WayAction>(); 47 private final Set<RelationAction> relationActions = new HashSet<RelationAction>(); 48 // Managed menu 49 private final JPopupMenu menu; 50 51 /** 52 * Constructs a new {@code RelationActionMenuHandler} for the specified popup menu. 53 * 54 * @param menu The menu to be managed 55 */ 56 public DataActionPopupMenuHandler(JPopupMenu menu) { 57 this.menu = menu; 58 } 59 60 /** 61 * Enables the action "Select relation" which can be then accessed with the method {@code #getSelectRelationAction()} 62 * @see #getSelectRelationAction 63 */ 64 public void enableSelectRelationAction() { 65 if (selectRelationAction == null) { 66 addAction(selectRelationAction = new SelectRelationAction(false)); 67 } 68 } 69 70 /** 71 * Enables the action "Select relation (add)" which can be then accessed with the method {@code #getAddRelationToSelectionAction()} 72 * @see #getAddRelationToSelectionAction 73 */ 74 public void enableAddRelationToSelectionAction() { 75 if (addRelationToSelectionAction == null) { 76 addAction(addRelationToSelectionAction = new SelectRelationAction(true)); 77 } 78 } 79 80 /** 81 * Enables the action "Select members" which can be then accessed with the method {@code #getSelectMembersAction()} 82 * @see #getSelectMembersAction 83 */ 84 public void enableSelectMembersAction() { 85 if (selectMembersAction == null) { 86 addAction(selectMembersAction = new SelectMembersAction(false)); 87 } 88 } 89 90 /** 91 * Enables the action "Select members (add)" which can be then accessed with the method {@code #getAddMembersToSelectionAction()} 92 * @see #getAddMembersToSelectionAction 93 */ 94 public void enableAddMembersToSelectionAction() { 95 if (addMembersToSelectionAction == null) { 96 addAction(addMembersToSelectionAction = new SelectMembersAction(true)); 97 } 98 } 99 100 /** 101 * Enables the action "Select in relation list" which can be then accessed with the method {@code #getSelectInRelationListAction()} 102 * @see #getSelectInRelationListAction 103 */ 104 public void enableSelectInRelationListAction() { 105 if (selectInRelationListAction == null) { 106 addAction(selectInRelationListAction = new SelectInRelationListAction()); 107 } 108 } 109 110 /** 111 * Enables the action "Edit relation" which can be then accessed with the method {@code #getEditRelationAction()} 112 * @see #getEditRelationAction 113 */ 114 public void enableEditRelationAction() { 115 if (editRelationAction == null) { 116 addAction(editRelationAction = new EditRelationAction()); 117 } 118 } 119 120 /** 121 * Enables the action "Download members" which can be then accessed with the method {@code #getDownloadMembersAction()} 122 * @see #getDownloadMembersAction 123 */ 124 public void enableDownloadMembersAction() { 125 if (downloadMembersAction == null) { 126 addAction(downloadMembersAction = new DownloadMembersAction()); 127 } 128 } 129 130 /** 131 * Enables the action "Download incomplete members" which can be then accessed with the method {@code #getDownloadSelectedIncompleteMembersAction()} 132 * @see #getDownloadSelectedIncompleteMembersAction 133 */ 134 public void enableDownloadIncompleteMembersAction() { 135 if (downloadIncompleteMembersAction == null) { 136 addAction(downloadIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction()); 137 } 138 } 139 140 /** 141 * Appends a new separator at the end of the menu. 142 * @see JPopupMenu#addSeparator 143 */ 144 public void addSeparator() { 145 menu.addSeparator(); 146 } 147 148 /** 149 * Appends a new menu item to the end of the menu which dispatches the specified <code>Action</code> object. 150 * 151 * @param a the <code>Action</code> to add to the menu 152 * @return the new menu item 153 * @see JPopupMenu#add(Action) 154 */ 155 public JMenuItem addAction(Action a) { 156 if (a != null) { 157 if (a instanceof NodeAction) { 158 nodeActions.add((NodeAction) a); 159 } 160 if (a instanceof WayAction) { 161 wayActions.add((WayAction) a); 162 } 163 if (a instanceof RelationAction) { 164 relationActions.add((RelationAction) a); 165 } 166 return menu.add(a); 167 } 168 return null; 169 } 170 171 /** 172 * Removes the menu item which dispatches the specified <code>Action</code> object. 173 * 174 * @param a the <code>Action</code> to remove from the menu 175 * @see JPopupMenu#remove(int) 176 */ 177 public void removeAction(Action a) { 178 if (a != null) { 179 if (a instanceof NodeAction) { 180 nodeActions.remove(a); 181 } 182 if (a instanceof WayAction) { 183 wayActions.remove(a); 184 } 185 if (a instanceof RelationAction) { 186 relationActions.remove(a); 187 } 188 MenuElement[] elements = menu.getSubElements(); 189 for (int i=0; i<elements.length; i++) { 190 if (elements[i] instanceof JMenuItem) { 191 if (((JMenuItem) elements[i]).getAction() == a) { 192 menu.remove(i); 193 return; 194 } 195 } 196 } 197 } 198 } 199 200 /** 201 * Adds a <code>PopupMenu</code> listener. 202 * 203 * @param l the <code>PopupMenuListener</code> to add 204 * @see JPopupMenu#addPopupMenuListener 205 */ 206 public void addListener(PopupMenuListener l) { 207 menu.addPopupMenuListener(l); 208 } 209 210 /** 211 * Removes a <code>PopupMenu</code> listener. 212 * 213 * @param l the <code>PopupMenuListener</code> to remove 214 * @see JPopupMenu#removePopupMenuListener 215 */ 216 public void removeListener(PopupMenuListener l) { 217 menu.removePopupMenuListener(l); 218 } 219 220 /** 221 * Returns all enabled node actions. 222 * @return All node actions that have been added. 223 * @see #addAction(Action) 224 */ 225 public Collection<NodeAction> getNodeActions() { 226 return Collections.unmodifiableCollection(nodeActions); 227 } 228 229 /** 230 * Returns all enabled way actions. 231 * @return All way actions that have been added. 232 * @see #addAction(Action) 233 */ 234 public Collection<WayAction> getWayActions() { 235 return Collections.unmodifiableCollection(wayActions); 236 } 237 238 /** 239 * Returns all enabled relation actions. 240 * @return All relation actions that have been added or enabled. 241 * @see #addAction(Action) 242 * @see #enableAddMembersToSelectionAction() 243 * @see #enableAddRelationToSelectionAction() 244 * @see #enableDownloadIncompleteMembersAction() 245 * @see #enableEditRelationAction() 246 * @see #enableSelectInRelationListAction() 247 * @see #enableSelectMembersAction() 248 * @see #enableSelectRelationAction() 249 */ 250 public Collection<RelationAction> getRelationActions() { 251 return Collections.unmodifiableCollection(relationActions); 252 } 253 254 /** 255 * Specifies the working set of nodes for all node actions. 256 * @param nodes The new working set of nodes. Can be null or empty 257 * @see NodeAction#setNodes 258 */ 259 public void setNodes(Collection<Node> nodes) { 260 for (NodeAction action : nodeActions) { 261 action.setNodes(nodes); 262 } 263 } 264 265 /** 266 * Specifies the working set of ways for all way actions. 267 * @param ways The new working set of ways. Can be null or empty 268 * @see WayAction#setWays 269 */ 270 public void setWays(Collection<Way> ways) { 271 for (WayAction action : wayActions) { 272 action.setWays(ways); 273 } 274 } 275 276 /** 277 * Specifies the working set of relations for all relation actions. 278 * @param relations The new working set of relations. Can be null or empty 279 * @see RelationAction#setRelations 280 */ 281 public void setRelations(Collection<Relation> relations) { 282 for (RelationAction action : relationActions) { 283 action.setRelations(relations); 284 } 285 } 286 287 /** 288 * Replies the "Select relation (add)" action. 289 * @return the "Select relation (add)" action, if previously enabled, {@code null} otherwise. 290 * @see #enableAddRelationToSelectionAction 291 */ 292 public final SelectRelationAction getAddRelationToSelectionAction() { 293 return addRelationToSelectionAction; 294 } 295 296 /** 297 * Replies the "Select members (add)" action. 298 * @return the "Select members (add)" action, if previously enabled, {@code null} otherwise. 299 * @see #enableAddMembersToSelectionAction 300 */ 301 public final SelectMembersAction getAddMembersToSelectionAction() { 302 return addMembersToSelectionAction; 303 } 304 305 /** 306 * Replies the "Select relation" action. 307 * @return the "Select relation" action, if previously enabled, {@code null} otherwise. 308 * @see #enableSelectRelationAction 309 */ 310 public final SelectRelationAction getSelectRelationAction() { 311 return selectRelationAction; 312 } 313 314 /** 315 * Replies the "Select in relation list" action. 316 * @return the "Select in relation list" action, if previously enabled, {@code null} otherwise. 317 * @see #enableSelectInRelationListAction 318 */ 319 public final SelectInRelationListAction getSelectInRelationListAction() { 320 return selectInRelationListAction; 321 } 322 323 /** 324 * Replies the "Edit relation" action. 325 * @return the "Edit relation" action, if previously enabled, {@code null} otherwise. 326 * @see #enableEditRelationAction 327 */ 328 public final EditRelationAction getEditRelationAction() { 329 return editRelationAction; 330 } 331 332 /** 333 * Replies the "Select members" action. 334 * @return the "Select members" action, if previously enabled, {@code null} otherwise. 335 * @see #enableSelectMembersAction 336 */ 337 public final SelectMembersAction getSelectMembersAction() { 338 return selectMembersAction; 339 } 340 341 /** 342 * Replies the "Download members" action. 343 * @return the "Download members" action, if previously enabled, {@code null} otherwise. 344 * @see #enableDownloadMembersAction 345 */ 346 public final DownloadMembersAction getDownloadMembersAction() { 347 return downloadMembersAction; 348 } 349 350 /** 351 * Replies the "Download incomplete members" action. 352 * @return the "Download incomplete members" action, if previously enabled, {@code null} otherwise. 353 * @see #enableDownloadIncompleteMembersAction 354 */ 355 public final DownloadSelectedIncompleteMembersAction getDownloadSelectedIncompleteMembersAction() { 356 return downloadIncompleteMembersAction; 357 } 358 } -
core/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
21 21 22 22 import javax.swing.AbstractAction; 23 23 import javax.swing.AbstractListModel; 24 import javax.swing.Action;25 24 import javax.swing.DefaultListSelectionModel; 26 25 import javax.swing.JComponent; 27 26 import javax.swing.JList; 28 import javax.swing.JMenuItem;29 27 import javax.swing.JPanel; 30 28 import javax.swing.JPopupMenu; 31 29 import javax.swing.JScrollPane; … … 38 36 import javax.swing.event.DocumentListener; 39 37 import javax.swing.event.ListSelectionEvent; 40 38 import javax.swing.event.ListSelectionListener; 41 import javax.swing.event.PopupMenuListener;42 39 43 40 import org.openstreetmap.josm.Main; 41 import org.openstreetmap.josm.actions.data.RelationAction; 44 42 import org.openstreetmap.josm.actions.relation.AddSelectionToRelations; 45 43 import org.openstreetmap.josm.actions.relation.DeleteRelationsAction; 46 import org.openstreetmap.josm.actions.relation.DownloadMembersAction;47 import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction;48 44 import org.openstreetmap.josm.actions.relation.DuplicateRelationAction; 49 45 import org.openstreetmap.josm.actions.relation.EditRelationAction; 50 import org.openstreetmap.josm.actions.relation.SelectMembersAction;51 46 import org.openstreetmap.josm.actions.relation.SelectRelationAction; 52 47 import org.openstreetmap.josm.actions.search.SearchCompiler; 53 48 import org.openstreetmap.josm.data.osm.DataSet; … … 64 59 import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent; 65 60 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 66 61 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 62 import org.openstreetmap.josm.gui.DataActionPopupMenuHandler; 67 63 import org.openstreetmap.josm.gui.DefaultNameFormatter; 68 64 import org.openstreetmap.josm.gui.MapView; 69 65 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; … … 94 90 95 91 private final NewAction newAction; 96 92 97 /** the popup menu */ 98 private final RelationDialogPopupMenu popupMenu; 93 /** the popup menu and its handler */ 94 private final JPopupMenu popupMenu; 95 private final DataActionPopupMenuHandler popupMenuHandler; 99 96 100 97 private final JTextField filter; 101 98 102 // Actions 99 // Actions specific to this dialog (other may be found inside popupMenu.handler) 103 100 /** the edit action */ 104 101 private final EditRelationAction editAction = new EditRelationAction(); 105 102 /** the delete action */ 106 103 private final DeleteRelationsAction deleteRelationsAction = new DeleteRelationsAction(); 107 104 /** the duplicate action */ 108 105 private final DuplicateRelationAction duplicateAction = new DuplicateRelationAction(); 109 private final DownloadMembersAction downloadMembersAction = new DownloadMembersAction(); 110 private final DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction(); 111 private final SelectMembersAction selectMemebersAction = new SelectMembersAction(false); 112 private final SelectMembersAction addMembersToSelectionAction = new SelectMembersAction(true); 113 private final SelectRelationAction selectRelationAction = new SelectRelationAction(false); 114 private final SelectRelationAction addRelationToSelectionAction = new SelectRelationAction(true); 115 /** add all selected primitives to the given realtions */ 106 /** add all selected primitives to the given relations */ 116 107 private final AddSelectionToRelations addSelectionToRelations = new AddSelectionToRelations(); 117 108 118 109 /** … … 153 144 updateActionsRelationLists(); 154 145 } 155 146 }); 147 148 // Create popup menu and relation actions 149 popupMenu = new JPopupMenu(); 150 popupMenuHandler = setupPopupMenuHandler(); 151 152 SelectRelationAction selectRelationAction = popupMenuHandler.getSelectRelationAction(); 156 153 157 154 JPanel pane = new JPanel(new BorderLayout()); 158 155 pane.add(filter, BorderLayout.NORTH); … … 174 171 // Select relation on Ctrl-Enter 175 172 InputMapUtils.addEnterAction(displaylist, selectRelationAction); 176 173 177 popupMenu = new RelationDialogPopupMenu();178 179 174 // Edit relation on Ctrl-Enter 180 175 displaylist.getActionMap().put("edit", editAction); 181 176 displaylist.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK), "edit"); … … 185 180 186 181 // inform all actions about list of relations they need 187 182 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); 183 List<Relation> rels = model.getSelectedRelations(); 184 for (RelationAction relAction : popupMenuHandler.getRelationActions()) { 185 if (relAction == popupMenuHandler.getDownloadMembersAction()) { 186 relAction.setRelations(model.getSelectedNonNewRelations()); 187 } else if (relAction == popupMenuHandler.getDownloadSelectedIncompleteMembersAction()) { 188 relAction.setRelations(model.getSelectedRelationsWithIncompleteMembers()); 189 } else { 190 relAction.setRelations(rels); 191 } 192 } 204 193 } 205 194 206 195 @Override public void showNotify() { … … 655 644 } 656 645 } 657 646 658 class RelationDialogPopupMenu extends JPopupMenu{659 660 public RelationDialogPopupMenu() {661 662 add(downloadMembersAction);647 private final DataActionPopupMenuHandler setupPopupMenuHandler() { 648 DataActionPopupMenuHandler handler = new DataActionPopupMenuHandler(popupMenu); 649 650 // -- download members action 651 handler.enableDownloadMembersAction(); 663 652 664 665 add(downloadSelectedIncompleteMembersAction);653 // -- download incomplete members action 654 handler.enableDownloadIncompleteMembersAction(); 666 655 667 656 handler.addSeparator(); 668 657 669 670 add(selectMemebersAction);671 add(addMembersToSelectionAction);658 // -- select members action 659 handler.enableSelectMembersAction(); 660 handler.enableAddMembersToSelectionAction(); 672 661 673 674 add(selectRelationAction);675 add(addRelationToSelectionAction);662 // -- select action 663 handler.enableSelectRelationAction(); 664 handler.enableAddRelationToSelectionAction(); 676 665 677 666 handler.addSeparator(); 678 667 679 add(addSelectionToRelations); 680 } 668 handler.addAction(addSelectionToRelations); 669 670 return handler; 681 671 } 682 672 683 673 /* ---------------------------------------------------------------------------------- */ 684 /* Methods that can be called from plugins 674 /* Methods that can be called from plugins */ 685 675 /* ---------------------------------------------------------------------------------- */ 686 676 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); 677 public DataActionPopupMenuHandler getPopupMenuHandler() { 678 return popupMenuHandler; 701 679 } 702 680 703 681 public Collection<Relation> getSelectedRelations() { -
core/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
23 23 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; 29 28 import javax.swing.JMenuItem; … … 34 33 import javax.swing.event.ListDataListener; 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; 40 38 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; 39 import org.openstreetmap.josm.actions.data.RelationAction; 44 40 import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting; 45 41 import org.openstreetmap.josm.data.SelectionChangedListener; 46 42 import org.openstreetmap.josm.data.osm.Node; … … 62 58 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent; 63 59 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent; 64 60 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 61 import org.openstreetmap.josm.gui.DataActionPopupMenuHandler; 65 62 import org.openstreetmap.josm.gui.DefaultNameFormatter; 66 63 import org.openstreetmap.josm.gui.MapView; 67 64 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener; … … 87 84 private SearchAction actSearch; 88 85 private ZoomToJOSMSelectionAction actZoomToJOSMSelection; 89 86 private ZoomToListSelection actZoomToListSelection; 90 private SelectInRelationListAction actSetRelationSelection;91 private EditRelationAction actEditRelationSelection;92 private DownloadSelectedIncompleteMembersAction actDownloadSelectedIncompleteMembers;93 87 94 private SelectionPopup popupMenu; 88 /** the popup menu and its handler */ 89 private final ListPopupMenu popupMenu; 90 private final DataActionPopupMenuHandler popupMenuHandler; 95 91 96 92 /** 97 93 * Builds the content panel for this dialog … … 143 139 model.addListDataListener(actZoomToJOSMSelection); 144 140 145 141 actZoomToListSelection = new ZoomToListSelection(); 146 actSetRelationSelection = new SelectInRelationListAction(); 147 actEditRelationSelection = new EditRelationAction();148 actDownloadSelectedIncompleteMembers = new DownloadSelectedIncompleteMembersAction();142 143 popupMenu = new ListPopupMenu(lstPrimitives); 144 popupMenuHandler = setupPopupMenuHandler(); 149 145 150 146 lstPrimitives.addListSelectionListener(new ListSelectionListener() { 151 147 @Override 152 148 public void valueChanged(ListSelectionEvent e) { 153 149 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); 150 Collection<OsmPrimitive> selection = model.getSelected(); 151 popupMenuHandler.setNodes(OsmPrimitive.getFilteredList(selection, Node.class)); 152 popupMenuHandler.setWays(OsmPrimitive.getFilteredList(selection, Way.class)); 153 List<Relation> rels = OsmPrimitive.getFilteredList(selection, Relation.class); 154 for (RelationAction relAction : popupMenuHandler.getRelationActions()) { 155 if (relAction == popupMenuHandler.getDownloadSelectedIncompleteMembersAction()) { 156 relAction.setRelations(model.getSelectedRelationsWithIncompleteMembers()); 157 } else { 158 relAction.setRelations(rels); 159 } 160 } 160 161 } 161 162 }); 162 163 163 164 lstPrimitives.addMouseListener(new SelectionPopupMenuLauncher()); 164 165 lstPrimitives.addMouseListener(new DblClickHandler()); 165 166 166 popupMenu = new SelectionPopup(lstPrimitives);167 167 InputMapUtils.addEnterAction(lstPrimitives, actZoomToListSelection); 168 168 } 169 169 … … 220 220 } 221 221 } 222 222 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 } 223 private final DataActionPopupMenuHandler setupPopupMenuHandler() { 224 DataActionPopupMenuHandler handler = new DataActionPopupMenuHandler(popupMenu); 225 handler.addAction(actZoomToJOSMSelection); 226 handler.addAction(actZoomToListSelection); 227 handler.addSeparator(); 228 handler.enableSelectInRelationListAction(); 229 handler.enableEditRelationAction(); 230 handler.addSeparator(); 231 handler.enableDownloadIncompleteMembersAction(); 232 return handler; 237 233 } 238 234 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); 235 public DataActionPopupMenuHandler getPopupMenuActionHandler() { 236 return popupMenuHandler; 253 237 } 254 238 255 239 public Collection<OsmPrimitive> getSelectedPrimitives() { -
core/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
51 51 52 52 import org.openstreetmap.josm.Main; 53 53 import org.openstreetmap.josm.actions.JosmAction; 54 import org.openstreetmap.josm.actions.relation.DownloadSelectedIncompleteMembersAction;55 import org.openstreetmap.josm.actions.relation.SelectMembersAction;56 import org.openstreetmap.josm.actions.relation.SelectRelationAction;57 54 import org.openstreetmap.josm.actions.search.SearchAction.SearchMode; 58 55 import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting; 59 56 import org.openstreetmap.josm.command.ChangeCommand; … … 72 69 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 73 70 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 74 71 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 72 import org.openstreetmap.josm.gui.DataActionPopupMenuHandler; 75 73 import org.openstreetmap.josm.gui.DefaultNameFormatter; 76 74 import org.openstreetmap.josm.gui.ExtendedDialog; 77 75 import org.openstreetmap.josm.gui.MapFrame; … … 110 108 * @author imi 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 117 117 /** … … 133 133 */ 134 134 private final JTable membershipTable = new JTable(membershipData); 135 135 136 private JPopupMenu propertyMenu;137 private JPopupMenu membershipMenu;136 private final JPopupMenu propertyMenu = new JPopupMenu(); 137 private final JPopupMenu membershipMenu = new JPopupMenu(); 138 138 139 139 private final Map<String, Map<String, Integer>> valueCount = new TreeMap<String, Map<String, Integer>>(); 140 140 /** … … 156 156 private final JosmAction[] josmActions = new JosmAction[]{addAction, editAction, deleteAction}; 157 157 158 158 // relation actions 159 private final DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction(); 160 private final SelectRelationAction addRelationToSelectionAction = new SelectRelationAction(true); 161 private final SelectMembersAction addMembersToSelectionAction = new SelectMembersAction(true); 162 private final SelectRelationAction selectRelationAction = new SelectRelationAction(false); 159 private final DataActionPopupMenuHandler membershipMenuHandler = new DataActionPopupMenuHandler(membershipMenu); 163 160 164 161 /** 165 162 * The Add button (needed to be able to disable it) … … 201 198 202 199 /** 203 200 * Create a new PropertiesDialog 201 * @param mapFrame The parent map fram 204 202 */ 205 203 public PropertiesDialog(MapFrame mapFrame) { 206 204 super(tr("Properties/Memberships"), "propertiesdialog", tr("Properties for selected objects."), … … 369 367 */ 370 368 private void setupMembershipMenu() { 371 369 // 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); 370 membershipMenuHandler.enableAddRelationToSelectionAction(); 371 membershipMenuHandler.enableSelectRelationAction(); 372 membershipMenuHandler.enableAddMembersToSelectionAction(); 373 membershipMenuHandler.enableDownloadIncompleteMembersAction(); 377 374 membershipMenu.addSeparator(); 378 375 membershipMenu.add(helpAction); 379 376 … … 388 385 membershipTable.changeSelection(row, 0, false, false); 389 386 idx = new int[]{row}; 390 387 } 391 List<Relation> rels = new ArrayList<Relation>(10);388 List<Relation> rels = new ArrayList<Relation>(); 392 389 for (int i: idx) { 393 390 Relation r = (Relation) (membershipData.getValueAt(i, 0)); 394 391 rels.add(r); 395 392 } 396 selectRelationAction.setRelations(rels); 397 addRelationToSelectionAction.setRelations(rels); 398 addMembersToSelectionAction.setRelations(rels); 399 downloadSelectedIncompleteMembersAction.setRelations(rels); 393 membershipMenuHandler.setRelations(rels); 400 394 membershipMenu.show(membershipTable, p.x, p.y-3); 401 395 } 402 396 }); … … 406 400 * creates the popup menu @field propertyMenu and its launcher on property table 407 401 */ 408 402 private void setupPropertiesMenu() { 409 propertyMenu = new JPopupMenu();410 403 propertyMenu.add(pasteValueAction); 411 404 propertyMenu.add(copyValueAction); 412 405 propertyMenu.add(copyKeyValueAction); … … 720 713 map.size() > 1 ? "" : map.keySet().iterator().next()); 721 714 } 722 715 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); 716 public DataActionPopupMenuHandler getMembershipPopupMenuHandler() { 717 return membershipMenuHandler; 737 718 } 738 719 739 720 public IRelation getSelectedMembershipRelation() {