Changeset 21468 in osm for applications/editors/josm/plugins
- Timestamp:
- 2010-05-27T18:08:02+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/PositionLayer.java
r21350 r21468 6 6 import java.util.Iterator; 7 7 import java.util.List; 8 import java.util.ListIterator; 8 9 import java.util.Timer; 9 10 import java.util.TimerTask; … … 11 12 import java.awt.Color; 12 13 import java.awt.Component; 14 import java.awt.Cursor; 13 15 import java.awt.Dimension; 14 16 import java.awt.Graphics2D; … … 20 22 import java.awt.event.MouseEvent; 21 23 import java.awt.event.MouseListener; 24 import java.awt.event.MouseMotionListener; 22 25 23 26 import javax.swing.*; … … 38 41 import org.openstreetmap.josm.tools.ImageProvider; 39 42 40 public class PositionLayer extends Layer implements MouseListener, KeyListener {43 public class PositionLayer extends Layer implements MouseListener,MouseMotionListener, KeyListener { 41 44 private List<WayPoint> ls; 45 private GpsPlayer l; 42 46 private Collection<WayPoint> selected; 43 private WayPoint sel; 44 private Iterator<WayPoint> it; 47 private TimerTask ani; 48 private boolean dragIcon=false; //do we move the icon by hand? 49 private Point mouse; 50 private ImageIcon icon; 45 51 46 52 public PositionLayer(String name, final List<WayPoint> ls) { 47 super(name); 48 this.ls = ls; 53 super(name); 54 this.ls=ls; 55 l= new GpsPlayer(ls); 56 selected = new ArrayList<WayPoint>(); 57 icon=ImageProvider.get("videomapping.png"); 49 58 Action a = new AbstractAction() { 50 59 public void actionPerformed(ActionEvent e) { 51 60 // TODO Auto-generated method stub 52 61 System.err.println("!!!boom!!!"); 53 }}; 54 selected = new ArrayList<WayPoint>(); 62 }}; 55 63 Main.map.mapView.addMouseListener(this); 64 Main.map.mapView.addMouseMotionListener(this); 56 65 57 66 //Main.panel.addKeyListener(this); 58 //Main.map.mapView.addKeyListener(this);59 Main.contentPane.getInputMap().put(KeyStroke.getKeyStroke("SPACE"),"pressed");60 Main.contentPane.getActionMap().put("pressed",a);67 Main.map.mapView.addKeyListener(this); 68 //Main.contentPane.getInputMap().put(KeyStroke.getKeyStroke("SPACE"),"pressed"); 69 //Main.contentPane.getActionMap().put("pressed",a); 61 70 62 71 //Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,0),a); 63 72 //Main.contentPane.getActionMap().put("doSomething",a); 64 73 65 it=ls.iterator(); 66 Timer t = new Timer(); 67 t.schedule(new TimerTask() { 74 TimerTask ani=new TimerTask() { 68 75 69 76 @Override 70 public void run() { 71 // TODO Auto-generated method stub 72 sel=it.next(); 73 System.out.println(sel.getTime()); 77 //some cheap animation stuff 78 public void run() { 79 l.next(); 74 80 Main.map.mapView.repaint(); 75 81 } 76 },100,100); 82 }; 83 Timer t= new Timer(); 84 //t.schedule(ani,2000,2000); 85 l.next();l.next(); 77 86 78 87 } … … 80 89 @Override 81 90 public Icon getIcon() { 82 return ImageProvider.get("videomapping.png");91 return icon; 83 92 } 84 93 … … 97 106 //TODO here my stuff 98 107 new JSeparator(), 99 new JMenuItem(new LayerListPopup.InfoAction(this)) 100 }; 108 new JMenuItem(new LayerListPopup.InfoAction(this))};//TODO here infos about the linked videos 101 109 } 102 110 … … 108 116 } 109 117 110 // no merging ne scesarry118 // no merging necessary 111 119 @Override 112 120 public boolean isMergable(Layer arg0) { … … 125 133 public void paint(Graphics2D g, MapView map, Bounds bound) { 126 134 Point p; 127 g.setColor(Color.green); 135 //TODO Source out redundant calculations 136 //TODO make icon transparent 137 //draw all GPS points 138 g.setColor(Color.GREEN); 128 139 for(WayPoint n: ls) { 129 140 p = Main.map.mapView.getPoint(n.getEastNorth()); 130 g.drawOval(p.x - 2, p.y - 2, 4, 4); // small circles 131 } 132 g.setColor(Color.red); 141 g.drawOval(p.x - 2, p.y - 2, 4, 4); 142 } 143 g.setColor(Color.RED); 144 //draw selected GPS points 133 145 for(WayPoint n:selected) 134 146 { 135 147 p = Main.map.mapView.getPoint(n.getEastNorth()); 136 g.drawOval(p.x - 2, p.y - 2, 4, 4); // small circles 137 } 138 if (sel!=null){ 139 p=Main.map.mapView.getPoint(sel.getEastNorth()); 140 //TODO Source out redundant calculations 141 //TODO make icon transparent 142 ImageProvider.get("videomapping.png").paintIcon(null, g, p.x-ImageProvider.get("videomapping.png").getIconWidth()/2, p.y-ImageProvider.get("videomapping.png").getIconHeight()/2); 143 }; 144 } 145 146 @Override 147 public void visitBoundingBox(BoundingXYVisitor arg0) { 148 // TODO dunno what to do here 149 150 } 151 152 //jump to the right position in video 153 public void mouseClicked(MouseEvent e) { 154 //only on leftclicks of our layer 155 if(e.getButton() == MouseEvent.BUTTON1) { 156 //JOptionPane.showMessageDialog(Main.parent,"test"); 157 getNearestNode(e.getPoint()); 158 Main.map.mapView.repaint(); 159 } 160 161 } 162 163 //finds the corresponding timecode in GPXtrack by given screen coordinates 164 private void getNearestNode(Point mouse) { 165 Point p; 166 Rectangle rect = new Rectangle(mouse, new Dimension(30, 30)); 148 g.drawOval(p.x - 2, p.y - 2, 4, 4); 149 } 150 //draw surrounding points 151 g.setColor(Color.YELLOW); 152 if(l.getPrev()!=null) 153 { 154 p = Main.map.mapView.getPoint(l.getPrev().getEastNorth()); 155 g.drawOval(p.x - 2, p.y - 2, 4, 4); 156 Point p2 = Main.map.mapView.getPoint(l.getCurr().getEastNorth()); 157 g.drawLine(p.x, p.y, p2.x, p2.y); 158 } 159 if(l.getNext()!=null) 160 { 161 p = Main.map.mapView.getPoint(l.getNext().getEastNorth()); 162 g.drawOval(p.x - 2, p.y - 2, 4, 4); 163 Point p2 = Main.map.mapView.getPoint(l.getCurr().getEastNorth()); 164 g.drawLine(p.x, p.y, p2.x, p2.y); 165 } 166 //draw cam icon 167 if(dragIcon) 168 { 169 if(mouse!=null) 170 { 171 p=mouse; 172 icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2); 173 } 174 } 175 else 176 { 177 if (l.getCurr()!=null){ 178 p=Main.map.mapView.getPoint(l.getCurr().getEastNorth()); 179 icon.paintIcon(null, g, p.x-icon.getIconWidth()/2, p.y-icon.getIconHeight()/2); 180 g.drawString(l.getCurr().getTime().toString(), p.x, p.y); 181 } 182 } 183 } 184 185 private void markNearestNode(Point mouse) { 186 final int MAX=10; 187 Point p; 188 Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,mouse.x+MAX/2,mouse.y+MAX/2); 167 189 //iterate through all possible notes 168 190 for(WayPoint n : ls) … … 172 194 { 173 195 selected.add(n); 174 sel=n;175 196 } 176 197 177 198 } 178 199 } 179 180 public void mouseEntered(MouseEvent arg0) { 181 // TODO Auto-generated method stub 182 200 201 private WayPoint getNearestPoint(Point mouse) 202 { 203 final int MAX=10; 204 Point p; 205 Rectangle rect = new Rectangle(mouse.x-MAX/2,mouse.y-MAX/2,mouse.x+MAX/2,mouse.y+MAX/2); 206 //iterate through all possible notes 207 for(WayPoint n : ls) //TODO this is not very clever, what better way to find this WP? 208 { 209 p = Main.map.mapView.getPoint(n.getEastNorth()); 210 if (rect.contains(p)) 211 { 212 return n; 213 } 214 215 } 216 return null; 217 218 } 219 220 @Override 221 public void visitBoundingBox(BoundingXYVisitor arg0) { 222 // TODO dunno what to do here 223 224 } 225 226 //mark selected points 227 public void mouseClicked(MouseEvent e) { 228 } 229 230 public void mouseEntered(MouseEvent arg0) { 183 231 } 184 232 185 233 public void mouseExited(MouseEvent arg0) { 186 // TODO Auto-generated method stub 187 188 } 189 190 public void mousePressed(MouseEvent arg0) { 191 // TODO Auto-generated method stub 192 193 } 194 195 public void mouseReleased(MouseEvent arg0) { 196 // TODO Auto-generated method stub 234 } 235 236 public void mousePressed(MouseEvent e) { 237 if(e.getButton() == MouseEvent.BUTTON1) { 238 //is it on the cam icon? 239 if (l.getCurr()!=null) 240 { 241 if (getIconRect().contains(e.getPoint())) 242 { 243 mouse=e.getPoint(); 244 dragIcon=true; 245 //ani.cancel(); 246 } 247 } 248 } 249 250 } 251 252 public void mouseReleased(MouseEvent e) { 253 254 //only on leftclicks of our layer 255 if(e.getButton() == MouseEvent.BUTTON1) { 256 if(dragIcon) 257 { 258 dragIcon=false; 259 } 260 else 261 { 262 //JOptionPane.showMessageDialog(Main.parent,"test"); 263 markNearestNode(e.getPoint()); 264 WayPoint wp = getNearestPoint(e.getPoint()); 265 if(wp!=null) 266 { 267 l.jump(wp); 268 } 269 } 270 Main.map.mapView.repaint(); 271 } 272 273 } 274 275 //gets point on the line between 276 private Point getInterpolated(Point m) 277 { 278 Point highest = Main.map.mapView.getPoint(l.getCurr().getEastNorth()); 279 Point smallest = Main.map.mapView.getPoint(l.getNext().getEastNorth()); 280 float slope=(float)(highest.y-smallest.y) / (float)(highest.x - smallest.x); 281 282 m.y = highest.y+Math.round(slope*(m.x-highest.x)); 283 if(m.x<smallest.x) 284 { 285 m=smallest; 286 } 287 if(m.x>highest.x) m=highest; 288 System.out.println((m)); 289 return m; 290 } 291 292 public void mouseDragged(MouseEvent e) { 293 if(dragIcon) 294 { 295 mouse=e.getPoint(); 296 //restrict to GPS track 297 mouse=getInterpolated(mouse); 298 299 Main.map.mapView.repaint(); 300 } 301 } 302 303 private Rectangle getIconRect() 304 { 305 Point p = Main.map.mapView.getPoint(l.getCurr().getEastNorth()); 306 return new Rectangle(p.x-icon.getIconWidth()/2,p.y-icon.getIconHeight()/2,icon.getIconWidth(),icon.getIconHeight()); 307 } 308 309 public void mouseMoved(MouseEvent e) { 310 311 if (l.getCurr()!=null) 312 { 313 if (getIconRect().contains(e.getPoint())) 314 { 315 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 316 } 317 else 318 { 319 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 320 } 321 } 197 322 198 323 } 199 324 200 325 public void keyPressed(KeyEvent e) { 326 int i; 201 327 System.out.println(e.getKeyCode()); 202 328 switch(e.getKeyCode()) 203 329 { 330 case KeyEvent.VK_RIGHT: 331 { 332 l.jump(10); 333 };break; 204 334 case KeyEvent.VK_LEFT: 205 { 206 it.next(); 207 it.next(); 208 it.next(); 209 it.next(); 210 it.next(); 211 it.next(); 212 it.next(); 213 it.next(); 214 it.next(); 215 it.next(); 216 it.next(); 217 it.next(); 218 it.next(); 219 it.next(); 220 it.next(); 221 it.next(); 222 it.next(); 223 } 335 { 336 l.jump(-10); 337 338 };break; 339 case KeyEvent.VK_SPACE: 340 { 341 ani.cancel(); 342 } 224 343 } 225 344
Note:
See TracChangeset
for help on using the changeset viewer.