Revision: 18192
http://sourceforge.net/p/gate/code/18192
Author: markagreenwood
Date: 2014-07-17 08:24:53 +0000 (Thu, 17 Jul 2014)
Log Message:
-----------
more code simplificiation and cleanup
Modified Paths:
--------------
gate/trunk/src/main/gate/gui/DocumentExportMenu.java
gate/trunk/src/main/gate/gui/NameBearerHandle.java
Modified: gate/trunk/src/main/gate/gui/DocumentExportMenu.java
===================================================================
--- gate/trunk/src/main/gate/gui/DocumentExportMenu.java 2014-07-17
07:50:05 UTC (rev 18191)
+++ gate/trunk/src/main/gate/gui/DocumentExportMenu.java 2014-07-17
08:24:53 UTC (rev 18192)
@@ -25,7 +25,6 @@
import gate.creole.ResourceData;
import gate.event.CreoleEvent;
import gate.event.CreoleListener;
-import gate.event.StatusListener;
import gate.swing.XJFileChooser;
import gate.swing.XJMenu;
import gate.util.Err;
@@ -77,28 +76,18 @@
protected IdentityHashMap<Resource, JMenuItem> itemByResource =
new IdentityHashMap<Resource, JMenuItem>();
- private Document document;
+ private Handle handle;
- private Corpus corpus;
-
- public DocumentExportMenu(Document document, StatusListener listener) {
- super("Save as...", "", listener);
- if(document == null)
- throw new NullPointerException("Document cannot be null!");
- this.document = document;
- // add(gateXML);
+ public DocumentExportMenu(NameBearerHandle handle) {
+ super("Save as...", "", handle.sListenerProxy);
+ if(!(handle.getTarget() instanceof Document)
+ && !(handle.getTarget() instanceof Corpus))
+ throw new IllegalArgumentException(
+ "We only deal with documents and corpora");
+ this.handle = handle;
init();
}
- public DocumentExportMenu(Corpus corpus, StatusListener listener) {
- super("Save as...", "", listener);
- if(corpus == null)
- throw new NullPointerException("Corpus cannot be null!");
- this.corpus = corpus;
- // add(gateXML);
- init();
- }
-
private void init() {
DocumentExporter gateXMLExporter =
@@ -124,6 +113,10 @@
DocumentExporter de, FeatureMap options) {
File selectedFile = null;
+ Document document =
+ (handle.getTarget() instanceof Document ? (Document)handle
+ .getTarget() : null);
+
if(document != null && document.getSourceUrl() != null) {
String fileName = "";
try {
@@ -232,13 +225,14 @@
Runnable runnable = new Runnable() {
public void run() {
- if(document != null) {
+ if(handle.getTarget() instanceof Document) {
long start = System.currentTimeMillis();
listener.statusChanged("Saving as " + de.getFileType()
+ " to " + selectedFile.toString() + "...");
try {
- de.export(document, selectedFile, options);
+ de.export((Document)handle.getTarget(), selectedFile,
+ options);
} catch(IOException e) {
e.printStackTrace();
}
@@ -247,7 +241,7 @@
listener.statusChanged("Finished saving as "
+ de.getFileType() + " into " + " the file: "
+ selectedFile.toString() + " in "
- + ((double)time) / 1000 + " s");
+ + ((double)time) / 1000 + "s");
} else {
try {
File dir = selectedFile;
@@ -264,12 +258,14 @@
MainFrame.lockGUI("Saving...");
+ Corpus corpus = (Corpus)handle.getTarget();
+
// iterate through all the docs and save
// each of
// them
Iterator<Document> docIter = corpus.iterator();
boolean overwriteAll = false;
- // int docCnt = corpus.size();
+ int docCnt = corpus.size();
int currentDocIndex = 0;
Set<String> usedFileNames = new HashSet<String>();
while(docIter.hasNext()) {
@@ -355,7 +351,7 @@
JOptionPane.QUESTION_MESSAGE,
null, null, fileName);
if(fileName == null) {
- // handle.processFinished();
+ handle.processFinished();
return;
}
MainFrame.lockGUI("Saving");
@@ -363,7 +359,7 @@
}
case 3: {
// user gave up; return
- // handle.processFinished();
+ handle.processFinished();
return;
}
}
@@ -396,12 +392,11 @@
Factory.deleteResource(currentDoc);
}
- // handle.progressChanged(100 *
- // currentDocIndex++ /
- // docCnt);
+ handle.progressChanged(100 * currentDocIndex++
+ / docCnt);
}// while(docIter.hasNext())
listener.statusChanged("Corpus Saved");
- // handle.processFinished();
+ handle.processFinished();
} finally {
MainFrame.unlockGUI();
Modified: gate/trunk/src/main/gate/gui/NameBearerHandle.java
===================================================================
--- gate/trunk/src/main/gate/gui/NameBearerHandle.java 2014-07-17 07:50:05 UTC
(rev 18191)
+++ gate/trunk/src/main/gate/gui/NameBearerHandle.java 2014-07-17 08:24:53 UTC
(rev 18192)
@@ -289,7 +289,7 @@
}
if(target instanceof gate.TextualDocument) {
staticPopupItems.add(null);
- staticPopupItems.add(new DocumentExportMenu((Document)target,
sListenerProxy));
+ staticPopupItems.add(new DocumentExportMenu(this));
}
else if(target instanceof Corpus) {
corpusFiller = new CorpusFillerComponent();
@@ -300,7 +300,7 @@
new PopulateCorpusFromSingleConcatenatedFileAction(),
sListenerProxy));
staticPopupItems.add(null);
- staticPopupItems.add(new DocumentExportMenu((Corpus)target,
sListenerProxy));
+ staticPopupItems.add(new DocumentExportMenu(this));
}
if(((LanguageResource)target).getDataStore() != null) {
// this item can be used only if the resource belongs to a
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs