Changeset 32789 in osm for applications/editors/josm/plugins/infomode/src
- Timestamp:
- 2016-08-09T01:53:49+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/infomode/src/org/openstreetmap/josm/plugins/infomode
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/infomode/src/org/openstreetmap/josm/plugins/infomode/InfoMode.java
r32491 r32789 1 /* 2 * This file is part of InfoMode plugin for JOSM. 3 * http://wiki.openstreetmap.org/wiki/JOSM/Plugins/InfoMode 4 * 5 * Licence: GPL v2 or later 6 * Author: Alexei Kasatkin, 2011 7 * Thanks to authors of BuildingTools, ImproveWayAccuracy 8 * for good sample code 9 */ 1 // License: GPL. For details, see LICENSE file. 10 2 package org.openstreetmap.josm.plugins.infomode; 11 3 … … 60 52 InfoMode(MapFrame mapFrame) { 61 53 super(tr("InfoMode"), "infomode.png", tr("GPX info mode"), 62 mapFrame, Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));63 infoPanel=new InfoPanel();64 54 Shortcut.registerShortcut("mapmode:infomode", tr("Mode: {0}", tr("GPX info mode")), KeyEvent.VK_BACK_SLASH, Shortcut.DIRECT), 55 mapFrame, Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 56 infoPanel = new InfoPanel(); 65 57 } 66 58 … … 90 82 AWTEvent.KEY_EVENT_MASK); 91 83 } catch (SecurityException ex) { 84 Main.error(ex); 92 85 } 93 86 } … … 100 93 101 94 Main.map.mapView.removeTemporaryLayer(this); 102 if (oldPopup !=null) oldPopup.hide();95 if (oldPopup != null) oldPopup.hide(); 103 96 104 97 try { 105 98 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 106 99 } catch (SecurityException ex) { 100 Main.error(ex); 107 101 } 108 102 … … 115 109 } 116 110 117 118 119 111 ////////// Event listener methods 120 112 … … 122 114 public void paint(Graphics2D g, MapView mv, Bounds bbox) { 123 115 if (pos == null) return; 124 Layer curL= mv.getLayerManager().getActiveLayer(); 116 Layer curL = mv.getLayerManager().getActiveLayer(); 125 117 if (curL instanceof GpxLayer) showLayerInfo(g, curL, mv); else { 126 118 for (Layer l : mv.getLayerManager().getLayers()) { … … 155 147 if (!isEnabled()) return; 156 148 if (e.getButton() != MouseEvent.BUTTON1) return; 157 if (oldPopup !=null) {149 if (oldPopup != null) { 158 150 oldPopup.hide(); 159 oldPopup=null; wpOld=null; 151 oldPopup = null; 152 wpOld = null; 160 153 } 161 154 repaint(); … … 164 157 @Override 165 158 public void mouseDragged(MouseEvent e) { 166 if (oldPopup !=null) {159 if (oldPopup != null) { 167 160 oldPopup.hide(); 168 oldPopup=null; wpOld=null; 161 oldPopup = null; 162 wpOld = null; 169 163 } 170 164 } … … 209 203 // </editor-fold> 210 204 211 212 213 205 private void repaint() { 214 if (Main.map !=null) Main.map.mapView.repaint();206 if (Main.map != null) Main.map.mapView.repaint(); 215 207 } 216 208 /*private void setStatusLine(String tr) { … … 222 214 Layer l = getLayerManager().getActiveLayer(); 223 215 224 if (l instanceof GpxLayer && pos !=null) {225 GpxLayer gpxL = (GpxLayer )l;216 if (l instanceof GpxLayer && pos != null) { 217 GpxLayer gpxL = (GpxLayer) l; 226 218 Set<GpxTrack> toRemove = new HashSet<>(); 227 219 for (GpxTrack track : gpxL.data.tracks) { 228 boolean f =true;220 boolean f = true; 229 221 sg: for (GpxTrackSegment seg : track.getSegments()) { 230 222 for (WayPoint S : seg.getWayPoints()) { 231 if (S.time!=0) {f=false; break sg;} 223 if (S.time != 0) { 224 f = false; 225 break sg; 226 } 232 227 } 233 228 } … … 239 234 240 235 private boolean showLayerInfo(Graphics2D g, Layer l, MapView mv) { 241 GpxLayer gpxL = (GpxLayer )l;242 243 double minDist =1e9,d;244 WayPoint wp =null,oldWp=null,prevWp=null;245 GpxTrack trk =null;236 GpxLayer gpxL = (GpxLayer) l; 237 238 double minDist = 1e9, d; 239 WayPoint wp = null, oldWp = null, prevWp = null; 240 GpxTrack trk = null; 246 241 double maxD = mv.getDist100Pixel()/3; 247 242 for (GpxTrack track : gpxL.data.tracks) { 248 243 for (GpxTrackSegment seg : track.getSegments()) { 249 oldWp =null;// next segment will have new previous point244 oldWp = null; // next segment will have new previous point 250 245 for (WayPoint S : seg.getWayPoints()) { 251 246 d = S.getEastNorth().distance(pos); 252 247 253 if (d <minDist && d<maxD) {248 if (d < minDist && d < maxD) { 254 249 minDist = d; 255 prevWp =oldWp;256 wp =S;257 trk =track;250 prevWp = oldWp; 251 wp = S; 252 trk = track; 258 253 } 259 oldWp =S;254 oldWp = S; 260 255 } 261 256 } 262 257 } 263 if (wp !=null) {258 if (wp != null) { 264 259 Point p = mv.getPoint(wp.getCoor()); 265 260 … … 267 262 g.fillOval(p.x-10, p.y-10, 20, 20); // mark selected point 268 263 if (shift) { // highlight track 269 g.setColor(new Color(255, 30,0,128));264 g.setColor(new Color(255, 30, 0, 128)); 270 265 Stroke oldStroke = g.getStroke(); 271 g.setStroke( 266 g.setStroke(new BasicStroke(10)); 272 267 for (GpxTrackSegment seg : trk.getSegments()) { 273 Point oldP =null,curP=null;// next segment will have new previous point268 Point oldP = null, curP = null; // next segment will have new previous point 274 269 for (WayPoint S : seg.getWayPoints()) { 275 270 curP = mv.getPoint(S.getEastNorth()); 276 if (oldP !=null) g.drawLine(oldP.x, oldP.y, curP.x, curP.y);271 if (oldP != null) g.drawLine(oldP.x, oldP.y, curP.x, curP.y); 277 272 oldP = curP; 278 273 } … … 280 275 g.setStroke(oldStroke); 281 276 } 282 Point s =mv.getLocationOnScreen();277 Point s = mv.getLocationOnScreen(); 283 278 int pcx = s.x+p.x-40; 284 279 int pcy = s.y+p.y+30; 285 if (shift) {pcx+=40; pcy-=30;} 286 287 if (wp!=wpOld) { 288 if (oldPopup!=null) oldPopup.hide(); 289 double vel=-1; 290 if (prevWp!=null && wp.time!=prevWp.time) { 291 vel=wp.getCoor().greatCircleDistance(prevWp.getCoor())/ 280 if (shift) { 281 pcx += 40; 282 pcy -= 30; 283 } 284 if (wp != wpOld) { 285 if (oldPopup != null) oldPopup.hide(); 286 double vel = -1; 287 if (prevWp != null && wp.time != prevWp.time) { 288 vel = wp.getCoor().greatCircleDistance(prevWp.getCoor())/ 292 289 (wp.time-prevWp.time)*3.6; 293 290 } 294 infoPanel.setData(wp,trk,vel,gpxL.data.tracks); 295 Popup pp=PopupFactory.getSharedInstance().getPopup(mv, infoPanel, 296 pcx, pcy); 291 infoPanel.setData(wp, trk, vel, gpxL.data.tracks); 292 Popup pp = PopupFactory.getSharedInstance().getPopup(mv, infoPanel, pcx, pcy); 297 293 pp.show(); 298 wpOld =wp;299 oldPopup =pp;294 wpOld = wp; 295 oldPopup = pp; 300 296 } 301 297 return true; -
applications/editors/josm/plugins/infomode/src/org/openstreetmap/josm/plugins/infomode/InfoModePlugin.java
r26503 r32789 1 /* 2 * This file is part of InfoMode plugin for JOSM. 3 * http://wiki.openstreetmap.org/wiki/JOSM/Plugins/InfoMode 4 * 5 * Licence: GPL v2 or later 6 * Author: Alexei Kasatkin, 2011 7 * Ideas by siberiano, Ilis, chnav, Polarbear-j, 8 */ 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.plugins.infomode; 9 3 10 package org.openstreetmap.josm.plugins.infomode;11 4 import org.openstreetmap.josm.Main; 12 5 import org.openstreetmap.josm.gui.IconToggleButton; … … 14 7 import org.openstreetmap.josm.plugins.Plugin; 15 8 import org.openstreetmap.josm.plugins.PluginInformation; 9 16 10 public class InfoModePlugin extends Plugin { 17 11 … … 24 18 if (oldFrame == null && newFrame != null) { 25 19 Main.map.addMapMode(new IconToggleButton(new InfoMode(Main.map))); 26 } 20 } 27 21 } 28 22 } -
applications/editors/josm/plugins/infomode/src/org/openstreetmap/josm/plugins/infomode/InfoPanel.java
r30737 r32789 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.infomode; 2 3 … … 32 33 private DateFormat df; 33 34 34 private JLabel label1 =new JLabel();35 private JLabel label2 =new JLabel();36 private JLabel label3 =new JLabel();37 private JLabel label4 =new JLabel();38 private JLabel label5 =new JLabel();39 private JLabel label6 =new JLabel();35 private JLabel label1 = new JLabel(); 36 private JLabel label2 = new JLabel(); 37 private JLabel label3 = new JLabel(); 38 private JLabel label4 = new JLabel(); 39 private JLabel label5 = new JLabel(); 40 private JLabel label6 = new JLabel(); 40 41 private JButton but1 = new JButton(tr("Delete this")); 41 42 private JButton but2 = new JButton(tr("Delete this&older")); 42 43 43 publicInfoPanel() {44 InfoPanel() { 44 45 super(new GridBagLayout()); 45 df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,DateFormat.DEFAULT, Locale.getDefault()); 46 setBorder(BorderFactory.createEmptyBorder(5, 5,5,5));47 add(label1, GBC.eol().insets(10, 0,0,0));48 add(label2, GBC.eol().insets(10, 0,0,0));49 add(label3, GBC.eol().insets(10, 0,0,0));50 add(label4, GBC.eol().insets(10, 0,0,0));51 add(label5, GBC.eol().insets(10, 0,0,0));52 add(label6, GBC.eol().insets(10, 0,0,0));53 add(but1, GBC.std().insets(10, 5,0,0));54 add(but2, GBC.eop().insets(10, 5,0,0));46 df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.getDefault()); 47 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 48 add(label1, GBC.eol().insets(10, 0, 0, 0)); 49 add(label2, GBC.eol().insets(10, 0, 0, 0)); 50 add(label3, GBC.eol().insets(10, 0, 0, 0)); 51 add(label4, GBC.eol().insets(10, 0, 0, 0)); 52 add(label5, GBC.eol().insets(10, 0, 0, 0)); 53 add(label6, GBC.eol().insets(10, 0, 0, 0)); 54 add(but1, GBC.std().insets(10, 5, 0, 0)); 55 add(but2, GBC.eop().insets(10, 5, 0, 0)); 55 56 // lightweight hyperlink 56 57 label6.addMouseListener(new MouseListener() { … … 58 59 public void mouseClicked(MouseEvent e) { 59 60 String s = label6.getText(); 60 OpenBrowser.displayUrl( 61 OpenBrowser.displayUrl(s.substring(9, s.length()-11)); 61 62 } 63 62 64 @Override 63 public void mousePressed(MouseEvent e) { } 65 public void mousePressed(MouseEvent e) { } 66 64 67 @Override 65 public void mouseReleased(MouseEvent e) { } 68 public void mouseReleased(MouseEvent e) { } 69 66 70 @Override 67 public void mouseEntered(MouseEvent e) { } 71 public void mouseEntered(MouseEvent e) { } 72 68 73 @Override 69 74 public void mouseExited(MouseEvent e) { } 70 75 }); 71 76 but1.addActionListener(new ActionListener() { 72 77 @Override 73 78 public void actionPerformed(ActionEvent e) { 74 if (tracks !=null) tracks.remove(trk);79 if (tracks != null) tracks.remove(trk); 75 80 Main.map.mapView.repaint(); 76 81 } … … 79 84 @Override 80 85 public void actionPerformed(ActionEvent e) { 81 if (tracks ==null) return;86 if (tracks == null) return; 82 87 Set<GpxTrack> toRemove = new HashSet<>(); 83 88 84 double tm =-1;89 double tm = -1; 85 90 for (GpxTrackSegment seg : trk.getSegments()) { 86 91 for (WayPoint S : seg.getWayPoints()) { 87 if (S.time>tm) {tm=S.time;} 92 if (S.time > tm) { 93 tm = S.time; 94 } 88 95 } 89 96 } 90 97 91 98 for (GpxTrack track : tracks) { 92 boolean f =true;99 boolean f = true; 93 100 sg: for (GpxTrackSegment seg : track.getSegments()) { 94 101 for (WayPoint S : seg.getWayPoints()) { 95 if (S.time>tm) {f=false; break sg;} 102 if (S.time > tm) { 103 f = false; 104 break sg; 105 } 96 106 } 97 107 } … … 107 117 108 118 void setData(WayPoint wp, GpxTrack trk, double vel, Collection<GpxTrack> tracks) { 109 this.tracks=tracks; 110 this.trk=trk; 111 if (wp.time==0.0) { label1.setText(tr("No timestamp")); 119 this.tracks = tracks; 120 this.trk = trk; 121 if (wp.time == 0.0) { 122 label1.setText(tr("No timestamp")); 112 123 but2.setVisible(false); 113 124 } else { … … 115 126 but2.setVisible(true); 116 127 } 117 if (vel >0) label2.setText(String.format("%.1f "+tr("km/h"), vel));118 128 if (vel > 0) label2.setText(String.format("%.1f "+tr("km/h"), vel)); 129 else label2.setText(null); 119 130 String s = (String) trk.getAttributes().get("name"); 120 if (s!=null) label3.setText(tr("Track name: ")+s); 121 else label3.setText(null); 131 if (s != null) 132 label3.setText(tr("Track name: ")+s); 133 else label3.setText(null); 122 134 s = (String) trk.getAttributes().get("desc"); 123 135 label4.setText(s); 124 136 s = (String) wp.attr.get("ele"); 125 String s1=""; 126 try {s1 = String.format("H=%3.1f ", Double.parseDouble(s));} catch (Exception e) { } 127 s1=s1+"L="+(int)trk.length(); 137 String s1 = ""; 138 try { 139 s1 = String.format("H=%3.1f ", Double.parseDouble(s)); 140 } catch (Exception e) { 141 Main.warn(e); 142 } 143 s1 = s1+"L="+(int) trk.length(); 128 144 label5.setText(s1); 129 145 if (trk.getAttributes().containsKey("url")) {
Note:
See TracChangeset
for help on using the changeset viewer.