Changeset 29958 in osm for applications/editors/josm
- Timestamp:
- 2013-09-24T21:50:36+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationModel.java
r29955 r29958 40 40 private GpxData gpxData; 41 41 private String name; 42 private WayPointMap children= new WayPointMap();42 private WayPointMap profiles = new WayPointMap(); 43 43 private List<IElevationModelListener> listeners = new ArrayList<IElevationModelListener>(); 44 44 private List<WayPoint> buffer = new ArrayList<WayPoint>(); … … 78 78 */ 79 79 protected WayPointMap getTracks() { 80 return children;80 return profiles; 81 81 } 82 82 … … 86 86 protected void fireModelChanged() { 87 87 for (IElevationModelListener listener : listeners) { 88 if ( children != null && children.size() > 0)88 if (profiles != null && profiles.size() > 0) 89 89 listener.elevationProfileChanged(getCurrentProfile()); 90 90 } … … 149 149 150 150 public void start() { 151 curProfile = new ElevationProfileBase(name); 152 } 153 154 public void end() { 155 String trackName = name; //gpxData.getString(GpxData.META_NAME);// "Track#" + trackCounter; 156 157 if (trackCounter > 0) { 158 trackName += "." + trackCounter; 151 curProfile = new ElevationProfileBase(name); 152 trackCounter++; 153 } 154 155 public void end() { 156 commitTrack(); 157 } 158 159 160 @Override 161 public void start(GpxTrack track) { 162 // check GPX data 163 String trackName = (String) track.get("name"); 164 165 // no name given, build artificial one 166 if (trackName == null) { 167 trackName = (String) track.get(GpxData.META_NAME); 168 if (trackName == null) { 169 trackName = name + "." + trackCounter; 159 170 } 160 addTrackOrRoute(trackName); 161 trackCounter++; 162 } 163 164 165 @Override 166 public void start(GpxTrack track) { 167 curProfile = new ElevationProfileBase(name); 171 } 172 173 curProfile = new ElevationProfileBase(trackName); 168 174 } 169 175 … … 173 179 174 180 curProfile.setDistance(track.length()); 175 addTrackOrRoute(name);181 commitTrack(); 176 182 } 177 183 … … 192 198 * @param trackName the track name 193 199 */ 194 private void addTrackOrRoute(String trackName) { 195 if (buffer.size() > 0) { 200 private void commitTrack() { 201 if (buffer.size() > 0) { 202 // assign way points to profile... 196 203 curProfile.setWayPoints(buffer); 197 curProfile.setName(trackName); 198 children.add(curProfile); 204 // ... and add to profile list 205 profiles.add(curProfile); 206 buffer.clear(); 199 207 } 200 208 } … … 214 222 @Override 215 223 public List<IElevationProfile> getProfiles() { 216 return children;224 return profiles; 217 225 } 218 226 … … 221 229 if (currentProfileIndex < 0 || currentProfileIndex >= profileCount()) return null; 222 230 223 return children.get(currentProfileIndex);231 return profiles.get(currentProfileIndex); 224 232 } 225 233 … … 228 236 CheckParameterUtil.ensureParameterNotNull(newProfile); 229 237 230 if (! children.contains(newProfile)) {231 children.add(newProfile);238 if (!profiles.contains(newProfile)) { 239 profiles.add(newProfile); 232 240 } 233 241 234 setCurrentProfile( children.indexOf(newProfile));242 setCurrentProfile(profiles.indexOf(newProfile)); 235 243 } 236 244 … … 245 253 @Override 246 254 public int profileCount() { 247 return children != null ? children.size() : 0;255 return profiles != null ? profiles.size() : 0; 248 256 } 249 257 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gpx/ElevationProfileBase.java
r29955 r29958 493 493 494 494 public String toString() { 495 return "ElevationProfileBase [start=" + getStart() + ", end=" + getEnd()495 return name; /*"ElevationProfileBase [start=" + getStart() + ", end=" + getEnd() 496 496 + ", minHeight=" + getMinHeight() + ", maxHeight=" 497 + getMaxHeight() + "]"; 497 + getMaxHeight() + "]";*/ 498 498 } 499 499 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileDialog.java
r29955 r29958 18 18 19 19 import java.awt.BorderLayout; 20 import java.awt.FlowLayout; 20 21 import java.awt.Font; 21 22 import java.awt.GridLayout; … … 23 24 import java.awt.event.ComponentListener; 24 25 import java.util.ArrayList; 26 import java.util.Collection; 25 27 import java.util.HashMap; 26 28 import java.util.List; 27 29 30 import javax.swing.ComboBoxModel; 31 import javax.swing.JComboBox; 28 32 import javax.swing.JLabel; 29 33 import javax.swing.JPanel; 30 import javax.swing. JRadioButton;31 import javax.swing. JTextField;34 import javax.swing.event.ListDataEvent; 35 import javax.swing.event.ListDataListener; 32 36 33 37 import org.openstreetmap.josm.Main; … … 44 48 import org.openstreetmap.josm.plugins.elevation.IElevationProfile; 45 49 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationModel; 46 import org.openstreetmap.josm.plugins.elevation.gpx.GeoidCorrectionKind;47 50 import org.openstreetmap.josm.tools.Shortcut; 48 51 /** … … 72 75 private JLabel totalTimeLabel; 73 76 private JLabel distLabel; 77 private JComboBox<IElevationProfile> trackCombo; 78 74 79 /* Listener to the elevation model */ 75 80 private List<IElevationModelListener> listeners = new ArrayList<IElevationModelListener>(); … … 78 83 * Corresponding layer instance within map view. 79 84 */ 80 private ElevationProfileLayer profileLayer; 85 private ElevationProfileLayer profileLayer; 86 81 87 82 88 /** … … 116 122 Shortcut shortcut, int preferredHeight, boolean defShow) { 117 123 super(name, iconName, tooltip, shortcut, preferredHeight, defShow); 124 125 // create model 126 model = new ElevationModel(); 118 127 119 JPanel dataPanel = new JPanel(); 120 GridLayout gridLayout = new GridLayout(2, 6); 121 dataPanel.setLayout(gridLayout); 128 // top panel 129 JPanel rootPanel = new JPanel(); 130 GridLayout gridLayout1 = new GridLayout(2, 1); 131 rootPanel.setLayout(gridLayout1); 132 133 // statistics panel 134 JPanel statPanel = new JPanel(); 135 GridLayout gridLayoutStat = new GridLayout(2, 6); 136 statPanel.setLayout(gridLayoutStat); 122 137 123 138 // first row: Headlines with bold font 124 JLabel lbl = new JLabel(tr("Min")); 125 lbl.setFont(getFont().deriveFont(Font.BOLD)); 126 dataPanel.add(lbl); 127 lbl = new JLabel(tr("Avrg")); 128 lbl.setFont(getFont().deriveFont(Font.BOLD)); 129 dataPanel.add(lbl); 130 lbl = new JLabel(tr("Max")); 131 lbl.setFont(getFont().deriveFont(Font.BOLD)); 132 dataPanel.add(lbl); 133 lbl = new JLabel(tr("Dist")); 134 lbl.setFont(getFont().deriveFont(Font.BOLD)); 135 dataPanel.add(lbl); 136 lbl = new JLabel(tr("Gain")); 137 lbl.setFont(getFont().deriveFont(Font.BOLD)); 138 dataPanel.add(lbl); 139 lbl = new JLabel(tr("Time")); 140 lbl.setFont(getFont().deriveFont(Font.BOLD)); 141 dataPanel.add(lbl); 142 139 String[] labels = new String[]{tr("Min"), tr("Avrg"), tr("Max"), tr("Dist"), tr("Gain"), tr("Time")}; 140 for (int i = 0; i < labels.length; i++) { 141 JLabel lbl = new JLabel(labels[i]); 142 lbl.setFont(getFont().deriveFont(Font.BOLD)); 143 statPanel.add(lbl); 144 } 145 143 146 // second row 144 147 minHeightLabel = new JLabel("0 m"); 145 dataPanel.add(minHeightLabel);148 statPanel.add(minHeightLabel); 146 149 avrgHeightLabel = new JLabel("0 m"); 147 dataPanel.add(avrgHeightLabel);150 statPanel.add(avrgHeightLabel); 148 151 maxHeightLabel = new JLabel("0 m"); 149 dataPanel.add(maxHeightLabel);152 statPanel.add(maxHeightLabel); 150 153 distLabel = new JLabel("0 km"); 151 dataPanel.add(distLabel);154 statPanel.add(distLabel); 152 155 elevationGainLabel = new JLabel("0 m"); 153 dataPanel.add(elevationGainLabel);156 statPanel.add(elevationGainLabel); 154 157 totalTimeLabel = new JLabel("0"); 155 dataPanel.add(totalTimeLabel); 156 157 add(dataPanel, BorderLayout.PAGE_END); 158 model = new ElevationModel(); 159 158 statPanel.add(totalTimeLabel); 159 160 // track selection panel 161 JPanel trackPanel = new JPanel(); 162 FlowLayout fl = new FlowLayout(FlowLayout.LEFT); 163 trackPanel.setLayout(fl); 164 165 JLabel lbTrack = new JLabel(tr("Tracks")); 166 lbTrack.setFont(getFont().deriveFont(Font.BOLD)); 167 trackPanel.add(lbTrack); 168 169 trackCombo = new JComboBox<IElevationProfile>(new TrackModel()); 170 trackPanel.add(trackCombo); 171 172 // assemble root panel 173 rootPanel.add(statPanel); 174 rootPanel.add(trackPanel); 175 176 add(rootPanel, BorderLayout.PAGE_END); 177 178 // add chart component 160 179 profPanel = new ElevationProfilePanel(null); 161 180 add(profPanel, BorderLayout.CENTER); … … 258 277 totalTimeLabel.setText(String.format("%d:%d h", hours, minutes)); 259 278 distLabel.setText(NavigatableComponent.getSystemOfMeasurement().getDistText(dist)); 279 trackCombo.setEnabled(model.profileCount() > 1); 260 280 } else { // no elevation data, -> switch back to empty view 261 281 setTitle(String.format("%s: (No data)", tr("Elevation Profile"))); … … 267 287 totalTimeLabel.setText(EMPTY_DATA_STRING); 268 288 distLabel.setText(EMPTY_DATA_STRING); 269 } 270 289 trackCombo.setEnabled(false); 290 } 291 271 292 fireModelChanged(); 272 293 repaint(); … … 398 419 public void componentShown(ComponentEvent e) { 399 420 } 421 422 423 class TrackModel implements ComboBoxModel<IElevationProfile> { 424 private Collection<ListDataListener> listeners; 425 426 @Override 427 public void addListDataListener(ListDataListener arg0) { 428 if (listeners == null) { 429 listeners = new ArrayList<ListDataListener>(); 430 } 431 listeners.add(arg0); 432 } 433 434 @Override 435 public IElevationProfile getElementAt(int index) { 436 if (model == null) return null; 437 438 IElevationProfile ep = model.getProfiles().get(index); 439 return ep; 440 } 441 442 @Override 443 public int getSize() { 444 if (model == null) return 0; 445 446 return model.profileCount(); 447 } 448 449 @Override 450 public void removeListDataListener(ListDataListener listener) { 451 if (listeners == null) return; 452 453 listeners.remove(listener); 454 } 455 456 @Override 457 public Object getSelectedItem() { 458 if (model == null) return null; 459 460 return model.getCurrentProfile(); 461 } 462 463 @Override 464 public void setSelectedItem(Object selectedObject) { 465 if (model != null && selectedObject instanceof IElevationProfile) { 466 model.setCurrentProfile((IElevationProfile) selectedObject); 467 profileLayer.setProfile(model.getCurrentProfile()); 468 469 repaint(); 470 } 471 } 472 473 } 400 474 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileLayer.java
r29955 r29958 31 31 import org.openstreetmap.josm.gui.layer.Layer; 32 32 import org.openstreetmap.josm.plugins.elevation.ElevationHelper; 33 import org.openstreetmap.josm.plugins.elevation.IElevationModelListener; 33 34 import org.openstreetmap.josm.plugins.elevation.IElevationProfile; 34 35 import org.openstreetmap.josm.plugins.elevation.gpx.ElevationWayPointKind; … … 42 43 * 43 44 */ 44 public class ElevationProfileLayer extends 45 org.openstreetmap.josm.gui.layer.Layer implements IElevationProfileSelectionListener { 45 public class ElevationProfileLayer extends Layer implements IElevationProfileSelectionListener { 46 46 47 private static final double Level_Factor = 100.0; 47 48 private IElevationProfile profile;
Note:
See TracChangeset
for help on using the changeset viewer.