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