Changeset 162

Show
Ignore:
Timestamp:
04/14/07 13:53:59 (2 years ago)
Author:
jlee
Message:

Change ManualSplit? to use new shitty system

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/org/thestaticvoid/iriverter/ConverterUI.java

    r161 r162  
    443443                        newDVD();*/ 
    444444                 
    445                 if (e.getSource() == manualSplit) 
    446                         newManualSplit(); 
     445                if (e.getSource() == manualSplit) { 
     446                        FileDialog fileDialog = new FileDialog(shell, SWT.OPEN); 
     447                        fileDialog.setText("Input Video"); 
     448                        fileDialog.setFilterExtensions(new String[]{"*.avi"}); 
     449                        fileDialog.setFilterNames(new String[]{"AVI Video (*.avi)"}); 
     450                        String file = fileDialog.open(); 
     451                        if (file != null) 
     452                                newManualSplit(file); 
     453                } 
    447454                 
    448455                if (e.getSource() == joinVideos) 
     
    741748        }*/ 
    742749         
    743         private ManualSplit newManualSplit() { 
     750        private void newManualSplit(String video) { 
    744751                CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE); 
    745                 ManualSplit manualSplit = new ManualSplit(tabFolder, SWT.NONE, tabItem); 
    746                 tabItem.setControl(manualSplit); 
    747                 tabFolder.setSelection(tabItem); 
    748                 tabChanged(false); 
    749                  
    750                 return manualSplit; 
     752                ManualSplit manualSplit = null; 
     753                 
     754                boolean canceled = false; 
     755                while (!canceled) 
     756                        try { 
     757                                manualSplit = new ManualSplit(tabFolder, SWT.NONE, tabItem, new InputVideo(video), MPlayerInfo.getMPlayerPath());  
     758                                tabItem.setControl(manualSplit); 
     759                                tabFolder.setSelection(tabItem); 
     760                                tabChanged(false); 
     761                                canceled = true; 
     762                        } catch (MPlayerNotFoundException mpe) { 
     763                                canceled = new MPlayerPathDialog(shell).open(); 
     764                        } catch (Exception e) { 
     765                                tabItem.dispose(); 
     766                                canceled = true; 
     767                        } 
    751768        } 
    752769         
  • trunk/src/org/thestaticvoid/iriverter/ManualSplit.java

    r157 r162  
    3131import org.eclipse.swt.layout.*; 
    3232 
    33 public class ManualSplit extends Composite implements SelectionListener, ManualSplitInfo
     33public class ManualSplit extends Composite implements SelectionListener, Job
    3434        private CTabItem tabItem; 
    35         private Text videoInput, hr, min, sec; 
    36         private Button videoSelect, add, remove; 
     35        private InputVideo inputVideo; 
     36        private Text hr, min, sec; 
     37        private Button add, remove; 
    3738        private Label length; 
    3839        private List marksList; 
    39         private String syncVideo; 
     40        private String mplayerPath, syncVideo; 
    4041        private Mark[] syncMarks; 
    4142         
    42         public ManualSplit(Composite parent, int style, CTabItem tabItem)
     43        public ManualSplit(Composite parent, int style, CTabItem tabItem, InputVideo inputVideo, String mplayerPath) throws Exception
    4344                super(parent, style); 
    4445                this.tabItem = tabItem; 
    45                  
    46                 tabItem.setText("New Manual Split"); 
     46                this.inputVideo = inputVideo; 
     47                this.mplayerPath = mplayerPath; 
     48                 
     49                MPlayerInfo inputVideoInfo = new MPlayerInfo(inputVideo, mplayerPath); 
     50                if (!inputVideoInfo.videoSupported()) { 
     51                        MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_ERROR); 
     52                        messageBox.setText("Unsupported Video"); 
     53                        messageBox.setMessage("MPlayer does not recognize this type of video:\n" + new File(inputVideo.getName()).getName()); 
     54                        messageBox.open(); 
     55                        throw new Exception("Unsupported video"); 
     56                } 
     57                 
     58                tabItem.setText(new File(inputVideo.getName()).getName()); 
    4759                 
    4860                GridLayout gridLayout = new GridLayout(); 
     
    6375                manualSplitLabel.setLayoutData(gridData); 
    6476                 
    65                 Label video = new Label(this, SWT.NONE); 
    66                 video.setText("Video:"); 
    67                  
    68                 videoInput = new Text(this, SWT.BORDER); 
    69                 videoInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 
    70                  
    71                 videoSelect = new Button(this, SWT.PUSH); 
    72                 videoSelect.setText("Select"); 
    73                 gridData = new GridData(); 
    74                 gridData.widthHint = 75; 
    75                 videoSelect.setLayoutData(gridData); 
    76                 videoSelect.addSelectionListener(this); 
    77                  
    78                 Group splitMarksGroup = new Group(this, SWT.NONE); 
    79                 splitMarksGroup.setText("Split Marks"); 
    80                 gridLayout = new GridLayout(); 
    81                 gridLayout.horizontalSpacing = 6; 
    82                 gridLayout.verticalSpacing = 6; 
    83                 gridLayout.marginHeight = 0; 
    84                 gridLayout.marginWidth = 0; 
    85                 gridLayout.numColumns = 3; 
    86                 //gridLayout.makeColumnsEqualWidth = true; 
    87                 splitMarksGroup.setLayout(gridLayout); 
    88                 gridData = new GridData(GridData.FILL_BOTH); 
    89                 gridData.horizontalSpan = 3; 
    90                 splitMarksGroup.setLayoutData(gridData); 
    91                  
    92                 Composite addMarkComp = new Composite(splitMarksGroup, SWT.NONE); 
     77                Composite addMarkComp = new Composite(this, SWT.NONE); 
    9378                gridLayout = new GridLayout(); 
    9479                gridLayout.horizontalSpacing = 6; 
     
    128113                sec.addSelectionListener(this); 
    129114                 
    130                 Composite addRemoveButtonComp = new Composite(splitMarksGroup, SWT.NONE); 
     115                Composite addRemoveButtonComp = new Composite(this, SWT.NONE); 
    131116                gridLayout = new GridLayout(); 
    132117                gridLayout.horizontalSpacing = 6; 
     
    145130                remove.addSelectionListener(this); 
    146131                 
    147                 Composite marksListComp = new Composite(splitMarksGroup, SWT.NONE); 
     132                Composite marksListComp = new Composite(this, SWT.NONE); 
    148133                gridLayout = new GridLayout(); 
    149134                gridLayout.horizontalSpacing = 6; 
     
    154139                marksList = new List(marksListComp, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); 
    155140                marksList.setLayoutData(new GridData(GridData.FILL_BOTH)); 
     141                 
     142                int length = inputVideoInfo.getLength(); 
     143                int seconds = length % 60; 
     144                int minutes = length / 60; 
     145                int hours = minutes / 60; 
     146                minutes = minutes - (hours * 60); 
     147 
     148                this.length.setText(hours + ":" + ((minutes < 10) ? "0" + minutes : "" + minutes) + ":" + ((seconds < 10) ? "0" + seconds : "" + seconds)); 
     149                hr.setText("0"); 
     150                min.setText("00"); 
     151                sec.setText("00"); 
     152                marksList.removeAll(); 
    156153        } 
    157154         
     
    160157        } 
    161158         
    162         public void widgetSelected(SelectionEvent e) { 
    163                 if (e.getSource() == videoSelect) { 
    164                         FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN); 
    165                         fileDialog.setText("Input Video"); 
    166                         fileDialog.setFilterExtensions(new String[]{"*.avi"}); 
    167                         fileDialog.setFilterNames(new String[]{"AVI Video (*.avi)"}); 
    168                         String file = fileDialog.open(); 
    169                         if (file != null) { 
    170                                 boolean canceled = false; 
    171                                 while (!canceled) 
    172                                         try { 
    173                                                 videoInput.setText(file); 
    174                                                 tabItem.setText(new File(file).getName()); 
    175  
    176                                                 MPlayerInfo titleInfo = new MPlayerInfo(videoInput.getText()); 
    177  
    178                                                 int length = titleInfo.getLength(); 
    179                                                 int seconds = length % 60; 
    180                                                 int minutes = length / 60; 
    181                                                 int hours = minutes / 60; 
    182                                                 minutes = minutes - (hours * 60); 
    183  
    184                                                 this.length.setText(hours + ":" + ((minutes < 10) ? "0" + minutes : "" + minutes) + ":" + ((seconds < 10) ? "0" + seconds : "" + seconds)); 
    185                                                 hr.setText("0"); 
    186                                                 min.setText("00"); 
    187                                                 sec.setText("00"); 
    188                                                 marksList.removeAll(); 
    189                                                  
    190                                                 canceled = true; 
    191                                         } catch (MPlayerNotFoundException mpe) { 
    192                                                 canceled = new MPlayerPathDialog(getParent().getShell()).open(); 
    193                                         } 
    194                         } 
    195                 } 
    196                  
     159        public void widgetSelected(SelectionEvent e) {           
    197160                if (e.getSource() == add || e.getSource() == hr || e.getSource() == min || e.getSource() == sec) { 
    198161                        try { 
     
    229192        } 
    230193         
    231         public synchronized String getVideo() { 
    232                 Display.getDefault().syncExec(new Runnable() { 
    233                         public void run() { 
    234                                 syncVideo = videoInput.getText(); 
    235                         } 
    236                 }); 
    237                  
    238                 return syncVideo; 
    239         } 
    240          
    241         public synchronized Mark[] getMarks() { 
     194        public Mark[] getMarks() { 
    242195                Display.getDefault().syncExec(new Runnable() { 
    243196                        public void run() { 
     
    253206        } 
    254207         
    255         public synchronized int getPart() { 
     208        public int getPart() { 
    256209                return -1; 
    257210        } 
     211         
     212        public String getDescription() { 
     213                return "Splitting " + new File(inputVideo.getName()).getName(); 
     214        } 
     215         
     216        public ShitToDo[] getShitToDo() { 
     217                java.util.List shitToDo = new java.util.ArrayList(); 
     218                 
     219                for (int i = 0; (i + 1) < getMarks().length; i++) { 
     220                        String inputVideo = this.inputVideo.getName(); 
     221                        String outputVideo = inputVideo.substring(0, inputVideo.lastIndexOf('.')) + ".part" + (i + 1) + ".avi"; 
     222                         
     223                        if (getMarks()[i].getTime() == Mark.START_MARK) 
     224                                shitToDo.add(new MencoderShit("Working on part " + (i + 1) + " of " + (getMarks().length - 1) + "...", new MencoderCommand(new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, "-ovc", "copy", "-oac", "copy", "-endpos", "" + getMarks()[i + 1].getTime()}, this.inputVideo, outputVideo))); 
     225                        else if (getMarks()[i + 1].getTime() == Mark.END_MARK) 
     226                                shitToDo.add(new MencoderShit("Working on part " + (i + 1) + " of " + (getMarks().length - 1) + "...", new MencoderCommand(new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, "-ovc", "copy", "-oac", "copy", "-ss", "" + getMarks()[i].getTime()}, this.inputVideo, outputVideo))); 
     227                        else 
     228                                shitToDo.add(new MencoderShit("Working on part " + (i + 1) + " of " + (getMarks().length - 1) + "...", new MencoderCommand(new String[]{mplayerPath + MPlayerInfo.MENCODER_BIN, "-ovc", "copy", "-oac", "copy", "-ss", "" + getMarks()[i].getTime(), "-endpos", "" + getMarks()[i + 1].getTime()}, this.inputVideo, outputVideo))); 
     229                } 
     230                 
     231                return (ShitToDo[]) shitToDo.toArray(new ShitToDo[]{}); 
     232        } 
    258233}