Changeset 2242 in josm


Ignore:
Timestamp:
2009-10-04T00:37:05+02:00 (15 years ago)
Author:
stoecker
Message:

fixed #3649 - show node coordinates in history dialog

Location:
trunk/src/org/openstreetmap/josm
Files:
3 added
8 edited

Legend:

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

    r2181 r2242  
    1010import java.util.List;
    1111import java.util.NoSuchElementException;
     12
     13import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1214
    1315public class History{
     
    195197        return versions.isEmpty();
    196198    }
     199
     200    public OsmPrimitiveType getType() {
     201        if (isEmpty())
     202            throw new NoSuchElementException(tr("No type found. History is empty."));
     203        return versions.get(0).getType();
     204    }
    197205}
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryNode.java

    r1670 r2242  
    55
    66import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     7import org.openstreetmap.josm.data.coor.LatLon;
    78
    89
     
    1314 */
    1415public class HistoryNode extends HistoryOsmPrimitive {
    15     public HistoryNode(long id, long version, boolean visible, String user, long uid, long changesetId, Date timestamp) {
     16    private LatLon coor;
     17    public HistoryNode(long id, long version, boolean visible, String user, long uid, long changesetId, Date timestamp,
     18    double lat, double lon) {
    1619        super(id, version, visible, user, uid, changesetId, timestamp);
     20        coor = new LatLon(lat, lon);
    1721    }
    1822
     
    2125        return OsmPrimitiveType.NODE;
    2226    }
     27
     28    public LatLon getCoordinate() {
     29        return coor;
     30    }
    2331}
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryOsmPrimitive.java

    r2181 r2242  
    3939    /**
    4040     * constructor
    41      * 
     41     *
    4242     * @param id the id (>0 required)
    4343     * @param version the version (> 0 required)
     
    4747     * @param changesetId the changeset id (> 0 required)
    4848     * @param timestamp the timestamp (! null required)
    49      * 
     49     *
    5050     * @throws IllegalArgumentException thrown if preconditions are violated
    5151     */
     
    5353        ensurePositiveLong(id, "id");
    5454        ensurePositiveLong(version, "version");
    55         ensurePositiveLong(uid, "uid");
     55        if(uid != -1) /* allow -1 for anonymous users */
     56            ensurePositiveLong(uid, "uid");
    5657        ensurePositiveLong(changesetId, "changesetId");
    5758        ensureNotNull(user, "user");
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowser.java

    r1709 r2242  
    1414
    1515import org.openstreetmap.josm.data.osm.history.History;
     16import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1617
    1718/**
    1819 * HistoryBrowser is an UI component which displays history information about an {@see OsmPrimitive}.
    19  * 
     20 *
    2021 *
    2122 */
     
    2425    /** the model */
    2526    private HistoryBrowserModel model;
     27    private JTabbedPane dataPane;
    2628
    2729    /**
    2830     * embedds table in a {@see JScrollPane}
    29      * 
     31     *
    3032     * @param table the table
    3133     * @return the {@see JScrollPane} with the embedded table
     
    4042    /**
    4143     * creates the table which shows the list of versions
    42      * 
     44     *
    4345     * @return  the panel with the version table
    4446     */
     
    5557     * creates the panel which shows information about two different versions
    5658     * of the same {@see OsmPrimitive}.
    57      * 
     59     *
    5860     * @return the panel
    5961     */
     62
    6063    protected JPanel createVersionComparePanel() {
    61         JTabbedPane pane = new JTabbedPane();
    62         pane.add(new TagInfoViewer(model));
    63         pane.setTitleAt(0, tr("Tags"));
     64        dataPane = new JTabbedPane();
     65        dataPane.add(new TagInfoViewer(model));
     66        dataPane.setTitleAt(0, tr("Tags"));
    6467
    65         pane.add(new NodeListViewer(model));
    66         pane.setTitleAt(1, tr("Nodes"));
     68        dataPane.add(new NodeListViewer(model));
     69        dataPane.setTitleAt(1, tr("Nodes"));
    6770
    68         pane.add(new RelationMemberListViewer(model));
    69         pane.setTitleAt(2, tr("Members"));
     71        dataPane.add(new RelationMemberListViewer(model));
     72        dataPane.setTitleAt(2, tr("Members"));
     73
     74        dataPane.add(new CoordinateViewer(model));
     75        dataPane.setTitleAt(3, tr("Coordinate"));
    7076
    7177        JPanel pnl = new JPanel();
    7278        pnl.setLayout(new BorderLayout());
    73         pnl.add(pane, BorderLayout.CENTER);
     79        pnl.add(dataPane, BorderLayout.CENTER);
    7480        return pnl;
    7581    }
     
    116122    /**
    117123     * populates the browser with the history of a specific {@see OsmPrimitive}
    118      * 
     124     *
    119125     * @param history the history
    120126     */
    121127    public void populate(History history) {
    122128        model.setHistory(history);
     129        OsmPrimitiveType type = history.getType();
     130        if(type != null)
     131        {
     132            if(type == OsmPrimitiveType.NODE)
     133            {
     134                dataPane.setEnabledAt(1, false);
     135                dataPane.setEnabledAt(2, false);
     136            }
     137            else if(type == OsmPrimitiveType.WAY)
     138            {
     139                dataPane.setEnabledAt(2, false);
     140                dataPane.setEnabledAt(3, false);
     141            }
     142            else
     143            {
     144                dataPane.setEnabledAt(3, false);
     145            }
     146        }
    123147    }
    124148
    125149    /**
    126150     * replies the {@see History} currently displayed by this browser
    127      * 
     151     *
    128152     * @return the current history
    129153     */
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r2182 r2242  
    1212import javax.swing.table.DefaultTableModel;
    1313
     14import org.openstreetmap.josm.data.coor.CoordinateFormat;
     15import org.openstreetmap.josm.data.coor.LatLon;
    1416import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1517import org.openstreetmap.josm.data.osm.history.History;
     18import org.openstreetmap.josm.data.osm.history.HistoryNode;
    1619import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
    1720import org.openstreetmap.josm.data.osm.history.HistoryRelation;
     
    2023/**
    2124 * This is the model used by the history browser.
    22  * 
     25 *
    2326 * The state this model manages consists of the following elements:
    2427 * <ul>
     
    4043 *  members  of the two selected versions (if the current history provides information about a {@see Relation}</li>
    4144 *  </ul>
    42  * 
     45 *
    4346 * @see HistoryBrowser
    4447 */
     
    5962    private RelationMemberTableModel currentRelationMemberTableModel;
    6063    private RelationMemberTableModel referenceRelationMemberTableModel;
     64    private CoordinateTableModel currentCoordinateTableModel;
     65    private CoordinateTableModel referenceCoordinateTableModel;
    6166
    6267    public HistoryBrowserModel() {
     
    6873        currentRelationMemberTableModel = new RelationMemberTableModel(PointInTimeType.CURRENT_POINT_IN_TIME);
    6974        referenceRelationMemberTableModel = new RelationMemberTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME);
     75        currentCoordinateTableModel = new CoordinateTableModel(PointInTimeType.CURRENT_POINT_IN_TIME);
     76        referenceCoordinateTableModel = new CoordinateTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME);
    7077    }
    7178
     
    8592    /**
    8693     * sets the history to be managed by this model
    87      * 
     94     *
    8895     * @param history the history
    89      * 
     96     *
    9097     */
    9198    public void setHistory(History history) {
     
    109116     * Replies the table model to be used in a {@see JTable} which
    110117     * shows the list of versions in this history.
    111      * 
     118     *
    112119     * @return the table model
    113120     */
     
    121128    }
    122129
    123     protected void initNodeListTabeModel() {
     130    protected void initNodeListTabeModels() {
    124131        currentNodeListTableModel.fireTableDataChanged();
    125132        referenceNodeListTableModel.fireTableDataChanged();
    126133    }
    127134
    128     protected void initMemberListTableModel() {
     135    protected void initMemberListTableModels() {
    129136        currentRelationMemberTableModel.fireTableDataChanged();
    130137        referenceRelationMemberTableModel.fireTableDataChanged();
    131138    }
    132139
     140    protected void initCoordinateTableModels() {
     141        currentCoordinateTableModel.fireTableDataChanged();
     142        referenceCoordinateTableModel.fireTableDataChanged();
     143    }
     144
    133145    /**
    134146     * replies the tag table model for the respective point in time
    135      * 
     147     *
    136148     * @param pointInTimeType the type of the point in time (must not be null)
    137149     * @return the tag table model
     
    169181        else if (pointInTimeType.equals(PointInTimeType.REFERENCE_POINT_IN_TIME))
    170182            return referenceRelationMemberTableModel;
     183
     184        // should not happen
     185        return null;
     186    }
     187
     188    public CoordinateTableModel getCoordinateTableModel(PointInTimeType pointInTimeType) throws IllegalArgumentException {
     189        if (pointInTimeType == null)
     190            throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "pointInTimeType"));
     191        if (pointInTimeType.equals(PointInTimeType.CURRENT_POINT_IN_TIME))
     192            return currentCoordinateTableModel;
     193        else if (pointInTimeType.equals(PointInTimeType.REFERENCE_POINT_IN_TIME))
     194            return referenceCoordinateTableModel;
    171195
    172196        // should not happen
     
    187211        this.reference = reference;
    188212        initTagTableModels();
    189         initNodeListTabeModel();
    190         initMemberListTableModel();
     213        initNodeListTabeModels();
     214        initMemberListTableModels();
     215        initCoordinateTableModels();
    191216        setChanged();
    192217        notifyObservers();
     
    205230        this.current = current;
    206231        initTagTableModels();
    207         initNodeListTabeModel();
    208         initMemberListTableModel();
     232        initNodeListTabeModels();
     233        initMemberListTableModels();
     234        initCoordinateTableModels();
    209235        setChanged();
    210236        notifyObservers();
     
    213239    /**
    214240     * Replies the history OSM primitive for the {@see PointInTimeType#CURRENT_POINT_IN_TIME}
    215      * 
     241     *
    216242     * @return the history OSM primitive for the {@see PointInTimeType#CURRENT_POINT_IN_TIME} (may be null)
    217243     */
     
    222248    /**
    223249     * Replies the history OSM primitive for the {@see PointInTimeType#REFERENCE_POINT_IN_TIME}
    224      * 
     250     *
    225251     * @return the history OSM primitive for the {@see PointInTimeType#REFERENCE_POINT_IN_TIME} (may be null)
    226252     */
     
    231257    /**
    232258     * replies the history OSM primitive for a given point in time
    233      * 
     259     *
    234260     * @param type the type of the point in time (must not be null)
    235261     * @return the respective primitive. Can be null.
     
    306332     * The table model for the tags of the version at {@see PointInTimeType#REFERENCE_POINT_IN_TIME}
    307333     * or {@see PointInTimeType#CURRENT_POINT_IN_TIME}
    308      * 
     334     *
    309335     */
    310336    public class TagTableModel extends DefaultTableModel {
     
    401427     * The table model for the nodes of the version at {@see PointInTimeType#REFERENCE_POINT_IN_TIME}
    402428     * or {@see PointInTimeType#CURRENT_POINT_IN_TIME}
    403      * 
     429     *
    404430     */
    405431    public class NodeListTableModel extends DefaultTableModel {
     
    493519     * The table model for the relation members of the version at {@see PointInTimeType#REFERENCE_POINT_IN_TIME}
    494520     * or {@see PointInTimeType#CURRENT_POINT_IN_TIME}
    495      * 
     521     *
    496522     */
    497523
     
    584610        }
    585611    }
     612
     613    /**
     614     * The table model for the coordinates of the version at {@see PointInTimeType#REFERENCE_POINT_IN_TIME}
     615     * or {@see PointInTimeType#CURRENT_POINT_IN_TIME}
     616     *
     617     */
     618    public class CoordinateTableModel extends DefaultTableModel {
     619
     620        private LatLon currentCoor = null;
     621        private LatLon referenceCoor = null;
     622        private PointInTimeType pointInTimeType;
     623
     624        protected CoordinateTableModel(PointInTimeType type) {
     625            pointInTimeType = type;
     626        }
     627
     628        @Override
     629        public int getRowCount() {
     630            if (current != null && current instanceof HistoryNode)
     631                currentCoor = ((HistoryNode)current).getCoordinate();
     632            else
     633                return 0;
     634            if (reference != null && reference instanceof HistoryNode)
     635                referenceCoor = ((HistoryNode)reference).getCoordinate();
     636            return 2;
     637        }
     638
     639        @Override
     640        public Object getValueAt(int row, int column) {
     641            if(currentCoor == null)
     642                return null;
     643            else if (pointInTimeType.equals(PointInTimeType.CURRENT_POINT_IN_TIME))
     644                return row == 0 ? currentCoor.latToString(CoordinateFormat.getDefaultFormat())
     645                : currentCoor.lonToString(CoordinateFormat.getDefaultFormat());
     646            else
     647                return row == 0 ? referenceCoor.latToString(CoordinateFormat.getDefaultFormat())
     648                : referenceCoor.lonToString(CoordinateFormat.getDefaultFormat());
     649        }
     650
     651        @Override
     652        public boolean isCellEditable(int row, int column) {
     653            return false;
     654        }
     655
     656        public boolean hasSameValueAsOpposite(int row) {
     657            if(currentCoor == null)
     658                return false;
     659            else if(row == 0)
     660                return currentCoor.lat() == referenceCoor.lat();
     661            return currentCoor.lon() == referenceCoor.lon();
     662        }
     663
     664        public PointInTimeType getPointInTimeType() {
     665            return pointInTimeType;
     666        }
     667
     668        public boolean isCurrentPointInTime() {
     669            return pointInTimeType.equals(PointInTimeType.CURRENT_POINT_IN_TIME);
     670        }
     671
     672        public boolean isReferencePointInTime() {
     673            return pointInTimeType.equals(PointInTimeType.REFERENCE_POINT_IN_TIME);
     674        }
     675    }
    586676}
  • trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java

    r2017 r2242  
    1212
    1313/**
    14  * TagInfoViewer is a UI component which displays the  list of tags of two
     14 * TagInfoViewer is a UI component which displays the list of tags of two
    1515 * version of a {@see OsmPrimitive} in a {@see History}.
    16  * 
     16 *
    1717 * <ul>
    1818 *   <li>on the left, it displays the list of tags for the version at {@see PointInTimeType#REFERENCE_POINT_IN_TIME}</li>
  • trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java

    r2181 r2242  
    2121 * VersionInfoPanel is an UI component which displays the basic properties of a version
    2222 * of a {@see OsmPrimitive}.
    23  * 
     23 *
    2424 */
    2525public class VersionInfoPanel extends JPanel implements Observer{
     
    5151                Long.toString(primitive.getVersion()),
    5252                new SimpleDateFormat().format(primitive.getTimestamp()),
    53                 primitive.getUser(),
     53                primitive.getUser().replace("<", "&lt;").replace(">", "&gt;"),
    5454                primitive.getChangesetId()
    5555        );
     
    6565    /**
    6666     * constructor
    67      * 
     67     *
    6868     * @param model  the model (must not be null)
    6969     * @param pointInTimeType the point in time this panel visualizes (must not be null)
  • trunk/src/org/openstreetmap/josm/io/OsmHistoryReader.java

    r2181 r2242  
    8080        }
    8181
     82        protected long getAttributeLong(Attributes attr, String name, long defaultValue) throws SAXException{
     83            String v = attr.getValue(name);
     84            if (v == null) {
     85                return defaultValue;
     86            }
     87            Long l = 0l;
     88            try {
     89                l = Long.parseLong(v);
     90            } catch(NumberFormatException e) {
     91                throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long. Got ''{1}''.", name, v));
     92            }
     93            if (l < 0) {
     94                throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long (>=0). Got ''{1}''.", name, v));
     95            }
     96            return l;
     97        }
     98
    8299        protected int getMandatoryAttributeInt(Attributes attr, String name) throws SAXException{
    83100            String v = attr.getValue(name);
     
    97114        }
    98115
     116        protected double getMandatoryAttributeDouble(Attributes attr, String name) throws SAXException{
     117            String v = attr.getValue(name);
     118            if (v == null) {
     119                throwException(tr("Missing mandatory attribute ''{0}''.", name));
     120            }
     121            double d = 0.0;
     122            try {
     123                d = Double.parseDouble(v);
     124            } catch(NumberFormatException e) {
     125                throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double. Got ''{1}''.", name, v));
     126            }
     127            return d;
     128        }
     129
    99130        protected String getMandatoryAttributeString(Attributes attr, String name) throws SAXException{
    100131            String v = attr.getValue(name);
     
    102133                throwException(tr("Missing mandatory attribute ''{0}''.", name));
    103134            }
     135            return v;
     136        }
     137
     138        protected String getAttributeString(Attributes attr, String name, String defaultValue) {
     139            String v = attr.getValue(name);
     140            if (v == null)
     141                v = defaultValue;
    104142            return v;
    105143        }
     
    119157        protected  HistoryOsmPrimitive createPrimitive(Attributes atts, OsmPrimitiveType type) throws SAXException {
    120158            long id = getMandatoryAttributeLong(atts,"id");
    121             long version = getMandatoryAttributeLong(atts,"version");
    122             long changesetId = getMandatoryAttributeLong(atts,"changeset");
    123             boolean visible= getMandatoryAttributeBoolean(atts, "visible");
    124             long uid = getMandatoryAttributeLong(atts, "uid");
    125             String user = getMandatoryAttributeString(atts, "user");
     159            long version = getMandatoryAttributeLong(atts, "version");
     160            long changesetId = getMandatoryAttributeLong(atts, "changeset");
     161            boolean visible = getMandatoryAttributeBoolean(atts, "visible");
     162            long uid = getAttributeLong(atts, "uid", -1);
     163            String user = getAttributeString(atts, "user", tr("<anonymous>"));
    126164            String v = getMandatoryAttributeString(atts, "timestamp");
    127165            Date timestamp = DateUtils.fromString(v);
    128166            HistoryOsmPrimitive primitive = null;
    129167            if (type.equals(OsmPrimitiveType.NODE)) {
     168                double lat = getMandatoryAttributeDouble(atts, "lat");
     169                double lon = getMandatoryAttributeDouble(atts, "lon");
    130170                primitive = new HistoryNode(
    131                         id,version,visible,user,uid,changesetId,timestamp
     171                        id,version,visible,user,uid,changesetId,timestamp,lat,lon
    132172                );
    133173            } else if (type.equals(OsmPrimitiveType.WAY)) {
Note: See TracChangeset for help on using the changeset viewer.