Changeset 5794 in josm for trunk/src/org


Ignore:
Timestamp:
2013-03-22T20:22:57+01:00 (12 years ago)
Author:
Don-vip
Message:

see #7846 - fix copyright + javadoc + potential NPEs

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.
    12package org.openstreetmap.josm.actions.relation;
    2 
    33
    44import java.util.Collection;
    55import java.util.Collections;
     6
    67import javax.swing.AbstractAction;
     8
    79import org.openstreetmap.josm.data.osm.Relation;
    810
     
    1012 * Ancestor for all actions that want to work with relation collection and
    1113 * to be disabled is the collection is empty
     14 * @since 5793
    1215 */
    1316public abstract class AbstractRelationAction extends AbstractAction {
     
    1518   
    1619    /**
    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
    1822     */
    1923    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.
    12package org.openstreetmap.josm.actions.relation;
    23
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
     5import static org.openstreetmap.josm.tools.I18n.tr;
     6
    37import 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;
    78
    89import org.openstreetmap.josm.Main;
     
    1011import org.openstreetmap.josm.tools.ImageProvider;
    1112
    12 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    13 import static org.openstreetmap.josm.tools.I18n.tr;
    14 
    1513/**
    1614 * The action for downloading members of relations
     15 * @since 5793
    1716 */
    1817public class DownloadMembersAction extends AbstractRelationAction {
    1918
     19    /**
     20     * Constructs a new <code>DownloadMembersAction</code>.
     21     */
    2022    public DownloadMembersAction() {
    2123        putValue(SHORT_DESCRIPTION, tr("Download all members of the selected relations"));
     
    2628   
    2729    public void actionPerformed(ActionEvent e) {
    28         if (!isEnabled() || relations.isEmpty()) return;
     30        if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.mapView==null) return;
    2931        Main.worker.submit(new DownloadRelationTask(relations, Main.map.mapView.getEditLayer()));
    3032    }
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadSelectedIncompleteMembersAction.java

    r5793 r5794  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.actions.relation;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    25
    36import java.awt.event.ActionEvent;
     
    58import java.util.HashSet;
    69import 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 
    1110
    1211import org.openstreetmap.josm.Main;
     
    1615import org.openstreetmap.josm.tools.ImageProvider;
    1716
    18 import static org.openstreetmap.josm.tools.I18n.tr;
    19 
    2017/**
    2118 * Action for downloading incomplete members of selected relations
     19 * @since 5793
    2220 */
    2321public class DownloadSelectedIncompleteMembersAction extends AbstractRelationAction {
    2422
     23    /**
     24     * Constructs a new <code>DownloadSelectedIncompleteMembersAction</code>.
     25     */
    2526    public DownloadSelectedIncompleteMembersAction() {
    2627        putValue(SHORT_DESCRIPTION, tr("Download incomplete members of selected relations"));
     
    2930    }
    3031
     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     */
    3137    public Set<OsmPrimitive> buildSetOfIncompleteMembers(Collection<Relation> rels) {
    3238        Set<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
     
    3844
    3945    public void actionPerformed(ActionEvent e) {
    40         if (!isEnabled() || relations.isEmpty()) return;
     46        if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.mapView==null) return;
    4147        Main.worker.submit(new DownloadRelationMemberTask(
    4248                relations,
     
    4450                Main.map.mapView.getEditLayer()));
    4551    }
    46 
    4752}
  • trunk/src/org/openstreetmap/josm/actions/relation/EditRelationAction.java

    r5793 r5794  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.actions.relation;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    25
    36import java.awt.event.ActionEvent;
    47import java.util.Collection;
    58import 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;
     9import java.util.Set;
     10
    1211import org.openstreetmap.josm.Main;
    1312import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    1514import org.openstreetmap.josm.data.osm.RelationMember;
    1615import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    17 import static org.openstreetmap.josm.tools.I18n.tr;
     16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1817import org.openstreetmap.josm.tools.ImageProvider;
    1918
    2019/**
    2120 * The action for editing a relation
     21 * @since 5793
    2222 */
    2323public class EditRelationAction extends AbstractRelationAction  {
     24
     25    /**
     26     * Constructs a new <code>EditRelationAction</code>.
     27     */
    2428    public EditRelationAction() {
    2529        putValue(NAME, tr("Edit"));
     
    2832    }
    2933
    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                }
    3650            }
    3751        }
     
    3953    }
    4054
     55    /**
     56     * Launches relation editor for the given relation.
     57     * @param toEdit The relation to edit
     58     */
    4159    public static void launchEditor(Relation toEdit) {
    42         if (toEdit == null) return;
     60        if (toEdit == null || Main.map==null || Main.map.mapView==null) return;
    4361        RelationEditor.getEditor(Main.map.mapView.getEditLayer(), toEdit,
    4462                getMembersForCurrentSelection(toEdit)).setVisible(true);
     
    5573        setEnabled( relations.size()==1 );
    5674    }
    57    
    58    
    5975}
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectInRelationListAction.java

    r5793 r5794  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.actions.relation;
    23
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
    36import 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 
    87
    98import org.openstreetmap.josm.Main;
    109import org.openstreetmap.josm.tools.ImageProvider;
    1110
    12 import static org.openstreetmap.josm.tools.I18n.tr;
    13 
    1411/**
    1512 * The action for activating a relation in relation list dialog
     13 * @since 5793
    1614 */
    1715public class SelectInRelationListAction extends AbstractRelationAction {
     16
     17    /**
     18     * Constructs a new <code>SelectInRelationListAction</code>.
     19     */
    1820    public SelectInRelationListAction() {
    1921        putValue(NAME, tr("Select in relation list"));
     
    2325
    2426    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);
    2829    }
    2930}
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectMembersAction.java

    r5793 r5794  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.actions.relation;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    25
    36import java.awt.event.ActionEvent;
    47import 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;
    88
    99import org.openstreetmap.josm.Main;
     
    1212import org.openstreetmap.josm.tools.ImageProvider;
    1313
    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 */
     18public class SelectMembersAction extends AbstractRelationAction {
     19   
     20    private final boolean add;
    1521
    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     */
    2126    public SelectMembersAction(boolean add) {
    2227        putValue(SHORT_DESCRIPTION,add ? tr("Add the members of all selected relations to current selection")
     
    2934    @Override
    3035    public void actionPerformed(ActionEvent e) {
    31         if (!isEnabled() || relations.isEmpty()) return;
     36        if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.mapView==null) return;
    3237       
    3338        HashSet<OsmPrimitive> members = new HashSet<OsmPrimitive>();
    34         for(Relation r: relations) {
     39        for (Relation r: relations) {
    3540            members.addAll(r.getMemberPrimitives());
    3641        }
    37         if(add) {
     42        if (add) {
    3843            Main.map.mapView.getEditLayer().data.addSelected(members);
    3944        } else {
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectRelationAction.java

    r5793 r5794  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.actions.relation;
    23
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
    36import 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
    78import org.openstreetmap.josm.Main;
    89import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    910import org.openstreetmap.josm.tools.ImageProvider;
    1011
    11 import static org.openstreetmap.josm.tools.I18n.tr;
    12 
    1312/**
    1413 * Sets the current selection to specified list of relations
     14 * @since 5793
    1515 */
    1616public class SelectRelationAction extends AbstractRelationAction {
    17     boolean add;
     17   
     18    private final boolean add;
    1819
     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     */
    1924    public SelectRelationAction(boolean add) {
    2025        putValue(SHORT_DESCRIPTION, add ? tr("Add the selected relations to the current selection") : tr("Set the current selection to the list of selected relations"));
     
    2530
    2631    public void actionPerformed(ActionEvent e) {
    27         if (!isEnabled() || relations.isEmpty()) return;
     32        if (!isEnabled() || relations.isEmpty() || Main.map==null || Main.map.mapView==null) return;
    2833        OsmDataLayer editLayer = Main.map.mapView.getEditLayer();
    2934        if (editLayer==null || editLayer.data==null) return;
Note: See TracChangeset for help on using the changeset viewer.