1 package com.nexuiz.demorecorder.ui.swinggui;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.awt.event.ItemEvent;
7 import java.awt.event.ItemListener;
11 import javax.swing.JButton;
12 import javax.swing.JCheckBox;
13 import javax.swing.JDialog;
14 import javax.swing.JLabel;
15 import javax.swing.JOptionPane;
17 import net.miginfocom.swing.MigLayout;
19 import com.nexuiz.demorecorder.application.DemoRecorderUtils;
20 import com.nexuiz.demorecorder.application.jobs.RecordJob;
22 public class ApplyTemplateDialog extends JDialog implements ActionListener, ItemListener {
24 private static final long serialVersionUID = 4807155579295688578L;
25 private Frame parentFrame;
26 private RecordJobTemplate template;
27 private List<RecordJob> jobs;
29 private JCheckBox engineCB = new JCheckBox("Engine", true);
30 private JCheckBox engineParametersCB = new JCheckBox("Engine parameters", true);
31 private JCheckBox dpVideoDirCB = new JCheckBox("DPVideo directory", true);
32 private JCheckBox relativeDemoPathCB = new JCheckBox("Relative demo path", true);
33 private JCheckBox jobNameCB = new JCheckBox("Job name", true);
34 private JCheckBox demoDirectoryCB = new JCheckBox("Demo directory", true);
35 private JCheckBox execBeforeCapCB = new JCheckBox("Exec before capture", true);
36 private JCheckBox execAfterCB = new JCheckBox("Exec after capture", true);
37 private JCheckBox videoDestination = new JCheckBox("Video destination", true);
38 private JCheckBox pluginSettingsCB = new JCheckBox("Plug-in settings", true);
39 private JCheckBox selectAllCB = new JCheckBox("Select/deselect all", true);
41 private JButton applyButton = new JButton("Apply");
42 private JButton cancelButton = new JButton("Cancel");
44 public ApplyTemplateDialog(Frame owner, RecordJobTemplate template, List<RecordJob> jobs) {
46 this.parentFrame = owner;
47 this.template = template;
50 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
51 setTitle("Apply template");
55 public void showDialog() {
57 this.setLocationRelativeTo(this.parentFrame);
58 this.setVisible(true);
61 private void setupLayout() {
62 setLayout(new MigLayout());
63 getContentPane().add(new JLabel("Select which properties you want to apply to the selected jobs"), "wrap");
65 this.setupCheckBoxes();
67 applyButton.addActionListener(this);
68 cancelButton.addActionListener(this);
69 getContentPane().add(applyButton);
70 getContentPane().add(cancelButton);
73 private void setupCheckBoxes() {
74 getContentPane().add(engineCB, "wrap");
75 getContentPane().add(engineParametersCB, "wrap");
76 getContentPane().add(dpVideoDirCB, "wrap");
77 getContentPane().add(relativeDemoPathCB, "wrap");
78 getContentPane().add(jobNameCB, "wrap");
79 getContentPane().add(demoDirectoryCB, "wrap");
80 getContentPane().add(execBeforeCapCB, "wrap");
81 getContentPane().add(execAfterCB, "wrap");
82 getContentPane().add(videoDestination, "wrap");
83 getContentPane().add(pluginSettingsCB, "wrap");
84 getContentPane().add(selectAllCB, "wrap");
86 selectAllCB.addItemListener(this);
90 public void actionPerformed(ActionEvent e) {
91 if (e.getSource() == applyButton) {
92 this.applyTemplates();
94 } else if (e.getSource() == cancelButton) {
99 private void applyTemplates() {
101 for (RecordJob job : this.jobs) {
103 this.applyTemplate(job);
104 } catch (Throwable e) {
105 errors += "Job <B>" + job.getJobName() + "</B>: " + e.getMessage() + "<BR>";
109 if (!errors.equals("")) {
111 String errorMsg = "<HTML><BODY>Error occurred while trying to apply templates:<BR><BR>" + errors + "</BODY></HTML>";
112 JOptionPane.showMessageDialog(this.parentFrame, errorMsg, "Error(s) while applying template", JOptionPane.INFORMATION_MESSAGE);
116 private void applyTemplate(RecordJob job) {
117 if (engineCB.isSelected()) {
118 job.setEnginePath(template.getEnginePath());
120 if (engineParametersCB.isSelected()) {
121 job.setEngineParameters(template.getEngineParameters());
123 if (dpVideoDirCB.isSelected()) {
124 job.setDpVideoPath(template.getDpVideoPath());
126 if (relativeDemoPathCB.isSelected()) {
127 job.setRelativeDemoPath(template.getRelativeDemoPath());
129 if (jobNameCB.isSelected()) {
130 job.setJobName(template.getJobName());
132 if (demoDirectoryCB.isSelected()) {
133 File demoDir = template.getDemoFile();
134 String demoFileName = DemoRecorderUtils.getJustFileNameOfPath(job.getDemoFile());
135 String newDemoPath = demoDir.getAbsolutePath() + File.separator + demoFileName;
136 job.setDemoFile(new File(newDemoPath));
138 if (execBeforeCapCB.isEnabled()) {
139 job.setExecuteBeforeCap(template.getExecuteBeforeCap());
141 if (execAfterCB.isSelected()) {
142 job.setExecuteAfterCap(template.getExecuteAfterCap());
144 if (videoDestination.isSelected()) {
145 File videoDestinatinDir = template.getVideoDestination();
146 String videoFileName = DemoRecorderUtils.getJustFileNameOfPath(job.getVideoDestination());
147 String newVideoPath = videoDestinatinDir.getAbsolutePath() + File.separator + videoFileName;
148 job.setVideoDestination(new File(newVideoPath));
150 if (pluginSettingsCB.isSelected()) {
151 job.setEncoderPluginSettings(template.getEncoderPluginSettings());
156 public void itemStateChanged(ItemEvent e) {
157 if (e.getSource() == selectAllCB) {
158 boolean selected = false;
159 if (e.getStateChange() == ItemEvent.SELECTED) {
163 engineCB.setSelected(selected);
164 engineParametersCB.setSelected(selected);
165 dpVideoDirCB.setSelected(selected);
166 relativeDemoPathCB.setSelected(selected);
167 jobNameCB.setSelected(selected);
168 demoDirectoryCB.setSelected(selected);
169 execBeforeCapCB.setSelected(selected);
170 execAfterCB.setSelected(selected);
171 videoDestination.setSelected(selected);
172 pluginSettingsCB.setSelected(selected);