Changeset 21295 in osm for applications/editors/josm/plugins/videomapping/src
- Timestamp:
- 2010-05-16T10:53:53+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PositionLayer.java
r21257 r21295 1 1 package org.openstreetmap.josm.plugins.videomapping; 2 3 4 import java.util.Iterator; 5 import java.util.Timer; 6 import java.util.TimerTask; 2 7 3 8 import java.awt.Color; 4 9 import java.awt.Component; 10 import java.awt.Dimension; 5 11 import java.awt.Graphics2D; 6 12 import java.awt.Point; 13 import java.awt.Rectangle; 7 14 import java.awt.event.MouseEvent; 8 15 import java.awt.event.MouseListener; … … 15 22 import org.openstreetmap.josm.data.Bounds; 16 23 import org.openstreetmap.josm.data.gpx.GpxData; 24 import org.openstreetmap.josm.data.osm.DataSet; 25 import org.openstreetmap.josm.data.osm.Node; 17 26 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 18 27 import org.openstreetmap.josm.gui.MapView; … … 23 32 24 33 public class PositionLayer extends Layer implements MouseListener { 25 private GpxData gps; 26 public PositionLayer(String name,GpxData gps) { 34 private DataSet ds; 35 private Node sel; 36 private Iterator<Node> it; 37 38 public PositionLayer(String name, final DataSet ds) { 27 39 super(name); 28 this.gps = gps; 29 Main.map.mapView.addMouseListener(this); 40 this.ds = ds; 41 Main.map.mapView.addMouseListener(this); 42 Timer t = new Timer(); 43 it=ds.getNodes().iterator(); 44 45 t.schedule(new TimerTask() { 46 47 @Override 48 public void run() { 49 // TODO Auto-generated method stub 50 sel=it.next(); 51 System.out.println(sel.getTimestamp()); 52 Main.map.mapView.repaint(); 53 } 54 },1000,1000); 55 30 56 } 31 57 … … 60 86 } 61 87 88 // no merging nescesarry 62 89 @Override 63 90 public boolean isMergable(Layer arg0) { … … 67 94 @Override 68 95 public void mergeFrom(Layer arg0) { 69 // no merging nescesarry96 70 97 } 71 98 99 100 72 101 @Override 102 //Draw the current position 73 103 public void paint(Graphics2D g, MapView map, Bounds bound) { 74 //TODO this is just an blue screen test 75 g.setColor(Color.BLUE); 76 g.fillRect(0, 0, map.getWidth(),map.getHeight()); 104 Point p; 105 for(Node n: ds.getNodes()) { 106 p = Main.map.mapView.getPoint(n.getEastNorth()); 107 if(n.isHighlighted()) 108 { 109 g.setColor(Color.red); 110 g.drawString(n.getTimestamp().toString(), p.x+10, p.y); 111 } 112 else 113 { 114 g.setColor(Color.green); 115 } 116 g.drawOval(p.x - 2, p.y - 2, 4, 4); // small circles 117 } 118 if (sel!=null){ 119 p=Main.map.mapView.getPoint(sel.getEastNorth());; 120 g.setColor(Color.CYAN); 121 g.drawRect(p.x, p.y, 100, 100); 122 }; 77 123 } 78 124 … … 84 130 85 131 //jump to the right position in video 86 public void mouseClicked(MouseEvent e) { 132 public void mouseClicked(MouseEvent e) { 133 //only on leftclicks of our layer 87 134 if(e.getButton() == MouseEvent.BUTTON1) { 88 if(Main.map.mapView.getActiveLayer() == this) { 89 //only on leftclicks of our layer 90 getNearestPoint(e.getPoint()); 91 } 135 JOptionPane.showMessageDialog(Main.parent,"test"); 136 getNearestNode(e.getPoint()); 137 Main.map.mapView.repaint(); 92 138 } 93 139 94 140 } 95 141 96 //finds the corresponding timecode in GPXtrack 97 private Point getNearestPoint(Point point) { 98 99 return point; 100 142 //finds the corresponding timecode in GPXtrack by given screen coordinates 143 private void getNearestNode(Point mouse) { 144 Point p; 145 Rectangle rect = new Rectangle(mouse, new Dimension(30, 30)); 146 //iterate through all possible notes 147 for(Node node : ds.getNodes()) 148 { 149 p = Main.map.mapView.getPoint(node); 150 if (rect.contains(p)) 151 { 152 node.setHighlighted(true); 153 } 154 155 } 101 156 } 102 157 -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoAction.java
r21226 r21295 3 3 import java.awt.event.ActionEvent; 4 4 import java.io.File; 5 import java.util.List; 6 5 7 6 8 import javax.swing.JFileChooser; … … 9 11 import org.openstreetmap.josm.Main; 10 12 import org.openstreetmap.josm.actions.JosmAction; 11 import org.openstreetmap.josm.data.gpx.GpxData; 13 import org.openstreetmap.josm.data.gpx.*; 14 import org.openstreetmap.josm.data.osm.DataSet; 15 import org.openstreetmap.josm.data.osm.Node; 16 import org.openstreetmap.josm.data.osm.Way; 17 import org.openstreetmap.josm.gui.layer.GpxLayer; 18 import org.openstreetmap.josm.tools.DateUtils; 12 19 import org.openstreetmap.josm.tools.Shortcut; 13 20 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; … … 17 24 18 25 private GpxData gps; 26 private DataSet ds; //all extracted GPS points 27 private List<WayPoint> ls; 19 28 20 29 public VideoAction() { … … 25 34 public void actionPerformed(ActionEvent arg0) { 26 35 27 // JFileChooser fc = new JFileChooser(); 28 // fc.setAcceptAllFileFilterUsed( false ); 29 // fc.setFileFilter( new VideoFileFilter() ); 30 // if (fc.showOpenDialog( Main.parent )==JFileChooser.APPROVE_OPTION) 31 // { 32 // VideoWindow w = new VideoWindow(fc.getSelectedFile()); 33 // } 34 Main.main.addLayer(new PositionLayer("test",gps)); 36 copyGPSLayer(); 37 Main.main.addLayer(new PositionLayer("test",ds)); 35 38 } 36 37 //restrict the file chooser38 private class VideoFileFilter extends FileFilter {39 40 @Override41 public boolean accept(File f) {42 43 String ext3 = ( f.getName().length() > 4 ) ? f.getName().substring( f.getName().length() - 4 ).toLowerCase() : "";44 String ext4 = ( f.getName().length() > 5 ) ? f.getName().substring( f.getName().length() - 5 ).toLowerCase() : "";45 46 // TODO: check what is supported by JMF or if there is a build in filter47 return ( f.isDirectory()48 || ext3.equals( ".avi" )49 || ext4.equals( ".wmv" )50 || ext3.equals( ".mpg" )51 );52 }53 54 55 @Override56 public String getDescription() {57 return tr("Video files");58 }59 39 60 }61 40 62 41 public void setGps(GpxData gps) { 63 42 this.gps = gps; 64 43 } 44 45 //makes a private flat copy for interaction 46 private void copyGPSLayer() 47 { 48 //TODO we assume that GPS points are in the correct order! 49 ds = new DataSet(); 50 for (GpxTrack trk : gps.tracks) { 51 for (GpxTrackSegment segment : trk.getSegments()) { 52 Way w = new Way(); 53 for (WayPoint p : segment.getWayPoints()) { 54 Node n = new Node(p.getCoor()); 55 String timestr = p.getString("time"); 56 if(timestr != null) 57 n.setTimestamp(DateUtils.fromString(timestr)); 58 ds.addPrimitive(n); 59 w.addNode(n); 60 //ls.add 61 } 62 ds.addPrimitive(w); 63 } 64 } 65 } 65 66 66 67 } -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoMappingPlugin.java
r21226 r21295 30 30 super(info); 31 31 //Register for GPS menu 32 VMenu = Main.main.menu.addMenu(tr("Video"), KeyEvent.VK_V, Main.main.menu.defaultMenuPos,ht("/Plugin/Videomapping")); 32 VMenu = Main.main.menu.addMenu(tr(" Video"), KeyEvent.VK_V, Main.main.menu.defaultMenuPos,ht("/Plugin/Videomapping"));//TODO no more ugly " video" hack 33 33 VMenu.setEnabled(false); //enabled only on GPS Layers 34 34 VAction = new VideoAction(); -
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoWindow.java
r21226 r21295 2 2 3 3 import java.awt.BorderLayout; 4 import java.awt.Canvas; 4 5 import java.awt.Component; 5 6 import java.awt.GraphicsConfiguration; … … 7 8 import java.io.File; 8 9 import java.io.IOException; 9 import javax.media.CannotRealizeException;10 import javax.media.Manager;11 import javax.media.NoPlayerException;12 import javax.media.Player;13 10 14 11 import javax.swing.JFrame; … … 16 13 import org.openstreetmap.josm.Main; 17 14 15 import uk.co.caprica.vlcj.player.*; 16 18 17 public class VideoWindow extends JFrame { 19 18 20 /**21 *22 */23 19 private static final long serialVersionUID = 2099614201397118560L; 24 20 25 21 public VideoWindow(File vfile) throws HeadlessException { 26 22 super(); 23 MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(null); 24 FullScreenStrategy fullScreenStrategy = new DefaultFullScreenStrategy(this); 25 MediaPlayer mediaPlayer = mediaPlayerFactory.newMediaPlayer(fullScreenStrategy); 26 mediaPlayer.setStandardMediaOptions(null); 27 //mediaPlayer.addMediaPlayerEventListener 28 Canvas videoSurface = new Canvas(); 29 mediaPlayer.setVideoSurface(videoSurface); 30 add(videoSurface); 27 31 try { 28 setTitle(vfile.getCanonicalPath()); 29 setSize(200,200); 30 setAlwaysOnTop(true); 31 32 try { 33 setLayout( new BorderLayout()); 34 Player mediaPlayer = Manager.createRealizedPlayer( vfile.toURL() ); 35 Component video = mediaPlayer.getVisualComponent(); 36 Component controls = mediaPlayer.getControlPanelComponent(); 37 add( video, BorderLayout.CENTER ); 38 add( controls, BorderLayout.SOUTH ); 39 } catch (NoPlayerException e) { 40 // TODO Auto-generated catch block 41 e.printStackTrace(); 42 } catch (CannotRealizeException e) { 43 // TODO Auto-generated catch block 44 e.printStackTrace(); 45 } 32 mediaPlayer.playMedia(vfile.getCanonicalPath(),null); 46 33 } catch (IOException e) { 47 34 // TODO Auto-generated catch block … … 49 36 } 50 37 setVisible(true); 51 38 mediaPlayer.release(); 39 mediaPlayerFactory.release(); 52 40 } 53 41
Note:
See TracChangeset
for help on using the changeset viewer.