|
From: <ada...@us...> - 2013-09-26 15:05:29
|
Revision: 16940
http://sourceforge.net/p/gate/code/16940
Author: adamfunk
Date: 2013-09-26 15:05:25 +0000 (Thu, 26 Sep 2013)
Log Message:
-----------
WIP on persistence of twitter population configuration.
Bugs in reloading so those buttons are not in the live dialog box.
Modified Paths:
--------------
gate/trunk/plugins/Twitter/src/gate/corpora/twitter/Population.java
gate/trunk/plugins/Twitter/src/gate/corpora/twitter/PopulationConfig.java
Modified: gate/trunk/plugins/Twitter/src/gate/corpora/twitter/Population.java
===================================================================
--- gate/trunk/plugins/Twitter/src/gate/corpora/twitter/Population.java 2013-09-26 13:12:22 UTC (rev 16939)
+++ gate/trunk/plugins/Twitter/src/gate/corpora/twitter/Population.java 2013-09-26 15:05:25 UTC (rev 16940)
@@ -202,14 +202,11 @@
return actions;
}
-
-
-
}
class PopulationDialogWrapper {
- private JDialog dialog;
+ protected JDialog dialog;
private PopulationConfig config;
private JTextField encodingField;
private JCheckBox checkbox;
@@ -259,10 +256,12 @@
configPersistenceBox.add(Box.createHorizontalGlue());
JButton loadConfigButton = new JButton("Load configuration");
loadConfigButton.setToolTipText("Replace the configuration above with a previously saved one");
+ loadConfigButton.addActionListener(new LoadConfigListener(config, dialog));
configPersistenceBox.add(loadConfigButton);
configPersistenceBox.add(Box.createHorizontalGlue());
JButton saveConfigButton = new JButton("Save configuration");
saveConfigButton.setToolTipText("Save the configuration above for re-use");
+ saveConfigButton.addActionListener(new SaveConfigListener(config, dialog));
configPersistenceBox.add(saveConfigButton);
configPersistenceBox.add(Box.createHorizontalGlue());
//dialog.add(configPersistenceBox);
Modified: gate/trunk/plugins/Twitter/src/gate/corpora/twitter/PopulationConfig.java
===================================================================
--- gate/trunk/plugins/Twitter/src/gate/corpora/twitter/PopulationConfig.java 2013-09-26 13:12:22 UTC (rev 16939)
+++ gate/trunk/plugins/Twitter/src/gate/corpora/twitter/PopulationConfig.java 2013-09-26 15:05:25 UTC (rev 16940)
@@ -15,7 +15,11 @@
import java.util.*;
import java.io.*;
import java.net.URL;
+import java.awt.event.*;
+import java.awt.Component;
+import javax.swing.JFileChooser;
+
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
import com.thoughtworks.xstream.io.xml.StaxDriver;
@@ -71,6 +75,7 @@
this.contentKeys = Arrays.asList(Population.DEFAULT_CONTENT_KEYS);
this.featureKeys = Arrays.asList(Population.DEFAULT_FEATURE_KEYS);
}
+
/**
* Constructor with all options.
@@ -87,6 +92,23 @@
}
+ public void reload(File file) {
+ PopulationConfig source = PopulationConfig.load(file);
+ this.tweetsPerDoc = source.tweetsPerDoc;
+ this.encoding = source.encoding;
+ this.contentKeys = source.contentKeys;
+ this.featureKeys = source.featureKeys;
+ }
+
+ public void reload(URL url) {
+ PopulationConfig source = PopulationConfig.load(url);
+ this.tweetsPerDoc = source.tweetsPerDoc;
+ this.encoding = source.encoding;
+ this.contentKeys = source.contentKeys;
+ this.featureKeys = source.featureKeys;
+ }
+
+
public static PopulationConfig load(File file) {
XStream xstream = new XStream(new StaxDriver());
return (PopulationConfig) xstream.fromXML(file);
@@ -107,3 +129,54 @@
}
+class LoadConfigListener implements ActionListener {
+ PopulationConfig config;
+ Component parentDialog;
+
+ public LoadConfigListener(PopulationConfig config, Component dialog) {
+ this.config = config;
+ this.parentDialog = dialog;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ JFileChooser chooser = new JFileChooser();
+ chooser.setDialogTitle("Load XML configuration");
+ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ int chosen = chooser.showOpenDialog(this.parentDialog);
+ if (chosen == JFileChooser.APPROVE_OPTION) {
+ config.reload(chooser.getSelectedFile());
+ }
+ }
+}
+
+
+class SaveConfigListener implements ActionListener {
+ PopulationConfig config;
+ Component parentDialog;
+
+ public SaveConfigListener(PopulationConfig config, Component dialog) {
+ this.config = config;
+ this.parentDialog = dialog;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ JFileChooser chooser = new JFileChooser();
+ chooser.setDialogTitle("Save configuration as XML");
+ chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ int chosen = chooser.showSaveDialog(this.parentDialog);
+ if (chosen == JFileChooser.APPROVE_OPTION) {
+ try {
+ config.saveXML(chooser.getSelectedFile());
+ }
+ catch(IOException e1) {
+ e1.printStackTrace();
+ }
+ }
+ }
+
+
+}
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|