Changeset 29982 in osm for applications/editors/josm
- Timestamp:
- 2013-09-27T21:04:17+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationHelper.java
r29979 r29982 21 21 import java.util.Locale; 22 22 23 import org.openstreetmap.josm.data.Bounds; 23 24 import org.openstreetmap.josm.data.coor.LatLon; 24 25 import org.openstreetmap.josm.data.gpx.WayPoint; … … 287 288 } 288 289 290 /** 291 * Checks given area for SRTM data. 292 * 293 * @param bounds the bounds/area to check 294 * @return true, if SRTM data are present; otherwise false 295 */ 296 public static boolean hasSrtmData(Bounds bounds) { 297 if (bounds == null) return false; 298 299 LatLon tl = bounds.getMin(); 300 LatLon br = bounds.getMax(); 301 302 return isValidElevation(getSrtmElevation(tl)) && 303 isValidElevation(getSrtmElevation(br)); 304 } 305 289 306 /* 290 307 * Gets the geoid height for the given way point. See also {@link -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileDialog.java
r29963 r29982 1 1 /** 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 2 * This program is free software: you can redistribute it and/or modify it under 3 * the terms of the GNU General Public License as published by the 4 * Free Software Foundation, either version 3 of the License, or 5 * (at your option) any later version. 6 6 * 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 7 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 8 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 9 * See the GNU General Public License for more details. 10 10 * 11 * You should have received a copy of the GNU General Public License along with this program. 11 * You should have received a copy of the GNU General Public License along with this program. 12 12 * If not, see <http://www.gnu.org/licenses/>. 13 13 */ … … 54 54 /** 55 55 * @author Oliver Wieland <oliver.wieland@online.de> 56 * Implements a JOSM ToggleDialog to show the elevation profile. It monitors the 57 * connection between layer and elevation profile. 56 * Implements a JOSM ToggleDialog to show the elevation profile. It monitors the 57 * connection between layer and elevation profile. 58 58 */ 59 59 public class ElevationProfileDialog extends ToggleDialog implements LayerChangeListener, ComponentListener { 60 60 61 private static final String EMPTY_DATA_STRING = "-"; 62 /** 63 * 64 */ 65 private static final long serialVersionUID = -868463893732535577L; 66 /* Elevation profile instance */ 67 private IElevationModel model; 68 /* GPX data */ 69 private GpxLayer activeLayer = null; 70 private HashMap<GpxLayer, ElevationModel> layerMap = new HashMap<GpxLayer, ElevationModel>(); 71 72 /* UI elements */ 73 private ElevationProfilePanel profPanel; 74 private JLabel minHeightLabel; 75 private JLabel maxHeightLabel; 76 private JLabel avrgHeightLabel; 77 private JLabel elevationGainLabel; 78 private JLabel totalTimeLabel; 79 private JLabel distLabel; 80 private JComboBox trackCombo; 81 private JButton zoomButton; 82 83 /* Listener to the elevation model */ 84 private List<IElevationModelListener> listeners = new ArrayList<IElevationModelListener>(); 85 86 /** 87 * Corresponding layer instance within map view. 88 */ 89 private ElevationProfileLayer profileLayer; 90 91 /** 92 * Default constructor 93 */ 94 public ElevationProfileDialog() { 95 this(tr("Elevation Profile"), "elevation", 96 tr("Open the elevation profile window."), null, 200, true); 97 } 98 99 /** 100 * Constructor (see below) 101 */ 102 public ElevationProfileDialog(String name, String iconName, String tooltip, 103 Shortcut shortcut, int preferredHeight) { 104 this(name, iconName, tooltip, shortcut, preferredHeight, false); 105 } 106 107 /** 108 * Constructor 109 * 110 * @param name 111 * the name of the dialog 112 * @param iconName 113 * the name of the icon to be displayed 114 * @param tooltip 115 * the tool tip 116 * @param shortcut 117 * the shortcut 118 * @param preferredHeight 119 * the preferred height for the dialog 120 * @param defShow 121 * if the dialog should be shown by default, if there is no 122 * preference 123 */ 124 public ElevationProfileDialog(String name, String iconName, String tooltip, 125 Shortcut shortcut, int preferredHeight, boolean defShow) { 126 super(name, iconName, tooltip, shortcut, preferredHeight, defShow); 127 128 // create model 129 model = new ElevationModel(); 130 131 // top panel 132 JPanel rootPanel = new JPanel(); 133 GridLayout gridLayout1 = new GridLayout(2, 1); 134 rootPanel.setLayout(gridLayout1); 135 136 // statistics panel 137 JPanel statPanel = new JPanel(); 138 GridLayout gridLayoutStat = new GridLayout(2, 6); 139 statPanel.setLayout(gridLayoutStat); 140 141 // first row: Headlines with bold font 142 String[] labels = new String[]{tr("Min"), tr("Avrg"), tr("Max"), tr("Dist"), tr("Gain"), tr("Time")}; 143 for (int i = 0; i < labels.length; i++) { 144 JLabel lbl = new JLabel(labels[i]); 145 lbl.setFont(getFont().deriveFont(Font.BOLD)); 146 statPanel.add(lbl); 61 private static final String EMPTY_DATA_STRING = "-"; 62 /** 63 * 64 */ 65 private static final long serialVersionUID = -868463893732535577L; 66 /* Elevation profile instance */ 67 private IElevationModel model; 68 /* GPX data */ 69 private GpxLayer activeLayer = null; 70 private final HashMap<GpxLayer, ElevationModel> layerMap = new HashMap<GpxLayer, ElevationModel>(); 71 72 /* UI elements */ 73 private final ElevationProfilePanel profPanel; 74 private final JLabel minHeightLabel; 75 private final JLabel maxHeightLabel; 76 private final JLabel avrgHeightLabel; 77 private final JLabel elevationGainLabel; 78 private final JLabel totalTimeLabel; 79 private final JLabel distLabel; 80 private final JComboBox trackCombo; 81 private final JButton zoomButton; 82 83 /* Listener to the elevation model */ 84 private final List<IElevationModelListener> listeners = new ArrayList<IElevationModelListener>(); 85 86 /** 87 * Corresponding layer instance within map view. 88 */ 89 private ElevationProfileLayer profileLayer; 90 91 /** 92 * Default constructor 93 */ 94 public ElevationProfileDialog() { 95 this(tr("Elevation Profile"), "elevation", 96 tr("Open the elevation profile window."), null, 200, true); 97 } 98 99 /** 100 * Constructor (see below) 101 */ 102 public ElevationProfileDialog(String name, String iconName, String tooltip, 103 Shortcut shortcut, int preferredHeight) { 104 this(name, iconName, tooltip, shortcut, preferredHeight, false); 105 } 106 107 /** 108 * Constructor 109 * 110 * @param name 111 * the name of the dialog 112 * @param iconName 113 * the name of the icon to be displayed 114 * @param tooltip 115 * the tool tip 116 * @param shortcut 117 * the shortcut 118 * @param preferredHeight 119 * the preferred height for the dialog 120 * @param defShow 121 * if the dialog should be shown by default, if there is no 122 * preference 123 */ 124 public ElevationProfileDialog(String name, String iconName, String tooltip, 125 Shortcut shortcut, int preferredHeight, boolean defShow) { 126 super(name, iconName, tooltip, shortcut, preferredHeight, defShow); 127 128 // create model 129 model = new ElevationModel(); 130 131 // top panel 132 JPanel rootPanel = new JPanel(); 133 GridLayout gridLayout1 = new GridLayout(2, 1); 134 rootPanel.setLayout(gridLayout1); 135 136 // statistics panel 137 JPanel statPanel = new JPanel(); 138 GridLayout gridLayoutStat = new GridLayout(2, 6); 139 statPanel.setLayout(gridLayoutStat); 140 141 // first row: Headlines with bold font 142 String[] labels = new String[]{tr("Min"), tr("Avrg"), tr("Max"), tr("Dist"), tr("Gain"), tr("Time")}; 143 for (int i = 0; i < labels.length; i++) { 144 JLabel lbl = new JLabel(labels[i]); 145 lbl.setFont(getFont().deriveFont(Font.BOLD)); 146 statPanel.add(lbl); 147 } 148 149 // second row 150 minHeightLabel = new JLabel("0 m"); 151 statPanel.add(minHeightLabel); 152 avrgHeightLabel = new JLabel("0 m"); 153 statPanel.add(avrgHeightLabel); 154 maxHeightLabel = new JLabel("0 m"); 155 statPanel.add(maxHeightLabel); 156 distLabel = new JLabel("0 km"); 157 statPanel.add(distLabel); 158 elevationGainLabel = new JLabel("0 m"); 159 statPanel.add(elevationGainLabel); 160 totalTimeLabel = new JLabel("0"); 161 statPanel.add(totalTimeLabel); 162 163 // track selection panel 164 JPanel trackPanel = new JPanel(); 165 FlowLayout fl = new FlowLayout(FlowLayout.LEFT); 166 trackPanel.setLayout(fl); 167 168 JLabel lbTrack = new JLabel(tr("Tracks")); 169 lbTrack.setFont(getFont().deriveFont(Font.BOLD)); 170 trackPanel.add(lbTrack); 171 172 zoomButton = new JButton(tr("Zoom")); 173 zoomButton.addActionListener(new ActionListener() { 174 @Override 175 public void actionPerformed(ActionEvent arg0) { 176 if (model != null) { 177 IElevationProfile profile = model.getCurrentProfile(); 178 if (profile != null) { 179 Main.map.mapView.zoomTo(profile.getBounds()); 180 } 147 181 } 148 149 // second row 150 minHeightLabel = new JLabel("0 m"); 151 statPanel.add(minHeightLabel); 152 avrgHeightLabel = new JLabel("0 m"); 153 statPanel.add(avrgHeightLabel); 154 maxHeightLabel = new JLabel("0 m"); 155 statPanel.add(maxHeightLabel); 156 distLabel = new JLabel("0 km"); 157 statPanel.add(distLabel); 158 elevationGainLabel = new JLabel("0 m"); 159 statPanel.add(elevationGainLabel); 160 totalTimeLabel = new JLabel("0"); 161 statPanel.add(totalTimeLabel); 162 163 // track selection panel 164 JPanel trackPanel = new JPanel(); 165 FlowLayout fl = new FlowLayout(FlowLayout.LEFT); 166 trackPanel.setLayout(fl); 167 168 JLabel lbTrack = new JLabel(tr("Tracks")); 169 lbTrack.setFont(getFont().deriveFont(Font.BOLD)); 170 trackPanel.add(lbTrack); 171 172 zoomButton = new JButton(tr("Zoom")); 173 zoomButton.addActionListener(new ActionListener() { 174 @Override 175 public void actionPerformed(ActionEvent arg0) { 176 if (model != null) { 177 IElevationProfile profile = model.getCurrentProfile(); 178 if (profile != null) { 179 Main.map.mapView.zoomTo(profile.getBounds()); 180 } 181 } 182 183 } 184 }); 185 zoomButton.setEnabled(false); 186 187 trackCombo = new JComboBox(new TrackModel()); 188 trackCombo.setPreferredSize(new Dimension(200, 24)); // HACK! 189 trackCombo.setEnabled(false); // we have no model on startup 190 191 trackPanel.add(trackCombo); 192 trackPanel.add(zoomButton); 193 194 // assemble root panel 195 rootPanel.add(statPanel); 196 rootPanel.add(trackPanel); 197 198 add(rootPanel, BorderLayout.PAGE_END); 199 200 // add chart component 201 profPanel = new ElevationProfilePanel(null); 202 add(profPanel, BorderLayout.CENTER); 203 profPanel.addComponentListener(this); 204 205 dock(); 206 } 207 182 183 } 184 }); 185 zoomButton.setEnabled(false); 186 187 trackCombo = new JComboBox(new TrackModel()); 188 trackCombo.setPreferredSize(new Dimension(200, 24)); // HACK! 189 trackCombo.setEnabled(false); // we have no model on startup 190 191 trackPanel.add(trackCombo); 192 trackPanel.add(zoomButton); 193 194 // assemble root panel 195 rootPanel.add(statPanel); 196 rootPanel.add(trackPanel); 197 198 add(rootPanel, BorderLayout.PAGE_END); 199 200 // add chart component 201 profPanel = new ElevationProfilePanel(null); 202 add(profPanel, BorderLayout.CENTER); 203 profPanel.addComponentListener(this); 204 205 dock(); 206 } 207 208 @Override 209 public void showNotify() { 210 MapView.addLayerChangeListener(this); 211 if (Main.isDisplayingMapView()) { 212 Layer layer = Main.map.mapView.getActiveLayer(); 213 if (layer instanceof GpxLayer) { 214 setActiveLayer((GpxLayer) layer); 215 } 216 } 217 } 218 219 @Override 220 public void hideNotify() { 221 MapView.removeLayerChangeListener(this); 222 } 223 224 /** 225 * Gets the elevation model instance. 226 * @return 227 */ 228 public IElevationModel getModel() { 229 return model; 230 } 231 232 /** 233 * Sets the elevation model instance. 234 * @param model The new model. 235 */ 236 public void setModel(IElevationModel model) { 237 if (this.model != model) { 238 this.model = model; 239 profPanel.setElevationModel(model); 240 updateView(); 241 } 242 } 243 244 /** 245 * Gets the associated layer instance of the elevation profile. 246 * @return 247 */ 248 public ElevationProfileLayer getProfileLayer() { 249 return profileLayer; 250 } 251 252 /** 253 * Sets the associated layer instance of the elevation profile. 254 * @param profileLayer The elevation profile layer. 255 */ 256 public void setProfileLayer(ElevationProfileLayer profileLayer) { 257 if (this.profileLayer != profileLayer) { 258 if (this.profileLayer != null) { 259 profPanel.removeSelectionListener(this.profileLayer); 260 } 261 this.profileLayer = profileLayer; 262 profPanel.addSelectionListener(this.profileLayer); 263 } 264 } 265 266 /** 267 * Refreshes the dialog when model data have changed and notifies clients 268 * that the model has changed. 269 */ 270 @SuppressWarnings("unchecked") // TODO: Can be removed in Java 1.7 271 private void updateView() { 272 if (model == null) { 273 disableView(); 274 return; 275 } 276 277 IElevationProfile profile = model.getCurrentProfile(); 278 if (profile != null) { 279 // Show name of profile in title 280 setTitle(String.format("%s: %s", tr("Elevation Profile"), profile.getName())); 281 282 if (profile.hasElevationData()) { 283 // Show elevation data 284 minHeightLabel.setText( 285 ElevationHelper.getElevationText(profile.getMinHeight())); 286 maxHeightLabel.setText( 287 ElevationHelper.getElevationText(profile.getMaxHeight())); 288 avrgHeightLabel.setText( 289 ElevationHelper.getElevationText(profile.getAverageHeight())); 290 elevationGainLabel.setText( 291 ElevationHelper.getElevationText(profile.getGain())); 292 } 293 294 // compute values for time and distance 295 long diff = profile.getTimeDifference(); 296 long minutes = diff / (1000 * 60); 297 long hours = minutes / 60; 298 minutes = minutes % 60; 299 300 double dist = profile.getDistance(); 301 302 totalTimeLabel.setText(String.format("%d:%02d h", hours, minutes)); 303 distLabel.setText(NavigatableComponent.getSystemOfMeasurement().getDistText(dist)); 304 trackCombo.setEnabled(model.profileCount() > 1); 305 trackCombo.setModel(new TrackModel()); 306 zoomButton.setEnabled(true); 307 } else { // no elevation data, -> switch back to empty view 308 disableView(); 309 } 310 311 fireModelChanged(); 312 repaint(); 313 } 314 315 private void disableView() { 316 setTitle(String.format("%s: (No data)", tr("Elevation Profile"))); 317 318 minHeightLabel.setText(EMPTY_DATA_STRING); 319 maxHeightLabel.setText(EMPTY_DATA_STRING); 320 avrgHeightLabel.setText(EMPTY_DATA_STRING); 321 elevationGainLabel.setText(EMPTY_DATA_STRING); 322 totalTimeLabel.setText(EMPTY_DATA_STRING); 323 distLabel.setText(EMPTY_DATA_STRING); 324 trackCombo.setEnabled(false); 325 zoomButton.setEnabled(false); 326 } 327 328 /** 329 * Fires the 'model changed' event to all listeners. 330 */ 331 protected void fireModelChanged() { 332 for (IElevationModelListener listener : listeners) { 333 listener.elevationProfileChanged(getModel().getCurrentProfile()); 334 } 335 } 336 337 /** 338 * Adds a model listener to this instance. 339 * 340 * @param listener 341 * The listener to add. 342 */ 343 public void addModelListener(IElevationModelListener listener) { 344 this.listeners.add(listener); 345 } 346 347 /** 348 * Removes a model listener from this instance. 349 * 350 * @param listener 351 * The listener to remove. 352 */ 353 public void removeModelListener(IElevationModelListener listener) { 354 this.listeners.remove(listener); 355 } 356 357 /** 358 * Removes all listeners from this instance. 359 */ 360 public void removeAllListeners() { 361 this.listeners.clear(); 362 } 363 364 /* (non-Javadoc) 365 * @see org.openstreetmap.josm.gui.MapView.LayerChangeListener#activeLayerChange(org.openstreetmap.josm.gui.layer.Layer, org.openstreetmap.josm.gui.layer.Layer) 366 */ 367 @Override 368 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 369 if (newLayer instanceof GpxLayer) { 370 setActiveLayer((GpxLayer) newLayer); 371 } 372 } 373 374 private void setActiveLayer(GpxLayer newLayer) { 375 if (activeLayer != newLayer) { 376 activeLayer = newLayer; 377 378 // layer does not exist -> create 379 if (!layerMap.containsKey(newLayer)) { 380 GpxData gpxData = newLayer.data; 381 ElevationModel newEM = new ElevationModel(newLayer.getName(), 382 gpxData); 383 layerMap.put(newLayer, newEM); 384 } 385 386 ElevationModel em = layerMap.get(newLayer); 387 setModel(em); 388 } 389 } 390 391 /* (non-Javadoc) 392 * @see org.openstreetmap.josm.gui.MapView.LayerChangeListener#layerAdded(org.openstreetmap.josm.gui.layer.Layer) 393 */ 394 @Override 395 public void layerAdded(Layer newLayer) { 396 if (newLayer instanceof GpxLayer) { 397 GpxLayer gpxLayer = (GpxLayer) newLayer; 398 setActiveLayer(gpxLayer); 399 } 400 } 401 402 /* (non-Javadoc) 403 * @see org.openstreetmap.josm.gui.MapView.LayerChangeListener#layerRemoved(org.openstreetmap.josm.gui.layer.Layer) 404 */ 405 @Override 406 public void layerRemoved(Layer oldLayer) { 407 if (layerMap.containsKey(oldLayer)) { 408 layerMap.remove(oldLayer); 409 } 410 411 if (layerMap.size() == 0) { 412 setModel(null); 413 if (profileLayer != null) { 414 profileLayer.setProfile(null); 415 } 416 } 417 } 418 419 /* 420 * (non-Javadoc) 421 * 422 * @seejava.awt.event.ComponentListener#componentHidden(java.awt.event. 423 * ComponentEvent) 424 */ 425 @Override 426 public void componentHidden(ComponentEvent e) { 427 } 428 429 /* 430 * (non-Javadoc) 431 * 432 * @see 433 * java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent 434 * ) 435 */ 436 @Override 437 public void componentMoved(ComponentEvent e) { 438 } 439 440 /* 441 * (non-Javadoc) 442 * 443 * @seejava.awt.event.ComponentListener#componentResized(java.awt.event. 444 * ComponentEvent) 445 */ 446 @Override 447 public void componentResized(ComponentEvent e) { 448 } 449 450 /* 451 * (non-Javadoc) 452 * 453 * @see 454 * java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent 455 * ) 456 */ 457 @Override 458 public void componentShown(ComponentEvent e) { 459 } 460 461 462 @SuppressWarnings("rawtypes") // TODO: Can be removed in Java 1.7 463 class TrackModel implements ComboBoxModel { 464 private Collection<ListDataListener> listeners; 465 208 466 @Override 209 public void showNotify() { 210 MapView.addLayerChangeListener(this); 211 if (Main.isDisplayingMapView()) { 212 Layer layer = Main.map.mapView.getActiveLayer(); 213 if (layer instanceof GpxLayer) { 214 setActiveLayer((GpxLayer) layer); 215 } 216 } 217 } 218 467 public void addListDataListener(ListDataListener arg0) { 468 if (listeners == null) { 469 listeners = new ArrayList<ListDataListener>(); 470 } 471 listeners.add(arg0); 472 } 473 219 474 @Override 220 public void hideNotify() { 221 MapView.removeLayerChangeListener(this); 222 } 223 224 /** 225 * Gets the elevation model instance. 226 * @return 227 */ 228 public IElevationModel getModel() { 229 return model; 230 } 231 232 /** 233 * Sets the elevation model instance. 234 * @param model The new model. 235 */ 236 public void setModel(IElevationModel model) { 237 if (this.model != model) { 238 this.model = model; 239 profPanel.setElevationModel(model); 240 updateView(); 241 } 242 } 243 244 /** 245 * Gets the associated layer instance of the elevation profile. 246 * @return 247 */ 248 public ElevationProfileLayer getProfileLayer() { 249 return profileLayer; 250 } 251 252 /** 253 * Sets the associated layer instance of the elevation profile. 254 * @param profileLayer The elevation profile layer. 255 */ 256 public void setProfileLayer(ElevationProfileLayer profileLayer) { 257 if (this.profileLayer != profileLayer) { 258 if (this.profileLayer != null) { 259 profPanel.removeSelectionListener(this.profileLayer); 260 } 261 this.profileLayer = profileLayer; 262 profPanel.addSelectionListener(this.profileLayer); 263 } 264 } 265 266 /** 267 * Refreshes the dialog when model data have changed and notifies clients 268 * that the model has changed. 269 */ 270 private void updateView() { 271 if (model == null) { 272 disableView(); 273 return; 274 } 275 276 IElevationProfile profile = model.getCurrentProfile(); 277 if (profile != null) { 278 // Show name of profile in title 279 setTitle(String.format("%s: %s", tr("Elevation Profile"), profile.getName())); 280 281 if (profile.hasElevationData()) { 282 // Show elevation data 283 minHeightLabel.setText( 284 ElevationHelper.getElevationText(profile.getMinHeight())); 285 maxHeightLabel.setText( 286 ElevationHelper.getElevationText(profile.getMaxHeight())); 287 avrgHeightLabel.setText( 288 ElevationHelper.getElevationText(profile.getAverageHeight())); 289 elevationGainLabel.setText( 290 ElevationHelper.getElevationText(profile.getGain())); 291 } 292 293 // compute values for time and distance 294 long diff = profile.getTimeDifference(); 295 long minutes = diff / (1000 * 60); 296 long hours = minutes / 60; 297 minutes = minutes % 60; 298 299 double dist = profile.getDistance(); 300 301 totalTimeLabel.setText(String.format("%d:%d h", hours, minutes)); 302 distLabel.setText(NavigatableComponent.getSystemOfMeasurement().getDistText(dist)); 303 trackCombo.setEnabled(model.profileCount() > 1); 304 trackCombo.setModel(new TrackModel()); 305 zoomButton.setEnabled(true); 306 } else { // no elevation data, -> switch back to empty view 307 disableView(); 308 } 309 310 fireModelChanged(); 311 repaint(); 312 } 313 314 private void disableView() { 315 setTitle(String.format("%s: (No data)", tr("Elevation Profile"))); 316 317 minHeightLabel.setText(EMPTY_DATA_STRING); 318 maxHeightLabel.setText(EMPTY_DATA_STRING); 319 avrgHeightLabel.setText(EMPTY_DATA_STRING); 320 elevationGainLabel.setText(EMPTY_DATA_STRING); 321 totalTimeLabel.setText(EMPTY_DATA_STRING); 322 distLabel.setText(EMPTY_DATA_STRING); 323 trackCombo.setEnabled(false); 324 zoomButton.setEnabled(false); 325 } 326 327 /** 328 * Fires the 'model changed' event to all listeners. 329 */ 330 protected void fireModelChanged() { 331 for (IElevationModelListener listener : listeners) { 332 listener.elevationProfileChanged(getModel().getCurrentProfile()); 333 } 334 } 335 336 /** 337 * Adds a model listener to this instance. 338 * 339 * @param listener 340 * The listener to add. 341 */ 342 public void addModelListener(IElevationModelListener listener) { 343 this.listeners.add(listener); 344 } 345 346 /** 347 * Removes a model listener from this instance. 348 * 349 * @param listener 350 * The listener to remove. 351 */ 352 public void removeModelListener(IElevationModelListener listener) { 353 this.listeners.remove(listener); 354 } 355 356 /** 357 * Removes all listeners from this instance. 358 */ 359 public void removeAllListeners() { 360 this.listeners.clear(); 361 } 362 363 /* (non-Javadoc) 364 * @see org.openstreetmap.josm.gui.MapView.LayerChangeListener#activeLayerChange(org.openstreetmap.josm.gui.layer.Layer, org.openstreetmap.josm.gui.layer.Layer) 365 */ 366 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 367 if (newLayer instanceof GpxLayer) { 368 setActiveLayer((GpxLayer) newLayer); 369 } 370 } 371 372 private void setActiveLayer(GpxLayer newLayer) { 373 if (activeLayer != newLayer) { 374 activeLayer = newLayer; 375 376 // layer does not exist -> create 377 if (!layerMap.containsKey(newLayer)) { 378 GpxData gpxData = newLayer.data; 379 ElevationModel newEM = new ElevationModel(newLayer.getName(), 380 gpxData); 381 layerMap.put(newLayer, newEM); 382 } 383 384 ElevationModel em = layerMap.get(newLayer); 385 setModel(em); 386 } 387 } 388 389 /* (non-Javadoc) 390 * @see org.openstreetmap.josm.gui.MapView.LayerChangeListener#layerAdded(org.openstreetmap.josm.gui.layer.Layer) 391 */ 392 public void layerAdded(Layer newLayer) { 393 if (newLayer instanceof GpxLayer) { 394 GpxLayer gpxLayer = (GpxLayer) newLayer; 395 setActiveLayer(gpxLayer); 396 } 397 } 398 399 /* (non-Javadoc) 400 * @see org.openstreetmap.josm.gui.MapView.LayerChangeListener#layerRemoved(org.openstreetmap.josm.gui.layer.Layer) 401 */ 402 public void layerRemoved(Layer oldLayer) { 403 if (layerMap.containsKey(oldLayer)) { 404 layerMap.remove(oldLayer); 405 } 406 407 if (layerMap.size() == 0) { 408 setModel(null); 409 if (profileLayer != null) { 410 profileLayer.setProfile(null); 411 } 412 } 413 } 414 415 /* 416 * (non-Javadoc) 417 * 418 * @seejava.awt.event.ComponentListener#componentHidden(java.awt.event. 419 * ComponentEvent) 420 */ 421 public void componentHidden(ComponentEvent e) { 422 } 423 424 /* 425 * (non-Javadoc) 426 * 427 * @see 428 * java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent 429 * ) 430 */ 431 public void componentMoved(ComponentEvent e) { 432 } 433 434 /* 435 * (non-Javadoc) 436 * 437 * @seejava.awt.event.ComponentListener#componentResized(java.awt.event. 438 * ComponentEvent) 439 */ 440 public void componentResized(ComponentEvent e) { 441 } 442 443 /* 444 * (non-Javadoc) 445 * 446 * @see 447 * java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent 448 * ) 449 */ 450 public void componentShown(ComponentEvent e) { 451 } 452 453 454 class TrackModel implements ComboBoxModel { 455 private Collection<ListDataListener> listeners; 456 457 @Override 458 public void addListDataListener(ListDataListener arg0) { 459 if (listeners == null) { 460 listeners = new ArrayList<ListDataListener>(); 461 } 462 listeners.add(arg0); 463 } 464 465 @Override 466 public IElevationProfile getElementAt(int index) { 467 if (model == null) return null; 468 469 IElevationProfile ep = model.getProfiles().get(index); 470 return ep; 471 } 472 473 @Override 474 public int getSize() { 475 if (model == null) return 0; 476 477 return model.profileCount(); 478 } 479 480 @Override 481 public void removeListDataListener(ListDataListener listener) { 482 if (listeners == null) return; 483 484 listeners.remove(listener); 485 } 486 487 @Override 488 public Object getSelectedItem() { 489 if (model == null) return null; 490 491 return model.getCurrentProfile(); 492 } 493 494 @Override 495 public void setSelectedItem(Object selectedObject) { 496 if (model != null && selectedObject instanceof IElevationProfile) { 497 model.setCurrentProfile((IElevationProfile) selectedObject); 498 profileLayer.setProfile(model.getCurrentProfile()); 499 500 repaint(); 501 } 502 } 503 504 } 475 public IElevationProfile getElementAt(int index) { 476 if (model == null) return null; 477 478 IElevationProfile ep = model.getProfiles().get(index); 479 return ep; 480 } 481 482 @Override 483 public int getSize() { 484 if (model == null) return 0; 485 486 return model.profileCount(); 487 } 488 489 @Override 490 public void removeListDataListener(ListDataListener listener) { 491 if (listeners == null) return; 492 493 listeners.remove(listener); 494 } 495 496 @Override 497 public Object getSelectedItem() { 498 if (model == null) return null; 499 500 return model.getCurrentProfile(); 501 } 502 503 @Override 504 public void setSelectedItem(Object selectedObject) { 505 if (model != null && selectedObject instanceof IElevationProfile) { 506 model.setCurrentProfile((IElevationProfile) selectedObject); 507 profileLayer.setProfile(model.getCurrentProfile()); 508 509 repaint(); 510 } 511 } 512 513 } 505 514 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfilePanel.java
r29981 r29982 52 52 */ 53 53 private static final long serialVersionUID = -7343429725259575319L; 54 private static final int BOTTOM_TEXT_Y_OFFSET = 7; 55 54 56 private IElevationModel model; 55 57 private Rectangle plotArea; … … 204 206 IElevationProfile profile = model.getCurrentProfile(); 205 207 if (profile != null && profile.hasElevationData()) { 206 drawAlignedString(formatDate(profile.getStart()), 5, y1 + 5, 208 // Draw start and end date 209 drawAlignedString(formatDate(profile.getStart()), 5, y1 + BOTTOM_TEXT_Y_OFFSET, 207 210 TextAlignment.Left, g); 208 211 drawAlignedString(formatDate(profile.getEnd()), 209 getPlotRight(), y1 + 5, TextAlignment.Right, g); 210 211 212 getPlotRight(), y1 + BOTTOM_TEXT_Y_OFFSET, TextAlignment.Right, g); 213 214 // Show SRTM indicator 215 if (ElevationHelper.hasSrtmData(profile.getBounds())) { 216 String txt = "SRTM"; 217 drawAlignedString(txt, getPlotHCenter(), y1 + BOTTOM_TEXT_Y_OFFSET, TextAlignment.Centered, g); 218 } 212 219 drawProfile(g); 213 220 drawElevationLines(g); … … 425 432 ElevationWayPointKind.Plain); 426 433 434 // draw cursor 427 435 if (i == this.selectedIndex) { 428 436 g.setColor(Color.BLACK); … … 435 443 c = renderer.getColorForWaypoint(profile, wpt, ElevationWayPointKind.Highlighted); 436 444 } 445 437 446 int yEle = getYForEelevation(eleVal); 438 447 int x = getPlotLeft() + i; … … 442 451 g.setColor(ElevationColors.EPLightBlue); 443 452 } 453 444 454 g.setColor(oldC); 445 455 }
Note:
See TracChangeset
for help on using the changeset viewer.