1 package com.nexuiz.demorecorder.ui.swinggui.tablemodels;
6 import javax.swing.JOptionPane;
7 import javax.swing.table.AbstractTableModel;
9 import org.jdesktop.swingx.JXTable;
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;
23 * - Relative demo path
26 * - execute before cap
34 public class RecordJobsTableModel extends AbstractTableModel {
36 private static final long serialVersionUID = 5024144640874313910L;
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;
51 private static final int columns[] = {
58 VIDEO_DESTINATION_PATH,
66 private DemoRecorderApplication appLayer;
67 private List<RecordJob> jobList = null;
69 public RecordJobsTableModel(DemoRecorderApplication appLayer) {
70 this.appLayer = appLayer;
71 this.jobList = this.appLayer.getRecordJobs();
74 public void deleteRecordJob(int modelRowIndex, int viewRowIndex) {
76 RecordJob job = this.jobList.get(modelRowIndex);
77 if (this.appLayer.deleteRecordJob(job)) {
78 this.jobList.remove(job);
79 fireTableRowsDeleted(viewRowIndex, viewRowIndex);
81 } catch (IndexOutOfBoundsException e) {
82 throw new DemoRecorderException("Couldn't find correspondig job for modelRowIndex " + modelRowIndex
83 + " and viewRowIndex " + viewRowIndex, e);
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) {
93 int count = this.appLayer.loadJobQueue(path, overwrite);
94 this.jobList = this.appLayer.getRecordJobs();
95 fireTableDataChanged();
97 jobsTable.setRowSelectionInterval(jobsTable.getRowCount() - count, jobsTable.getRowCount() - 1);
101 public RecordJob getRecordJob(int modelRowIndex) {
102 return this.jobList.get(modelRowIndex);
105 public int getColumnCount() {
106 return columns.length;
109 public int getRowCount() {
110 return this.jobList.size();
113 public Object getValueAt(int rowIndex, int columnIndex) {
114 RecordJob job = this.jobList.get(rowIndex);
119 if (columnIndex < 0 || columnIndex >= columns.length) {
123 String cellData = "UNDEF";
124 switch (columnIndex) {
126 cellData = job.getJobName(); break;
128 cellData = job.getEnginePath().getAbsolutePath(); break;
129 case ENGINE_PARAMETERS:
130 cellData = job.getEngineParameters(); break;
132 cellData = DemoRecorderUtils.getJustFileNameOfPath(job.getDemoFile()); break;
133 case RELATIVE_DEMO_PATH:
134 cellData = job.getRelativeDemoPath(); break;
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;
144 cellData = String.valueOf(job.getStartSecond()); break;
146 cellData = String.valueOf(job.getEndSecond()); break;
148 if (job.getState() == RecordJob.State.DONE) {
150 } else if (job.getState() == RecordJob.State.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";
165 public String getColumnName(int column) {
166 if (column < 0 || column >= columns.length) {
170 String columnName = "UNDEFINED";
173 columnName = "Name"; break;
175 columnName = "Engine path"; break;
176 case ENGINE_PARAMETERS:
177 columnName = "Engine parameters"; break;
179 columnName = "Demo name"; break;
180 case RELATIVE_DEMO_PATH:
181 columnName = "Relative demo path"; break;
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;
191 columnName = "Start"; break;
193 columnName = "End"; break;
195 columnName = "Status"; break;
201 public List<RecordJob> getRecordJobs() {