Ignore:
Timestamp:
2016-07-28T01:24:39+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13223 - Minor command class fixes (patch by michael2402, modified) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm/command
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java

    r9371 r10663  
    3838        this.way = way;
    3939        this.newNodes = newNodes;
     40        if (newNodes.isEmpty()) {
     41            throw new IllegalArgumentException("Cannot set nodes to be an empty list.");
     42        }
    4043    }
    4144
     
    5558    @Override
    5659    public String getDescriptionText() {
    57         return tr("Changed nodes of {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
     60        return tr("Change nodes of {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
    5861    }
    5962
  • trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java

    r10308 r10663  
    156156            String msg;
    157157            Map.Entry<String, String> entry = tags.entrySet().iterator().next();
    158             if (entry.getValue() == null) {
     158            if (entry.getValue() == null || entry.getValue().isEmpty()) {
    159159                switch(OsmPrimitiveType.from(primitive)) {
    160160                case NODE: msg = marktr("Remove \"{0}\" for node ''{1}''"); break;
     
    175175        } else if (objects.size() > 1 && tags.size() == 1) {
    176176            Map.Entry<String, String> entry = tags.entrySet().iterator().next();
    177             if (entry.getValue() == null) {
     177            if (entry.getValue() == null || entry.getValue().isEmpty()) {
    178178                /* I18n: plural form for objects, but value < 2 not possible! */
    179179                text = trn("Remove \"{0}\" for {1} object", "Remove \"{0}\" for {1} objects", objects.size(), entry.getKey(), objects.size());
     
    186186            boolean allnull = true;
    187187            for (Map.Entry<String, String> tag : this.tags.entrySet()) {
    188                 if (tag.getValue() != null) {
     188                if (tag.getValue() != null && !tag.getValue().isEmpty()) {
    189189                    allnull = false;
    190190                    break;
     
    226226                    return Collections.singleton(osm);
    227227                }
    228 
    229228            });
    230229        }
  • trunk/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java

    r9371 r10663  
    6666            return false; // save old
    6767        for (OsmPrimitive osm : objects) {
    68             if (osm.hasKeys()) {
     68            if (osm.hasKey(key) || osm.hasKey(newKey)) {
    6969                osm.setModified(true);
    7070                String oldValue = osm.get(key);
     
    8787            NameVisitor v = new NameVisitor();
    8888            objects.get(0).accept(v);
    89             text += ' '+tr(v.className)+' '+v.name;
     89            text += " "+tr(v.className)+" "+v.name;
    9090        } else {
    91             text += ' '+objects.size()+' '+trn("object", "objects", objects.size());
     91            text += " "+objects.size()+" "+trn("object", "objects", objects.size());
    9292        }
    9393        return text;
     
    108108        for (final OsmPrimitive osm : objects) {
    109109            osm.accept(v);
     110            final String name = v.name;
     111            final Icon icon = v.icon;
    110112            children.add(new PseudoCommand() {
    111113                @Override
    112114                public String getDescriptionText() {
    113                     return v.name;
     115                    return name;
    114116                }
    115117
    116118                @Override
    117119                public Icon getDescriptionIcon() {
    118                     return v.icon;
     120                    return icon;
    119121                }
    120122
  • trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java

    r10250 r10663  
    4949    public boolean executeCommand() {
    5050        if (position < 0 || position >= relation.getMembersCount())
    51             return false;
     51            return true;
    5252
    5353        oldRole = relation.getMember(position).getRole();
     
    6262    @Override
    6363    public void undoCommand() {
    64         relation.setMember(position, new RelationMember(oldRole, relation.getMember(position).getMember()));
    65         if (oldModified != null) {
    66             relation.setModified(oldModified);
     64        if (position >= 0 && position < relation.getMembersCount()) {
     65            relation.setMember(position, new RelationMember(oldRole, relation.getMember(position).getMember()));
     66            if (oldModified != null) {
     67                relation.setModified(oldModified);
     68            }
    6769        }
    6870    }
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r10599 r10663  
    188188     * the removed layer)
    189189     *
    190      * @param oldLayer the old layer
    191      * @return true if this command
     190     * @param oldLayer the old layer that was removed
     191     * @return true if this command is invalid after that layer is removed.
    192192     */
    193193    public boolean invalidBecauselayerRemoved(Layer oldLayer) {
    194         if (!(oldLayer instanceof OsmDataLayer))
    195             return false;
    196194        return layer == oldLayer;
    197195    }
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r10216 r10663  
    5151 */
    5252public class DeleteCommand extends Command {
     53    private static final class DeleteChildCommand implements PseudoCommand {
     54        private final OsmPrimitive osm;
     55
     56        private DeleteChildCommand(OsmPrimitive osm) {
     57            this.osm = osm;
     58        }
     59
     60        @Override
     61        public String getDescriptionText() {
     62            return tr("Deleted ''{0}''", osm.getDisplayName(DefaultNameFormatter.getInstance()));
     63        }
     64
     65        @Override
     66        public Icon getDescriptionIcon() {
     67            return ImageProvider.get(osm.getDisplayType());
     68        }
     69
     70        @Override
     71        public Collection<? extends OsmPrimitive> getParticipatingPrimitives() {
     72            return Collections.singleton(osm);
     73        }
     74
     75        @Override
     76        public String toString() {
     77            return "DeleteChildCommand [osm=" + osm + "]";
     78        }
     79    }
     80
    5381    /**
    5482     * The primitives that get deleted.
     
    6593    public DeleteCommand(Collection<? extends OsmPrimitive> data) {
    6694        CheckParameterUtil.ensureParameterNotNull(data, "data");
    67         if (data.isEmpty())
    68             throw new IllegalArgumentException(tr("At least one object to delete required, got empty collection"));
    6995        this.toDelete = data;
    7096        checkConsistency();
     
    106132        super(layer);
    107133        CheckParameterUtil.ensureParameterNotNull(data, "data");
    108         if (data.isEmpty())
    109             throw new IllegalArgumentException(tr("At least one object to delete required, got empty collection"));
    110134        this.toDelete = data;
    111135        checkConsistency();
     
    113137
    114138    private void checkConsistency() {
     139        if (toDelete.isEmpty()) {
     140            throw new IllegalArgumentException(tr("At least one object to delete required, got empty collection"));
     141        }
    115142        for (OsmPrimitive p : toDelete) {
    116143            if (p == null) {
     
    216243            List<PseudoCommand> children = new ArrayList<>(toDelete.size());
    217244            for (final OsmPrimitive osm : toDelete) {
    218                 children.add(new PseudoCommand() {
    219 
    220                     @Override public String getDescriptionText() {
    221                         return tr("Deleted ''{0}''", osm.getDisplayName(DefaultNameFormatter.getInstance()));
    222                     }
    223 
    224                     @Override public Icon getDescriptionIcon() {
    225                         return ImageProvider.get(osm.getDisplayType());
    226                     }
    227 
    228                     @Override public Collection<? extends OsmPrimitive> getParticipatingPrimitives() {
    229                         return Collections.singleton(osm);
    230                     }
    231 
    232                 });
     245                children.add(new DeleteChildCommand(osm));
    233246            }
    234247            return children;
     
    441454    }
    442455
     456    /**
     457     * Create a command that deletes a single way segment. The way may be split by this.
     458     * @param layer The layer the segment is in.
     459     * @param ws The way segment that should be deleted
     460     * @return A matching command to safely delete that segment.
     461     */
    443462    public static Command deleteWaySegment(OsmDataLayer layer, WaySegment ws) {
    444463        if (ws.way.getNodesCount() < 3)
  • trunk/src/org/openstreetmap/josm/command/MoveCommand.java

    r10378 r10663  
    243243    public Collection<Node> getParticipatingPrimitives() {
    244244        return nodes;
     245    }
     246
     247    /**
     248     * Gets the offset.
     249     * @return The current offset.
     250     */
     251    protected EastNorth getOffset() {
     252        return new EastNorth(x, y);
    245253    }
    246254
  • trunk/src/org/openstreetmap/josm/command/RotateCommand.java

    r10378 r10663  
    3939     * @param currentEN cuurent eats/north
    4040     */
    41     public RotateCommand(Collection<OsmPrimitive> objects, EastNorth currentEN) {
     41    public RotateCommand(Collection<? extends OsmPrimitive> objects, EastNorth currentEN) {
    4242        super(objects);
    4343
     
    7171
    7272    /**
     73     * Set the rotation angle.
     74     * @param rotationAngle The rotate angle
     75     */
     76    protected void setRotationAngle(double rotationAngle) {
     77        this.rotationAngle = rotationAngle;
     78    }
     79
     80    /**
    7381     * Rotate nodes.
    7482     */
    7583    @Override
    7684    protected void transformNodes() {
     85        double cosPhi = Math.cos(rotationAngle);
     86        double sinPhi = Math.sin(rotationAngle);
    7787        for (Node n : nodes) {
    78             double cosPhi = Math.cos(rotationAngle);
    79             double sinPhi = Math.sin(rotationAngle);
    8088            EastNorth oldEastNorth = oldStates.get(n).getEastNorth();
    8189            double x = oldEastNorth.east() - pivot.east();
  • trunk/src/org/openstreetmap/josm/command/ScaleCommand.java

    r10378 r10663  
    3535     * @param currentEN cuurent eats/north
    3636     */
    37     public ScaleCommand(Collection<OsmPrimitive> objects, EastNorth currentEN) {
     37    public ScaleCommand(Collection<? extends OsmPrimitive> objects, EastNorth currentEN) {
    3838        super(objects);
    3939
     
    5858        double startDistance = pivot.distance(startEN);
    5959        double currentDistance = pivot.distance(currentEN);
    60         scalingFactor = Math.cos(startAngle-endAngle) * currentDistance / startDistance;
     60        setScalingFactor(Math.cos(startAngle-endAngle) * currentDistance / startDistance);
    6161        transformNodes();
     62    }
     63
     64    /**
     65     * Set the scaling factor
     66     * @param scalingFactor The scaling factor.
     67     */
     68    protected void setScalingFactor(double scalingFactor) {
     69        this.scalingFactor = scalingFactor;
    6270    }
    6371
  • trunk/src/org/openstreetmap/josm/command/SelectCommand.java

    r10364 r10663  
    55
    66import java.util.Collection;
     7import java.util.Collections;
     8import java.util.HashSet;
    79import java.util.Objects;
    810
     
    2830     */
    2931    public SelectCommand(Collection<OsmPrimitive> newSelection) {
    30         this.newSelection = newSelection;
     32        if (newSelection == null || newSelection.isEmpty()) {
     33            this.newSelection = Collections.emptySet();
     34        } else {
     35            this.newSelection = new HashSet<>(newSelection);
     36        }
    3137    }
    3238
  • trunk/src/org/openstreetmap/josm/command/TransformNodesCommand.java

    r10248 r10663  
    4949     * @param objects objects to fetch nodes from
    5050     */
    51     public TransformNodesCommand(Collection<OsmPrimitive> objects) {
     51    public TransformNodesCommand(Collection<? extends OsmPrimitive> objects) {
    5252        this.nodes = AllNodesVisitor.getAllNodes(objects);
    5353        storeOldState();
Note: See TracChangeset for help on using the changeset viewer.