-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathExportMovieDialog.java
More file actions
172 lines (146 loc) · 5.29 KB
/
ExportMovieDialog.java
File metadata and controls
172 lines (146 loc) · 5.29 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package nodebox.client;
import nodebox.client.movie.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/**
* Dialog presented when exporting a movie.
*/
public class ExportMovieDialog extends JDialog implements ActionListener {
private boolean dialogSuccessful = false;
private JTextField fromField;
private JTextField toField;
private JTextField fileField;
private JComboBox formatBox;
private File exportPath;
private int fromValue;
private int toValue;
private JButton exportButton;
public ExportMovieDialog(Frame frame, File exportPath) {
super(frame, "Export Movie");
setModal(true);
setResizable(false);
this.exportPath = exportPath;
// Main
setLayout(new BorderLayout(5, 5));
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
mainPanel.setBorder(new Theme.InsetsBorder(10, 10, 10, 10));
add(mainPanel, BorderLayout.CENTER);
// Directory
JPanel filePanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
filePanel.add(new JLabel("File: "));
fileField = new JTextField(20);
fileField.setEditable(false);
filePanel.add(fileField);
JButton chooseButton = new JButton("...");
chooseButton.putClientProperty("JButton.buttonType", "gradient");
chooseButton.setPreferredSize(new Dimension(30, 27));
chooseButton.addActionListener(this);
filePanel.add(chooseButton);
mainPanel.add(filePanel);
mainPanel.add(Box.createVerticalStrut(10));
// Format
JPanel formatPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
formatPanel.add(new JLabel("Format/Device: "));
mainPanel.add(formatPanel);
formatBox = new JComboBox();
for (VideoFormat format : Movie.VIDEO_FORMATS)
formatBox.addItem(format);
formatBox.setSelectedItem(Movie.DEFAULT_FORMAT);
formatPanel.add(formatBox);
mainPanel.add(Box.createVerticalStrut(10));
// Range
JPanel rangePanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 0));
rangePanel.add(new JLabel("From:"));
fromField = new JTextField("1", 5);
rangePanel.add(fromField);
rangePanel.add(new JLabel("To:"));
toField = new JTextField("100", 5);
rangePanel.add(toField);
mainPanel.add(rangePanel);
mainPanel.add(Box.createVerticalGlue());
// Buttons
mainPanel.add(Box.createVerticalStrut(10));
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 10, 0));
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
doCancel();
}
});
buttonPanel.add(cancelButton);
exportButton = new JButton("Export");
exportButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
doExport();
}
});
if (exportPath == null)
exportButton.setEnabled(false);
buttonPanel.add(exportButton);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
pack();
getRootPane().setDefaultButton(exportButton);
if (this.exportPath != null && this.exportPath.isFile())
setExportPath(this.exportPath);
}
private void doCancel() {
setVisible(false);
}
private void doExport() {
try {
fromValue = Integer.valueOf(fromField.getText());
} catch (NumberFormatException e) {
fromValue = 1;
}
try {
toValue = Integer.valueOf(toField.getText());
} catch (NumberFormatException e) {
toValue = 100;
}
dialogSuccessful = true;
setVisible(false);
}
public boolean isDialogSuccessful() {
return dialogSuccessful;
}
public File getExportPath() {
return exportPath;
}
private void setExportPath(File d) {
this.exportPath = d;
if (this.exportPath == null)
fileField.setText("");
else
fileField.setText(this.exportPath.getAbsolutePath());
exportButton.setEnabled(this.exportPath != null);
}
public VideoFormat getVideoFormat() {
return (VideoFormat) formatBox.getSelectedItem();
}
public int getFromValue() {
return fromValue;
}
public int getToValue() {
return toValue;
}
/**
* Called when an output file needs to be chosen.
*
* @param e the action event
*/
public void actionPerformed(ActionEvent e) {
String path = exportPath == null ? null : exportPath.getAbsolutePath();
File chosenFile = FileUtils.showSaveDialog(NodeBoxDocument.getCurrentDocument(), path, "mov,avi,mp4", "Movie files");
setExportPath(chosenFile != null ? chosenFile : this.exportPath);
}
public static void main(String[] args) {
ExportMovieDialog d = new ExportMovieDialog(null, null);
d.setVisible(true);
}
}