Changeset 162
- Timestamp:
- 04/14/07 13:53:59 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/org/thestaticvoid/iriverter/ConverterUI.java
r161 r162 443 443 newDVD();*/ 444 444 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 } 447 454 448 455 if (e.getSource() == joinVideos) … … 741 748 }*/ 742 749 743 private ManualSplit newManualSplit() {750 private void newManualSplit(String video) { 744 751 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 } 751 768 } 752 769 trunk/src/org/thestaticvoid/iriverter/ManualSplit.java
r157 r162 31 31 import org.eclipse.swt.layout.*; 32 32 33 public class ManualSplit extends Composite implements SelectionListener, ManualSplitInfo{33 public class ManualSplit extends Composite implements SelectionListener, Job { 34 34 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; 37 38 private Label length; 38 39 private List marksList; 39 private String syncVideo;40 private String mplayerPath, syncVideo; 40 41 private Mark[] syncMarks; 41 42 42 public ManualSplit(Composite parent, int style, CTabItem tabItem ){43 public ManualSplit(Composite parent, int style, CTabItem tabItem, InputVideo inputVideo, String mplayerPath) throws Exception { 43 44 super(parent, style); 44 45 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()); 47 59 48 60 GridLayout gridLayout = new GridLayout(); … … 63 75 manualSplitLabel.setLayoutData(gridData); 64 76 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); 93 78 gridLayout = new GridLayout(); 94 79 gridLayout.horizontalSpacing = 6; … … 128 113 sec.addSelectionListener(this); 129 114 130 Composite addRemoveButtonComp = new Composite( splitMarksGroup, SWT.NONE);115 Composite addRemoveButtonComp = new Composite(this, SWT.NONE); 131 116 gridLayout = new GridLayout(); 132 117 gridLayout.horizontalSpacing = 6; … … 145 130 remove.addSelectionListener(this); 146 131 147 Composite marksListComp = new Composite( splitMarksGroup, SWT.NONE);132 Composite marksListComp = new Composite(this, SWT.NONE); 148 133 gridLayout = new GridLayout(); 149 134 gridLayout.horizontalSpacing = 6; … … 154 139 marksList = new List(marksListComp, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER); 155 140 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(); 156 153 } 157 154 … … 160 157 } 161 158 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) { 197 160 if (e.getSource() == add || e.getSource() == hr || e.getSource() == min || e.getSource() == sec) { 198 161 try { … … 229 192 } 230 193 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() { 242 195 Display.getDefault().syncExec(new Runnable() { 243 196 public void run() { … … 253 206 } 254 207 255 public synchronizedint getPart() {208 public int getPart() { 256 209 return -1; 257 210 } 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 } 258 233 }
