Changeset 23721 in osm for applications/editors/josm/plugins/ElevationProfile/src
- Timestamp:
- 2010-10-20T00:26:35+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/ElevationProfile
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile
-
Property svn:ignore
set to
lib
build
doc
test
-
Property svn:ignore
set to
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationProfileBase.java
r23709 r23721 443 443 */ 444 444 public boolean hasElevationData() { 445 return minHeight == maxHeight;445 return minHeight != maxHeight; 446 446 } 447 447 -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationProfilePlugin.java
r23709 r23721 65 65 if (newFrame != null) { 66 66 newFrame.addToggleDialog(eleProfileDlg); 67 eleProfileDlg.addModelListener(eleMode); 67 eleProfileDlg.addModelListener(eleMode); 68 68 } 69 69 … … 73 73 Main.map.mapView.addPropertyChangeListener(eleProfileDlg); 74 74 MapView.addLayerChangeListener(eleProfileDlg); 75 eleProfileDlg.setProfileLayer(getCurrentLayer()); 75 76 } 76 77 } … … 84 85 if(currentLayer == null){ 85 86 currentLayer = new ElevationProfileLayer("Elevation profile"); 86 Main.main.addLayer(currentLayer); 87 Main.main.addLayer(currentLayer); 87 88 } 88 89 return currentLayer; -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/ElevationWayPointKind.java
r23709 r23721 21 21 public enum ElevationWayPointKind { 22 22 Plain, // Simple way point 23 Highlighted, // Highlighted waypoint 23 24 StartPoint, // First way point 24 25 EndPoint, // Last way point … … 27 28 ElevationGain, // Elevation gain 28 29 ElevationLoss, // Elevation loss 29 FullHour // Full Hour 30 FullHour // Full Hour 30 31 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/DefaultElevationProfileRenderer.java
r23709 r23721 88 88 return LOW_COLOR; 89 89 } 90 case Highlighted: 91 return Color.ORANGE; 90 92 case ElevationGain: 91 93 return Color.GREEN; … … 98 100 case MinElevation: 99 101 return LOW_COLOR; 100 102 101 103 case StartPoint: 102 104 return START_COLOR; … … 177 179 if (kind == ElevationWayPointKind.FullHour) { 178 180 int hour = WayPointHelper.getHourOfWayPoint(wpt); 179 drawLabel(String.format("%d:00", hour), pnt.x, pnt.y + g.getFontMetrics().getHeight(), g); 181 drawLabel(String.format("%02d:00", hour), pnt.x, pnt.y + g.getFontMetrics().getHeight(), g); 182 } 183 184 if (kind == ElevationWayPointKind.Highlighted) { 185 int eleH = (int) WayPointHelper.getElevation(wpt); 186 int hour = WayPointHelper.getHourOfWayPoint(wpt); 187 int min = WayPointHelper.getMinuteOfWayPoint(wpt); 188 drawSphere(g, Color.WHITE, c, pnt.x, pnt.y, r2 * 2); 189 drawLabel(String.format("%02d:%02d", hour, min), pnt.x, pnt.y - g.getFontMetrics().getHeight(), g); 190 drawLabel(String.format("%dm", eleH), pnt.x, pnt.y + g.getFontMetrics().getHeight(), g); 180 191 } 181 192 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationColors.java
r23709 r23721 26 26 public static Color EPLightBlue = new Color(176, 187, 208); 27 27 28 public static Color EPOrange = new Color(180, 140, 115); 29 28 30 public static Color EPLightBeige = new Color(235, 235, 215); 29 31 public static Color EPMidBeige = new Color(227, 222, 215); -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileDialog.java
r23709 r23721 38 38 import javax.swing.JTextField; 39 39 40 import org.openstreetmap.josm.Main; 40 41 import org.openstreetmap.josm.data.gpx.GpxData; 41 42 import org.openstreetmap.josm.gui.MapView; … … 81 82 private JRadioButton geoidFixed; 82 83 private JTextField geoidFixedValue; 84 85 private ElevationProfileLayer profileLayer; 83 86 84 87 /** … … 118 121 Shortcut shortcut, int preferredHeight, boolean defShow) { 119 122 super(name, iconName, tooltip, shortcut, preferredHeight, defShow); 120 123 121 124 JPanel dataPanel = new JPanel(new GridBagLayout()); 122 125 GridBagConstraints c = new GridBagConstraints(); … … 273 276 updateView(); 274 277 } 278 } 279 } 280 281 public ElevationProfileLayer getProfileLayer() { 282 return profileLayer; 283 } 284 285 public void setProfileLayer(ElevationProfileLayer profileLayer) { 286 if (this.profileLayer != profileLayer) { 287 if (this.profileLayer != null) { 288 profPanel.removeSelectionListener(this.profileLayer); 289 } 290 this.profileLayer = profileLayer; 291 profPanel.addSelectionListener(this.profileLayer); 275 292 } 276 293 } … … 399 416 layerMap.put(newLayer, em); 400 417 } 401 418 419 System.out.println("Active layer: " + newLayer.getName()); 402 420 ElevationModel em = layerMap.get(newLayer); 403 421 em.setSliceSize(slices); 404 422 setModel(em); 423 405 424 } 406 425 } … … 408 427 public void layerAdded(Layer newLayer) { 409 428 createLayer(newLayer); 429 System.out.println("layerAdded: " + newLayer.getName()); 410 430 } 411 431 -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfileLayer.java
r23709 r23721 41 41 */ 42 42 public class ElevationProfileLayer extends 43 org.openstreetmap.josm.gui.layer.Layer {43 org.openstreetmap.josm.gui.layer.Layer implements IElevationProfileSelectionListener { 44 44 private IElevationProfile profile; 45 45 private IElevationProfileRenderer renderer = new DefaultElevationProfileRenderer(); 46 private WayPoint selWayPoint = null; 46 47 47 48 /** … … 154 155 WayPoint lastWpt = null; 155 156 int lastEle = 0; 157 int index = 0; 156 158 157 159 if (profile != null) { … … 159 161 int ele = (int) WayPointHelper.getElevation(wpt); 160 162 161 if (lastWpt != null) { 162 int h1 = WayPointHelper.getHourOfWayPoint(wpt); 163 int h2 = WayPointHelper.getHourOfWayPoint(lastWpt); 164 if (h1 != h2) { // hour changed? 163 if (selWayPoint == null) { 164 if (lastWpt != null) { 165 int h1 = WayPointHelper.getHourOfWayPoint(wpt); 166 int h2 = WayPointHelper.getHourOfWayPoint(lastWpt); 167 if (h1 != h2) { // hour changed? 168 renderer.renderWayPoint(g, profile, mv, wpt, 169 ElevationWayPointKind.FullHour); 170 } else { // check for elevation gain 171 if (ele > lastEle) { 172 renderer.renderWayPoint(g, profile, mv, wpt, 173 ElevationWayPointKind.ElevationGain); 174 } else { 175 renderer.renderWayPoint(g, profile, mv, wpt, 176 ElevationWayPointKind.ElevationLoss); 177 } 178 } 179 } 180 } else { 181 if (selWayPoint == wpt) { 165 182 renderer.renderWayPoint(g, profile, mv, wpt, 166 ElevationWayPointKind.FullHour);167 } else { // check for elevation gain183 ElevationWayPointKind.Highlighted); 184 } else { 168 185 if (ele > lastEle) { 169 186 renderer.renderWayPoint(g, profile, mv, wpt, … … 175 192 } 176 193 } 177 194 178 195 // remember for next iteration 179 196 lastEle = (int) WayPointHelper.getElevation(wpt); 180 197 lastWpt = wpt; 198 index++; 181 199 } 182 200 … … 206 224 } 207 225 226 @Override 227 public void selectedWayPointChanged(WayPoint newWayPoint) { 228 if (selWayPoint != newWayPoint) { 229 selWayPoint = newWayPoint; 230 Main.map.repaint(); 231 } 232 } 233 208 234 } -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/gui/ElevationProfilePanel.java
r23709 r23721 5 5 import java.awt.Color; 6 6 import java.awt.Dimension; 7 import java.awt.Event; 7 8 import java.awt.Font; 8 9 import java.awt.FontMetrics; … … 11 12 import java.awt.event.ComponentEvent; 12 13 import java.awt.event.ComponentListener; 14 import java.awt.event.MouseEvent; 15 import java.awt.event.MouseListener; 16 import java.awt.event.MouseMotionListener; 13 17 import java.text.Format; 14 18 import java.text.SimpleDateFormat; 19 import java.util.ArrayList; 15 20 import java.util.Date; 21 import java.util.List; 16 22 17 23 import javax.swing.BorderFactory; … … 24 30 import org.openstreetmap.josm.plugins.elevation.WayPointHelper; 25 31 26 public class ElevationProfilePanel extends JPanel implements ComponentListener { 32 /** 33 * Provides the panel showing the elevation profile. 34 * @author Oliver 35 * 36 */ 37 public class ElevationProfilePanel extends JPanel implements ComponentListener, MouseMotionListener { 27 38 /** 28 39 * Serial version UID … … 32 43 private Rectangle plotArea; 33 44 private IElevationProfileRenderer renderer = new DefaultElevationProfileRenderer(); 34 45 private int selectedIndex = -1; 46 private List<IElevationProfileSelectionListener> selectionChangedListeners = new ArrayList<IElevationProfileSelectionListener>(); 47 private boolean isPainting; 48 49 /** 50 * Constructs a new ElevationProfilePanel with the given elevation profile. 51 * @param profile The elevation profile to show in the panel. 52 */ 35 53 public ElevationProfilePanel(IElevationProfile profile) { 36 54 super(); … … 40 58 createOrUpdatePlotArea(); 41 59 addComponentListener(this); 42 } 43 60 addMouseMotionListener(this); 61 } 62 63 /** 64 * Gets the elevation profile instance. 65 * @return 66 */ 44 67 public IElevationProfile getProfile() { 45 68 return profile; 46 69 } 47 70 71 /** 72 * Sets the new elevation profile instance. 73 * @param profile 74 */ 48 75 public void setElevationModel(IElevationProfile profile) { 49 this.profile = profile; 50 } 51 76 if (this.profile != profile) { 77 this.profile = profile; 78 invalidate(); 79 } 80 } 81 82 /** 83 * Gets the plot area coordinates. 84 * @return 85 */ 52 86 public Rectangle getPlotArea() { 53 87 return plotArea; 54 88 } 55 89 90 /** 91 * Sets the plot area coordinates. 92 * @param plotArea 93 */ 56 94 public void setPlotArea(Rectangle plotArea) { 57 95 this.plotArea = plotArea; 58 96 } 59 97 98 /** 99 * Gets the selected index of the bar. 100 * @return 101 */ 102 public int getSelectedIndex() { 103 return selectedIndex; 104 } 105 106 /** 107 * Sets the selected index of the bar. 108 * @param selectedIndex 109 */ 110 public void setSelectedIndex(int selectedIndex) { 111 this.selectedIndex = selectedIndex; 112 } 113 114 /** 115 * Gets the selected (highlighted) way point. 116 * @return The selected way point or null, if no way point is selected. 117 */ 118 public WayPoint getSelectedWayPoint() { 119 if (this.selectedIndex != -1 && profile != null && profile.getWayPoints() != null && profile.getWayPoints().size() > this.selectedIndex) { 120 return profile.getWayPoints().get(this.selectedIndex); 121 } else { 122 return null; 123 } 124 } 125 126 /** 127 * Adds a selection listener. 128 * @param listener The listener instance to add. 129 */ 130 public void addSelectionListener(IElevationProfileSelectionListener listener) { 131 if (listener == null) return; 132 133 selectionChangedListeners.add(listener); 134 } 135 136 /** 137 * Removes a selection listener from the list. 138 * @param listener The listener instance to remove. 139 */ 140 public void removeSelectionListener(IElevationProfileSelectionListener listener) { 141 if (listener == null) return; 142 143 selectionChangedListeners.remove(listener); 144 } 145 146 /** 147 * Removes all selection listeners. 148 */ 149 public void removeAllSelectionListeners() { 150 selectionChangedListeners.clear(); 151 } 152 153 protected void fireSelectionChanged(WayPoint selWayPoint) { 154 for (IElevationProfileSelectionListener listener : selectionChangedListeners) { 155 listener.selectedWayPointChanged(selWayPoint); 156 } 157 } 158 159 /* (non-Javadoc) 160 * @see javax.swing.JComponent#paint(java.awt.Graphics) 161 */ 60 162 @Override 61 163 public void paint(Graphics g) { 164 isPainting = true; 62 165 super.paint(g); 63 166 … … 91 194 } finally { 92 195 setFont(oldFont); 93 } 94 } 95 196 isPainting = false; 197 } 198 } 199 200 /** 201 * Draw a string with a specified alignment. 202 * @param s The text to display. 203 * @param x The x coordinate. 204 * @param y The y coordinate. 205 * @param align The text alignment. 206 * @param g The graphics context. 207 * @return The resulting rectangle of the drawn string. 208 */ 96 209 private Rectangle drawAlignedString(String s, int x, int y, 97 210 TextAlignment align, Graphics g) { … … 115 228 } 116 229 230 /** 231 * Draw a string which is horizontally centered around (x,y). 232 * @param s The text to display. 233 * @param x The x coordinate. 234 * @param y The y coordinate. 235 * @param g The graphics context. 236 * @return The resulting rectangle of the drawn string. 237 */ 117 238 private void drawHCenteredString(String s, int x, int y, Graphics g) { 118 FontMetrics fm = g.getFontMetrics(); 119 int xoff = fm.stringWidth(s) / 2; 120 // int yoff = (fm.getAscent() + fm.getDescent()) / 2; 121 122 g.drawString(s, x - xoff, y); 123 } 124 239 drawAlignedString(s, x, y, TextAlignment.Centered, g); 240 } 241 242 /** 243 * Formats the date in a predefined manner: "21. Oct 2010, 12:10". 244 * @param date 245 * @return 246 */ 125 247 private String formatDate(Date date) { 126 248 Format formatter = new SimpleDateFormat("d MMM yy, HH:mm"); … … 129 251 } 130 252 253 /** 254 * Helper function to draw elevation axes. 255 * @param g 256 */ 131 257 private void drawElevationLines(Graphics g) { 132 258 double diff = profile.getHeightDifference(); … … 257 383 Color c = renderer.getColorForWaypoint(profile, wpt, 258 384 ElevationWayPointKind.Plain); 385 386 if (i == this.selectedIndex) { 387 c = renderer.getColorForWaypoint(profile, wpt, ElevationWayPointKind.Highlighted); 388 } 259 389 int yEle = getYForEelevation(eleVal); 260 390 int x = getPlotLeft() + i; … … 276 406 } 277 407 408 409 /* (non-Javadoc) 410 * @see javax.swing.JComponent#paintBorder(java.awt.Graphics) 411 */ 278 412 @Override 279 413 protected void paintBorder(Graphics g) { … … 284 418 } 285 419 420 421 /** 422 * Determines the size of the plot area depending on the panel size. 423 */ 286 424 private void createOrUpdatePlotArea() { 287 425 Dimension caSize = getSize(); … … 306 444 public void componentHidden(ComponentEvent arg0) { 307 445 // TODO Auto-generated method stub 308 309 446 } 310 447 … … 318 455 public void componentMoved(ComponentEvent arg0) { 319 456 // TODO Auto-generated method stub 320 321 457 } 322 458 … … 343 479 } 344 480 481 @Override 482 public void mouseDragged(MouseEvent arg0) { 483 // TODO Auto-generated method stub 484 485 } 486 487 @Override 488 public void mouseMoved(MouseEvent arg0) { 489 if (isPainting || arg0.isControlDown() || arg0.isAltDown() || arg0.isShiftDown()) arg0.consume(); 490 491 int x = arg0.getX(); 492 int l = this.getX(); 493 int pl = this.getPlotLeft(); 494 int newIdx = x - l - pl; 495 496 if (newIdx != this.selectedIndex && newIdx > 0) { 497 this.selectedIndex = newIdx; 498 this.repaint(); 499 fireSelectionChanged(getSelectedWayPoint()); 500 } 501 } 502 345 503 }
Note:
See TracChangeset
for help on using the changeset viewer.