]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/tablemodels/RecordJobTemplatesTableModel.java
fix lots of CRLFs
[xonotic/xonotic.git] / misc / tools / NexuizDemoRecorder / main / src / main / java / com / nexuiz / demorecorder / ui / swinggui / tablemodels / RecordJobTemplatesTableModel.java
index f5aa069d7e89618edbc009ffd881add8ae776c9f..0e1b4fd07e90cab33a183081307824d80a397053 100644 (file)
-package com.nexuiz.demorecorder.ui.swinggui.tablemodels;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.io.ObjectInputStream;\r
-import java.io.ObjectOutputStream;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import javax.swing.JOptionPane;\r
-import javax.swing.table.AbstractTableModel;\r
-\r
-import org.jdesktop.swingx.JXTable;\r
-\r
-import com.nexuiz.demorecorder.application.DemoRecorderApplication;\r
-import com.nexuiz.demorecorder.application.DemoRecorderException;\r
-import com.nexuiz.demorecorder.application.DemoRecorderUtils;\r
-import com.nexuiz.demorecorder.ui.swinggui.RecordJobTemplate;\r
-import com.nexuiz.demorecorder.ui.swinggui.SwingGUI;\r
-\r
-/**\r
- * Columns:\r
- * - Job Name\r
- * - Engine path\r
- * - Engine parameters\r
- * - Demo file\r
- * - Relative demo path\r
- * - dpvideo path\r
- * - video destination\r
- * - execute before cap\r
- * - execute after cap\r
- * - start second\r
- * - end second\r
- * - status\r
- * @author Marius\r
- *\r
- */\r
-public class RecordJobTemplatesTableModel extends AbstractTableModel {\r
-       \r
-       private static final long serialVersionUID = 6541517890817708306L;\r
-       \r
-       public static final int TEMPLATE_NAME = 0;\r
-       public static final int TEMPLATE_SUMMARY = 1;\r
-       public static final int JOB_NAME = 2;\r
-       public static final int ENGINE_PATH = 3;\r
-       public static final int ENGINE_PARAMETERS = 4;\r
-       public static final int DEMO_FILE_PATH = 5;\r
-       public static final int RELATIVE_DEMO_PATH = 6;\r
-       public static final int DPVIDEO_PATH = 7;\r
-       public static final int VIDEO_DESTINATION_PATH = 8;\r
-       public static final int EXECUTE_BEFORE_CAP = 9;\r
-       public static final int EXECUTE_AFTER_CAP = 10;\r
-       \r
-       private static final int columns[] = {\r
-               TEMPLATE_NAME,\r
-               TEMPLATE_SUMMARY,\r
-               JOB_NAME,\r
-               ENGINE_PATH,\r
-               ENGINE_PARAMETERS,\r
-               DEMO_FILE_PATH,\r
-               RELATIVE_DEMO_PATH,\r
-               DPVIDEO_PATH,\r
-               VIDEO_DESTINATION_PATH,\r
-               EXECUTE_BEFORE_CAP,\r
-               EXECUTE_AFTER_CAP\r
-       };\r
-       \r
-       private List<RecordJobTemplate> templates;\r
-       \r
-       public RecordJobTemplatesTableModel() {\r
-               templates = new ArrayList<RecordJobTemplate>();\r
-               \r
-               //load table content\r
-               File path = DemoRecorderUtils.computeLocalFile(DemoRecorderApplication.PREFERENCES_DIRNAME, SwingGUI.TEMPLATE_TABLE_CONTENT_FILENAME);\r
-               this.loadTemplateListFromFile(path, true);\r
-       }\r
-       \r
-       public void deleteRecordJobTemplate(int modelRowIndex, int viewRowIndex) {\r
-               try {\r
-                       this.templates.remove(modelRowIndex);\r
-                       fireTableRowsDeleted(viewRowIndex, viewRowIndex);\r
-               } catch (IndexOutOfBoundsException e) {\r
-                       throw new DemoRecorderException("Couldn't find correspondig template for modelRowIndex " + modelRowIndex\r
-                                       + " and viewRowIndex " + viewRowIndex, e);\r
-               }\r
-       }\r
-       \r
-       public void addRecordJobTemplate(RecordJobTemplate template) {\r
-               this.templates.add(template);\r
-               int position = this.templates.size() - 1;\r
-               fireTableRowsInserted(position, position);\r
-       }\r
-       \r
-       public RecordJobTemplate getRecordJobTemplate(int modelRowIndex) {\r
-               return this.templates.get(modelRowIndex);\r
-       }\r
-\r
-       public int getColumnCount() {\r
-               return columns.length;\r
-       }\r
-\r
-       public int getRowCount() {\r
-               return this.templates.size();\r
-       }\r
-       \r
-       public void saveTemplateListToFile(File path) {\r
-               DemoRecorderUtils.attemptFileCreation(path);\r
-               \r
-               String exceptionMessage = "Could not save the templates to file " + path.getAbsolutePath();\r
-               \r
-               if (!path.exists()) {\r
-                       DemoRecorderException ex = new DemoRecorderException(exceptionMessage);\r
-                       DemoRecorderUtils.showNonCriticalErrorDialog(ex);\r
-                       return;\r
-               }\r
-               \r
-               try {\r
-                       FileOutputStream fout = new FileOutputStream(path);\r
-                       ObjectOutputStream oos = new ObjectOutputStream(fout);\r
-                       oos.writeObject(this.templates);\r
-                       oos.close();\r
-               } catch (Exception e) {\r
-                       DemoRecorderUtils.showNonCriticalErrorDialog(exceptionMessage, e, true);\r
-               }\r
-       }\r
-       \r
-       @SuppressWarnings("unchecked")\r
-       private int loadTemplateListFromFile(File path, boolean overwrite) {\r
-               if (!path.exists()) {\r
-                       return 0;\r
-               }\r
-               \r
-               List<RecordJobTemplate> newTemplateList;\r
-               try {\r
-                       FileInputStream fin = new FileInputStream(path);\r
-                       ObjectInputStream ois = new ObjectInputStream(fin);\r
-                       newTemplateList = (List<RecordJobTemplate>) ois.readObject();\r
-                       if (overwrite) {\r
-                               this.templates = newTemplateList;\r
-                       } else {\r
-                               this.templates.addAll(newTemplateList);\r
-                       }\r
-                       return newTemplateList.size();\r
-               } catch (Exception e) {\r
-                       DemoRecorderUtils.showNonCriticalErrorDialog("Could not load the templates from file " + path.getAbsolutePath(), e, true);\r
-                       return 0;\r
-               }\r
-               \r
-       }\r
-       \r
-       public void loadNewTemplateList(SwingGUI gui, File path, JXTable templatesTable) {\r
-               int result = JOptionPane.showConfirmDialog(gui, "Do you want to overwrite the current template list? When pressing 'no' the loaded templates will be added to the current list!", "Confirm overwrite", JOptionPane.YES_NO_OPTION);\r
-               boolean overwrite = false;\r
-               if (result == JOptionPane.YES_OPTION) {\r
-                       overwrite = true;\r
-               }\r
-               int count = loadTemplateListFromFile(path, overwrite);\r
-               fireTableDataChanged();\r
-               if (count > 0) {\r
-                       templatesTable.setRowSelectionInterval(templatesTable.getRowCount() - count, templatesTable.getRowCount() - 1);\r
-               }\r
-       }\r
-\r
-       public Object getValueAt(int rowIndex, int columnIndex) {\r
-               RecordJobTemplate template = this.templates.get(rowIndex);\r
-               if (template == null) {\r
-                       return null;\r
-               }\r
-               \r
-               if (columnIndex < 0 || columnIndex >= columns.length) {\r
-                       return null;\r
-               }\r
-               \r
-               String cellData = "UNDEF";\r
-               switch (columnIndex) {\r
-               case TEMPLATE_NAME:\r
-                       cellData = template.getName(); break;\r
-               case TEMPLATE_SUMMARY:\r
-                       cellData = template.getSummary(); break;\r
-               case JOB_NAME:\r
-                       cellData = template.getJobName(); break;\r
-               case ENGINE_PATH:\r
-                       cellData = template.getEnginePath().getAbsolutePath(); break;\r
-               case ENGINE_PARAMETERS:\r
-                       cellData = template.getEngineParameters(); break;\r
-               case DEMO_FILE_PATH:\r
-                       cellData = DemoRecorderUtils.getJustFileNameOfPath(template.getDemoFile()); break;\r
-               case RELATIVE_DEMO_PATH:\r
-                       cellData = template.getRelativeDemoPath(); break;\r
-               case DPVIDEO_PATH:\r
-                       cellData = template.getDpVideoPath().getAbsolutePath(); break;\r
-               case VIDEO_DESTINATION_PATH:\r
-                       cellData = template.getVideoDestination().getAbsolutePath(); break;\r
-               case EXECUTE_BEFORE_CAP:\r
-                       cellData = template.getExecuteBeforeCap(); break;\r
-               case EXECUTE_AFTER_CAP:\r
-                       cellData = template.getExecuteAfterCap(); break;\r
-               }\r
-               \r
-               return cellData;\r
-       }\r
-\r
-       @Override\r
-       public String getColumnName(int column) {\r
-               if (column < 0 || column >= columns.length) {\r
-                       return "";\r
-               }\r
-               \r
-               String columnName = "UNDEFINED";\r
-               switch (column) {\r
-               case TEMPLATE_NAME:\r
-                       columnName = "Name"; break;\r
-               case TEMPLATE_SUMMARY:\r
-                       columnName = "Summary"; break;\r
-               case JOB_NAME:\r
-                       columnName = "Job name"; break;\r
-               case ENGINE_PATH:\r
-                       columnName = "Engine path"; break;\r
-               case ENGINE_PARAMETERS:\r
-                       columnName = "Engine parameters"; break;\r
-               case DEMO_FILE_PATH:\r
-                       columnName = "Demo directory"; break;\r
-               case RELATIVE_DEMO_PATH:\r
-                       columnName = "Relative demo path"; break;\r
-               case DPVIDEO_PATH:\r
-                       columnName = "DPVideo path"; break;\r
-               case VIDEO_DESTINATION_PATH:\r
-                       columnName = "Video destination"; break;\r
-               case EXECUTE_BEFORE_CAP:\r
-                       columnName = "Exec before"; break;\r
-               case EXECUTE_AFTER_CAP:\r
-                       columnName = "Exec after"; break;\r
-               }\r
-               \r
-               return columnName;\r
-       }\r
-       \r
-       public List<RecordJobTemplate> getRecordJobTemplates() {\r
-               return this.templates;\r
-       }\r
-}\r
+package com.nexuiz.demorecorder.ui.swinggui.tablemodels;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.JOptionPane;
+import javax.swing.table.AbstractTableModel;
+
+import org.jdesktop.swingx.JXTable;
+
+import com.nexuiz.demorecorder.application.DemoRecorderApplication;
+import com.nexuiz.demorecorder.application.DemoRecorderException;
+import com.nexuiz.demorecorder.application.DemoRecorderUtils;
+import com.nexuiz.demorecorder.ui.swinggui.RecordJobTemplate;
+import com.nexuiz.demorecorder.ui.swinggui.SwingGUI;
+
+/**
+ * Columns:
+ * - Job Name
+ * - Engine path
+ * - Engine parameters
+ * - Demo file
+ * - Relative demo path
+ * - dpvideo path
+ * - video destination
+ * - execute before cap
+ * - execute after cap
+ * - start second
+ * - end second
+ * - status
+ * @author Marius
+ *
+ */
+public class RecordJobTemplatesTableModel extends AbstractTableModel {
+       
+       private static final long serialVersionUID = 6541517890817708306L;
+       
+       public static final int TEMPLATE_NAME = 0;
+       public static final int TEMPLATE_SUMMARY = 1;
+       public static final int JOB_NAME = 2;
+       public static final int ENGINE_PATH = 3;
+       public static final int ENGINE_PARAMETERS = 4;
+       public static final int DEMO_FILE_PATH = 5;
+       public static final int RELATIVE_DEMO_PATH = 6;
+       public static final int DPVIDEO_PATH = 7;
+       public static final int VIDEO_DESTINATION_PATH = 8;
+       public static final int EXECUTE_BEFORE_CAP = 9;
+       public static final int EXECUTE_AFTER_CAP = 10;
+       
+       private static final int columns[] = {
+               TEMPLATE_NAME,
+               TEMPLATE_SUMMARY,
+               JOB_NAME,
+               ENGINE_PATH,
+               ENGINE_PARAMETERS,
+               DEMO_FILE_PATH,
+               RELATIVE_DEMO_PATH,
+               DPVIDEO_PATH,
+               VIDEO_DESTINATION_PATH,
+               EXECUTE_BEFORE_CAP,
+               EXECUTE_AFTER_CAP
+       };
+       
+       private List<RecordJobTemplate> templates;
+       
+       public RecordJobTemplatesTableModel() {
+               templates = new ArrayList<RecordJobTemplate>();
+               
+               //load table content
+               File path = DemoRecorderUtils.computeLocalFile(DemoRecorderApplication.PREFERENCES_DIRNAME, SwingGUI.TEMPLATE_TABLE_CONTENT_FILENAME);
+               this.loadTemplateListFromFile(path, true);
+       }
+       
+       public void deleteRecordJobTemplate(int modelRowIndex, int viewRowIndex) {
+               try {
+                       this.templates.remove(modelRowIndex);
+                       fireTableRowsDeleted(viewRowIndex, viewRowIndex);
+               } catch (IndexOutOfBoundsException e) {
+                       throw new DemoRecorderException("Couldn't find correspondig template for modelRowIndex " + modelRowIndex
+                                       + " and viewRowIndex " + viewRowIndex, e);
+               }
+       }
+       
+       public void addRecordJobTemplate(RecordJobTemplate template) {
+               this.templates.add(template);
+               int position = this.templates.size() - 1;
+               fireTableRowsInserted(position, position);
+       }
+       
+       public RecordJobTemplate getRecordJobTemplate(int modelRowIndex) {
+               return this.templates.get(modelRowIndex);
+       }
+
+       public int getColumnCount() {
+               return columns.length;
+       }
+
+       public int getRowCount() {
+               return this.templates.size();
+       }
+       
+       public void saveTemplateListToFile(File path) {
+               DemoRecorderUtils.attemptFileCreation(path);
+               
+               String exceptionMessage = "Could not save the templates to file " + path.getAbsolutePath();
+               
+               if (!path.exists()) {
+                       DemoRecorderException ex = new DemoRecorderException(exceptionMessage);
+                       DemoRecorderUtils.showNonCriticalErrorDialog(ex);
+                       return;
+               }
+               
+               try {
+                       FileOutputStream fout = new FileOutputStream(path);
+                       ObjectOutputStream oos = new ObjectOutputStream(fout);
+                       oos.writeObject(this.templates);
+                       oos.close();
+               } catch (Exception e) {
+                       DemoRecorderUtils.showNonCriticalErrorDialog(exceptionMessage, e, true);
+               }
+       }
+       
+       @SuppressWarnings("unchecked")
+       private int loadTemplateListFromFile(File path, boolean overwrite) {
+               if (!path.exists()) {
+                       return 0;
+               }
+               
+               List<RecordJobTemplate> newTemplateList;
+               try {
+                       FileInputStream fin = new FileInputStream(path);
+                       ObjectInputStream ois = new ObjectInputStream(fin);
+                       newTemplateList = (List<RecordJobTemplate>) ois.readObject();
+                       if (overwrite) {
+                               this.templates = newTemplateList;
+                       } else {
+                               this.templates.addAll(newTemplateList);
+                       }
+                       return newTemplateList.size();
+               } catch (Exception e) {
+                       DemoRecorderUtils.showNonCriticalErrorDialog("Could not load the templates from file " + path.getAbsolutePath(), e, true);
+                       return 0;
+               }
+               
+       }
+       
+       public void loadNewTemplateList(SwingGUI gui, File path, JXTable templatesTable) {
+               int result = JOptionPane.showConfirmDialog(gui, "Do you want to overwrite the current template list? When pressing 'no' the loaded templates will be added to the current list!", "Confirm overwrite", JOptionPane.YES_NO_OPTION);
+               boolean overwrite = false;
+               if (result == JOptionPane.YES_OPTION) {
+                       overwrite = true;
+               }
+               int count = loadTemplateListFromFile(path, overwrite);
+               fireTableDataChanged();
+               if (count > 0) {
+                       templatesTable.setRowSelectionInterval(templatesTable.getRowCount() - count, templatesTable.getRowCount() - 1);
+               }
+       }
+
+       public Object getValueAt(int rowIndex, int columnIndex) {
+               RecordJobTemplate template = this.templates.get(rowIndex);
+               if (template == null) {
+                       return null;
+               }
+               
+               if (columnIndex < 0 || columnIndex >= columns.length) {
+                       return null;
+               }
+               
+               String cellData = "UNDEF";
+               switch (columnIndex) {
+               case TEMPLATE_NAME:
+                       cellData = template.getName(); break;
+               case TEMPLATE_SUMMARY:
+                       cellData = template.getSummary(); break;
+               case JOB_NAME:
+                       cellData = template.getJobName(); break;
+               case ENGINE_PATH:
+                       cellData = template.getEnginePath().getAbsolutePath(); break;
+               case ENGINE_PARAMETERS:
+                       cellData = template.getEngineParameters(); break;
+               case DEMO_FILE_PATH:
+                       cellData = DemoRecorderUtils.getJustFileNameOfPath(template.getDemoFile()); break;
+               case RELATIVE_DEMO_PATH:
+                       cellData = template.getRelativeDemoPath(); break;
+               case DPVIDEO_PATH:
+                       cellData = template.getDpVideoPath().getAbsolutePath(); break;
+               case VIDEO_DESTINATION_PATH:
+                       cellData = template.getVideoDestination().getAbsolutePath(); break;
+               case EXECUTE_BEFORE_CAP:
+                       cellData = template.getExecuteBeforeCap(); break;
+               case EXECUTE_AFTER_CAP:
+                       cellData = template.getExecuteAfterCap(); break;
+               }
+               
+               return cellData;
+       }
+
+       @Override
+       public String getColumnName(int column) {
+               if (column < 0 || column >= columns.length) {
+                       return "";
+               }
+               
+               String columnName = "UNDEFINED";
+               switch (column) {
+               case TEMPLATE_NAME:
+                       columnName = "Name"; break;
+               case TEMPLATE_SUMMARY:
+                       columnName = "Summary"; break;
+               case JOB_NAME:
+                       columnName = "Job name"; break;
+               case ENGINE_PATH:
+                       columnName = "Engine path"; break;
+               case ENGINE_PARAMETERS:
+                       columnName = "Engine parameters"; break;
+               case DEMO_FILE_PATH:
+                       columnName = "Demo directory"; break;
+               case RELATIVE_DEMO_PATH:
+                       columnName = "Relative demo path"; break;
+               case DPVIDEO_PATH:
+                       columnName = "DPVideo path"; break;
+               case VIDEO_DESTINATION_PATH:
+                       columnName = "Video destination"; break;
+               case EXECUTE_BEFORE_CAP:
+                       columnName = "Exec before"; break;
+               case EXECUTE_AFTER_CAP:
+                       columnName = "Exec after"; break;
+               }
+               
+               return columnName;
+       }
+       
+       public List<RecordJobTemplate> getRecordJobTemplates() {
+               return this.templates;
+       }
+}