1 package com.nexuiz.demorecorder.ui.swinggui.tablemodels;
\r
4 import java.io.FileInputStream;
\r
5 import java.io.FileOutputStream;
\r
6 import java.io.ObjectInputStream;
\r
7 import java.io.ObjectOutputStream;
\r
8 import java.util.ArrayList;
\r
9 import java.util.List;
\r
11 import javax.swing.table.AbstractTableModel;
\r
13 import com.nexuiz.demorecorder.application.DemoRecorderApplication;
\r
14 import com.nexuiz.demorecorder.application.DemoRecorderException;
\r
15 import com.nexuiz.demorecorder.application.DemoRecorderUtils;
\r
16 import com.nexuiz.demorecorder.ui.swinggui.RecordJobTemplate;
\r
17 import com.nexuiz.demorecorder.ui.swinggui.SwingGUI;
\r
23 * - Engine parameters
\r
25 * - Relative demo path
\r
27 * - video destination
\r
28 * - execute before cap
\r
29 * - execute after cap
\r
36 public class RecordJobTemplatesTableModel extends AbstractTableModel {
\r
38 private static final long serialVersionUID = 6541517890817708306L;
\r
40 public static final int TEMPLATE_NAME = 0;
\r
41 public static final int TEMPLATE_SUMMARY = 1;
\r
42 public static final int JOB_NAME = 2;
\r
43 public static final int ENGINE_PATH = 3;
\r
44 public static final int ENGINE_PARAMETERS = 4;
\r
45 public static final int DEMO_FILE_PATH = 5;
\r
46 public static final int RELATIVE_DEMO_PATH = 6;
\r
47 public static final int DPVIDEO_PATH = 7;
\r
48 public static final int VIDEO_DESTINATION_PATH = 8;
\r
49 public static final int EXECUTE_BEFORE_CAP = 9;
\r
50 public static final int EXECUTE_AFTER_CAP = 10;
\r
52 private static final int columns[] = {
\r
61 VIDEO_DESTINATION_PATH,
\r
66 private List<RecordJobTemplate> templates;
\r
68 public RecordJobTemplatesTableModel() {
\r
69 templates = new ArrayList<RecordJobTemplate>();
\r
71 //load table content
\r
72 File path = DemoRecorderUtils.computeLocalFile(DemoRecorderApplication.PREFERENCES_DIRNAME, SwingGUI.TEMPLATE_TABLE_CONTENT_FILENAME);
\r
73 this.loadTemplateListFromFile(path);
\r
76 public void deleteRecordJobTemplate(int modelRowIndex, int viewRowIndex) {
\r
78 this.templates.remove(modelRowIndex);
\r
79 fireTableRowsDeleted(viewRowIndex, viewRowIndex);
\r
80 } catch (IndexOutOfBoundsException e) {
\r
81 throw new DemoRecorderException("Couldn't find correspondig template for modelRowIndex " + modelRowIndex
\r
82 + " and viewRowIndex " + viewRowIndex, e);
\r
86 public void addRecordJobTemplate(RecordJobTemplate template) {
\r
87 this.templates.add(template);
\r
88 int position = this.templates.size() - 1;
\r
89 fireTableRowsInserted(position, position);
\r
92 public RecordJobTemplate getRecordJobTemplate(int modelRowIndex) {
\r
93 return this.templates.get(modelRowIndex);
\r
96 public int getColumnCount() {
\r
97 return columns.length;
\r
100 public int getRowCount() {
\r
101 return this.templates.size();
\r
104 public void saveTemplateListToFile(File path) {
\r
105 DemoRecorderUtils.attemptFileCreation(path);
\r
107 String exceptionMessage = "Could not save the templates to file " + path.getAbsolutePath();
\r
109 if (!path.exists()) {
\r
110 DemoRecorderException ex = new DemoRecorderException(exceptionMessage);
\r
111 DemoRecorderUtils.showNonCriticalErrorDialog(ex);
\r
116 FileOutputStream fout = new FileOutputStream(path);
\r
117 ObjectOutputStream oos = new ObjectOutputStream(fout);
\r
118 oos.writeObject(this.templates);
\r
120 } catch (Exception e) {
\r
121 DemoRecorderUtils.showNonCriticalErrorDialog(exceptionMessage, e, true);
\r
125 @SuppressWarnings("unchecked")
\r
126 public void loadTemplateListFromFile(File path) {
\r
127 if (!path.exists()) {
\r
131 List<RecordJobTemplate> newTemplateList;
\r
133 FileInputStream fin = new FileInputStream(path);
\r
134 ObjectInputStream ois = new ObjectInputStream(fin);
\r
135 newTemplateList = (List<RecordJobTemplate>) ois.readObject();
\r
136 } catch (Exception e) {
\r
137 DemoRecorderUtils.showNonCriticalErrorDialog("Could not load the templates from file " + path.getAbsolutePath(), e, true);
\r
140 this.templates = newTemplateList;
\r
141 // fireTableRowsInserted(0, this.templates.size());
\r
144 public Object getValueAt(int rowIndex, int columnIndex) {
\r
145 RecordJobTemplate template = this.templates.get(rowIndex);
\r
146 if (template == null) {
\r
150 if (columnIndex < 0 || columnIndex >= columns.length) {
\r
154 String cellData = "UNDEF";
\r
155 switch (columnIndex) {
\r
156 case TEMPLATE_NAME:
\r
157 cellData = template.getName(); break;
\r
158 case TEMPLATE_SUMMARY:
\r
159 cellData = template.getSummary(); break;
\r
161 cellData = template.getJobName(); break;
\r
163 cellData = template.getEnginePath().getAbsolutePath(); break;
\r
164 case ENGINE_PARAMETERS:
\r
165 cellData = template.getEngineParameters(); break;
\r
166 case DEMO_FILE_PATH:
\r
167 cellData = DemoRecorderUtils.getJustFileNameOfPath(template.getDemoFile()); break;
\r
168 case RELATIVE_DEMO_PATH:
\r
169 cellData = template.getRelativeDemoPath(); break;
\r
171 cellData = template.getDpVideoPath().getAbsolutePath(); break;
\r
172 case VIDEO_DESTINATION_PATH:
\r
173 cellData = template.getVideoDestination().getAbsolutePath(); break;
\r
174 case EXECUTE_BEFORE_CAP:
\r
175 cellData = template.getExecuteBeforeCap(); break;
\r
176 case EXECUTE_AFTER_CAP:
\r
177 cellData = template.getExecuteAfterCap(); break;
\r
184 public String getColumnName(int column) {
\r
185 if (column < 0 || column >= columns.length) {
\r
189 String columnName = "UNDEFINED";
\r
191 case TEMPLATE_NAME:
\r
192 columnName = "Name"; break;
\r
193 case TEMPLATE_SUMMARY:
\r
194 columnName = "Summary"; break;
\r
196 columnName = "Job name"; break;
\r
198 columnName = "Engine path"; break;
\r
199 case ENGINE_PARAMETERS:
\r
200 columnName = "Engine parameters"; break;
\r
201 case DEMO_FILE_PATH:
\r
202 columnName = "Demo directory"; break;
\r
203 case RELATIVE_DEMO_PATH:
\r
204 columnName = "Relative demo path"; break;
\r
206 columnName = "DPVideo path"; break;
\r
207 case VIDEO_DESTINATION_PATH:
\r
208 columnName = "Video destination"; break;
\r
209 case EXECUTE_BEFORE_CAP:
\r
210 columnName = "Exec before"; break;
\r
211 case EXECUTE_AFTER_CAP:
\r
212 columnName = "Exec after"; break;
\r
218 public List<RecordJobTemplate> getRecordJobTemplates() {
\r
219 return this.templates;
\r