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