- Timestamp:
- 2016-01-14T17:26:20+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java
r9223 r9441 14 14 import javax.swing.JPanel; 15 15 16 import org.openstreetmap.gui.jmapviewer.JMapViewer; 17 import org.openstreetmap.gui.jmapviewer.MapMarkerDot; 16 18 import org.openstreetmap.josm.data.coor.CoordinateFormat; 17 19 import org.openstreetmap.josm.data.coor.LatLon; … … 21 23 import org.openstreetmap.josm.gui.util.GuiHelper; 22 24 import org.openstreetmap.josm.tools.CheckParameterUtil; 25 import org.openstreetmap.josm.tools.Pair; 23 26 24 27 /** … … 28 31 */ 29 32 public class CoordinateInfoViewer extends JPanel { 30 31 /** background color used when the coordinates are different */32 public static final Color BGCOLOR_DIFFERENCE = new Color(255, 197, 197);33 33 34 34 /** the model */ … … 44 44 /** the info panel for distance between the two coordinates */ 45 45 private DistanceViewer distanceViewer; 46 /** the map panel showing the old+new coordinate */ 47 private MapViewer mapViewer; 46 48 47 49 protected void build() { … … 76 78 gc.gridy = 1; 77 79 gc.weightx = 0.5; 78 gc.weighty = 1.0;79 gc.fill = GridBagConstraints. BOTH;80 gc.weighty = 0.0; 81 gc.fill = GridBagConstraints.HORIZONTAL; 80 82 gc.anchor = GridBagConstraints.NORTHWEST; 81 83 add(referenceLatLonViewer = new LatLonViewer(model, PointInTimeType.REFERENCE_POINT_IN_TIME), gc); … … 84 86 gc.gridy = 1; 85 87 gc.weightx = 0.5; 86 gc.weighty = 1.0;87 gc.fill = GridBagConstraints. BOTH;88 gc.weighty = 0.0; 89 gc.fill = GridBagConstraints.HORIZONTAL; 88 90 gc.anchor = GridBagConstraints.NORTHWEST; 89 91 add(currentLatLonViewer = new LatLonViewer(model, PointInTimeType.CURRENT_POINT_IN_TIME), gc); … … 98 100 gc.weighty = 0.0; 99 101 add(distanceViewer = new DistanceViewer(model), gc); 102 103 // the map panel 104 gc.gridx = 0; 105 gc.gridy = 3; 106 gc.gridwidth = 2; 107 gc.fill = GridBagConstraints.BOTH; 108 gc.weightx = 1.0; 109 gc.weighty = 1.0; 110 gc.insets = new Insets(5, 5, 5, 5); 111 add(mapViewer = new MapViewer(model), gc); 112 mapViewer.setZoomContolsVisible(false); 100 113 } 101 114 … … 128 141 model.deleteObserver(distanceViewer); 129 142 } 143 if (mapViewer != null) { 144 model.deleteObserver(mapViewer); 145 } 130 146 } 131 147 … … 145 161 if (distanceViewer != null) { 146 162 model.addObserver(distanceViewer); 163 } 164 if (mapViewer != null) { 165 model.addObserver(mapViewer); 147 166 } 148 167 } … … 163 182 } 164 183 184 private static class Updater { 185 private final transient HistoryBrowserModel model; 186 private final PointInTimeType role; 187 188 public Updater(HistoryBrowserModel model, PointInTimeType role) { 189 this.model = model; 190 this.role = role; 191 } 192 193 protected HistoryOsmPrimitive getPrimitive() { 194 if (model == null || role == null) 195 return null; 196 return model.getPointInTime(role); 197 } 198 199 protected HistoryOsmPrimitive getOppositePrimitive() { 200 if (model == null || role == null) 201 return null; 202 return model.getPointInTime(role.opposite()); 203 } 204 205 protected final Pair<LatLon, LatLon> getCoordinates() { 206 HistoryOsmPrimitive p = getPrimitive(); 207 HistoryOsmPrimitive opposite = getOppositePrimitive(); 208 if (!(p instanceof HistoryNode)) return null; 209 if (!(opposite instanceof HistoryNode)) return null; 210 HistoryNode node = (HistoryNode) p; 211 HistoryNode oppositeNode = (HistoryNode) opposite; 212 213 return Pair.create(node.getCoords(), oppositeNode.getCoords()); 214 } 215 216 } 217 165 218 /** 166 219 * A UI widgets which displays the Lan/Lon-coordinates of a … … 172 225 private JLabel lblLat; 173 226 private JLabel lblLon; 174 private final transient HistoryBrowserModel model; 175 private final PointInTimeType role; 176 177 protected LatLon coord; 178 protected LatLon oppositeCoord; 179 180 protected HistoryOsmPrimitive getPrimitive() { 181 if (model == null || role == null) 182 return null; 183 return model.getPointInTime(role); 184 } 185 186 protected HistoryOsmPrimitive getOppositePrimitive() { 187 if (model == null || role == null) 188 return null; 189 return model.getPointInTime(role.opposite()); 190 } 227 private final Updater updater; 228 private final Color modifiedColor; 191 229 192 230 protected void build() { … … 231 269 lblLon.setOpaque(true); 232 270 lblLon.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); 233 234 // fill the remaining space235 gc.gridx = 0;236 gc.gridy = 2;237 gc.gridwidth = 2;238 gc.fill = GridBagConstraints.BOTH;239 gc.weightx = 1.0;240 gc.weighty = 1.0;241 add(new JPanel(), gc);242 271 } 243 272 … … 248 277 */ 249 278 LatLonViewer(HistoryBrowserModel model, PointInTimeType role) { 279 this.updater = new Updater(model, role); 280 this.modifiedColor = PointInTimeType.CURRENT_POINT_IN_TIME.equals(role) 281 ? TwoColumnDiff.Item.DiffItemType.INSERTED.getColor() 282 : TwoColumnDiff.Item.DiffItemType.DELETED.getColor(); 250 283 build(); 251 this.model = model;252 this.role = role;253 }254 255 protected final boolean prepareRefresh() {256 HistoryOsmPrimitive p = getPrimitive();257 HistoryOsmPrimitive opposite = getOppositePrimitive();258 if (!(p instanceof HistoryNode)) return false;259 if (!(opposite instanceof HistoryNode)) return false;260 HistoryNode node = (HistoryNode) p;261 HistoryNode oppositeNode = (HistoryNode) opposite;262 263 coord = node.getCoords();264 oppositeCoord = oppositeNode.getCoords();265 return true;266 284 } 267 285 268 286 protected void refresh() { 269 if (!prepareRefresh()) return; 287 final Pair<LatLon, LatLon> coordinates = updater.getCoordinates(); 288 if (coordinates == null) return; 289 final LatLon coord = coordinates.a; 290 final LatLon oppositeCoord = coordinates.b; 270 291 271 292 // display the coordinates … … 278 299 GuiHelper.setBackgroundReadable(lblLat, Color.WHITE); 279 300 } else { 280 GuiHelper.setBackgroundReadable(lblLat, BGCOLOR_DIFFERENCE);301 GuiHelper.setBackgroundReadable(lblLat, modifiedColor); 281 302 } 282 303 if (coord == oppositeCoord || … … 284 305 GuiHelper.setBackgroundReadable(lblLon, Color.WHITE); 285 306 } else { 286 GuiHelper.setBackgroundReadable(lblLon, BGCOLOR_DIFFERENCE);307 GuiHelper.setBackgroundReadable(lblLon, modifiedColor); 287 308 } 288 309 } … … 294 315 } 295 316 296 private static class DistanceViewer extends LatLonViewer { 317 private static class MapViewer extends JMapViewer implements Observer { 318 319 private final Updater updater; 320 321 public MapViewer(HistoryBrowserModel model) { 322 this.updater = new Updater(model, PointInTimeType.REFERENCE_POINT_IN_TIME); 323 setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); 324 } 325 326 @Override 327 public void update(Observable o, Object arg) { 328 final Pair<LatLon, LatLon> coordinates = updater.getCoordinates(); 329 if (coordinates == null) { 330 return; 331 } 332 333 final MapMarkerDot oldMarker = new MapMarkerDot(coordinates.a.lat(), coordinates.a.lon()); 334 final MapMarkerDot newMarker = new MapMarkerDot(coordinates.b.lat(), coordinates.b.lon()); 335 oldMarker.setBackColor(TwoColumnDiff.Item.DiffItemType.DELETED.getColor()); 336 newMarker.setBackColor(TwoColumnDiff.Item.DiffItemType.INSERTED.getColor()); 337 338 removeAllMapMarkers(); 339 addMapMarker(oldMarker); 340 addMapMarker(newMarker); 341 setDisplayToFitMapMarkers(); 342 } 343 } 344 345 private static class DistanceViewer extends JPanel implements Observer { 297 346 298 347 private JLabel lblDistance; 348 private final Updater updater; 299 349 300 350 DistanceViewer(HistoryBrowserModel model) { 301 super(model, PointInTimeType.REFERENCE_POINT_IN_TIME);302 }303 304 @Override 351 this.updater = new Updater(model, PointInTimeType.REFERENCE_POINT_IN_TIME); 352 build(); 353 } 354 305 355 protected void build() { 306 356 setLayout(new GridBagLayout()); … … 328 378 } 329 379 330 @Override331 380 protected void refresh() { 332 if (!prepareRefresh()) return; 381 final Pair<LatLon, LatLon> coordinates = updater.getCoordinates(); 382 if (coordinates == null) return; 383 final LatLon coord = coordinates.a; 384 final LatLon oppositeCoord = coordinates.b; 333 385 334 386 // update distance … … 336 388 if (coord != null && oppositeCoord != null) { 337 389 double distance = coord.greatCircleDistance(oppositeCoord); 338 GuiHelper.setBackgroundReadable(lblDistance, distance > 0 ? BGCOLOR_DIFFERENCE : Color.WHITE); 390 GuiHelper.setBackgroundReadable(lblDistance, distance > 0 391 ? TwoColumnDiff.Item.DiffItemType.CHANGED.getColor() 392 : Color.WHITE); 339 393 lblDistance.setText(NavigatableComponent.getDistText(distance)); 340 394 } else { 341 GuiHelper.setBackgroundReadable(lblDistance, coord != oppositeCoord ? BGCOLOR_DIFFERENCE : Color.WHITE); 395 GuiHelper.setBackgroundReadable(lblDistance, coord != oppositeCoord 396 ? TwoColumnDiff.Item.DiffItemType.CHANGED.getColor() 397 : Color.WHITE); 342 398 lblDistance.setText(tr("(none)")); 343 399 } 344 400 } 401 402 @Override 403 public void update(Observable o, Object arg) { 404 refresh(); 405 } 345 406 } 346 407 }
Note:
See TracChangeset
for help on using the changeset viewer.