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

fixed #3649 - show node coordinates in history dialog

Location:
trunk/src/org/openstreetmap/josm/gui/history
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • 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)
Note: See TracChangeset for help on using the changeset viewer.