Changeset 25865 in osm


Ignore:
Timestamp:
2011-04-18T14:59:07+02:00 (13 years ago)
Author:
guardian
Message:

added IPO

Location:
applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoPlugin.java

    r25864 r25865  
    55import java.awt.event.ActionEvent;
    66import java.awt.event.KeyEvent;
     7import java.beans.PropertyChangeListener;
    78import java.io.File;
    89import java.text.ParseException;
    910import java.text.SimpleDateFormat;
     11import java.util.Calendar;
    1012import java.util.Date;
    1113
     14import javax.swing.Action;
    1215import javax.swing.Box;
    1316import javax.swing.InputVerifier;
     
    1821import javax.swing.JFileChooser;
    1922import javax.swing.JFormattedTextField;
     23import javax.swing.JLabel;
    2024import javax.swing.JMenu;
    2125import javax.swing.JMenuItem;
     
    6670    private String mostRecentFolder;
    6771        private GpxLayer gpsLayer;
     72        private VideoPositionLayer videoPositionLayer;
     73        private GPSVideoPlayer gpsVideoPlayer;
    6874
    6975        public VideoPlugin(PluginInformation info) {
     
    94100        VStart = new JosmAction(tr("Play/Pause"), "audio-playpause", tr("starts/pauses video playback"),
    95101                Shortcut.registerShortcut("videomapping:startstop","Video: "+tr("Play/Pause"),KeyEvent.VK_NUMPAD5, Shortcut.GROUP_DIRECT), false) {           
    96             public void actionPerformed(ActionEvent e) {                               
    97                
     102            public void actionPerformed(ActionEvent e) {
     103                gpsVideoPlayer.pause();               
    98104            }
    99105        };
     
    101107                Shortcut.registerShortcut("videomapping:backward","Video: "+tr("Backward"),KeyEvent.VK_NUMPAD4, Shortcut.GROUP_DIRECT), false) {
    102108            public void actionPerformed(ActionEvent e) {
    103                
     109                gpsVideoPlayer.backward();
    104110            }
    105111        };
     
    107113                Shortcut.registerShortcut("videomapping:forward","Video: "+tr("Forward"),KeyEvent.VK_NUMPAD6, Shortcut.GROUP_DIRECT), false) {           
    108114            public void actionPerformed(ActionEvent e) {
    109                
     115                gpsVideoPlayer.forward();
    110116                           
    111117            }
     
    115121           
    116122            public void actionPerformed(ActionEvent e) {
    117                
     123                gpsVideoPlayer.setSpeed(gpsVideoPlayer.getSpeed()+20);
    118124                           
    119125            }
     
    123129           
    124130            public void actionPerformed(ActionEvent e) {
    125                
     131                gpsVideoPlayer.setSpeed(gpsVideoPlayer.getSpeed()-20);
    126132                           
    127133            }
     
    129135        VJump= new JosmAction(tr("Jump To"), "jumpto", tr("jumps to the entered gps time"),null, false) {         
    130136            public void actionPerformed(ActionEvent e) {
    131                
    132 
     137                showJumpTo();
    133138            }
    134139                           
     
    138143                Shortcut.registerShortcut("videomapping:loop","Video: "+tr("loop"),KeyEvent.VK_NUMPAD7, Shortcut.GROUP_DIRECT), false) {           
    139144            public void actionPerformed(ActionEvent e) {
    140 
    141                            
     145                gpsVideoPlayer.toggleLooping();
    142146            }
    143147        };
     
    146150        VCenterIcon = new JCheckBoxMenuItem(new JosmAction(tr("Keep centered"), null, tr("follows the video icon automaticly"),null, false) {           
    147151            public void actionPerformed(ActionEvent e) {
    148 
    149                            
    150             }
    151         });
    152         //now the options menu
     152                videoPositionLayer.setAutoCenter(VCenterIcon.isSelected());
     153            }
     154        });
     155       
    153156        VSubTitles = new JCheckBoxMenuItem(new JosmAction(tr("Subtitles"), null, tr("Show subtitles in video"),null, false) {           
    154157            public void actionPerformed(ActionEvent e) {
    155  
    156                            
     158                gpsVideoPlayer.setSubtitles(VSubTitles.isSelected());                           
    157159            }
    158160        });
    159161       
    160162        VJumpLength = new JMenuItem(new JosmAction(tr("Jump length"), null, tr("Set the length of a jump"),null, false) {           
    161             public void actionPerformed(ActionEvent e) {                       
     163            public void actionPerformed(ActionEvent e) {
     164                Object[] possibilities = {"200", "500", "1000", "2000", "10000"};
     165                String s = (String)JOptionPane.showInputDialog(Main.parent,tr("Jump in video for x ms"),tr("Jump length"),JOptionPane.QUESTION_MESSAGE,null,possibilities,jumpLength);
     166                jumpLength=Integer.getInteger(s);
     167                saveProperties();
    162168            }
    163169        });
     
    165171        VLoopLength = new JMenuItem(new JosmAction(tr("Loop length"), null, tr("Set the length around a looppoint"),null, false) {           
    166172            public void actionPerformed(ActionEvent e) {
    167                
    168                            
     173                Object[] possibilities = {"500", "1000", "3000", "5000", "10000"};
     174                String s = (String)JOptionPane.showInputDialog(Main.parent,tr("Jump in video for x ms"),tr("Loop length"),JOptionPane.QUESTION_MESSAGE,null,possibilities,loopLength);
     175                loopLength=Integer.getInteger(s);
     176                saveProperties();
    169177            }
    170178        });       
    171179        VDeinterlacer= new JMenu("Deinterlacer");
    172180        VIntNone= new JRadioButtonMenuItem(new JosmAction(tr("none"), null, tr("no deinterlacing"),null, false) {           
    173             public void actionPerformed(ActionEvent e) {               
     181            public void actionPerformed(ActionEvent e) {
     182                gpsVideoPlayer.setDeinterlacer("none");
    174183            }
    175184        });
    176185        VIntBob= new JRadioButtonMenuItem(new JosmAction("bob", null, tr("deinterlacing using line doubling"),null, false) {           
    177186            public void actionPerformed(ActionEvent e) {
    178 
     187                gpsVideoPlayer.setDeinterlacer("bob");
    179188            }
    180189        });
    181190        VIntLinear= new JRadioButtonMenuItem(new JosmAction("linear", null, tr("deinterlacing using linear interpolation"),null, false) {           
    182191            public void actionPerformed(ActionEvent e) {
    183 
     192                gpsVideoPlayer.setDeinterlacer("linear");
    184193            }
    185194        });
     
    211220                mostRecentFolder=fc.getSelectedFile().getAbsolutePath();
    212221                saveProperties();
    213                 VideoPositionLayer videoPositionLayer= new VideoPositionLayer(gpsLayer);
    214                 GPSVideoPlayer gpsVideoPlayer = new GPSVideoPlayer(new SimpleDateFormat("hh:mm:ss") ,videoPositionLayer);
     222                videoPositionLayer= new VideoPositionLayer(gpsLayer);
     223                gpsVideoPlayer = new GPSVideoPlayer(new SimpleDateFormat("hh:mm:ss") ,videoPositionLayer);
     224                gpsVideoPlayer.setJumpLength(jumpLength);
     225                gpsVideoPlayer.setLoopLength(loopLength);
    215226                gpsVideoPlayer.addVideo(fc.getSelectedFile());
     227                enableVideoControlMenus(true);
    216228        }
    217229               
     
    273285        }
    274286       
     287        private void showJumpTo()
     288        {
     289                String s;
     290        try {
     291                JOptionPane d=new JOptionPane(tr("Jump to"), JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);               
     292                SimpleDateFormat gpsTimeFormat= new SimpleDateFormat("HH:mm:ss");
     293                String timerange=gpsTimeFormat.format(videoPositionLayer.getFirstWayPoint().getTime())+" - ";
     294                timerange=timerange+gpsTimeFormat.format(videoPositionLayer.getLastWayPoint().getTime());
     295                d.add(new JLabel(timerange)); //TODO for some reason this doesn't work -> use dialog
     296                final JFormattedTextField inp = new JFormattedTextField(new MaskFormatter("##:##:##"));
     297                inp.setText(gpsTimeFormat.format( videoPositionLayer.getGPSDate()));
     298                inp.setInputVerifier(new InputVerifier() {                                     
     299                                @Override
     300                                public boolean verify(JComponent input) {
     301                                        return false;
     302                                }
     303                        });
     304                //hack to set the focus
     305                SwingUtilities.invokeLater(new Runnable() {
     306                    public void run() {
     307                        inp.requestFocus();
     308                        inp.setCaretPosition(0);
     309                    }
     310                });
     311                if(d.showConfirmDialog(Main.main.panel,inp, tr("Jump to GPS time"),JOptionPane.OK_CANCEL_OPTION)==JOptionPane.OK_OPTION)
     312                {
     313                        //add the day to the time
     314                        Date t = gpsTimeFormat.parse(inp.getText());                   
     315                        Calendar time = Calendar.getInstance();
     316                        Calendar date = Calendar.getInstance();
     317                        time.setTime(t);
     318                        date.setTime(videoPositionLayer.getFirstWayPoint().getTime());
     319                        time.set(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DATE));
     320                    if (t!=null)
     321                    {
     322                        videoPositionLayer.jump(time.getTime());
     323                    }                       
     324                }
     325        } catch (ParseException e1) {
     326                e1.printStackTrace();
     327        }
     328        }
     329       
    275330
    276331        public void activeLayerChange(Layer oldLayer, Layer newLayer) {
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/VideoPositionLayer.java

    r25864 r25865  
    4747        private final int GPS_INTERVALL=1000;
    4848        private GPSVideoPlayer gpsVideoPlayer;
     49        private boolean autoCenter;
    4950
    5051        public VideoPositionLayer(GpxLayer gpsLayer) {
     
    142143       
    143144        //creates a waypoint for the corresponding time
    144         private WayPoint interpolate(Date GPSTime)
     145        public WayPoint interpolate(Date GPSTime)
    145146        {
    146147                WayPoint before =getWayPointBefore(GPSTime);
     
    227228               
    228229        }
     230       
     231        public void jump(Date GPSTime)
     232        {
     233                setIconPosition(getWayPointBefore(GPSTime));
     234               
     235        }
     236
     237        public void setIconPosition(WayPoint wp) {
     238                iconPosition=wp;
     239                Main.map.mapView.repaint();
     240                if (autoCenter)
     241                        Main.map.mapView.zoomTo(iconPosition.getCoor());
     242               
     243        }
    229244
    230245        public void mouseReleased(MouseEvent e) {
     
    239254                        gpsVideoPlayer.jumpTo(wp.getTime());
    240255                }
    241                 iconPosition=wp;
    242                 Main.map.mapView.repaint();
     256                setIconPosition(wp);
    243257            }           
    244258        }
    245259               
    246260        }
    247        
     261
    248262        //finds the first waypoint that is nearby the given point
    249263    private WayPoint getNearestWayPoint(Point mouse)
     
    341355                gpsVideoPlayer=player;
    342356        }
     357
     358        public void setAutoCenter(boolean enabled) {
     359                autoCenter=enabled;
     360               
     361        }
     362
     363        public void unload() {
     364                Main.main.removeLayer(this);
     365               
     366        }
    343367   
    344368}
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/GPSVideo.java

    r25864 r25865  
    9696                        System.out.println(diff);
    9797                }
    98         } 
     98        }
     99       
     100        public WayPoint getCurrentWayPoint()
     101        {
     102                if (isSynced())
     103                {
     104                        long videotime=player.getTime();
     105                        Date gpstime=new Date(start.getTime()+videotime);
     106                        return videoPositionLayer.interpolate(gpstime);
     107                }
     108                return null;
     109        }
    99110
    100111}
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/GPSVideoPlayer.java

    r25864 r25865  
    8484                return true;           
    8585        }
     86
     87
     88        @Override
     89        public void update_plays() {           
     90                super.update_plays();
     91                if (areAllVideosSynced())
     92                        videoPositionLayer.setIconPosition( videos.get(0).getCurrentWayPoint());
     93        }
     94       
     95        @Override
     96        public void windowClosing(WindowEvent arg0) {
     97                videoPositionLayer.unload();
     98                super.windowClosing(arg0);
     99        }
     100       
    86101       
    87102       
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/VideoPlayer.java

    r25864 r25865  
    6060//basic class of a videoplayer for one video
    6161public class VideoPlayer extends JFrame implements WindowListener, VideosObserver, VideoPlayerObserver{
    62         private static final int notificationIntervall = 1000;
     62        private static final int notificationIntervall = 500;
    6363        protected JPanel screenPanel,controlsPanel,canvasPanel;
    6464    private JSlider timeline;
     
    111111
    112112       
    113         protected void pause(){
     113        public void pause(){
    114114                if (notificationTimer!=null)
    115115                {
     
    124124        }
    125125
    126         protected void backward() {
     126        public void backward() {
    127127                videoengine.jump(-jumpLength); 
    128128        }
    129129
    130         protected void forward() {
     130        public void forward() {
    131131                videoengine.jump(jumpLength);   
    132132        }
    133133
    134         protected void toggleLooping() {
     134        public void setSpeed(Integer percent)
     135        {
     136                speed.setValue(percent);               
     137        }
     138       
     139        public Integer getSpeed()
     140        {
     141                return speed.getValue();
     142        }
     143       
     144        public void setDeinterlacer(String deinterlacer)
     145        {
     146                videoengine.setDeinterlacer(deinterlacer);
     147        }
     148       
     149        public void setSubtitles(boolean enabled)
     150        {
     151                videoengine.setSubtitles(enabled);
     152        }
     153
     154        public void mute()
     155        {
     156                videoengine.mute();
     157        }
     158
     159        public void toggleLooping() {
    135160                if(loopingTimer==null)
    136161                {
     
    236261
    237262            public void actionPerformed(ActionEvent arg0) {
    238                 videoengine.mute();
     263                mute();
    239264            }
    240265        });
     
    254279       
    255280        speed.addChangeListener(new ChangeListener() {           
    256             public void stateChanged(ChangeEvent arg0) {
     281            public void stateChanged(ChangeEvent arg0) {                           
    257282                if(!speed.getValueIsAdjusting())
    258283                {
  • applications/editors/josm/plugins/videomapping/src/org/openstreetmap/josm/plugins/videomapping/video/VideoPlayerObserver.java

    r25765 r25865  
    33public interface VideoPlayerObserver {
    44        public void update_plays();
     5
    56}
Note: See TracChangeset for help on using the changeset viewer.