]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/JobDialog.java
Merge branch 'master' of ssh://git.xonotic.org/xonotic
[xonotic/xonotic.git] / misc / tools / NexuizDemoRecorder / main / src / main / java / com / nexuiz / demorecorder / ui / swinggui / JobDialog.java
1 package com.nexuiz.demorecorder.ui.swinggui;
2
3 import java.awt.Dimension;
4 import java.awt.Frame;
5 import java.awt.Toolkit;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8 import java.io.File;
9 import java.util.HashMap;
10 import java.util.Map;
11 import java.util.Properties;
12 import java.util.Set;
13
14 import javax.swing.JButton;
15 import javax.swing.JCheckBox;
16 import javax.swing.JComponent;
17 import javax.swing.JDialog;
18 import javax.swing.JFileChooser;
19 import javax.swing.JLabel;
20 import javax.swing.JPanel;
21 import javax.swing.JScrollPane;
22 import javax.swing.JTextArea;
23 import javax.swing.JTextField;
24 import javax.swing.ScrollPaneConstants;
25 import javax.swing.border.EmptyBorder;
26 import javax.swing.filechooser.FileFilter;
27
28 import net.miginfocom.swing.MigLayout;
29
30 import org.jdesktop.swingx.JXTable;
31 import org.jdesktop.swingx.JXTitledSeparator;
32
33 import com.nexuiz.demorecorder.application.DemoRecorderApplication;
34 import com.nexuiz.demorecorder.application.DemoRecorderUtils;
35 import com.nexuiz.demorecorder.application.NDRPreferences;
36 import com.nexuiz.demorecorder.application.jobs.RecordJob;
37 import com.nexuiz.demorecorder.application.plugins.EncoderPlugin;
38 import com.nexuiz.demorecorder.ui.swinggui.tablemodels.RecordJobTemplatesTableModel;
39 import com.nexuiz.demorecorder.ui.swinggui.utils.SwingGUIUtils;
40
41 /**
42  * Shows the dialog that allows to create a new job, create one from a template
43  * or edit an existing job.
44  */
45
46 public class JobDialog extends JDialog implements ActionListener {
47         private static final long serialVersionUID = 6926246716804560522L;
48         public static final int CREATE_NEW_JOB = 0;
49         public static final int EDIT_JOB = 1;
50         public static final int CREATE_NEW_TEMPLATE = 2;
51         public static final int EDIT_TEMPLATE = 3;
52         public static final int CREATE_JOB_FROM_TEMPLATE = 4;
53
54         private DemoRecorderApplication appLayer;
55         private RecordJobTemplatesTableModel tableModel;
56 //      private JXTable templatesTable;
57         private Frame parentFrame;
58         private int dialogType;
59         private RecordJob job = null;
60         private JPanel inputPanel;
61         private JPanel buttonPanel;
62
63         private JTextField templateNameField;
64         private JTextField templateSummaryField;
65         private JTextField enginePathField;
66         private JButton enginePathChooserButton;
67         private JTextField engineParameterField;
68         private JTextField dpVideoDirField;
69         private JButton dpVideoDirChooserButton;
70         private JTextField relativeDemoPathField;
71         private JTextField jobNameField;
72         private JTextField demoFileField;
73         private JButton demoFileChooserButton;
74         private JTextField startSecondField;
75         private JTextField endSecondField;
76         private JTextArea execBeforeField;
77         private JTextArea execAfterField;
78         private JTextField videoDestinationField;
79         private JButton videoDestinationChooserButton;
80         
81         private JButton createButton;
82         private JButton cancelButton;
83         
84         //file choosers
85         private JFileChooser enginePathFC;
86         private JFileChooser dpVideoDirFC;
87         private JFileChooser demoFileFC;
88         private JFileChooser videoDestinationFC;
89         
90         private FileFilter userDirFilter = new NexuizUserDirFilter();
91         
92         private Map<String, JComponent> pluginDialogSettings = new HashMap<String, JComponent>();
93
94         /**
95          * Constructor to create a dialog when creating a new job.
96          * @param owner
97          * @param appLayer
98          */
99         public JobDialog(Frame owner, DemoRecorderApplication appLayer) {
100                 super(owner, true);
101                 this.parentFrame = owner;
102                 this.dialogType = CREATE_NEW_JOB;
103                 this.appLayer = appLayer;
104                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
105
106                 setTitle("Create new job");
107
108                 this.setupLayout();
109         }
110         
111         /**
112          * Constructor to create a dialog when creating a new template.
113          * @param owner
114          * @param dialogType
115          * @param appLayer
116          */
117         public JobDialog(Frame owner, RecordJobTemplatesTableModel tableModel, JXTable templatesTable, DemoRecorderApplication appLayer) {
118                 super(owner, true);
119                 this.parentFrame = owner;
120                 this.dialogType = CREATE_NEW_TEMPLATE;
121                 this.tableModel = tableModel;
122                 this.appLayer = appLayer;
123 //              this.templatesTable = templatesTable; seems we don't need it
124                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
125                 setTitle("Create new template");
126
127                 this.setupLayout();
128         }
129         
130         /**
131          * Constructor to use when creating a new job from a template, or when editing a template.
132          * @param owner
133          * @param template
134          * @param type either CREATE_JOB_FROM_TEMPLATE or EDIT_TEMPLATE
135          */
136         public JobDialog(Frame owner, RecordJobTemplate template, DemoRecorderApplication appLayer, int type) {
137                 super(owner, true);
138                 this.parentFrame = owner;
139                 
140                 this.job = template;
141                 this.appLayer = appLayer;
142                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
143                 
144                 if (type != CREATE_JOB_FROM_TEMPLATE && type != EDIT_TEMPLATE) {
145                         throw new RuntimeException("Illegal paraameter \"type\"");
146                 }
147                 
148                 this.dialogType = type;
149                 if (type == CREATE_JOB_FROM_TEMPLATE) {
150                         setTitle("Create job from template");
151                 } else {
152                         setTitle("Edit template");
153                 }
154
155                 this.setupLayout();
156         }
157         
158         /**
159          * Constructor to create a dialog to be used when editing an existing job.
160          * @param owner
161          * @param job
162          */
163         public JobDialog(Frame owner, RecordJob job, DemoRecorderApplication appLayer) {
164                 super(owner, true);
165                 this.parentFrame = owner;
166                 this.dialogType = EDIT_JOB;
167                 this.appLayer = appLayer;
168                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
169
170                 setTitle("Edit job");
171                 this.job = job;
172
173                 this.setupLayout();
174         }
175         
176         
177         
178         public void showDialog() {
179                 this.pack();
180                 Toolkit t = Toolkit.getDefaultToolkit();
181                 Dimension screenSize = t.getScreenSize();
182                 if (getHeight() > screenSize.height) {
183                         Dimension newPreferredSize = getPreferredSize();
184                         newPreferredSize.height = screenSize.height - 100;
185                         setPreferredSize(newPreferredSize);
186                         this.pack();
187                 }
188                 this.setLocationRelativeTo(this.parentFrame);
189                 this.setVisible(true);
190         }
191
192         private void setupLayout() {
193 //              setLayout(new MigLayout("wrap 1", "[grow,fill]", "[]20[]"));
194                 setLayout(new MigLayout("wrap 1", "[grow,fill]", "[][]"));
195                 this.setupInputMask();
196                 this.setupButtonPart();
197
198         }
199
200         private void setupInputMask() {
201                 inputPanel = new JPanel(new MigLayout("insets 0,wrap 3", "[][250::,grow,fill][30::]"));
202                 JScrollPane inputScrollPane = new JScrollPane(inputPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
203                 inputScrollPane.setBorder(new EmptyBorder(0,0,0,0));
204                 
205                 JXTitledSeparator environmentHeading = new JXTitledSeparator("Environment settings");
206                 inputPanel.add(environmentHeading, "span 3,grow");
207
208                 this.setupTemplateNameAndSummary();
209                 this.setupEnginePath();
210                 this.setupEngineParameters();
211                 this.setupDPVideoDir();
212                 this.setupRelativeDemoPath();
213
214                 JXTitledSeparator jobSettingsHeading = new JXTitledSeparator("Job settings");
215                 inputPanel.add(jobSettingsHeading, "span 3,grow");
216
217                 this.setupJobName();
218                 this.setupDemoFile();
219                 this.setupStartSecond();
220                 this.setupEndSecond();
221                 this.setupExecBefore();
222                 this.setupExecAfter();
223                 this.setupVideoDestination();
224                 
225                 this.setupPluginPreferences();
226
227                 getContentPane().add(inputScrollPane);
228         }
229         
230         private void setupTemplateNameAndSummary() {
231                 if (this.dialogType != CREATE_NEW_TEMPLATE && this.dialogType != EDIT_TEMPLATE) {
232                         return;
233                 }
234                 
235                 //layout stuff
236                 inputPanel.add(new JLabel("Template name:"));
237                 templateNameField = new JTextField();
238                 inputPanel.add(templateNameField, "wrap");
239                 
240                 inputPanel.add(new JLabel("Summary:"));
241                 templateSummaryField = new JTextField();
242                 inputPanel.add(templateSummaryField, "wrap");
243                 
244                 //UI logic stuff
245                 if (this.dialogType == EDIT_TEMPLATE) {
246                         RecordJobTemplate template = (RecordJobTemplate) this.job;
247                         templateNameField.setText(template.getName());
248                         templateSummaryField.setText(template.getSummary());
249                 }
250         }
251         
252         private void setupEnginePath() {
253                 //layout stuff
254                 inputPanel.add(new JLabel("Engine:"));
255                 enginePathField = new JTextField();
256                 enginePathField.setEditable(false);
257                 inputPanel.add(enginePathField);
258                 enginePathChooserButton = new FileChooserButton();
259                 inputPanel.add(enginePathChooserButton);
260                 
261                 //UI logic stuff
262                 this.enginePathFC = createConfiguredFileChooser();
263                 enginePathChooserButton.addActionListener(this);
264                 if (this.dialogType == EDIT_JOB || this.dialogType == EDIT_TEMPLATE || this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
265                         this.enginePathFC.setSelectedFile(this.job.getEnginePath());
266                         this.enginePathField.setText(this.job.getEnginePath().getAbsolutePath());
267                 }
268         }
269         
270         private void setupEngineParameters() {
271                 //layout stuff
272                 inputPanel.add(new JLabel("Engine parameters:"));
273                 engineParameterField = new JTextField();
274                 inputPanel.add(engineParameterField, "wrap");
275                 
276                 //UI logic stuff
277                 if (this.dialogType == EDIT_JOB || this.dialogType == EDIT_TEMPLATE || this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
278                         engineParameterField.setText(this.job.getEngineParameters());
279                 }
280         }
281         
282         private void setupDPVideoDir() {
283                 //layout stuff
284                 inputPanel.add(new JLabel("DPVideo directory:"));
285                 dpVideoDirField = new JTextField();
286                 dpVideoDirField.setEditable(false);
287                 inputPanel.add(dpVideoDirField);
288                 dpVideoDirChooserButton = new FileChooserButton();
289                 inputPanel.add(dpVideoDirChooserButton);
290                 
291                 //UI logic stuff
292                 dpVideoDirChooserButton.addActionListener(this);
293                 this.dpVideoDirFC = createConfiguredFileChooser();
294                 this.dpVideoDirFC.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
295                 if (this.dialogType == EDIT_JOB || this.dialogType == EDIT_TEMPLATE || this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
296                         this.dpVideoDirFC.setSelectedFile(this.job.getDpVideoPath());
297                         this.dpVideoDirField.setText(this.job.getDpVideoPath().getAbsolutePath());
298                 }
299         }
300         
301         private void setupRelativeDemoPath() {
302                 //layout stuff
303                 inputPanel.add(new JLabel("Relative demo path:"));
304                 relativeDemoPathField = new JTextField();
305                 inputPanel.add(relativeDemoPathField, "wrap 20");
306                 
307                 //UI logic stuff
308                 if (this.dialogType == CREATE_NEW_JOB || this.dialogType == CREATE_NEW_TEMPLATE) {
309                         relativeDemoPathField.setText("demos");
310                 }
311                 if (this.dialogType == EDIT_JOB || this.dialogType == EDIT_TEMPLATE || this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
312                         relativeDemoPathField.setText(this.job.getRelativeDemoPath());
313                 }
314         }
315         
316         private void setupJobName() {
317                 inputPanel.add(new JLabel("Job name:"));
318                 
319                 jobNameField = new JTextField();
320                 inputPanel.add(jobNameField, "wrap");
321                 
322                 //UI logic stuff
323                 if (this.dialogType != CREATE_NEW_TEMPLATE && this.dialogType != CREATE_NEW_JOB) {
324                         jobNameField.setText(this.job.getJobName());
325                 }
326         }
327         
328         private void setupDemoFile() {
329                 String label;
330                 if (this.dialogType == CREATE_NEW_JOB || this.dialogType == EDIT_JOB || this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
331                         label = "Demo file:";
332                 } else {
333                         label = "Demo directory:";
334                 }
335                 
336                 //layout stuff
337                 inputPanel.add(new JLabel(label));
338                 demoFileField = new JTextField();
339                 demoFileField.setEditable(false);
340                 inputPanel.add(demoFileField);
341                 demoFileChooserButton = new FileChooserButton();
342                 inputPanel.add(demoFileChooserButton);
343                 
344                 //UI logic stuff
345                 this.demoFileFC = createConfiguredFileChooser();
346                 demoFileChooserButton.addActionListener(this);
347                 if (this.dialogType == EDIT_JOB || this.dialogType == EDIT_TEMPLATE || this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
348                         if (this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
349                                 this.demoFileFC.setCurrentDirectory(this.job.getDemoFile());
350                         } else {
351                                 this.demoFileFC.setSelectedFile(this.job.getDemoFile());
352                         }
353                         
354                         this.demoFileField.setText(this.job.getDemoFile().getAbsolutePath());
355                 }
356                 
357                 //only specify directories for templates
358                 if (this.dialogType == CREATE_NEW_TEMPLATE || this.dialogType == EDIT_TEMPLATE) {
359                         this.demoFileFC.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
360                 }
361         }
362         
363         private void setupStartSecond() {
364                 //only exists for jobs, not for templates
365                 if (this.dialogType != CREATE_NEW_JOB && this.dialogType != EDIT_JOB && this.dialogType != CREATE_JOB_FROM_TEMPLATE) {
366                         return;
367                 }
368                 
369                 //layout stuff
370                 inputPanel.add(new JLabel("Start second:"));
371                 startSecondField = new JTextField();
372                 inputPanel.add(startSecondField, "wrap");
373                 
374                 //UI logic stuff
375                 if (this.dialogType == EDIT_JOB) {
376                         startSecondField.setText(String.valueOf( this.job.getStartSecond() ));
377                 }
378         }
379         
380         private void setupEndSecond() {
381                 //only exists for jobs, not for templates
382                 if (this.dialogType != CREATE_NEW_JOB && this.dialogType != EDIT_JOB && this.dialogType != CREATE_JOB_FROM_TEMPLATE) {
383                         return;
384                 }
385                 
386                 //layout stuff
387                 inputPanel.add(new JLabel("End second:"));
388                 endSecondField = new JTextField();
389                 inputPanel.add(endSecondField, "wrap");
390                 
391                 //UI logic stuff
392                 if (this.dialogType == EDIT_JOB) {
393                         endSecondField.setText(String.valueOf( this.job.getEndSecond() ));
394                 }
395         }
396         
397         private void setupExecBefore() {
398                 //layout stuff
399                 inputPanel.add(new JLabel("Exec before capture:"));
400                 execBeforeField = new JTextArea(3, 1);
401                 inputPanel.add(new JScrollPane(execBeforeField), "wrap");
402                 
403                 //UI logic stuff
404                 if (this.dialogType == EDIT_JOB || this.dialogType == EDIT_TEMPLATE || this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
405                         execBeforeField.setText(this.job.getExecuteBeforeCap());
406                 }
407         }
408         
409         private void setupExecAfter() {
410                 //layout stuff
411                 inputPanel.add(new JLabel("Exec after capture:"));
412                 execAfterField = new JTextArea(3, 1);
413                 inputPanel.add(new JScrollPane(execAfterField), "wrap");
414                 
415                 //UI logic stuff
416                 if (this.dialogType == EDIT_JOB || this.dialogType == EDIT_TEMPLATE || this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
417                         execAfterField.setText(this.job.getExecuteAfterCap());
418                 }
419         }
420         
421         private void setupVideoDestination() {
422                 //layout stuff
423                 inputPanel.add(new JLabel("Video destination:"));
424                 videoDestinationField = new JTextField();
425                 videoDestinationField.setEditable(false);
426                 inputPanel.add(videoDestinationField);
427                 videoDestinationChooserButton = new FileChooserButton();
428                 inputPanel.add(videoDestinationChooserButton, "wrap 20");
429                 
430                 //UI logic stuff
431                 videoDestinationChooserButton.addActionListener(this);
432                 this.videoDestinationFC = createConfiguredFileChooser();
433                 if (this.dialogType == EDIT_JOB || this.dialogType == EDIT_TEMPLATE || this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
434                         if (this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
435                                 this.videoDestinationFC.setCurrentDirectory(this.job.getVideoDestination());
436                         } else {
437                                 this.videoDestinationFC.setSelectedFile(this.job.getVideoDestination());
438                         }
439                         
440                         this.videoDestinationField.setText(this.job.getVideoDestination().getAbsolutePath());
441                 }
442                 if (this.dialogType == CREATE_NEW_TEMPLATE || this.dialogType == EDIT_TEMPLATE) {
443                         this.videoDestinationFC.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
444                 }
445         }
446         
447         private void setupPluginPreferences() {
448                 for (EncoderPlugin plugin : this.appLayer.getEncoderPlugins()) {
449                         String pluginName = plugin.getName();
450                         //only display settings if the plugin actually has any...
451                         Properties jobSpecificDefaultPluginPreferences = plugin.getJobSpecificPreferences();
452                         Properties jobPluginPreferences = null;
453                         if (this.job != null) {
454                                 jobPluginPreferences = this.job.getEncoderPluginSettings(plugin);
455                         }
456                         if (jobSpecificDefaultPluginPreferences.size() > 0 && plugin.isEnabled()) {
457                                 //add heading
458                                 JXTitledSeparator pluginHeading = new JXTitledSeparator(pluginName + " plugin settings");
459                                 inputPanel.add(pluginHeading, "span 3,grow");
460                                 
461                                 for (String pluginPreferenceKey : plugin.getJobSpecificPreferencesOrder()) {
462                                         String value = jobSpecificDefaultPluginPreferences.getProperty(pluginPreferenceKey);
463                                         if (this.job != null) {
464                                                 if (jobPluginPreferences.containsKey(pluginPreferenceKey)) {
465                                                         value = jobPluginPreferences.getProperty(pluginPreferenceKey);
466                                                 }
467                                         }
468                                         
469                                         this.setupSinglePluginSetting(plugin, pluginPreferenceKey, value);
470                                 }
471                         }
472                 }
473         }
474         
475         private void setupSinglePluginSetting(EncoderPlugin plugin, String key, String value) {
476                 inputPanel.add(new JLabel(key + ":"));
477                 
478                 if (SwingGUIUtils.isBooleanValue(value)) {
479                         JCheckBox checkbox = new JCheckBox();
480                         checkbox.setSelected(Boolean.valueOf(value));
481                         inputPanel.add(checkbox, "wrap");
482                         this.pluginDialogSettings.put(NDRPreferences.getConcatenatedKey(plugin.getName(), key), checkbox);
483                 } else if (SwingGUIUtils.isFileChooser(value)) {
484                         final JFileChooser fc = new JFileChooser();
485                         fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
486                         JButton fcButton = new JButton("...");
487                         final JTextField filePathField = new JTextField();
488                         filePathField.setEditable(false);
489                         inputPanel.add(filePathField);
490                         fcButton.addActionListener(new ActionListener() {
491                                 @Override
492                                 public void actionPerformed(ActionEvent e) {
493                                         int returnValue = fc.showOpenDialog(JobDialog.this);
494                                         if (returnValue == JFileChooser.APPROVE_OPTION) {
495                                                 File selectedFile = fc.getSelectedFile();
496                                                 filePathField.setText(selectedFile.getAbsolutePath());
497                                         }
498                                 }
499                         });
500                         
501                         try {
502                                 File selectedFile = new File(value);
503                                 if (selectedFile.exists()) {
504                                         fc.setSelectedFile(selectedFile);
505                                         filePathField.setText(selectedFile.getAbsolutePath());
506                                 }
507                         } catch (Throwable e) {}
508                         this.pluginDialogSettings.put(NDRPreferences.getConcatenatedKey(plugin.getName(), key), fc);
509                         inputPanel.add(fcButton);
510                 } else {
511                         //textfield
512                         JTextField textField = new JTextField();
513                         textField.setText(value);
514                         this.pluginDialogSettings.put(NDRPreferences.getConcatenatedKey(plugin.getName(), key), textField);
515                         inputPanel.add(textField, "wrap");
516                 }
517         }
518
519         private void setupButtonPart() {
520                 String createButtonText;
521                 if (this.dialogType == CREATE_NEW_JOB || this.dialogType == CREATE_NEW_TEMPLATE || this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
522                         createButtonText = "Create";
523                 } else {
524                         createButtonText = "Save";
525                 }
526                 buttonPanel = new JPanel(new MigLayout("insets 0"));
527                 createButton = new JButton(createButtonText);
528                 createButton.addActionListener(this);
529                 cancelButton = new JButton("Cancel");
530                 cancelButton.addActionListener(this);
531                 
532                 buttonPanel.add(createButton);
533                 buttonPanel.add(cancelButton);
534
535                 getContentPane().add(buttonPanel);
536         }
537         
538         
539         public void actionPerformed(ActionEvent e) {
540                 if (e.getSource() == enginePathChooserButton) {
541                         int returnValue = this.enginePathFC.showOpenDialog(this);
542                         if (returnValue == JFileChooser.APPROVE_OPTION) {
543                                 File selectedFile = this.enginePathFC.getSelectedFile();
544                                 this.enginePathField.setText(selectedFile.getAbsolutePath());
545                         }
546                 } else if (e.getSource() == dpVideoDirChooserButton) {
547                         int returnValue = this.dpVideoDirFC.showOpenDialog(this);
548                         if (returnValue == JFileChooser.APPROVE_OPTION) {
549                                 File selectedFile = this.dpVideoDirFC.getSelectedFile();
550                                 this.dpVideoDirField.setText(selectedFile.getAbsolutePath());
551                         }
552                 } else if (e.getSource() == demoFileChooserButton) {
553                         int returnValue = this.demoFileFC.showOpenDialog(this);
554                         if (returnValue == JFileChooser.APPROVE_OPTION) {
555                                 File selectedFile = this.demoFileFC.getSelectedFile();
556                                 if (this.dialogType == CREATE_NEW_JOB || this.dialogType == EDIT_JOB || this.dialogType == CREATE_JOB_FROM_TEMPLATE) {
557                                         this.demoFileField.setText(DemoRecorderUtils.getJustFileNameOfPath(selectedFile));
558                                 } else {
559                                         //template, show full path of directory
560                                         this.demoFileField.setText(selectedFile.getAbsolutePath());
561                                 }
562                                 
563                         }
564                 } else if (e.getSource() == videoDestinationChooserButton) {
565                         int returnValue = this.videoDestinationFC.showSaveDialog(this);
566                         if (returnValue == JFileChooser.APPROVE_OPTION) {
567                                 File selectedFile = this.videoDestinationFC.getSelectedFile();
568                                 this.videoDestinationField.setText(selectedFile.getAbsolutePath());
569                         }
570                 } else if (e.getSource() == createButton) {
571                         switch (this.dialogType) {
572                         case CREATE_NEW_JOB:
573                         case CREATE_JOB_FROM_TEMPLATE:
574                                 this.requestNewRecordJob(); break;
575                         case CREATE_NEW_TEMPLATE:
576                                 this.createNewTemplate();
577                                 break;
578                         case EDIT_JOB:
579                                 this.editJob();
580                                 break;
581                         case EDIT_TEMPLATE:
582                                 this.editTemplate();
583                                 break;
584                         }
585                 } else if (e.getSource() == cancelButton) {
586                         dispose();
587                 }
588         }
589         
590         private void requestNewRecordJob() {
591                 float startSecond, endSecond = -1;
592                 try {
593                         startSecond = Float.valueOf(this.startSecondField.getText());
594                         endSecond = Float.valueOf(this.endSecondField.getText());
595                 } catch (Exception e) {
596                         DemoRecorderUtils.showNonCriticalErrorDialog("Make sure that start and end second are floating point numbers", e, true);
597                         return;
598                 }
599                 
600                 try {
601                         RecordJob j = this.appLayer.createRecordJob(
602                                 this.jobNameField.getText(),
603                                 this.enginePathFC.getSelectedFile(),
604                                 this.engineParameterField.getText(),
605                                 this.demoFileFC.getSelectedFile(),
606                                 this.relativeDemoPathField.getText(),
607                                 this.dpVideoDirFC.getSelectedFile(),
608                                 this.videoDestinationFC.getSelectedFile(),
609                                 this.execBeforeField.getText(),
610                                 this.execAfterField.getText(),
611                                 startSecond,
612                                 endSecond
613                         );
614                         this.saveEncoderPluginSettings(j);
615                         dispose();
616                 } catch (Exception e) {
617                         DemoRecorderUtils.showNonCriticalErrorDialog(e);
618                         return;
619                 }
620                 
621         }
622         
623         private void editJob() {
624                 float startSecond, endSecond = -1;
625                 try {
626                         startSecond = Float.valueOf(this.startSecondField.getText());
627                         endSecond = Float.valueOf(this.endSecondField.getText());
628                 } catch (Exception e) {
629                         DemoRecorderUtils.showNonCriticalErrorDialog("Make sure that start and end second are floating point numbers", e, true);
630                         return;
631                 }
632                 
633                 try {
634                         this.job.setJobName(this.jobNameField.getText());
635                         this.job.setEnginePath(this.enginePathFC.getSelectedFile());
636                         this.job.setEngineParameters(this.engineParameterField.getText());
637                         this.job.setDemoFile(this.demoFileFC.getSelectedFile());
638                         this.job.setRelativeDemoPath(this.relativeDemoPathField.getText());
639                         this.job.setDpVideoPath(this.dpVideoDirFC.getSelectedFile());
640                         this.job.setVideoDestination(this.videoDestinationFC.getSelectedFile());
641                         this.job.setExecuteBeforeCap(this.execBeforeField.getText());
642                         this.job.setExecuteAfterCap(this.execAfterField.getText());
643                         this.job.setStartSecond(startSecond);
644                         this.job.setEndSecond(endSecond);
645                         this.saveEncoderPluginSettings(this.job);
646                         this.appLayer.fireUserInterfaceUpdate(this.job);
647                         dispose();
648                 } catch (Exception e) {
649                         DemoRecorderUtils.showNonCriticalErrorDialog(e);
650                         return;
651                 }
652                 
653         }
654         
655         private void createNewTemplate() {
656                 try {
657                         RecordJobTemplate templ = new RecordJobTemplate(
658                                 this.templateNameField.getText(),
659                                 this.templateSummaryField.getText(),
660                                 this.jobNameField.getText(),
661                                 this.enginePathFC.getSelectedFile(),
662                                 this.engineParameterField.getText(),
663                                 this.demoFileFC.getSelectedFile(),
664                                 this.relativeDemoPathField.getText(),
665                                 this.dpVideoDirFC.getSelectedFile(),
666                                 this.videoDestinationFC.getSelectedFile(),
667                                 this.execBeforeField.getText(),
668                                 this.execAfterField.getText()
669                         );
670                         this.saveEncoderPluginSettings(templ);
671                         this.tableModel.addRecordJobTemplate(templ);
672                         dispose();
673                 } catch (NullPointerException e) {
674                         DemoRecorderUtils.showNonCriticalErrorDialog("Make sure that you chose a file/directory in each case!", e, true);
675                 } catch (Exception e) {
676                         DemoRecorderUtils.showNonCriticalErrorDialog(e);
677                         return;
678                 }
679         }
680         
681         private void editTemplate() {
682                 try {
683                         RecordJobTemplate template = (RecordJobTemplate) this.job;
684                         template.setName(this.templateNameField.getText());
685                         template.setSummary(this.templateSummaryField.getText());
686                         template.setJobName(this.jobNameField.getText());
687                         template.setEnginePath(this.enginePathFC.getSelectedFile());
688                         template.setEngineParameters(this.engineParameterField.getText());
689                         template.setDpVideoPath(this.dpVideoDirFC.getSelectedFile());
690                         template.setRelativeDemoPath(this.relativeDemoPathField.getText());
691                         template.setDemoFile(this.demoFileFC.getSelectedFile());
692                         template.setExecuteBeforeCap(this.execBeforeField.getText());
693                         template.setExecuteAfterCap(this.execAfterField.getText());
694                         template.setVideoDestination(this.videoDestinationFC.getSelectedFile());
695                         this.saveEncoderPluginSettings(template);
696                         dispose();
697                 } catch (Exception e) {
698                         DemoRecorderUtils.showNonCriticalErrorDialog(e);
699                         return;
700                 }
701         }
702         
703         private void saveEncoderPluginSettings(RecordJob job) {
704                 Set<String> keys = this.pluginDialogSettings.keySet();
705                 //remember, the keys are concatenated, containing both the category and actual key 
706                 for (String key : keys) {
707                         JComponent component = this.pluginDialogSettings.get(key);
708                         if (component instanceof JCheckBox) {
709                                 JCheckBox checkbox = (JCheckBox) component;
710                                 job.setEncoderPluginSetting(NDRPreferences.getCategory(key), NDRPreferences.getKey(key), String.valueOf(checkbox.isSelected()));
711                         } else if (component instanceof JFileChooser) {
712                                 JFileChooser fileChooser = (JFileChooser) component;
713                                 if (fileChooser.getSelectedFile() != null) {
714                                         String path = fileChooser.getSelectedFile().getAbsolutePath();
715                                         job.setEncoderPluginSetting(NDRPreferences.getCategory(key), NDRPreferences.getKey(key), path);
716                                 }
717                         } else if (component instanceof JTextField) {
718                                 JTextField textField = (JTextField) component;
719                                 job.setEncoderPluginSetting(NDRPreferences.getCategory(key), NDRPreferences.getKey(key), textField.getText());
720                         }
721                 }
722         }
723         
724         private static class FileChooserButton extends JButton {
725                 private static final long serialVersionUID = 1335571540372856959L;
726                 public FileChooserButton() {
727                         super("...");
728                 }
729         }
730         
731         private JFileChooser createConfiguredFileChooser() {
732                 JFileChooser fc = new JFileChooser();
733                 fc.setFileHidingEnabled(false);
734                 fc.setFileFilter(userDirFilter);
735                 return fc;
736         }
737 }