Changeset 5794 in josm for trunk/src/org
- Timestamp:
- 2013-03-22T20:22:57+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/actions/relation
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/relation/AbstractRelationAction.java
r5793 r5794 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.actions.relation; 2 3 3 4 4 import java.util.Collection; 5 5 import java.util.Collections; 6 6 7 import javax.swing.AbstractAction; 8 7 9 import org.openstreetmap.josm.data.osm.Relation; 8 10 … … 10 12 * Ancestor for all actions that want to work with relation collection and 11 13 * to be disabled is the collection is empty 14 * @since 5793 12 15 */ 13 16 public abstract class AbstractRelationAction extends AbstractAction { … … 15 18 16 19 /** 17 * This fuction should be called to specify working set of relations 20 * Specifies the working set of relations. 21 * @param relations The new working set of relations. Can be null or empty 18 22 */ 19 23 public void setRelations(Collection<Relation> relations) { -
trunk/src/org/openstreetmap/josm/actions/relation/DownloadMembersAction.java
r5793 r5794 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.actions.relation; 2 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 3 7 import java.awt.event.ActionEvent; 4 import static javax.swing.Action.NAME;5 import static javax.swing.Action.SHORT_DESCRIPTION;6 import static javax.swing.Action.SMALL_ICON;7 8 8 9 import org.openstreetmap.josm.Main; … … 10 11 import org.openstreetmap.josm.tools.ImageProvider; 11 12 12 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;13 import static org.openstreetmap.josm.tools.I18n.tr;14 15 13 /** 16 14 * The action for downloading members of relations 15 * @since 5793 17 16 */ 18 17 public class DownloadMembersAction extends AbstractRelationAction { 19 18 19 /** 20 * Constructs a new <code>DownloadMembersAction</code>. 21 */ 20 22 public DownloadMembersAction() { 21 23 putValue(SHORT_DESCRIPTION, tr("Download all members of the selected relations")); … … 26 28 27 29 public void actionPerformed(ActionEvent e) { 28 if (!isEnabled() || relations.isEmpty() ) return;30 if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.mapView==null) return; 29 31 Main.worker.submit(new DownloadRelationTask(relations, Main.map.mapView.getEditLayer())); 30 32 } -
trunk/src/org/openstreetmap/josm/actions/relation/DownloadSelectedIncompleteMembersAction.java
r5793 r5794 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.actions.relation; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 2 5 3 6 import java.awt.event.ActionEvent; … … 5 8 import java.util.HashSet; 6 9 import java.util.Set; 7 import static javax.swing.Action.NAME;8 import static javax.swing.Action.SHORT_DESCRIPTION;9 import static javax.swing.Action.SMALL_ICON;10 11 10 12 11 import org.openstreetmap.josm.Main; … … 16 15 import org.openstreetmap.josm.tools.ImageProvider; 17 16 18 import static org.openstreetmap.josm.tools.I18n.tr;19 20 17 /** 21 18 * Action for downloading incomplete members of selected relations 19 * @since 5793 22 20 */ 23 21 public class DownloadSelectedIncompleteMembersAction extends AbstractRelationAction { 24 22 23 /** 24 * Constructs a new <code>DownloadSelectedIncompleteMembersAction</code>. 25 */ 25 26 public DownloadSelectedIncompleteMembersAction() { 26 27 putValue(SHORT_DESCRIPTION, tr("Download incomplete members of selected relations")); … … 29 30 } 30 31 32 /** 33 * Returns the set of incomplete members of the given relations. 34 * @param rels The relations to inspect. 35 * @return The set of incomplete members of the given relations. 36 */ 31 37 public Set<OsmPrimitive> buildSetOfIncompleteMembers(Collection<Relation> rels) { 32 38 Set<OsmPrimitive> ret = new HashSet<OsmPrimitive>(); … … 38 44 39 45 public void actionPerformed(ActionEvent e) { 40 if (!isEnabled() || relations.isEmpty() ) return;46 if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.mapView==null) return; 41 47 Main.worker.submit(new DownloadRelationMemberTask( 42 48 relations, … … 44 50 Main.map.mapView.getEditLayer())); 45 51 } 46 47 52 } -
trunk/src/org/openstreetmap/josm/actions/relation/EditRelationAction.java
r5793 r5794 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.actions.relation; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 2 5 3 6 import java.awt.event.ActionEvent; 4 7 import java.util.Collection; 5 8 import java.util.HashSet; 6 import javax.swing.AbstractAction; 7 import static javax.swing.Action.NAME; 8 import static javax.swing.Action.SHORT_DESCRIPTION; 9 import static javax.swing.Action.SMALL_ICON; 10 import javax.swing.event.ListSelectionEvent; 11 import javax.swing.event.ListSelectionListener; 9 import java.util.Set; 10 12 11 import org.openstreetmap.josm.Main; 13 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 15 14 import org.openstreetmap.josm.data.osm.RelationMember; 16 15 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 17 import static org.openstreetmap.josm.tools.I18n.tr;16 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 18 17 import org.openstreetmap.josm.tools.ImageProvider; 19 18 20 19 /** 21 20 * The action for editing a relation 21 * @since 5793 22 22 */ 23 23 public class EditRelationAction extends AbstractRelationAction { 24 25 /** 26 * Constructs a new <code>EditRelationAction</code>. 27 */ 24 28 public EditRelationAction() { 25 29 putValue(NAME, tr("Edit")); … … 28 32 } 29 33 30 public static Collection<RelationMember> getMembersForCurrentSelection(Relation r) { 31 Collection<RelationMember> members = new HashSet<RelationMember>(); 32 Collection<OsmPrimitive> selection = Main.map.mapView.getEditLayer().data.getSelected(); 33 for (RelationMember member: r.getMembers()) { 34 if (selection.contains(member.getMember())) { 35 members.add(member); 34 /** 35 * Returns the set of currently selected relation members for the given relation. 36 * @param r The relation to inspect 37 * @return The set of currently selected relation members for the given relation. 38 */ 39 public static Set<RelationMember> getMembersForCurrentSelection(Relation r) { 40 Set<RelationMember> members = new HashSet<RelationMember>(); 41 if (Main.map != null && Main.map.mapView != null) { 42 OsmDataLayer editLayer = Main.map.mapView.getEditLayer(); 43 if (editLayer != null && editLayer.data != null) { 44 Collection<OsmPrimitive> selection = editLayer.data.getSelected(); 45 for (RelationMember member: r.getMembers()) { 46 if (selection.contains(member.getMember())) { 47 members.add(member); 48 } 49 } 36 50 } 37 51 } … … 39 53 } 40 54 55 /** 56 * Launches relation editor for the given relation. 57 * @param toEdit The relation to edit 58 */ 41 59 public static void launchEditor(Relation toEdit) { 42 if (toEdit == null ) return;60 if (toEdit == null || Main.map==null || Main.map.mapView==null) return; 43 61 RelationEditor.getEditor(Main.map.mapView.getEditLayer(), toEdit, 44 62 getMembersForCurrentSelection(toEdit)).setVisible(true); … … 55 73 setEnabled( relations.size()==1 ); 56 74 } 57 58 59 75 } -
trunk/src/org/openstreetmap/josm/actions/relation/SelectInRelationListAction.java
r5793 r5794 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.actions.relation; 2 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 3 6 import java.awt.event.ActionEvent; 4 import static javax.swing.Action.NAME;5 import static javax.swing.Action.SHORT_DESCRIPTION;6 import static javax.swing.Action.SMALL_ICON;7 8 7 9 8 import org.openstreetmap.josm.Main; 10 9 import org.openstreetmap.josm.tools.ImageProvider; 11 10 12 import static org.openstreetmap.josm.tools.I18n.tr;13 14 11 /** 15 12 * The action for activating a relation in relation list dialog 13 * @since 5793 16 14 */ 17 15 public class SelectInRelationListAction extends AbstractRelationAction { 16 17 /** 18 * Constructs a new <code>SelectInRelationListAction</code>. 19 */ 18 20 public SelectInRelationListAction() { 19 21 putValue(NAME, tr("Select in relation list")); … … 23 25 24 26 public void actionPerformed(ActionEvent e) { 25 if (!isEnabled() || relations.isEmpty()) return; 26 if (Main.map.relationListDialog!=null) 27 Main.map.relationListDialog.selectRelations(relations); 27 if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.relationListDialog==null) return; 28 Main.map.relationListDialog.selectRelations(relations); 28 29 } 29 30 } -
trunk/src/org/openstreetmap/josm/actions/relation/SelectMembersAction.java
r5793 r5794 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.actions.relation; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 2 5 3 6 import java.awt.event.ActionEvent; 4 7 import java.util.HashSet; 5 import static javax.swing.Action.NAME;6 import static javax.swing.Action.SHORT_DESCRIPTION;7 import static javax.swing.Action.SMALL_ICON;8 8 9 9 import org.openstreetmap.josm.Main; … … 12 12 import org.openstreetmap.josm.tools.ImageProvider; 13 13 14 import static org.openstreetmap.josm.tools.I18n.tr; 14 /** 15 * Sets the current selection to the list of relations selected in this dialog 16 * @since 5793 17 */ 18 public class SelectMembersAction extends AbstractRelationAction { 19 20 private final boolean add; 15 21 16 /** 17 * Sets the current selection to the list of relations selected in this dialog 18 */ 19 public class SelectMembersAction extends AbstractRelationAction { 20 boolean add; 22 /** 23 * Constructs a new <code>SelectMembersAction</code>. 24 * @param add if <code>true</code>, the members will be added to current selection. If <code>false</code>, the members will replace the current selection. 25 */ 21 26 public SelectMembersAction(boolean add) { 22 27 putValue(SHORT_DESCRIPTION,add ? tr("Add the members of all selected relations to current selection") … … 29 34 @Override 30 35 public void actionPerformed(ActionEvent e) { 31 if (!isEnabled() || relations.isEmpty() ) return;36 if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.mapView==null) return; 32 37 33 38 HashSet<OsmPrimitive> members = new HashSet<OsmPrimitive>(); 34 for (Relation r: relations) {39 for (Relation r: relations) { 35 40 members.addAll(r.getMemberPrimitives()); 36 41 } 37 if (add) {42 if (add) { 38 43 Main.map.mapView.getEditLayer().data.addSelected(members); 39 44 } else { -
trunk/src/org/openstreetmap/josm/actions/relation/SelectRelationAction.java
r5793 r5794 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.actions.relation; 2 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 3 6 import java.awt.event.ActionEvent; 4 import static javax.swing.Action.NAME; 5 import static javax.swing.Action.SHORT_DESCRIPTION; 6 import static javax.swing.Action.SMALL_ICON; 7 7 8 import org.openstreetmap.josm.Main; 8 9 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 9 10 import org.openstreetmap.josm.tools.ImageProvider; 10 11 11 import static org.openstreetmap.josm.tools.I18n.tr;12 13 12 /** 14 13 * Sets the current selection to specified list of relations 14 * @since 5793 15 15 */ 16 16 public class SelectRelationAction extends AbstractRelationAction { 17 boolean add; 17 18 private final boolean add; 18 19 20 /** 21 * Constructs a new <code>SelectRelationAction</code>. 22 * @param add if <code>true</code>, the relation will be added to current selection. If <code>false</code>, the relation will replace the current selection. 23 */ 19 24 public SelectRelationAction(boolean add) { 20 25 putValue(SHORT_DESCRIPTION, add ? tr("Add the selected relations to the current selection") : tr("Set the current selection to the list of selected relations")); … … 25 30 26 31 public void actionPerformed(ActionEvent e) { 27 if (!isEnabled() || relations.isEmpty() ) return;32 if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.mapView==null) return; 28 33 OsmDataLayer editLayer = Main.map.mapView.getEditLayer(); 29 34 if (editLayer==null || editLayer.data==null) return;
Note:
See TracChangeset
for help on using the changeset viewer.