Changeset 26389 in osm for applications/editors/josm/plugins/infomode/src/org
- Timestamp:
- 2011-07-24T19:07:08+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/infomode/src/org/openstreetmap/josm/plugins/infomode/InfoMode.java
r26364 r26389 25 25 import java.awt.event.InputEvent; 26 26 import java.awt.event.KeyEvent; 27 import java.text.DateFormat; 28 import java.util.Locale; 27 import java.util.HashSet; 28 import java.util.Set; 29 import javax.swing.Popup; 30 import javax.swing.PopupFactory; 29 31 30 32 import org.openstreetmap.josm.Main; … … 49 51 private boolean oldShift; 50 52 private EastNorth pos; 51 DateFormat df; 53 private WayPoint wpOld; 54 private Popup oldPopup; 55 private InfoPanel infoPanel; 52 56 53 57 InfoMode(MapFrame mapFrame) { … … 56 60 tr("Mode: {0}", tr("GPX info mode")), 57 61 KeyEvent.VK_BACK_SLASH, Shortcut.GROUP_EDIT), mapFrame, Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 58 df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,DateFormat.DEFAULT, Locale.getDefault());62 infoPanel=new InfoPanel(); 59 63 60 64 } … … 92 96 93 97 Main.map.mapView.removeTemporaryLayer(this); 98 if (oldPopup!=null) oldPopup.hide(); 94 99 95 100 try { … … 119 124 120 125 double minDist=1e9,d,len=0; 121 WayPoint wp=null; 126 WayPoint wp=null,oldWp=null,prevWp=null; 122 127 GpxTrack trk=null; 123 128 for (GpxTrack track : gpxL.data.tracks) { … … 125 130 for (WayPoint S : seg.getWayPoints()) { 126 131 d = S.getEastNorth().distance(pos); 127 if (d<minDist && d<10) { 132 if (d<minDist && d<100) { 128 133 minDist = d; 134 prevWp=oldWp; 129 135 wp=S; 130 136 trk=track; 131 137 } 132 if (track==trk) len+=seg.length(); 133 } 138 oldWp=wp; 134 139 } 140 } 135 141 } 136 142 if (wp!=null) { 137 143 Point p = mv.getPoint(wp.getCoor()); 144 138 145 g.setColor(Color.RED); 139 146 g.fillOval(p.x-10, p.y-10, 20, 20); // mark selected point 140 p.translate(20, 5); 141 g.setColor(Color.WHITE); 142 g.fillRoundRect(p.x, p.y-25, 200, 50,10,10); 143 g.setColor(Color.BLACK); 144 g.drawString(df.format(wp.getTime()), p.x+5, p.y-10); 145 String s = (String) trk.getAttributes().get("name"); 146 if (s!=null) g.drawString(s, p.x+5, p.y+5); 147 System.out.println(trk.getAttributes().toString()); 148 System.out.println(wp.attr.toString()); 149 s = (String) wp.attr.get("ele"); 150 String s1=null; 151 try {s1 = String.format("%3.1f", Double.parseDouble(s));} catch (Exception e) { } 152 if (s1!=null) g.drawString("H="+s1, p.x+5, p.y+20); 147 148 if (wp!=wpOld) { 149 if (oldPopup!=null) oldPopup.hide(); 150 double vel=-1; 151 if (prevWp!=null && wp.time!=prevWp.time) { 152 vel=wp.getCoor().greatCircleDistance(prevWp.getCoor())/ 153 (wp.time-prevWp.time)*3.6; 154 } 155 infoPanel.setData(wp,trk,vel,gpxL.data.tracks); 156 Point s=mv.getLocationOnScreen(); 157 Popup pp=PopupFactory.getSharedInstance().getPopup(mv, infoPanel, 158 s.x+p.x+10, s.y+p.y+10); 159 pp.show(); 160 wpOld=wp; 161 oldPopup=pp; 162 } 153 163 } 154 164 … … 170 180 if (!isEnabled()) return; 171 181 if (e.getButton() != MouseEvent.BUTTON1) return; 172 173 182 //setStatusLine(tr("Please move the mouse to draw new way")); 174 183 repaint(); … … 180 189 if (!isEnabled()) return; 181 190 if (e.getButton() != MouseEvent.BUTTON1) return; 182 191 if (oldPopup!=null) { 192 oldPopup.hide(); 193 oldPopup=null; wpOld=null; 194 } 183 195 repaint(); 184 196 } … … 186 198 @Override 187 199 public void mouseDragged(MouseEvent e) { 188 mouseMoved(e); 200 if (oldPopup!=null) { 201 oldPopup.hide(); 202 oldPopup=null; wpOld=null; 203 } 189 204 } 190 205 … … 199 214 /// System.out.println(e); 200 215 if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { 201 } 202 } 216 filterTracks(); 217 repaint(); 218 } 219 } 220 203 221 204 222 /** … … 222 240 223 241 private void repaint() { 224 Main.map.mapView.repaint(); 242 if (Main.map!=null) Main.map.mapView.repaint(); 225 243 } 226 244 private void setStatusLine(String tr) { … … 229 247 } 230 248 249 private synchronized void filterTracks() { 250 Layer l = Main.main.getActiveLayer(); 251 252 if (l instanceof GpxLayer && pos!=null) { 253 GpxLayer gpxL = (GpxLayer )l; 254 Set<GpxTrack> toRemove = new HashSet<GpxTrack>(); 255 for (GpxTrack track : gpxL.data.tracks) { 256 boolean f=true; 257 sg: for (GpxTrackSegment seg : track.getSegments()) { 258 for (WayPoint S : seg.getWayPoints()) { 259 if (S.time!=0) {f=false; break sg;} 260 } 261 } 262 if (f) toRemove.add(track); 263 } 264 gpxL.data.tracks.removeAll(toRemove); 265 266 267 } 268 } 269 231 270 232 271
Note:
See TracChangeset
for help on using the changeset viewer.