Changeset 183

Show
Ignore:
Timestamp:
03/09/08 16:03:46 (10 months ago)
Author:
Stuart Thiel
Message:

-cleaned up the fix for #152 a bit more.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • MediAnnotate/trunk/src/org/mediannotate/app/PlayerPanel.java

    r181 r183  
    1818import org.mediannotate.dom.IMovieObserver; 
    1919import org.mediannotate.dom.Movie; 
    20 import org.mediannotate.ui.TimeCodePanel; 
    2120import org.mediannotate.ui.TimeLinePanel; 
    22 import org.mediannotate.ui.ToolButtonPanel; 
     21import org.mediannotate.ui.UtilityPanel; 
    2322import org.mediannotate.ui.listener.PlayButtonListener; 
    2423import org.mediannotate.ui.listener.StopButtonListener; 
     
    3635        private Time durationTime; 
    3736        private TimeLinePanel timeLinePanel = new TimeLinePanel(); 
    38         private ToolButtonPanel toolButtonPanel; 
    39         private TimeCodePanel timeCodePanel; 
     37        private UtilityPanel utilityPanel; 
    4038        private Component currentMovieComponent; 
    4139        private JPanel moviePanel = new JPanel(); 
     
    6866         
    6967        public void setTime(long time) { 
    70                 timeCodePanel.updateTime(); 
     68                utilityPanel.updateTime(); 
    7169                timeLinePanel.setLocation(time/(float)durationTime.getAllInMilli()); 
    7270        } 
     
    111109                        moviePanel.repaint(); 
    112110                        durationTime = new Time(currentMovie.getDuration()); 
    113                         timeCodePanel.setDuration(currentMovie.getDuration()); 
     111                        utilityPanel.setDuration(currentMovie.getDuration()); 
    114112                         
    115113                        stopListener.setMovie(currentMovie); 
     
    128126                stopListener = new StopButtonListener(); 
    129127                 
    130                 toolButtonPanel = new ToolButtonPanel(this); 
     128                utilityPanel = new UtilityPanel(this); 
    131129                 
    132130                JPanel jp_outter = new JPanel(); 
    133131                jp_outter.setLayout(new GridLayout(2, 1)); 
    134                 jp_outter.add(toolButtonPanel, 0); 
     132                jp_outter.add(utilityPanel, 0); 
    135133                 
    136134                jp_outter.add(timeLinePanel, 1); 
     
    142140                 */ 
    143141                timeLineListener.setTimeLinePanel(timeLinePanel); 
    144                  
    145                 timeCodePanel = new TimeCodePanel(this, toolButtonPanel); 
    146                  
     142 
    147143                add(jp_outter, BorderLayout.NORTH); 
    148144                 
     
    246242 
    247243        public void mouseClicked(MouseEvent e) { 
    248                 if(!e.getComponent().equals(timeCodePanel)) { 
    249                         this.requestFocusInWindow(); 
    250                 } 
    251                  
     244                        this.requestFocusInWindow();     
    252245        } 
    253246         
  • MediAnnotate/trunk/src/org/mediannotate/ui/UtilityPanel.java

    r182 r183  
    33import java.awt.event.ActionEvent; 
    44import java.awt.event.ActionListener; 
     5import java.awt.event.FocusEvent; 
     6import java.awt.event.FocusListener; 
    57import java.awt.image.BufferedImage; 
    68import java.io.IOException; 
     
    1012import javax.swing.ImageIcon; 
    1113import javax.swing.JButton; 
     14import javax.swing.JLabel; 
     15import javax.swing.JOptionPane; 
    1216import javax.swing.JPanel; 
     17import javax.swing.JTextField; 
    1318import javax.swing.ToolTipManager; 
    1419 
     
    1823import org.mediannotate.app.PlayerPanel; 
    1924 
    20 public class ToolButtonPanel extends JPanel
     25public class UtilityPanel extends JPanel implements FocusListener
    2126        /** 
    2227         *  
     
    2429        private static final long serialVersionUID = 8627867059092046561L; 
    2530 
     31        private static final String TIME_CODE_LABEL_FORMAT = "%02d hrs %02d min %02d sec"; 
     32 
     33        private static final String TIME_CODE_FORMAT = "%02d:%02d:%02d.%02d"; 
    2634         
     35        private JTextField timeField; 
     36        private JLabel durationLabel; 
     37        private PlayerPanel myPlayerPanel; 
     38        private String innerTime = "";   
     39        private boolean timecodeHasFocus; 
    2740         
    28         public ToolButtonPanel(PlayerPanel p) { 
     41        public UtilityPanel(PlayerPanel p) { 
    2942                super(); 
    3043                BufferedImage annotationImage = null; 
     
    5265                } 
    5366                JButton jb = new JButton(new ImageIcon(annotationImage)); 
    54                 jb.addActionListener(new ToolButtonPanel.addAnnotationEventListener()); 
     67                jb.addActionListener(new UtilityPanel.addAnnotationEventListener()); 
    5568                jb.setToolTipText("Save Annotation"); 
    5669                this.add(jb); 
    5770                 
    5871                jb = new JButton(new ImageIcon(inImage)); 
    59                 jb.addActionListener(new ToolButtonPanel.markInEventHandler(p)); 
     72                jb.addActionListener(new UtilityPanel.markInEventHandler(p)); 
    6073                jb.setToolTipText("Mark Start of Annotation (ctrl-i)"); 
    6174                this.add(jb); 
    6275                 
    6376                jb = new JButton(new ImageIcon(outImage)); 
    64                 jb.addActionListener(new ToolButtonPanel.markOutEventHandler(p)); 
     77                jb.addActionListener(new UtilityPanel.markOutEventHandler(p)); 
    6578                jb.setToolTipText("Mark End of Annotation (ctrl-o)"); 
    6679                this.add(jb); 
     
    7689                this.add(jb); 
    7790                 
     91                 
     92                timeField = new JTextField(String.format(TIME_CODE_FORMAT, 0, 0, 0, 0), 8); 
     93                durationLabel = new JLabel(String.format(TIME_CODE_LABEL_FORMAT, 0, 0, 0)); 
     94                this.add(timeField); 
     95                this.add(durationLabel); 
     96                this.myPlayerPanel = p; 
     97                timeField.addKeyListener(p); 
     98                timeField.addFocusListener(this); 
     99                 
    78100        } 
    79101 
     102        public void setDuration(long duration) { 
     103                durationLabel.setText(String.format(TIME_CODE_LABEL_FORMAT,  
     104                                (duration/1000/60/60),  
     105                                ((duration%(1000*60*60))/1000/60),  
     106                                ((duration%(1000*60))/1000))); 
     107        } 
     108 
     109        public void focusGained(FocusEvent e) { 
     110                timecodeHasFocus = true; 
     111                innerTime = timeField.getText();                 
     112                if(myPlayerPanel.getCurrentMovie() != null) { 
     113                        myPlayerPanel.getCurrentMovie().stop(); 
     114                } 
     115        } 
     116 
     117        public void focusLost(FocusEvent e) {    
     118                if(myPlayerPanel.getCurrentMovie() != null) { 
     119                        if(timeField.getText().matches("^(\\d{2}):(\\d{2}):(\\d{2}).(\\d{2})$")) { 
     120                                try { 
     121                                long time = Long.parseLong(timeField.getText().replaceAll("^(\\d{2}):(\\d{2}):(\\d{2}).(\\d{2})$", "$1"))*1000*60*60 + 
     122                                Long.parseLong(timeField.getText().replaceAll("^(\\d{2}):(\\d{2}):(\\d{2}).(\\d{2})$", "$2"))*1000*60 + 
     123                                Long.parseLong(timeField.getText().replaceAll("^(\\d{2}):(\\d{2}):(\\d{2}).(\\d{2})$", "$3"))*1000 + 
     124                                Long.parseLong(timeField.getText().replaceAll("^(\\d{2}):(\\d{2}):(\\d{2}).(\\d{2})$", "$4"))*33; 
     125                                myPlayerPanel.getCurrentMovie().setTime(time); 
     126                                } catch (NumberFormatException e1) { 
     127                                        JOptionPane.showMessageDialog(myPlayerPanel, "There was a problem processing your timecode"); 
     128                                        timeField.setText(innerTime);    
     129                                } 
     130                        } else { 
     131                                JOptionPane.showMessageDialog(myPlayerPanel, "Timecodes must match the format hh:mm:ss.ff"); 
     132                                timeField.setText(innerTime); 
     133                        } 
     134                }        
     135                timecodeHasFocus = false; 
     136        } 
     137 
     138        public void updateTime() { 
     139                if(!timecodeHasFocus) 
     140                timeField.setText(String.format(TIME_CODE_FORMAT,  
     141                                (myPlayerPanel.getCurrentMovie().getTime()/1000/60/60),  
     142                                ((myPlayerPanel.getCurrentMovie().getTime()%(1000*60*60))/1000/60),  
     143                                ((myPlayerPanel.getCurrentMovie().getTime()%(1000*60))/1000),  
     144                                (int)((myPlayerPanel.getCurrentMovie().getTime()%1000)/33.3))); 
     145                 
     146        }        
     147         
    80148        public class addAnnotationEventListener implements ActionListener { 
    81149                protected PlayerPanel myPanel; 
     
    103171        }        
    104172         
    105         public class markInEventHandler extends ToolButtonPanel.vertovEventListener { 
     173        public class markInEventHandler extends UtilityPanel.vertovEventListener { 
    106174 
    107175                public markInEventHandler(PlayerPanel myPanel) { 
     
    115183        } 
    116184         
    117         public class markOutEventHandler extends ToolButtonPanel.vertovEventListener { 
     185        public class markOutEventHandler extends UtilityPanel.vertovEventListener { 
    118186 
    119187                public markOutEventHandler(PlayerPanel myPanel) {