2d2f5fcdf6acd24f8e694f135f0fe2e928d511ee
[divverent/nexuiz.git] / misc / tools / NexuizDemoRecorder / main / src / main / java / com / nexuiz / demorecorder / ui / swinggui / tablemodels / RecordJobsTableModel.java
1 package com.nexuiz.demorecorder.ui.swinggui.tablemodels;\r
2 \r
3 import java.io.File;\r
4 import java.util.List;\r
5 \r
6 import javax.swing.table.AbstractTableModel;\r
7 \r
8 import com.nexuiz.demorecorder.application.DemoRecorderApplication;\r
9 import com.nexuiz.demorecorder.application.DemoRecorderException;\r
10 import com.nexuiz.demorecorder.application.DemoRecorderUtils;\r
11 import com.nexuiz.demorecorder.application.jobs.RecordJob;\r
12 \r
13 /**\r
14  * Columns:\r
15  * - Job Name\r
16  * - Engine path\r
17  * - Engine parameters\r
18  * - Demo file\r
19  * - Relative demo path\r
20  * - dpvideo path\r
21  * - video destination\r
22  * - execute before cap\r
23  * - execute after cap\r
24  * - start second\r
25  * - end second\r
26  * - status\r
27  * @author Marius\r
28  *\r
29  */\r
30 public class RecordJobsTableModel extends AbstractTableModel {\r
31         \r
32         private static final long serialVersionUID = 5024144640874313910L;\r
33         \r
34         public static final int JOB_NAME = 0;\r
35         public static final int ENGINE_PATH = 1;\r
36         public static final int ENGINE_PARAMETERS = 2;\r
37         public static final int DEMO_FILE_PATH = 3;\r
38         public static final int RELATIVE_DEMO_PATH = 4;\r
39         public static final int DPVIDEO_PATH = 5;\r
40         public static final int VIDEO_DESTINATION_PATH = 6;\r
41         public static final int EXECUTE_BEFORE_CAP = 7;\r
42         public static final int EXECUTE_AFTER_CAP = 8;\r
43         public static final int START_SECOND = 9;\r
44         public static final int END_SECOND = 10;\r
45         public static final int STATUS = 11;\r
46         \r
47         private static final int columns[] = {\r
48                 JOB_NAME,\r
49                 ENGINE_PATH,\r
50                 ENGINE_PARAMETERS,\r
51                 DEMO_FILE_PATH,\r
52                 RELATIVE_DEMO_PATH,\r
53                 DPVIDEO_PATH,\r
54                 VIDEO_DESTINATION_PATH,\r
55                 EXECUTE_BEFORE_CAP,\r
56                 EXECUTE_AFTER_CAP,\r
57                 START_SECOND,\r
58                 END_SECOND,\r
59                 STATUS\r
60         };\r
61         \r
62         private DemoRecorderApplication appLayer;\r
63         private List<RecordJob> jobList = null;\r
64         \r
65         public RecordJobsTableModel(DemoRecorderApplication appLayer) {\r
66                 this.appLayer = appLayer;\r
67                 this.jobList = this.appLayer.getRecordJobs();\r
68         }\r
69         \r
70         public void deleteRecordJob(int modelRowIndex, int viewRowIndex) {\r
71                 try {\r
72                         RecordJob job = this.jobList.get(modelRowIndex);\r
73                         if (this.appLayer.deleteRecordJob(job)) {\r
74                                 this.jobList.remove(job);\r
75                                 fireTableRowsDeleted(viewRowIndex, viewRowIndex);\r
76                         }\r
77                 } catch (IndexOutOfBoundsException e) {\r
78                         throw new DemoRecorderException("Couldn't find correspondig job for modelRowIndex " + modelRowIndex\r
79                                         + " and viewRowIndex " + viewRowIndex, e);\r
80                 }\r
81         }\r
82         \r
83         public void loadNewJobQueue(File path) {\r
84                 this.appLayer.loadJobQueue(path);\r
85                 this.jobList = this.appLayer.getRecordJobs();\r
86                 fireTableDataChanged();\r
87         }\r
88         \r
89         public RecordJob getRecordJob(int modelRowIndex) {\r
90                 return this.jobList.get(modelRowIndex);\r
91         }\r
92 \r
93         public int getColumnCount() {\r
94                 return columns.length;\r
95         }\r
96 \r
97         public int getRowCount() {\r
98                 return this.jobList.size();\r
99         }\r
100 \r
101         public Object getValueAt(int rowIndex, int columnIndex) {\r
102                 RecordJob job = this.jobList.get(rowIndex);\r
103                 if (job == null) {\r
104                         return null;\r
105                 }\r
106                 \r
107                 if (columnIndex < 0 || columnIndex >= columns.length) {\r
108                         return null;\r
109                 }\r
110                 \r
111                 String cellData = "UNDEF";\r
112                 switch (columnIndex) {\r
113                 case JOB_NAME:\r
114                         cellData = job.getJobName(); break;\r
115                 case ENGINE_PATH:\r
116                         cellData = job.getEnginePath().getAbsolutePath(); break;\r
117                 case ENGINE_PARAMETERS:\r
118                         cellData = job.getEngineParameters(); break;\r
119                 case DEMO_FILE_PATH:\r
120                         cellData = DemoRecorderUtils.getJustFileNameOfPath(job.getDemoFile()); break;\r
121                 case RELATIVE_DEMO_PATH:\r
122                         cellData = job.getRelativeDemoPath(); break;\r
123                 case DPVIDEO_PATH:\r
124                         cellData = job.getDpVideoPath().getAbsolutePath(); break;\r
125                 case VIDEO_DESTINATION_PATH:\r
126                         cellData = job.getVideoDestination().getAbsolutePath(); break;\r
127                 case EXECUTE_BEFORE_CAP:\r
128                         cellData = job.getExecuteBeforeCap(); break;\r
129                 case EXECUTE_AFTER_CAP:\r
130                         cellData = job.getExecuteAfterCap(); break;\r
131                 case START_SECOND:\r
132                         cellData = String.valueOf(job.getStartSecond()); break;\r
133                 case END_SECOND:\r
134                         cellData = String.valueOf(job.getEndSecond()); break;\r
135                 case STATUS:\r
136                         if (job.getState() == RecordJob.State.DONE) {\r
137                                 cellData = "done";\r
138                         } else if (job.getState() == RecordJob.State.ERROR) {\r
139                                 cellData = "error";\r
140                         } else if (job.getState() == RecordJob.State.ERROR_PLUGIN) {\r
141                                 cellData = "plug-in error";\r
142                         } else if (job.getState() == RecordJob.State.PROCESSING) {\r
143                                 cellData = "processing";\r
144                         } else if (job.getState() == RecordJob.State.WAITING) {\r
145                                 cellData = "waiting";\r
146                         }\r
147                 }\r
148                 \r
149                 return cellData;\r
150         }\r
151 \r
152         @Override\r
153         public String getColumnName(int column) {\r
154                 if (column < 0 || column >= columns.length) {\r
155                         return "";\r
156                 }\r
157                 \r
158                 String columnName = "UNDEFINED";\r
159                 switch (column) {\r
160                 case JOB_NAME:\r
161                         columnName = "Name"; break;\r
162                 case ENGINE_PATH:\r
163                         columnName = "Engine path"; break;\r
164                 case ENGINE_PARAMETERS:\r
165                         columnName = "Engine parameters"; break;\r
166                 case DEMO_FILE_PATH:\r
167                         columnName = "Demo name"; break;\r
168                 case RELATIVE_DEMO_PATH:\r
169                         columnName = "Relative demo path"; break;\r
170                 case DPVIDEO_PATH:\r
171                         columnName = "DPVideo path"; break;\r
172                 case VIDEO_DESTINATION_PATH:\r
173                         columnName = "Video destination"; break;\r
174                 case EXECUTE_BEFORE_CAP:\r
175                         columnName = "Exec before"; break;\r
176                 case EXECUTE_AFTER_CAP:\r
177                         columnName = "Exec after"; break;\r
178                 case START_SECOND:\r
179                         columnName = "Start"; break;\r
180                 case END_SECOND:\r
181                         columnName = "End"; break;\r
182                 case STATUS:\r
183                         columnName = "Status"; break;\r
184                 }\r
185                 \r
186                 return columnName;\r
187         }\r
188         \r
189         public List<RecordJob> getRecordJobs() {\r
190                 return this.jobList;\r
191         }\r
192 }\r