Changeset 5759 in josm for trunk/src/org


Ignore:
Timestamp:
2013-03-06T22:41:42+01:00 (12 years ago)
Author:
Don-vip
Message:

fix NPE if a SequenceCommand is created before an edit layer exists + fix warnings in Command class

File:
1 edited

Legend:

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

    r5266 r5759  
    11//License: GPL. Copyright 2007 by Immanuel Scholz and others
    22package org.openstreetmap.josm.command;
    3 
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    53
    64import java.awt.GridBagLayout;
     
    1614import javax.swing.JOptionPane;
    1715import javax.swing.JPanel;
    18 import javax.swing.tree.DefaultMutableTreeNode;
    19 import javax.swing.tree.MutableTreeNode;
    2016
    2117import org.openstreetmap.josm.Main;
     
    5955
    6056    /** the layer which this command is applied to */
    61     private OsmDataLayer layer;
    62 
     57    private final OsmDataLayer layer;
     58
     59    /**
     60     * Creates a new command in the context of the current edit layer, if any
     61     */
    6362    public Command() {
    64         this.layer = Main.map.mapView.getEditLayer();
     63        this.layer = Main.map != null && Main.map.mapView != null ? Main.map.mapView.getEditLayer() : null;
    6564    }
    6665
     
    7978     * Executes the command on the dataset. This implementation will remember all
    8079     * primitives returned by fillModifiedData for restoring them on undo.
     80     * @return true
    8181     */
    8282    public boolean executeCommand() {
     
    124124     * Lets other commands access the original version
    125125     * of the object. Usually for undoing.
     126     * @param osm The requested OSM object
     127     * @return The original version of the requested object, if any
    126128     */
    127129    public PrimitiveData getOrig(OsmPrimitive osm) {
    128         PrimitiveData o = cloneMap.get(osm);
    129         if (o != null)
    130             return o;
    131         for (OsmPrimitive t : cloneMap.keySet()) {
    132             PrimitiveData to = cloneMap.get(t);
    133         }
    134         return o;
     130        return cloneMap.get(osm);
    135131    }
    136132
Note: See TracChangeset for help on using the changeset viewer.