[nexuiz-commits] r8653 - in trunk/misc/tools/NexuizDemoRecorder/main: . src/main/java/com/nexuiz/demorecorder/application src/main/java/com/nexuiz/demorecorder/ui/swinggui src/main/java/com/nexuiz/demorecorder/ui/swinggui/tablemodels
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Thu Feb 18 16:51:58 EST 2010
Author: greenmarine
Date: 2010-02-18 16:51:58 -0500 (Thu, 18 Feb 2010)
New Revision: 8653
Modified:
trunk/misc/tools/NexuizDemoRecorder/main/pom.xml
trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/application/DemoRecorderApplication.java
trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/SwingGUI.java
trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/tablemodels/RecordJobTemplatesTableModel.java
trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/tablemodels/RecordJobsTableModel.java
Log:
NexuizDemoRecorder: added ability to save and load templates (might make sense for plug-in developers so that they can ship their own templates with preset plug-in settings)
Load dialog for templates or jobs allows the user to select whether to overwrite the current list or whether to append the loaded items to the current list
Modified: trunk/misc/tools/NexuizDemoRecorder/main/pom.xml
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/main/pom.xml 2010-02-18 21:28:24 UTC (rev 8652)
+++ trunk/misc/tools/NexuizDemoRecorder/main/pom.xml 2010-02-18 21:51:58 UTC (rev 8653)
@@ -4,7 +4,7 @@
<groupId>NexuizDemoRecorder</groupId>
<artifactId>NexuizDemoRecorder</artifactId>
<packaging>jar</packaging>
- <version>0.2</version>
+ <version>0.3-SNAPSHOT</version>
<name>NexuizDemoRecorder</name>
<url>http://maven.apache.org</url>
<dependencies>
Modified: trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/application/DemoRecorderApplication.java
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/application/DemoRecorderApplication.java 2010-02-18 21:28:24 UTC (rev 8652)
+++ trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/application/DemoRecorderApplication.java 2010-02-18 21:51:58 UTC (rev 8653)
@@ -311,26 +311,40 @@
private void loadJobQueue() {
File defaultFile = DemoRecorderUtils.computeLocalFile(PREFERENCES_DIRNAME, JOBQUEUE_FILENAME);
- this.loadJobQueue(defaultFile);
+ this.loadJobQueue(defaultFile, true);
}
+ /**
+ * Loads the jobs from the given file path. If override is enabled, the previous
+ * job list will be overwritten with the newly loaded list. Otherwise the loaded jobs
+ * are added to the already existing list.
+ * @param path
+ * @param override
+ * @return the number of jobs loaded from the file
+ */
@SuppressWarnings("unchecked")
- public void loadJobQueue(File path) {
+ public int loadJobQueue(File path, boolean override) {
if (!path.exists()) {
- return;
+ return 0;
}
try {
FileInputStream fin = new FileInputStream(path);
ObjectInputStream ois = new ObjectInputStream(fin);
- this.jobs = (List<RecordJob>) ois.readObject();
- for (RecordJob currentJob : this.jobs) {
+ List<RecordJob> newList = (List<RecordJob>) ois.readObject();
+ for (RecordJob currentJob : newList) {
currentJob.setAppLayer(this);
}
+ if (override) {
+ this.jobs = newList;
+ } else {
+ this.jobs.addAll(newList);
+ }
+ return newList.size();
} catch (Exception e) {
DemoRecorderUtils.showNonCriticalErrorDialog("Could not load the job queue file " + path.getAbsolutePath(), e, true);
+ return 0;
}
-
}
public void saveJobQueue() {
Modified: trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/SwingGUI.java
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/SwingGUI.java 2010-02-18 21:28:24 UTC (rev 8652)
+++ trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/SwingGUI.java 2010-02-18 21:51:58 UTC (rev 8653)
@@ -100,11 +100,14 @@
private ActionListener menuButtonActionListener = new MenuButtonActionListener();
private JMenuItem fileLoadQueue = new JMenuItem("Load job queue", getIcon("fileopen.png"));
private JMenuItem fileSaveQueue = new JMenuItem("Save job queue", getIcon("filesave.png"));
+ private JMenuItem fileLoadTemplates = new JMenuItem("Load templates", getIcon("fileopen.png"));
+ private JMenuItem fileSaveTemplates = new JMenuItem("Save templates", getIcon("filesave.png"));
private JMenuItem filePreferences = new JMenuItem("Preferences", getIcon("advanced.png"));
private JMenuItem fileExit = new JMenuItem("Exit", getIcon("exit.png"));
private JMenuItem helpHelp = new JMenuItem("Show help", getIcon("help.png"));
private JMenuItem helpAbout = new JMenuItem("About", getIcon("info.png"));
private JFileChooser jobQueueSaveAsFC = new JFileChooser();
+ private JFileChooser templatesSaveAsFC = new JFileChooser();
private JButton jobs_create = new JButton(LABEL_JOB_CREATE, getIcon("edit_add.png"));
private JButton jobs_createFromTempl = new JButton(LABEL_JOB_CREATE_FROM_TEMPL, getIcon("view_right_p.png"));
@@ -316,12 +319,16 @@
JMenu fileMenu = new JMenu("File");
fileMenu.add(fileLoadQueue);
fileMenu.add(fileSaveQueue);
+ fileMenu.add(fileLoadTemplates);
+ fileMenu.add(fileSaveTemplates);
fileMenu.add(filePreferences);
fileMenu.add(fileExit);
menuBar.add(fileMenu);
fileLoadQueue.addActionListener(menuButtonActionListener);
fileSaveQueue.addActionListener(menuButtonActionListener);
+ fileLoadTemplates.addActionListener(menuButtonActionListener);
+ fileSaveTemplates.addActionListener(menuButtonActionListener);
filePreferences.addActionListener(menuButtonActionListener);
fileExit.addActionListener(menuButtonActionListener);
@@ -456,7 +463,7 @@
File selectedFile = jobQueueSaveAsFC.getSelectedFile();
if (selectedFile.isFile()) {
RecordJobsTableModel tableModel = (RecordJobsTableModel) jobsTable.getModel();
- tableModel.loadNewJobQueue(selectedFile);
+ tableModel.loadNewJobQueue(SwingGUI.this, selectedFile, jobsTable);
configureTableButtons();
}
}
@@ -477,6 +484,32 @@
}
appLayer.saveJobQueue(selectedFile);
}
+ } else if (e.getSource() == fileLoadTemplates) {
+ int result = templatesSaveAsFC.showOpenDialog(SwingGUI.this);
+ if (result == JFileChooser.APPROVE_OPTION) {
+ File selectedFile = templatesSaveAsFC.getSelectedFile();
+ if (selectedFile.isFile()) {
+ RecordJobTemplatesTableModel tableModel = (RecordJobTemplatesTableModel) templatesTable.getModel();
+ tableModel.loadNewTemplateList(SwingGUI.this, selectedFile, templatesTable);
+ configureTableButtons();
+ }
+ }
+ } else if (e.getSource() == fileSaveTemplates) {
+ int result = templatesSaveAsFC.showSaveDialog(SwingGUI.this);
+ if (result == JFileChooser.APPROVE_OPTION) {
+ File selectedFile = templatesSaveAsFC.getSelectedFile();
+ if (!DemoRecorderUtils.getFileExtension(selectedFile).equals("templ")) {
+ selectedFile = new File(selectedFile.getAbsoluteFile() + ".templ");
+ }
+ if (selectedFile.exists()) {
+ int confirm = JOptionPane.showConfirmDialog(SwingGUI.this, "File already exists. Are you sure you want to overwrite it?", "Confirm overwrite", JOptionPane.YES_NO_OPTION);
+ if (confirm == JOptionPane.NO_OPTION) {
+ return;
+ }
+ }
+ RecordJobTemplatesTableModel model = (RecordJobTemplatesTableModel) templatesTable.getModel();
+ model.saveTemplateListToFile(selectedFile);
+ }
} else if (e.getSource() == filePreferences) {
preferencesDialog.showDialog();
} else if (e.getSource() == fileExit) {
Modified: trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/tablemodels/RecordJobTemplatesTableModel.java
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/tablemodels/RecordJobTemplatesTableModel.java 2010-02-18 21:28:24 UTC (rev 8652)
+++ trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/tablemodels/RecordJobTemplatesTableModel.java 2010-02-18 21:51:58 UTC (rev 8653)
@@ -8,8 +8,11 @@
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;
@@ -70,7 +73,7 @@
//load table content
File path = DemoRecorderUtils.computeLocalFile(DemoRecorderApplication.PREFERENCES_DIRNAME, SwingGUI.TEMPLATE_TABLE_CONTENT_FILENAME);
- this.loadTemplateListFromFile(path);
+ this.loadTemplateListFromFile(path, true);
}
public void deleteRecordJobTemplate(int modelRowIndex, int viewRowIndex) {
@@ -123,9 +126,9 @@
}
@SuppressWarnings("unchecked")
- public void loadTemplateListFromFile(File path) {
+ private int loadTemplateListFromFile(File path, boolean overwrite) {
if (!path.exists()) {
- return;
+ return 0;
}
List<RecordJobTemplate> newTemplateList;
@@ -133,13 +136,31 @@
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;
+ return 0;
}
- this.templates = newTemplateList;
-// fireTableRowsInserted(0, this.templates.size());
+
}
+
+ 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);
Modified: trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/tablemodels/RecordJobsTableModel.java
===================================================================
--- trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/tablemodels/RecordJobsTableModel.java 2010-02-18 21:28:24 UTC (rev 8652)
+++ trunk/misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/tablemodels/RecordJobsTableModel.java 2010-02-18 21:51:58 UTC (rev 8653)
@@ -3,12 +3,16 @@
import java.io.File;
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.application.jobs.RecordJob;
+import com.nexuiz.demorecorder.ui.swinggui.SwingGUI;
/**
* Columns:
@@ -80,10 +84,18 @@
}
}
- public void loadNewJobQueue(File path) {
- this.appLayer.loadJobQueue(path);
+ public void loadNewJobQueue(SwingGUI gui, File path, JXTable jobsTable) {
+ 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);
+ boolean overwrite = false;
+ if (result == JOptionPane.YES_OPTION) {
+ overwrite = true;
+ }
+ int count = this.appLayer.loadJobQueue(path, overwrite);
this.jobList = this.appLayer.getRecordJobs();
fireTableDataChanged();
+ if (count > 0) {
+ jobsTable.setRowSelectionInterval(jobsTable.getRowCount() - count, jobsTable.getRowCount() - 1);
+ }
}
public RecordJob getRecordJob(int modelRowIndex) {
More information about the nexuiz-commits
mailing list