Changeset 30639 in osm for applications/editors/josm
- Timestamp:
- 2014-09-15T02:11:10+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/videomapping
- Files:
-
- 5 added
- 5 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/videomapping/.classpath
r30416 r30639 4 4 <classpathentry kind="src" path="test"/> 5 5 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> 6 <classpathentry exported="true" kind="lib" path="lib/vlcj-2.1.0.jar" sourcepath="lib/vlcj-2.1.0-sources.jar">7 <attributes>8 <attribute name="javadoc_location" value="jar:platform:/resource/VideoMapping/lib/vlcj-2.1.0-javadoc.jar!/"/>9 </attributes>10 </classpathentry>11 6 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> 12 <classpathentry exported="true" kind="lib" path="lib/jna-3.4.0.jar"/>13 <classpathentry exported="true" kind="lib" path="lib/platform-3.4.0.jar"/>14 7 <classpathentry combineaccessrules="false" kind="src" path="/JOSM-log4j"/> 8 <classpathentry kind="lib" path="lib/jna-3.5.2.jar"/> 9 <classpathentry kind="lib" path="lib/platform-3.5.2.jar"/> 10 <classpathentry kind="lib" path="lib/vlcj-3.0.1.jar"/> 15 11 <classpathentry kind="output" path="bin"/> 16 12 </classpath> -
applications/editors/josm/plugins/videomapping/build.xml
r30530 r30639 14 14 <import file="../build-common.xml"/> 15 15 16 <property name="vlcj" value="${plugin.lib.dir}/vlcj- 2.1.0.jar"/>17 <property name="jna" value="${plugin.lib.dir}/jna-3. 4.0.jar"/>18 <property name="platform" value="${plugin.lib.dir}/platform-3. 4.0.jar"/>16 <property name="vlcj" value="${plugin.lib.dir}/vlcj-3.0.1.jar"/> 17 <property name="jna" value="${plugin.lib.dir}/jna-3.5.2.jar"/> 18 <property name="platform" value="${plugin.lib.dir}/platform-3.5.2.jar"/> 19 19 <!-- classpath --> 20 20 <path id="classpath"> -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoPlugin.java
r30479 r30639 65 65 private GPSVideoPlayer gpsVideoPlayer; 66 66 67 public static String VLC_VERSION = "2. 0.x";67 public static String VLC_VERSION = "2.1.x"; 68 68 69 69 public VideoPlugin(PluginInformation info) { -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoPositionLayer.java
r29531 r30639 1 1 package org.openstreetmap.josm.plugins.videomapping; 2 3 2 4 3 import static org.openstreetmap.josm.tools.I18n.tr; … … 39 38 //Basic rendering and GPS layer interaction 40 39 public class VideoPositionLayer extends Layer implements MouseListener,MouseMotionListener { 41 42 43 44 45 46 47 48 49 50 51 52 53 54 40 private List<WayPoint> gpsTrack; 41 private ImageIcon layerIcon; 42 private DateFormat gpsTimeFormat; 43 private WayPoint iconPosition; 44 private final int GPS_INTERVALL=1000; 45 private GPSVideoPlayer gpsVideoPlayer; 46 private boolean autoCenter; 47 48 public VideoPositionLayer(GpxLayer gpsLayer) { 49 super("videolayer"); 50 layerIcon = new ImageIcon("images/videomapping.png"); 51 gpsTrack=importGPSLayer(gpsLayer.data); 52 gpsTimeFormat= new SimpleDateFormat("HH:mm:ss"); 53 Main.map.mapView.addMouseListener(this); 55 54 Main.map.mapView.addMouseMotionListener(this); 56 55 iconPosition=gpsTrack.get(0); 57 56 Main.main.addLayer(this); 58 59 } 60 61 //make a flat copy 62 private List<WayPoint> importGPSLayer(GpxData gps) { 63 LinkedList<WayPoint> ls = new LinkedList<WayPoint>(); 57 } 58 59 //make a flat copy 60 private List<WayPoint> importGPSLayer(GpxData gps) { 61 LinkedList<WayPoint> ls = new LinkedList<WayPoint>(); 64 62 for (GpxTrack trk : gps.tracks) { 65 63 for (GpxTrackSegment segment : trk.getSegments()) { … … 69 67 Collections.sort(ls); //sort basing upon time 70 68 return ls; 71 72 73 74 75 76 77 78 79 80 81 82 69 } 70 71 @Override 72 public void paint(Graphics2D g, MapView map, Bounds bound) { 73 paintGpsTrack(g, map); 74 paintSyncedTrack(g, map); 75 paintPositionIcon(g, map); 76 //paintInterpolatedSegment(g); //just a test for my own 77 } 78 79 private void paintGpsTrack(Graphics2D g, MapView map) { 80 g.setColor(Color.YELLOW); 83 81 for(WayPoint n: gpsTrack) { 84 82 Point p = map.getPoint(n.getEastNorth()); 85 83 g.drawOval(p.x - 2, p.y - 2, 4, 4); 86 84 } 87 88 89 90 91 92 if (n.attr.containsKey("synced")) 93 { 94 Point p = map.getPoint(n.getEastNorth());95 g.drawOval(p.x - 2, p.y - 2, 4, 4); 96 } 97 } 98 99 } 100 101 private void paintPositionIcon(Graphics2D g, MapView map) { 102 Point p=map.getPoint(iconPosition.getEastNorth());103 layerIcon.paintIcon(null, g, p.x-layerIcon.getIconWidth()/2, p.y-layerIcon.getIconHeight()/2);104 g.drawString(gpsTimeFormat.format(iconPosition.getTime()),p.x-15,p.y-15);105 106 /* 107 108 109 85 } 86 87 private void paintSyncedTrack(Graphics2D g, MapView map) { 88 g.setColor(Color.GREEN); 89 for (WayPoint n : gpsTrack) { 90 if (n.attr.containsKey("synced")) { 91 Point p = map.getPoint(n.getEastNorth()); 92 g.drawOval(p.x - 2, p.y - 2, 4, 4); 93 } 94 } 95 } 96 97 private void paintPositionIcon(Graphics2D g, MapView map) { 98 if (iconPosition != null) { 99 Point p = map.getPoint(iconPosition.getEastNorth()); 100 layerIcon.paintIcon(null, g, p.x-layerIcon.getIconWidth()/2, p.y-layerIcon.getIconHeight()/2); 101 g.drawString(gpsTimeFormat.format(iconPosition.getTime()),p.x-15,p.y-15); 102 } 103 } 104 /* 105 private void paintInterpolatedSegment(Graphics2D g) { 106 g.setColor(Color.CYAN); 107 List<WayPoint>ls=getInterpolatedSegment(iconPosition,5,5); 110 108 for(WayPoint n: ls) { 111 109 Point p = Main.map.mapView.getPoint(n.getEastNorth()); 112 110 g.drawOval(p.x - 2, p.y - 2, 4, 4); 113 111 } 114 115 } 116 117 //just a Demo to show up IPO on a whole segment 118 private List<WayPoint> getInterpolatedSegment(WayPoint center, int before, int after) { 119 LinkedList<WayPoint> ls = new LinkedList<WayPoint>(); 120 if(gpsTrack.indexOf(iconPosition)!=0) 121 { 122 WayPoint prev=gpsTrack.get(gpsTrack.indexOf(iconPosition)-1); 123 for(int i=1;i<=before;i++) 124 { 125 ls.add(interpolate(prev,(float)100f/before*i)); 126 } 127 } 128 for(int i=1;i<=after;i++) 129 { 130 ls.add(interpolate(iconPosition,(float)100f/before*i)); 131 } 132 //test code 133 Date test=getFirstWayPoint().getTime(); 134 test.setHours(14); 135 test.setMinutes(50); 136 test.setSeconds(33); 137 ls.add(getWayPointBefore(new Date(test.getTime()+500))); 138 ls.add(interpolate(new Date(test.getTime()+500))); 139 return ls; 140 } 141 */ 142 //creates a waypoint for the corresponding time 143 public WayPoint interpolate(Date GPSTime) 144 { 145 WayPoint before =getWayPointBefore(GPSTime); 146 long diff=GPSTime.getTime()-before.getTime().getTime(); 147 assert diff>=0; 148 assert diff<GPS_INTERVALL; 149 float perc=((float)diff/(float)GPS_INTERVALL)*100; 150 return interpolate(before,perc); 151 } 152 153 public WayPoint getWayPointBefore(Date GPSTime) 154 { 155 assert GPSTime.after(getFirstWayPoint().getTime())==true; 156 assert GPSTime.before(getLastWayPoint().getTime())==true; 157 158 Date first=getFirstWayPoint().getTime(); 159 long diff=GPSTime.getTime()-first.getTime(); 160 //assumes that GPS intervall is constant 161 int id=(int) (diff/GPS_INTERVALL); 162 return gpsTrack.get(id); 163 } 164 165 public WayPoint getFirstWayPoint() 166 { 167 return gpsTrack.get(0); 168 } 169 170 public WayPoint getLastWayPoint() 171 { 172 return gpsTrack.get(gpsTrack.size()-1); 173 } 174 175 //interpolates a waypoint between this and the following waypoint at percent 176 private WayPoint interpolate(WayPoint first, float percent) { 177 assert (percent>0); 178 assert (percent<100); 179 double dX,dY; 112 113 } 114 115 //just a Demo to show up IPO on a whole segment 116 private List<WayPoint> getInterpolatedSegment(WayPoint center, int before, int after) { 117 LinkedList<WayPoint> ls = new LinkedList<WayPoint>(); 118 if(gpsTrack.indexOf(iconPosition)!=0) 119 { 120 WayPoint prev=gpsTrack.get(gpsTrack.indexOf(iconPosition)-1); 121 for(int i=1;i<=before;i++) 122 { 123 ls.add(interpolate(prev,(float)100f/before*i)); 124 } 125 } 126 for(int i=1;i<=after;i++) 127 { 128 ls.add(interpolate(iconPosition,(float)100f/before*i)); 129 } 130 //test code 131 Date test=getFirstWayPoint().getTime(); 132 test.setHours(14); 133 test.setMinutes(50); 134 test.setSeconds(33); 135 ls.add(getWayPointBefore(new Date(test.getTime()+500))); 136 ls.add(interpolate(new Date(test.getTime()+500))); 137 return ls; 138 } 139 */ 140 //creates a waypoint for the corresponding time 141 public WayPoint interpolate(Date GPSTime) { 142 WayPoint before = getWayPointBefore(GPSTime); 143 if (before == null) { 144 return null; 145 } 146 long diff = GPSTime.getTime() - before.getTime().getTime(); 147 assert diff>=0; 148 assert diff<GPS_INTERVALL; 149 float perc=((float)diff/(float)GPS_INTERVALL)*100; 150 return interpolate(before,perc); 151 } 152 153 public WayPoint getWayPointBefore(Date GPSTime) { 154 assert GPSTime.after(getFirstWayPoint().getTime())==true; 155 assert GPSTime.before(getLastWayPoint().getTime())==true; 156 157 Date first=getFirstWayPoint().getTime(); 158 long diff=GPSTime.getTime()-first.getTime(); 159 //assumes that GPS intervall is constant 160 int id = (int) (diff/GPS_INTERVALL); 161 return 0 <= id && id < gpsTrack.size() ? gpsTrack.get(id) : null; 162 } 163 164 public WayPoint getFirstWayPoint() { 165 return gpsTrack.isEmpty() ? null : gpsTrack.get(0); 166 } 167 168 public WayPoint getLastWayPoint() { 169 return gpsTrack.isEmpty() ? null : gpsTrack.get(gpsTrack.size()-1); 170 } 171 172 //interpolates a waypoint between this and the following waypoint at percent 173 private WayPoint interpolate(WayPoint first, float percent) { 174 assert (percent>0); 175 assert (percent<100); 176 double dX,dY; 180 177 WayPoint leftP,rightP; 181 182 178 183 179 WayPoint next=gpsTrack.get(gpsTrack.indexOf(first)+1); … … 190 186 dY=(rightP.getCoor().lat()-leftP.getCoor().lat())*percent; 191 187 //move in the right direction 192 if (first==leftP) 193 { 194 return new WayPoint(new LatLon(leftP.getCoor().lat()+dY,leftP.getCoor().lon()+dX)); 195 } 196 else 197 return new WayPoint(new LatLon(rightP.getCoor().lat()-dY,rightP.getCoor().lon()-dX)); 198 199 200 } 201 202 private WayPoint getLeftPoint(WayPoint p1,WayPoint p2) 203 { 188 if (first==leftP) { 189 return new WayPoint(new LatLon(leftP.getCoor().lat()+dY,leftP.getCoor().lon()+dX)); 190 } else { 191 return new WayPoint(new LatLon(rightP.getCoor().lat()-dY,rightP.getCoor().lon()-dX)); 192 } 193 } 194 195 private WayPoint getLeftPoint(WayPoint p1,WayPoint p2) { 204 196 if(p1.getCoor().lon()<p2.getCoor().lon()) return p1; else return p2; 205 197 } 206 198 207 private WayPoint getRightPoint(WayPoint p1, WayPoint p2) 208 { 199 private WayPoint getRightPoint(WayPoint p1, WayPoint p2) { 209 200 if(p1.getCoor().lon()>p2.getCoor().lon()) return p1; else return p2; 210 201 } 211 202 212 public Date getGPSDate() 213 { 214 return iconPosition.getTime(); 215 } 216 217 public WayPoint getCurrentWayPoint() 218 { 219 return iconPosition; 220 } 221 222 223 224 public List<WayPoint> getTrack() { 225 return gpsTrack; 226 227 } 228 229 public void jump(Date GPSTime) 230 { 231 setIconPosition(getWayPointBefore(GPSTime)); 232 233 } 234 235 public void setIconPosition(WayPoint wp) { 236 iconPosition=wp; 237 Main.map.mapView.repaint(); 238 if (autoCenter) 239 Main.map.mapView.zoomTo(iconPosition.getCoor()); 240 241 } 242 243 public void mouseReleased(MouseEvent e) { 244 //only leftclicks on our layer 203 public Date getGPSDate() { 204 return iconPosition.getTime(); 205 } 206 207 public WayPoint getCurrentWayPoint() { 208 return iconPosition; 209 } 210 211 public List<WayPoint> getTrack() { 212 return gpsTrack; 213 } 214 215 public void jump(Date GPSTime) { 216 setIconPosition(getWayPointBefore(GPSTime)); 217 } 218 219 public void setIconPosition(WayPoint wp) { 220 iconPosition = wp; 221 if (Main.isDisplayingMapView()) { 222 Main.map.mapView.repaint(); 223 if (autoCenter) 224 Main.map.mapView.zoomTo(iconPosition.getCoor()); 225 } 226 } 227 228 public void mouseReleased(MouseEvent e) { 229 //only leftclicks on our layer 245 230 if(e.getButton() == MouseEvent.BUTTON1) { 246 WayPoint wp = getNearestWayPoint(e.getPoint()); 247 if(wp!=null) 248 { 249 if (gpsVideoPlayer.areAllVideosSynced()) 250 { 251 //we set the video to corresponding position 252 gpsVideoPlayer.jumpTo(wp.getTime()); 253 } 254 setIconPosition(wp); 231 WayPoint wp = getNearestWayPoint(e.getPoint()); 232 if (wp != null) { 233 if (gpsVideoPlayer.areAllVideosSynced()) { 234 //we set the video to corresponding position 235 gpsVideoPlayer.jumpTo(wp.getTime()); 236 } 237 setIconPosition(wp); 255 238 } 256 239 } 257 258 } 259 260 //finds the first waypoint that is nearby the given point 261 private WayPoint getNearestWayPoint(Point mouse) 262 { 240 } 241 242 //finds the first waypoint that is nearby the given point 243 private WayPoint getNearestWayPoint(Point mouse) { 263 244 final int MAX=10; 264 245 Point p; 265 246 Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,MAX,MAX); 266 247 //iterate through all possible notes 267 for(WayPoint n : gpsTrack) 268 { 248 for(WayPoint n : gpsTrack) { 269 249 p = Main.map.mapView.getPoint(n.getEastNorth()); 270 if (rect.contains(p)) 271 { 250 if (rect.contains(p)) { 272 251 return n; 273 252 } 274 275 253 } 276 254 return null; 277 278 } 279 280 @Override 281 public Icon getIcon() { 282 return layerIcon; 283 } 284 285 @Override 286 public Object getInfoComponent() { 287 // TODO Auto-generated method stub 288 return null; 289 } 290 291 @Override 292 public Action[] getMenuEntries() { 293 return new Action[]{ 255 } 256 257 @Override 258 public Icon getIcon() { 259 return layerIcon; 260 } 261 262 @Override 263 public Object getInfoComponent() { 264 // TODO Auto-generated method stub 265 return null; 266 } 267 268 @Override 269 public Action[] getMenuEntries() { 270 return new Action[]{ 294 271 LayerListDialog.getInstance().createActivateLayerAction(this), 295 272 LayerListDialog.getInstance().createShowHideLayerAction(), … … 297 274 SeparatorLayerAction.INSTANCE, 298 275 new LayerListPopup.InfoAction(this)}; 299 } 300 301 302 @Override 303 public String getToolTipText() { 304 return tr("Shows current position in the video"); 305 } 306 307 @Override 308 public boolean isMergable(Layer arg0) { 309 return false; 310 } 311 312 @Override 313 public void mergeFrom(Layer arg0) { 314 315 } 316 317 @Override 318 public void visitBoundingBox(BoundingXYVisitor arg0) { 319 // TODO Auto-generated method stub 320 321 } 322 323 public void mouseClicked(MouseEvent arg0) { 324 // TODO Auto-generated method stub 325 326 } 327 328 public void mouseEntered(MouseEvent arg0) { 329 // TODO Auto-generated method stub 330 331 } 332 333 public void mouseExited(MouseEvent arg0) { 334 // TODO Auto-generated method stub 335 336 } 337 338 public void mousePressed(MouseEvent e) { 339 } 340 341 public void mouseDragged(MouseEvent arg0) { 342 // TODO Auto-generated method stub 343 344 } 345 346 public void mouseMoved(MouseEvent arg0) { 347 // TODO Auto-generated method stub 348 349 } 350 351 public void setGPSVideoPlayer(GPSVideoPlayer player) 352 { 353 gpsVideoPlayer=player; 354 } 355 356 public void setAutoCenter(boolean enabled) { 357 autoCenter=enabled; 358 359 } 360 361 public void unload() { 362 Main.main.removeLayer(this); 363 364 } 365 276 } 277 278 @Override 279 public String getToolTipText() { 280 return tr("Shows current position in the video"); 281 } 282 283 @Override 284 public boolean isMergable(Layer arg0) { 285 return false; 286 } 287 288 @Override 289 public void mergeFrom(Layer arg0) { 290 } 291 292 @Override 293 public void visitBoundingBox(BoundingXYVisitor arg0) { 294 } 295 296 public void mouseClicked(MouseEvent arg0) { 297 } 298 299 public void mouseEntered(MouseEvent arg0) { 300 } 301 302 public void mouseExited(MouseEvent arg0) { 303 } 304 305 public void mousePressed(MouseEvent e) { 306 } 307 308 public void mouseDragged(MouseEvent arg0) { 309 } 310 311 public void mouseMoved(MouseEvent arg0) { 312 } 313 314 public void setGPSVideoPlayer(GPSVideoPlayer player) { 315 gpsVideoPlayer = player; 316 } 317 318 public void setAutoCenter(boolean enabled) { 319 autoCenter = enabled; 320 } 321 322 public void unload() { 323 Main.main.removeLayer(this); 324 } 366 325 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/GPSVideo.java
r28924 r30639 13 13 14 14 // a specific synced video 15 public class GPSVideo extends Video {15 public class GPSVideo extends Video { 16 16 private static final String SYNC_KEY = "synced"; 17 17 public JComponent SyncComponent; … … 28 28 } 29 29 30 public GPSVideo(Video video) 31 { 30 public GPSVideo(Video video) { 32 31 super(video.filename, video.id, video.mediaPlayerFactory); 33 32 this.player = video.player; … … 36 35 //calculates attributes basing upon the current position 37 36 public void doSync(VideoPositionLayer layer) { 38 this.videoPositionLayer =layer;37 this.videoPositionLayer = layer; 39 38 if (isSynced()) 40 39 removeSyncedWayPoints(); 41 syncWayPoint =layer.getCurrentWayPoint();42 syncVideoTime =getCurrentTime();40 syncWayPoint = layer.getCurrentWayPoint(); 41 syncVideoTime = getCurrentTime(); 43 42 //calc now, to avoid calculations on every click 44 start=new Date(syncWayPoint.getTime().getTime()-syncVideoTime); 45 end=new Date(start.getTime()+player.getLength()); 46 firstWayPoint=getFirstGPS(); 47 lastWayPoint=getLastGPS(); 43 if (syncWayPoint != null) { 44 start = new Date(syncWayPoint.getTime().getTime()-syncVideoTime); 45 end = new Date(start.getTime()+player.getLength()); 46 } else { 47 start = null; 48 end = null; 49 } 50 firstWayPoint = getFirstGPS(); 51 lastWayPoint = getLastGPS(); 48 52 markSyncedWayPoints(); 49 53 Main.map.mapView.repaint(); … … 52 56 //make sure we don't leave the GPS track 53 57 private WayPoint getFirstGPS() { 54 if(start.before(videoPositionLayer.getFirstWayPoint().getTime())) 55 { 58 if (start == null || start.before(videoPositionLayer.getFirstWayPoint().getTime())) { 56 59 return videoPositionLayer.getFirstWayPoint(); 57 } 58 else 59 { 60 } else { 60 61 return videoPositionLayer.getWayPointBefore(start); 61 62 } … … 63 64 64 65 //make sure we don't leave the GPS track 65 private WayPoint getLastGPS() { 66 if(end.after(videoPositionLayer.getLastWayPoint().getTime())) 67 { 66 private WayPoint getLastGPS() { 67 if (end == null || end.after(videoPositionLayer.getLastWayPoint().getTime())) { 68 68 return videoPositionLayer.getLastWayPoint(); 69 } 70 else 71 { 69 } else { 72 70 return videoPositionLayer.getWayPointBefore(end); 73 71 } … … 75 73 76 74 private void removeSyncedWayPoints() { 77 List <WayPoint> track =videoPositionLayer.getTrack(); 78 int start=track.indexOf(firstWayPoint); 79 int end=track.indexOf(lastWayPoint); 80 List <WayPoint> ls =videoPositionLayer.getTrack().subList(start, end); 81 for (WayPoint n : ls) { 82 n.attr.keySet().remove(SYNC_KEY); 83 } 75 List <WayPoint> track = videoPositionLayer.getTrack(); 76 int start = track.indexOf(firstWayPoint); 77 int end = track.indexOf(lastWayPoint); 78 if (0 <= start && start <= end && end < track.size()) { 79 for (WayPoint n : track.subList(start, end)) { 80 n.attr.keySet().remove(SYNC_KEY); 81 } 82 } 84 83 } 85 84 86 85 private void markSyncedWayPoints() { 87 List <WayPoint> track =videoPositionLayer.getTrack(); 88 int start=track.indexOf(firstWayPoint); 89 int end=track.indexOf(lastWayPoint); 90 List <WayPoint> ls =videoPositionLayer.getTrack().subList(start, end); 91 for (WayPoint n : ls) { 92 n.attr.put(SYNC_KEY, id); 93 } 86 List <WayPoint> track = videoPositionLayer.getTrack(); 87 int start = track.indexOf(firstWayPoint); 88 int end = track.indexOf(lastWayPoint); 89 if (0 <= start && start <= end && end < track.size()) { 90 for (WayPoint n : track.subList(start, end)) { 91 n.attr.put(SYNC_KEY, id); 92 } 93 } 94 94 } 95 95 96 96 public boolean isSynced() { 97 return firstWayPoint!=null;97 return syncWayPoint != null; 98 98 } 99 99 100 100 //if synced jump in video to this GPS timecode 101 101 public void jumpTo(Date GPSTime) { 102 if((GPSTime.after(firstWayPoint.getTime())&(GPSTime.before(lastWayPoint.getTime())))) 103 { 104 long diff=GPSTime.getTime()-start.getTime(); 102 if((GPSTime.after(firstWayPoint.getTime())&(GPSTime.before(lastWayPoint.getTime())))) { 103 long diff = GPSTime.getTime()-start.getTime(); 105 104 player.setTime(diff); 106 105 System.out.println(diff); … … 108 107 } 109 108 110 public WayPoint getCurrentWayPoint() 111 { 112 if (isSynced()) 113 { 114 long videotime=player.getTime(); 115 Date gpstime=new Date(start.getTime()+videotime); 109 public WayPoint getCurrentWayPoint() { 110 if (isSynced()) { 111 long videotime = player.getTime(); 112 Date gpstime = new Date(start.getTime()+videotime); 116 113 return videoPositionLayer.interpolate(gpstime); 117 114 } 118 115 return null; 119 116 } 120 121 117 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/GPSVideoPlayer.java
r29769 r30639 18 18 19 19 //extends video playback, major control has the video player 20 public class GPSVideoPlayer extends VideoPlayer 21 { 20 public class GPSVideoPlayer extends VideoPlayer { 22 21 private List<GPSVideo> videos; 23 22 private VideoPositionLayer videoPositionLayer; … … 69 68 70 69 //jump in all videos this date, if possible 71 public void jumpTo(Date date) 72 { 70 public void jumpTo(Date date) { 73 71 for (GPSVideo video : videos) { 74 72 video.jumpTo(date); … … 76 74 } 77 75 78 public boolean areAllVideosSynced() 79 { 76 public boolean areAllVideosSynced() { 80 77 for (GPSVideo video : videos) { 81 78 if (!video.isSynced()) return false; … … 83 80 return true; 84 81 } 85 86 82 87 83 @Override … … 97 93 super.windowClosing(arg0); 98 94 } 99 100 101 102 103 104 105 106 107 108 109 110 111 95 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/VideoPlayer.java
r29769 r30639 28 28 import javax.swing.event.ChangeListener; 29 29 30 import org.openstreetmap.josm.gui.util.GuiHelper; 31 30 32 import uk.co.caprica.vlcj.player.DeinterlaceMode; 31 33 … … 33 35 */ 34 36 public class VideoPlayer extends JFrame implements WindowListener, VideosObserver, VideoPlayerObserver { 35 36 37 private static final int notificationIntervall = 500; 38 protected JPanel screenPanel,controlsPanel,canvasPanel; 37 39 private JSlider timeline; 38 40 private JButton play,back,forward; … … 43 45 private long jumpLength; 44 46 private long loopLength; 45 46 47 48 49 50 51 super(); 52 // 53 54 55 56 observers=new LinkedList<VideoPlayerObserver>(); 57 58 59 60 61 62 63 64 65 setAlwaysOnTop(true);66 67 68 69 70 71 72 73 47 private Timer loopingTimer; 48 private boolean isManualJump; 49 private Timer notificationTimer; 50 private List<VideoPlayerObserver> observers; 51 52 public VideoPlayer(DateFormat videoTimeFormat) throws HeadlessException { 53 super(); 54 // this.videoTimeFormat=videoTimeFormat; 55 //setup playback notifications 56 videoengine=new VideoEngine(this); 57 videoengine.addObserver(this); 58 observers=new LinkedList<VideoPlayerObserver>(); 59 addObserver(this); 60 //setup GUI 61 setSize(400, 300); //later we apply movie size 62 setAlwaysOnTop(true); 63 createUI(); 64 addUI(); 65 addUIListeners(); 66 setVisible(true); 67 setAlwaysOnTop(true); 68 this.addWindowListener(this); 69 } 70 71 public Video addVideo(File videofile, String id) { 72 Video video = new Video(videofile,id,videoengine.mediaPlayerFactory); 73 canvasPanel.add(video.panel); 74 video.canvas.setSize(new Dimension(300, 300)); // will be updated by the video engine itself 75 videoengine.add(video); 74 76 pack(); 75 77 startNotificationTimer(); 76 78 return video; 77 } 78 79 public List <Video> getVideos() 80 { 81 return videoengine.getVideos(); 82 } 83 84 85 public void pause() { 86 videoengine.pause(); 87 if (videoengine.isNoVideoPlaying()) 88 stopNotificationTimer(); 89 else 90 startNotificationTimer(); 91 } 92 93 public void pauseAll() 94 { 95 stopNotificationTimer(); 96 videoengine.pauseAll(); 97 } 98 99 public void backward() { 100 videoengine.jumpFor(-jumpLength); 101 } 102 103 public void forward() { 104 videoengine.jumpFor(jumpLength); 105 } 106 107 public void setSpeed(Integer percent) 108 { 109 speed.setValue(percent); 110 } 111 112 public Integer getSpeed() 113 { 114 return speed.getValue(); 115 } 116 117 public void setDeinterlacer(DeinterlaceMode deinterlacer) 118 { 119 videoengine.setDeinterlacer(deinterlacer); 120 } 121 122 public void setSubtitles(boolean enabled) 123 { 124 videoengine.setSubtitles(enabled); 125 } 126 127 public void mute() 128 { 129 videoengine.mute(); 130 } 131 132 //TODO auf mehrere Videos umstellen 133 public void toggleLooping() { 134 if(loopingTimer==null) 135 { 136 //do reset after loop time experienced 137 final long videoResetTime=(long) videoengine.getVideoTime()-loopLength/2; 138 TimerTask reset=new TimerTask() { 79 } 80 81 public List <Video> getVideos() { 82 return videoengine.getVideos(); 83 } 84 85 public void pause() { 86 videoengine.pause(); 87 if (videoengine.isNoVideoPlaying()) 88 stopNotificationTimer(); 89 else 90 startNotificationTimer(); 91 } 92 93 public void pauseAll() { 94 stopNotificationTimer(); 95 videoengine.pauseAll(); 96 } 97 98 public void backward() { 99 videoengine.jumpFor(-jumpLength); 100 } 101 102 public void forward() { 103 videoengine.jumpFor(jumpLength); 104 } 105 106 public void setSpeed(Integer percent) { 107 speed.setValue(percent); 108 } 109 110 public Integer getSpeed() { 111 return speed.getValue(); 112 } 113 114 public void setDeinterlacer(DeinterlaceMode deinterlacer) { 115 videoengine.setDeinterlacer(deinterlacer); 116 } 117 118 public void setSubtitles(boolean enabled) { 119 videoengine.setSubtitles(enabled); 120 } 121 122 public void mute() { 123 videoengine.mute(); 124 } 125 126 //TODO auf mehrere Videos umstellen 127 public void toggleLooping() { 128 if (loopingTimer==null) { 129 //do reset after loop time experienced 130 final long videoResetTime = (long) videoengine.getVideoTime()-loopLength/2; 131 TimerTask reset = new TimerTask() { 139 132 @Override 140 133 public void run() { … … 144 137 loopingTimer= new Timer(); 145 138 loopingTimer.schedule(reset,loopLength/2,loopLength); 139 } else { 140 loopingTimer.cancel(); 141 loopingTimer=null; 146 142 } 147 else 148 { 149 loopingTimer.cancel(); 150 loopingTimer=null; 151 } 152 153 } 154 155 //create all normal player controls 156 private void createUI() { 143 } 144 145 //create all normal player controls 146 private void createUI() { 157 147 //setIconImage(); 158 148 timeline = new JSlider(0,100,0); … … 176 166 speed.setPaintLabels(true); 177 167 } 178 179 180 181 168 169 //puts all player controls to screen 170 private void addUI() { 171 //create layouts 182 172 this.setLayout(new BorderLayout()); 183 173 screenPanel=new JPanel(); … … 201 191 mute.setSelected(false); 202 192 } 203 204 193 194 //add UI functionality 205 195 private void addUIListeners() { 206 196 207 197 play.addActionListener(new ActionListener() { 208 @Override public void actionPerformed(ActionEvent arg0) { 209 pause(); 198 @Override 199 public void actionPerformed(ActionEvent arg0) { 200 pause(); 210 201 } 211 202 }); 212 203 213 204 back.addActionListener(new ActionListener() { 214 215 @Overridepublic void actionPerformed(ActionEvent arg0) {205 @Override 206 public void actionPerformed(ActionEvent arg0) { 216 207 backward(); 217 208 } … … 219 210 220 211 forward.addActionListener(new ActionListener() { 221 222 @Overridepublic void actionPerformed(ActionEvent arg0) {212 @Override 213 public void actionPerformed(ActionEvent arg0) { 223 214 forward(); 224 215 } … … 226 217 227 218 loop.addActionListener(new ActionListener() { 228 229 @Overridepublic void actionPerformed(ActionEvent arg0) {219 @Override 220 public void actionPerformed(ActionEvent arg0) { 230 221 toggleLooping(); 231 222 } … … 233 224 234 225 mute.addActionListener(new ActionListener() { 235 236 @Overridepublic void actionPerformed(ActionEvent arg0) {226 @Override 227 public void actionPerformed(ActionEvent arg0) { 237 228 mute(); 238 229 } … … 242 233 @Override 243 234 public void stateChanged(ChangeEvent e) { 244 //skip events, fired by this sliede, one cycle ago 245 if(!isManualJump) 246 { 247 isManualJump=true; 248 videoengine.jumpToPosition((timeline.getValue())); 249 System.out.println("manual jump"); 250 } 251 } 235 //skip events, fired by this sliede, one cycle ago 236 if (!isManualJump) { 237 isManualJump = true; 238 videoengine.jumpToPosition((timeline.getValue())); 239 } 240 } 241 }); 242 243 speed.addChangeListener(new ChangeListener() { 244 @Override 245 public void stateChanged(ChangeEvent arg0) { 246 if(!speed.getValueIsAdjusting()) { 247 videoengine.setSpeed(speed.getValue()); 248 } 249 } 250 }); 251 } 252 253 public void setJumpLength(long ms) { 254 jumpLength = ms; 255 } 256 257 public void setLoopLength(long ms) { 258 loopLength = ms; 259 } 260 261 public void enableSingleVideoMode(boolean enabled) { 262 pauseAll(); 263 videoengine.enableSingleVideoMode(enabled); 264 } 265 266 public void addObserver(VideoPlayerObserver observer) { 267 observers.add(observer); 268 } 269 270 private void stopNotificationTimer() { 271 /* 272 if(notificationTimer!=null) 273 { 274 notificationTimer.cancel(); 275 notificationTimer=null; 276 } 277 */ 278 } 279 280 private void startNotificationTimer() { 281 notificationTimer= new Timer(); 282 notificationTimer.schedule(new TimerTask() { 283 @Override 284 public void run() { 285 notifyObservers(); 252 286 253 }); 254 255 speed.addChangeListener(new ChangeListener() { 256 @Override 257 public void stateChanged(ChangeEvent arg0) { 258 if(!speed.getValueIsAdjusting()) 259 { 260 videoengine.setSpeed(speed.getValue()); 261 } 262 } 263 }); 264 265 } 266 267 public void setJumpLength(long ms) 268 { 269 jumpLength=ms; 270 } 271 272 public void setLoopLength(long ms) 273 { 274 loopLength=ms; 275 } 276 277 public void enableSingleVideoMode(boolean enabled) 278 { 279 pauseAll(); 280 videoengine.enableSingleVideoMode(enabled); 281 } 282 283 public void addObserver(VideoPlayerObserver observer) 284 { 285 observers.add(observer); 286 } 287 288 289 private void stopNotificationTimer() { 290 /* 291 if(notificationTimer!=null) 292 { 293 notificationTimer.cancel(); 294 notificationTimer=null; 295 } 296 */ 297 } 298 299 private void startNotificationTimer() { 300 notificationTimer= new Timer(); 301 notificationTimer.schedule(new TimerTask() { 302 @Override 303 public void run() { 304 notifyObservers(); 305 306 } 307 },notificationIntervall,notificationIntervall); 308 } 309 310 private void notifyObservers() { 311 for (VideoPlayerObserver observer : observers) { 312 observer.update_plays();//TODO hier müssten gleich die Zeiten übergeben werden 313 } 314 } 315 316 @Override 317 public void windowActivated(WindowEvent arg0) { } 318 319 @Override 320 public void windowClosed(WindowEvent arg0) { } 321 322 @Override 323 public void windowClosing(WindowEvent arg0) { 324 videoengine.unload(); 325 } 326 327 @Override 328 public void windowDeactivated(WindowEvent arg0) { } 329 330 @Override 331 public void windowDeiconified(WindowEvent arg0) { } 332 333 @Override 334 public void windowIconified(WindowEvent arg0) { } 335 336 @Override 337 public void windowOpened(WindowEvent arg0) { } 338 339 @Override 340 public void update(VideoObserversEvents event) { 341 switch (event) 342 { 343 case resizing: 344 { 345 pack(); 346 break; 347 } 348 case speeding: 349 { 350 speed.setValue(videoengine.getSpeed()); 351 break; 352 } 353 case jumping: 354 { 355 break; 356 } 357 } 358 } 359 360 //keep internal controls up to date during playback 361 @Override 362 public void update_plays() { 363 timeline.setValue(videoengine.getPosition()); 364 setTitle(Long.toString(videoengine.getVideoTime())); 365 isManualJump=false; 366 System.out.println("update"); 367 368 } 369 370 public boolean isCorrectlyInitiliazed() { 371 return videoengine != null && videoengine.mediaPlayerFactory != null; 372 } 287 } 288 },notificationIntervall,notificationIntervall); 289 } 290 291 private void notifyObservers() { 292 for (VideoPlayerObserver observer : observers) { 293 observer.update_plays();//TODO hier müssten gleich die Zeiten übergeben werden 294 } 295 } 296 297 @Override 298 public void windowActivated(WindowEvent arg0) { } 299 300 @Override 301 public void windowClosed(WindowEvent arg0) { } 302 303 @Override 304 public void windowClosing(WindowEvent arg0) { 305 videoengine.unload(); 306 } 307 308 @Override 309 public void windowDeactivated(WindowEvent arg0) { } 310 311 @Override 312 public void windowDeiconified(WindowEvent arg0) { } 313 314 @Override 315 public void windowIconified(WindowEvent arg0) { } 316 317 @Override 318 public void windowOpened(WindowEvent arg0) { } 319 320 @Override 321 public void update(VideoObserversEvents event) { 322 switch (event) 323 { 324 case resizing: 325 { 326 pack(); 327 break; 328 } 329 case speeding: 330 { 331 speed.setValue(videoengine.getSpeed()); 332 break; 333 } 334 case jumping: 335 { 336 break; 337 } 338 } 339 } 340 341 //keep internal controls up to date during playback 342 @Override 343 public void update_plays() { 344 GuiHelper.runInEDT(new Runnable() { 345 @Override 346 public void run() { 347 timeline.setValue(videoengine.getPosition()); 348 setTitle(Long.toString(videoengine.getVideoTime())); 349 } 350 }); 351 isManualJump = false; 352 } 353 354 public boolean isCorrectlyInitiliazed() { 355 return videoengine != null && videoengine.mediaPlayerFactory != null; 356 } 373 357 }
Note:
See TracChangeset
for help on using the changeset viewer.