-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTitleAndCreditBackground.java
More file actions
74 lines (65 loc) · 2.06 KB
/
Copy pathTitleAndCreditBackground.java
File metadata and controls
74 lines (65 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package mediaPlayer;
import java.awt.BorderLayout;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.JTextArea;
import javax.swing.SwingWorker;
public class TitleAndCreditBackground extends SwingWorker<Integer, Integer> {
private String _instruction;
private JFrame progressBar = new JFrame("Adding Text");
private JProgressBar pbar = new JProgressBar();
private JTextArea progress = new JTextArea("Progress:");
public TitleAndCreditBackground (String instruction,int frames) {;
_instruction = instruction;
progressBar.add(progress,BorderLayout.CENTER);
progressBar.add(pbar,BorderLayout.SOUTH);
pbar.setMaximum(frames);
progressBar.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
progressBar.setSize(500, 60);
progressBar.setVisible(true);
}
@Override
protected Integer doInBackground() throws Exception {
try {
ProcessBuilder titleAdder = new ProcessBuilder("bash", "-c", _instruction);
titleAdder.redirectErrorStream(true);
Process downloadProcess = titleAdder.start();
BufferedReader stdoutDownload = new BufferedReader(new InputStreamReader(downloadProcess.getInputStream()));
String line = stdoutDownload.readLine();
while (line != null && !isCancelled()) {
line = stdoutDownload.readLine();
String[] lines = line.split(" ");
try {
int i = Integer.parseInt(lines[1]);
publish((int) i);
} catch (Exception e) {
}
}
} catch (Exception e) {
}
return null;
}
@Override
protected void process(List<Integer> chunks) {
for (int percent : chunks) {
pbar.setValue(percent);
}
}
@Override
protected void done() {
if (!this.isCancelled()) {
JOptionPane.showMessageDialog(null, "Text successfully added to video");
progressBar.dispose();
} else if (this.isCancelled()) {
JOptionPane.showMessageDialog(null, "Something went wrong :(");
progressBar.dispose();
}
}
}