1 package com.nexuiz.demorecorder.ui.swinggui.tablemodels;
\r
4 import java.util.List;
\r
6 import javax.swing.JOptionPane;
\r
7 import javax.swing.table.AbstractTableModel;
\r
9 import org.jdesktop.swingx.JXTable;
\r
11 import com.nexuiz.demorecorder.application.DemoRecorderApplication;
\r
12 import com.nexuiz.demorecorder.application.DemoRecorderException;
\r
13 import com.nexuiz.demorecorder.application.DemoRecorderUtils;
\r
14 import com.nexuiz.demorecorder.application.jobs.RecordJob;
\r
15 import com.nexuiz.demorecorder.ui.swinggui.SwingGUI;
\r
21 * - Engine parameters
\r
23 * - Relative demo path
\r
25 * - video destination
\r
26 * - execute before cap
\r
27 * - execute after cap
\r
34 public class RecordJobsTableModel extends AbstractTableModel {
\r
36 private static final long serialVersionUID = 5024144640874313910L;
\r
38 public static final int JOB_NAME = 0;
\r
39 public static final int ENGINE_PATH = 1;
\r
40 public static final int ENGINE_PARAMETERS = 2;
\r
41 public static final int DEMO_FILE_PATH = 3;
\r
42 public static final int RELATIVE_DEMO_PATH = 4;
\r
43 public static final int DPVIDEO_PATH = 5;
\r
44 public static final int VIDEO_DESTINATION_PATH = 6;
\r
45 public static final int EXECUTE_BEFORE_CAP = 7;
\r
46 public static final int EXECUTE_AFTER_CAP = 8;
\r
47 public static final int START_SECOND = 9;
\r
48 public static final int END_SECOND = 10;
\r
49 public static final int STATUS = 11;
\r
51 private static final int columns[] = {
\r
58 VIDEO_DESTINATION_PATH,
\r
66 private DemoRecorderApplication appLayer;
\r
67 private List<RecordJob> jobList = null;
\r
69 public RecordJobsTableModel(DemoRecorderApplication appLayer) {
\r
70 this.appLayer = appLayer;
\r
71 this.jobList = this.appLayer.getRecordJobs();
\r
74 public void deleteRecordJob(int modelRowIndex, int viewRowIndex) {
\r
76 RecordJob job = this.jobList.get(modelRowIndex);
\r
77 if (this.appLayer.deleteRecordJob(job)) {
\r
78 this.jobList.remove(job);
\r
79 fireTableRowsDeleted(viewRowIndex, viewRowIndex);
\r
81 } catch (IndexOutOfBoundsException e) {
\r
82 throw new DemoRecorderException("Couldn't find correspondig job for modelRowIndex " + modelRowIndex
\r
83 + " and viewRowIndex " + viewRowIndex, e);
\r
87 public void loadNewJobQueue(SwingGUI gui, File path, JXTable jobsTable) {
\r
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);
\r
89 boolean overwrite = false;
\r
90 if (result == JOptionPane.YES_OPTION) {
\r
93 int count = this.appLayer.loadJobQueue(path, overwrite);
\r
94 this.jobList = this.appLayer.getRecordJobs();
\r
95 fireTableDataChanged();
\r
97 jobsTable.setRowSelectionInterval(jobsTable.getRowCount() - count, jobsTable.getRowCount() - 1);
\r
101 public RecordJob getRecordJob(int modelRowIndex) {
\r
102 return this.jobList.get(modelRowIndex);
\r
105 public int getColumnCount() {
\r
106 return columns.length;
\r
109 public int getRowCount() {
\r
110 return this.jobList.size();
\r
113 public Object getValueAt(int rowIndex, int columnIndex) {
\r
114 RecordJob job = this.jobList.get(rowIndex);
\r
119 if (columnIndex < 0 || columnIndex >= columns.length) {
\r
123 String cellData = "UNDEF";
\r
124 switch (columnIndex) {
\r
126 cellData = job.getJobName(); break;
\r
128 cellData = job.getEnginePath().getAbsolutePath(); break;
\r
129 case ENGINE_PARAMETERS:
\r
130 cellData = job.getEngineParameters(); break;
\r
131 case DEMO_FILE_PATH:
\r
132 cellData = DemoRecorderUtils.getJustFileNameOfPath(job.getDemoFile()); break;
\r
133 case RELATIVE_DEMO_PATH:
\r
134 cellData = job.getRelativeDemoPath(); break;
\r
136 cellData = job.getDpVideoPath().getAbsolutePath(); break;
\r
137 case VIDEO_DESTINATION_PATH:
\r
138 cellData = job.getVideoDestination().getAbsolutePath(); break;
\r
139 case EXECUTE_BEFORE_CAP:
\r
140 cellData = job.getExecuteBeforeCap(); break;
\r
141 case EXECUTE_AFTER_CAP:
\r
142 cellData = job.getExecuteAfterCap(); break;
\r
144 cellData = String.valueOf(job.getStartSecond()); break;
\r
146 cellData = String.valueOf(job.getEndSecond()); break;
\r
148 if (job.getState() == RecordJob.State.DONE) {
\r
150 } else if (job.getState() == RecordJob.State.ERROR) {
\r
151 cellData = "error";
\r
152 } else if (job.getState() == RecordJob.State.ERROR_PLUGIN) {
\r
153 cellData = "plug-in error";
\r
154 } else if (job.getState() == RecordJob.State.PROCESSING) {
\r
155 cellData = "processing";
\r
156 } else if (job.getState() == RecordJob.State.WAITING) {
\r
157 cellData = "waiting";
\r
165 public String getColumnName(int column) {
\r
166 if (column < 0 || column >= columns.length) {
\r
170 String columnName = "UNDEFINED";
\r
173 columnName = "Name"; break;
\r
175 columnName = "Engine path"; break;
\r
176 case ENGINE_PARAMETERS:
\r
177 columnName = "Engine parameters"; break;
\r
178 case DEMO_FILE_PATH:
\r
179 columnName = "Demo name"; break;
\r
180 case RELATIVE_DEMO_PATH:
\r
181 columnName = "Relative demo path"; break;
\r
183 columnName = "DPVideo path"; break;
\r
184 case VIDEO_DESTINATION_PATH:
\r
185 columnName = "Video destination"; break;
\r
186 case EXECUTE_BEFORE_CAP:
\r
187 columnName = "Exec before"; break;
\r
188 case EXECUTE_AFTER_CAP:
\r
189 columnName = "Exec after"; break;
\r
191 columnName = "Start"; break;
\r
193 columnName = "End"; break;
\r
195 columnName = "Status"; break;
\r
201 public List<RecordJob> getRecordJobs() {
\r
202 return this.jobList;
\r