Changeset 5440 in josm


Ignore:
Timestamp:
Aug 13, 2012 2:37:03 AM (10 months ago)
Author:
Don-vip
Message:

fix #7716 - History shows same version number, wrong date, user, and CT for modified objects

Location:
trunk/src/org/openstreetmap/josm
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryNode.java

    r5346 r5440  
    1515 */ 
    1616public class HistoryNode extends HistoryOsmPrimitive { 
     17     
    1718    /** the coordinates. May be null for deleted nodes */ 
    18  
    1919    private LatLon coords; 
    2020 
    21     public HistoryNode(long id, long version, boolean visible, User user, long changesetId, Date timestamp, LatLon coords) { 
    22         super(id, version, visible, user, changesetId, timestamp); 
     21    /** 
     22     * Constructs a new {@code HistoryNode}. 
     23     *  
     24     * @param id the id (> 0 required) 
     25     * @param version the version (> 0 required) 
     26     * @param visible whether the node is still visible 
     27     * @param user the user (! null required) 
     28     * @param changesetId the changeset id (> 0 required) 
     29     * @param timestamp the timestamp (! null required) 
     30     * @param coords the coordinates 
     31     * @throws IllegalArgumentException if preconditions are violated 
     32     */ 
     33    public HistoryNode(long id, long version, boolean visible, User user, long changesetId, Date timestamp, LatLon coords) throws IllegalArgumentException { 
     34        this(id, version, visible, user, changesetId, timestamp, coords, true); 
     35    } 
     36 
     37    /** 
     38     * Constructs a new {@code HistoryNode} with a configurable checking of historic parameters. 
     39     * This is needed to build virtual HistoryNodes for modified nodes, which do not have a timestamp and a changeset id. 
     40     *  
     41     * @param id the id (> 0 required) 
     42     * @param version the version (> 0 required) 
     43     * @param visible whether the node is still visible 
     44     * @param user the user (! null required) 
     45     * @param changesetId the changeset id (> 0 required if {@code checkHistoricParams} is true) 
     46     * @param timestamp the timestamp (! null required if {@code checkHistoricParams} is true) 
     47     * @param coords the coordinates 
     48     * @param checkHistoricParams if true, checks values of {@code changesetId} and {@code timestamp} 
     49     * @throws IllegalArgumentException if preconditions are violated 
     50     * @since 5440 
     51     */ 
     52    public HistoryNode(long id, long version, boolean visible, User user, long changesetId, Date timestamp, LatLon coords, boolean checkHistoricParams) throws IllegalArgumentException { 
     53        super(id, version, visible, user, changesetId, timestamp, checkHistoricParams); 
    2354        setCoords(coords); 
    2455    } 
    2556 
    26     public HistoryNode(Node p) { 
    27         super(p); 
    28         setCoords(p.getCoor()); 
     57    /** 
     58     * Constructs a new {@code HistoryNode} from an existing {@link Node}. 
     59     * @param n the node 
     60     */ 
     61    public HistoryNode(Node n) { 
     62        super(n); 
     63        setCoords(n.getCoor()); 
    2964    } 
    3065 
     
    3469    } 
    3570 
     71    /** 
     72     * Replies the coordinates. May be null. 
     73     * @return the coordinates. May be null. 
     74     */ 
    3675    public LatLon getCoords() { 
    3776        return coords; 
    3877    } 
    3978 
     79    /** 
     80     * Sets the coordinates. Can be null. 
     81     * @param coords the coordinates. Can be null. 
     82     */ 
    4083    public void setCoords(LatLon coords) { 
    4184        this.coords = coords; 
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryOsmPrimitive.java

    r5339 r5440  
    4242 
    4343    /** 
    44      * constructor 
    45      * 
    46      * @param id the id (>0 required) 
     44     * Constructs a new {@code HistoryOsmPrimitive}. 
     45     * 
     46     * @param id the id (> 0 required) 
    4747     * @param version the version (> 0 required) 
    4848     * @param visible whether the primitive is still visible 
    49      * @param user  the user (! null required) 
    50      * @param uid the user id (> 0 required) 
    51      * @param changesetId the changeset id (may be null if the changeset isn't known) 
     49     * @param user the user (! null required) 
     50     * @param changesetId the changeset id (> 0 required) 
    5251     * @param timestamp the timestamp (! null required) 
    5352     * 
    54      * @throws IllegalArgumentException thrown if preconditions are violated 
     53     * @throws IllegalArgumentException if preconditions are violated 
    5554     */ 
    5655    public HistoryOsmPrimitive(long id, long version, boolean visible, User user, long changesetId, Date timestamp) throws IllegalArgumentException { 
     56        this(id, version, visible, user, changesetId, timestamp, true); 
     57    } 
     58 
     59    /** 
     60     * Constructs a new {@code HistoryOsmPrimitive} with a configurable checking of historic parameters. 
     61     * This is needed to build virtual HistoryOsmPrimitives for modified primitives, which do not have a timestamp and a changeset id. 
     62     * 
     63     * @param id the id (> 0 required) 
     64     * @param version the version (> 0 required) 
     65     * @param visible whether the primitive is still visible 
     66     * @param user the user (! null required) 
     67     * @param changesetId the changeset id (> 0 required if {@code checkHistoricParams} is true) 
     68     * @param timestamp the timestamp (! null required if {@code checkHistoricParams} is true) 
     69     * @param checkHistoricParams if true, checks values of {@code changesetId} and {@code timestamp} 
     70     * 
     71     * @throws IllegalArgumentException if preconditions are violated 
     72     * @since 5440 
     73     */ 
     74    public HistoryOsmPrimitive(long id, long version, boolean visible, User user, long changesetId, Date timestamp, boolean checkHistoricParams) throws IllegalArgumentException { 
    5775        ensurePositiveLong(id, "id"); 
    5876        ensurePositiveLong(version, "version"); 
    5977        CheckParameterUtil.ensureParameterNotNull(user, "user"); 
    60         CheckParameterUtil.ensureParameterNotNull(timestamp, "timestamp"); 
     78        if (checkHistoricParams) { 
     79            ensurePositiveLong(changesetId, "changesetId"); 
     80            CheckParameterUtil.ensureParameterNotNull(timestamp, "timestamp"); 
     81        } 
    6182        this.id = id; 
    6283        this.version = version; 
    6384        this.visible = visible; 
    6485        this.user = user; 
    65         // FIXME: restrict to IDs > 0 as soon as OsmPrimitive holds the 
    66         // changeset id too 
    6786        this.changesetId  = changesetId; 
    6887        this.timestamp = timestamp; 
    6988        tags = new HashMap<String, String>(); 
    7089    } 
    71  
     90     
     91    /** 
     92     * Constructs a new {@code HistoryOsmPrimitive} from an existing {@link OsmPrimitive}. 
     93     * @param p the primitive 
     94     */ 
    7295    public HistoryOsmPrimitive(OsmPrimitive p) { 
    73         this(p.getId(), p.getVersion(), p.isVisible(), 
    74                 p.getUser(), 
    75                 p.getChangesetId(), p.getTimestamp()); 
    76     } 
    77  
     96        this(p.getId(), p.getVersion(), p.isVisible(), p.getUser(), p.getChangesetId(), p.getTimestamp()); 
     97    } 
     98 
     99    /** 
     100     * Replies a new {@link HistoryNode}, {@link HistoryWay} or {@link HistoryRelation} from an existing {@link OsmPrimitive}. 
     101     * @param p the primitive 
     102     * @return a new {@code HistoryNode}, {@code HistoryWay} or {@code HistoryRelation} from {@code p}. 
     103     */ 
    78104    public static HistoryOsmPrimitive forOsmPrimitive(OsmPrimitive p) { 
    79105        if (p instanceof Node) { 
     
    173199    /** 
    174200     * Replies the display name of a primitive formatted by <code>formatter</code> 
     201     * @param formatter The formatter used to generate a display name 
    175202     * 
    176203     * @return the display name 
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryRelation.java

    r5266 r5440  
    3030     * @param visible whether the primitive is still visible 
    3131     * @param user  the user (! null required) 
    32      * @param uid the user id (> 0 required) 
    3332     * @param changesetId the changeset id (> 0 required) 
    3433     * @param timestamp the timestamp (! null required) 
    3534     * 
    36      * @throws IllegalArgumentException thrown if preconditions are violated 
     35     * @throws IllegalArgumentException if preconditions are violated 
    3736     */ 
    38     public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, 
    39             Date timestamp) throws IllegalArgumentException { 
     37    public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, Date timestamp) throws IllegalArgumentException { 
    4038        super(id, version, visible, user, changesetId, timestamp); 
    4139    } 
     40 
    4241    /** 
    4342     * constructor 
     
    4746     * @param visible whether the primitive is still visible 
    4847     * @param user  the user (! null required) 
    49      * @param uid the user id (> 0 required) 
     48     * @param changesetId the changeset id (> 0 required if {@code checkHistoricParams} is true) 
     49     * @param timestamp the timestamp (! null required if {@code checkHistoricParams} is true) 
     50     * @param checkHistoricParams If true, checks values of {@code changesetId} and {@code timestamp} 
     51     * 
     52     * @throws IllegalArgumentException if preconditions are violated 
     53     * @since 5440 
     54     */ 
     55    public HistoryRelation(long id, long version, boolean visible, User user, long changesetId, Date timestamp, boolean checkHistoricParams) throws IllegalArgumentException { 
     56        super(id, version, visible, user, changesetId, timestamp, checkHistoricParams); 
     57    } 
     58 
     59    /** 
     60     * constructor 
     61     * 
     62     * @param id the id (>0 required) 
     63     * @param version the version (> 0 required) 
     64     * @param visible whether the primitive is still visible 
     65     * @param user  the user (! null required) 
    5066     * @param changesetId the changeset id (> 0 required) 
    5167     * @param timestamp the timestamp (! null required) 
     
    6278    } 
    6379 
    64     public HistoryRelation(Relation p) { 
    65         super(p); 
     80    /** 
     81     * Constructs a new {@code HistoryRelation} from an existing {@link Relation}. 
     82     * @param r the relation 
     83     */ 
     84    public HistoryRelation(Relation r) { 
     85        super(r); 
    6686    } 
    6787 
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryWay.java

    r5266 r5440  
    1212import org.openstreetmap.josm.data.osm.User; 
    1313import org.openstreetmap.josm.data.osm.Way; 
     14import org.openstreetmap.josm.tools.CheckParameterUtil; 
    1415 
    1516/** 
     
    2223    private ArrayList<Long> nodeIds = new ArrayList<Long>(); 
    2324 
    24     public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp) { 
     25    /** 
     26     * Constructs a new {@code HistoryWay}. 
     27     *  
     28     * @param id the id (> 0 required) 
     29     * @param version the version (> 0 required) 
     30     * @param visible whether the node is still visible 
     31     * @param user the user (! null required) 
     32     * @param changesetId the changeset id (> 0 required if {@code checkHistoricParams} is true) 
     33     * @param timestamp the timestamp (! null required if {@code checkHistoricParams} is true) 
     34     * @throws IllegalArgumentException if preconditions are violated 
     35     */ 
     36    public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp) throws IllegalArgumentException { 
    2537        super(id, version, visible, user, changesetId, timestamp); 
    2638    } 
    2739 
    28     public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp, ArrayList<Long> nodeIdList) { 
     40    /** 
     41     * Constructs a new {@code HistoryWay} with a configurable checking of historic parameters. 
     42     * This is needed to build virtual HistoryWays for modified ways, which do not have a timestamp and a changeset id. 
     43     *  
     44     * @param id the id (> 0 required) 
     45     * @param version the version (> 0 required) 
     46     * @param visible whether the node is still visible 
     47     * @param user the user (! null required) 
     48     * @param changesetId the changeset id (> 0 required if {@code checkHistoricParams} is true) 
     49     * @param timestamp the timestamp (! null required if {@code checkHistoricParams} is true) 
     50     * @param checkHistoricParams if true, checks values of {@code changesetId} and {@code timestamp} 
     51     * @throws IllegalArgumentException if preconditions are violated 
     52     * @since 5440 
     53     */ 
     54    public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp, boolean checkHistoricParams) throws IllegalArgumentException { 
     55        super(id, version, visible, user, changesetId, timestamp, checkHistoricParams); 
     56    } 
     57 
     58    /** 
     59     * Constructs a new {@code HistoryWay} with a given list of node ids. 
     60     *  
     61     * @param id the id (> 0 required) 
     62     * @param version the version (> 0 required) 
     63     * @param visible whether the node is still visible 
     64     * @param user the user (! null required) 
     65     * @param changesetId the changeset id (> 0 required if {@code checkHistoricParams} is true) 
     66     * @param timestamp the timestamp (! null required if {@code checkHistoricParams} is true) 
     67     * @param nodeIdList the node ids (! null required) 
     68     * @throws IllegalArgumentException if preconditions are violated 
     69     */ 
     70    public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp, ArrayList<Long> nodeIdList) throws IllegalArgumentException { 
    2971        this(id, version, visible, user, changesetId, timestamp); 
     72        CheckParameterUtil.ensureParameterNotNull(nodeIdList, "nodeIdList"); 
    3073        this.nodeIds.addAll(nodeIdList); 
    3174    } 
    3275 
    33     public HistoryWay(Way p) { 
    34         super(p); 
     76    /** 
     77     * Constructs a new {@code HistoryWay} from an existing {@link Way}. 
     78     * @param w the way 
     79     */ 
     80    public HistoryWay(Way w) { 
     81        super(w); 
    3582    } 
    3683 
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowser.java

    r5266 r5440  
    1313import javax.swing.JTable; 
    1414 
     15import org.openstreetmap.josm.data.osm.OsmPrimitive; 
    1516import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 
    1617import org.openstreetmap.josm.data.osm.history.History; 
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r5340 r5440  
    2020import org.openstreetmap.josm.data.osm.RelationMemberData; 
    2121import org.openstreetmap.josm.data.osm.User; 
     22import org.openstreetmap.josm.data.osm.UserInfo; 
    2223import org.openstreetmap.josm.data.osm.Way; 
    2324import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 
     
    3637import org.openstreetmap.josm.data.osm.history.HistoryWay; 
    3738import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 
     39import org.openstreetmap.josm.gui.JosmUserIdentityManager; 
    3840import org.openstreetmap.josm.gui.MapView; 
    3941import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 
     
    437439            case 4: { 
    438440                    HistoryOsmPrimitive p = getPrimitive(row); 
    439                     if (p != null) 
     441                    if (p != null && p.getTimestamp() != null) 
    440442                        return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(p.getTimestamp()); 
    441443                    return null; 
     
    877879 
    878880        public void visit(Node n) { 
    879             clone = new HistoryNode(n.getId(), n.getVersion(), n.isVisible(), n.getUser(), 0, n.getTimestamp(), n.getCoor()); 
     881            clone = new HistoryNode(n.getId(), n.getVersion(), n.isVisible(), getCurrentUser(), 0, null, n.getCoor(), false); 
    880882            clone.setTags(n.getKeys()); 
    881883        } 
    882884 
    883885        public void visit(Relation r) { 
    884             clone = new HistoryRelation(r.getId(), r.getVersion(), r.isVisible(), r.getUser(), 0, r.getTimestamp()); 
     886            clone = new HistoryRelation(r.getId(), r.getVersion(), r.isVisible(), getCurrentUser(), 0, null, false); 
    885887            clone.setTags(r.getKeys()); 
    886888            HistoryRelation hr = (HistoryRelation)clone; 
     
    891893 
    892894        public void visit(Way w) { 
    893             clone = new HistoryWay(w.getId(), w.getVersion(), w.isVisible(), w.getUser(), 0, w.getTimestamp()); 
     895            clone = new HistoryWay(w.getId(), w.getVersion(), w.isVisible(), getCurrentUser(), 0, null, false); 
    894896            clone.setTags(w.getKeys()); 
    895897            for (Node n: w.getNodes()) { 
     
    898900        } 
    899901 
     902        private User getCurrentUser() { 
     903            UserInfo info = JosmUserIdentityManager.getInstance().getUserInfo(); 
     904            return info == null ? User.getAnonymous() : User.createOsmUser(info.getId(), info.getDisplayName()); 
     905        } 
     906 
    900907        public HistoryOsmPrimitive build(OsmPrimitive primitive) { 
    901908            primitive.visit(this); 
  • trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java

    r5319 r5440  
    2020import org.openstreetmap.josm.Main; 
    2121import org.openstreetmap.josm.actions.AbstractInfoAction; 
     22import org.openstreetmap.josm.data.osm.OsmPrimitive; 
    2223import org.openstreetmap.josm.data.osm.User; 
    2324import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 
    2425import org.openstreetmap.josm.gui.JMultilineLabel; 
     26import org.openstreetmap.josm.gui.JosmUserIdentityManager; 
    2527import org.openstreetmap.josm.gui.layer.OsmDataLayer; 
    26 import org.openstreetmap.josm.io.auth.CredentialsManager; 
    2728import org.openstreetmap.josm.tools.CheckParameterUtil; 
    2829import org.openstreetmap.josm.tools.UrlLabel; 
     
    153154            lblUser.setDescription(username); 
    154155        } else { 
    155             String user = CredentialsManager.getInstance().getUsername(); 
     156            String user = JosmUserIdentityManager.getInstance().getUserName(); 
    156157            if (user == null) { 
    157158                lblUser.setDescription(tr("anonymous")); 
     159                lblUser.setUrl(null); 
    158160            } else { 
    159161                try { 
  • trunk/src/org/openstreetmap/josm/gui/history/VersionTableColumnModel.java

    r5340 r5440  
    77import javax.swing.table.DefaultTableColumnModel; 
    88import javax.swing.table.TableColumn; 
     9import javax.swing.table.TableColumnModel; 
    910 
    1011/** 
     
    5859    } 
    5960 
     61    /** 
     62     * Creates a new {@code VersionTableColumnModel}. 
     63     */ 
    6064    public VersionTableColumnModel() { 
    6165        createColumns(); 
  • trunk/src/org/openstreetmap/josm/tools/UrlLabel.java

    r5050 r5440  
    4949        if (url != null) { 
    5050            setText("<html><a href=\""+url+"\">"+description+"</a></html>"); 
     51            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 
     52            setToolTipText(String.format("<html>%s<br/>%s</html>", url, tr("Right click = copy to clipboard"))); 
    5153        } else { 
    5254            setText("<html>" + description + "</html>"); 
     55            setCursor(null); 
     56            setToolTipText(null); 
    5357        } 
    54         setToolTipText(String.format("<html>%s<br/>%s</html>",url, tr("Right click = copy to clipboard"))); 
    5558    } 
    5659 
Note: See TracChangeset for help on using the changeset viewer.