Ignore:
Timestamp:
2012-02-19T02:20:18+01:00 (12 years ago)
Author:
Don-vip
Message:

fix #7161 - Show distance of moved node in history window

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java

    r3083 r4990  
    1717import org.openstreetmap.josm.data.osm.history.HistoryNode;
    1818import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
     19import org.openstreetmap.josm.gui.NavigatableComponent;
    1920import org.openstreetmap.josm.tools.CheckParameterUtil;
    2021
     
    3940    /** the info panel for coordinates for the node in role CURRENT_POINT_IN_TIME */
    4041    private LatLonViewer currentLatLonViewer;
     42    /** the info panel for distance between the two coordinates */
     43    private DistanceViewer distanceViewer;
    4144
    4245    protected void build() {
     
    8386        gc.anchor = GridBagConstraints.NORTHWEST;
    8487        add(currentLatLonViewer = new LatLonViewer(model, PointInTimeType.CURRENT_POINT_IN_TIME), gc);
     88
     89        // --------------------
     90        // the distance panel
     91        gc.gridx = 0;
     92        gc.gridy = 2;
     93        gc.gridwidth = 2;
     94        gc.fill = GridBagConstraints.HORIZONTAL;
     95        gc.weightx = 1.0;
     96        gc.weighty = 0.0;
     97        add(distanceViewer = new DistanceViewer(model), gc);
    8598    }
    8699
     
    110123            model.deleteObserver(referenceLatLonViewer);
    111124        }
     125        if (distanceViewer != null) {
     126            model.deleteObserver(distanceViewer);
     127        }
    112128    }
    113129
     
    124140        if (referenceLatLonViewer != null) {
    125141            model.addObserver(referenceLatLonViewer);
     142        }
     143        if (distanceViewer != null) {
     144            model.addObserver(distanceViewer);
    126145        }
    127146    }
     
    261280        }
    262281    }
     282   
     283    private static class DistanceViewer extends LatLonViewer {
     284
     285        private JLabel lblDistance;
     286       
     287        public DistanceViewer(HistoryBrowserModel model) {
     288            super(model, PointInTimeType.REFERENCE_POINT_IN_TIME);
     289        }
     290
     291        protected void build() {
     292            setLayout(new GridBagLayout());
     293            setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
     294            GridBagConstraints gc = new GridBagConstraints();
     295
     296            // --------
     297            gc.gridx = 0;
     298            gc.gridy = 0;
     299            gc.fill = GridBagConstraints.NONE;
     300            gc.weightx = 0.0;
     301            gc.insets = new Insets(5,5,5,5);
     302            gc.anchor = GridBagConstraints.NORTHWEST;
     303            add(new JLabel(tr("Distance: ")), gc);
     304
     305            // --------
     306            gc.gridx = 1;
     307            gc.gridy = 0;
     308            gc.fill = GridBagConstraints.HORIZONTAL;
     309            gc.weightx = 1.0;
     310            add(lblDistance = new JLabel(), gc);
     311            lblDistance.setBackground(Color.WHITE);
     312            lblDistance.setOpaque(true);
     313            lblDistance.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
     314        }
     315
     316        protected void refresh() {
     317            HistoryOsmPrimitive p = getPrimitive();
     318            HistoryOsmPrimitive opposite = getOppositePrimitive();
     319            if (p == null || ! ( p instanceof HistoryNode)) return;
     320            if (opposite == null || ! (opposite instanceof HistoryNode)) return;
     321            HistoryNode node = (HistoryNode) p;
     322            HistoryNode oppositeNode = (HistoryNode) opposite;
     323
     324            // update distance
     325            //
     326            double distance = node.getCoords().greatCircleDistance(oppositeNode.getCoords());
     327            if (distance > 0) {
     328                lblDistance.setBackground(BGCOLOR_DIFFERENCE);
     329            } else {
     330                lblDistance.setBackground(Color.WHITE);
     331            }
     332            lblDistance.setText(NavigatableComponent.getDistText(distance));
     333        }
     334    }
    263335}
Note: See TracChangeset for help on using the changeset viewer.