You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2007/05/28 11:50:28 UTC
svn commit: r542182 - in
/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd:
./ control/
Author: twgoetz
Date: Mon May 28 02:50:27 2007
New Revision: 542182
URL: http://svn.apache.org/viewvc?view=rev&rev=542182
Log:
Jira UIMA-416: add XMI CAS reading and writing to CVD. Also in
this commit: further CVD code clean-up.
http://issues.apache.org/jira/browse/UIMA-416
Added:
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XmiCasFileOpenHandler.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XmiCasSaveHandler.java
Modified:
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/MainFrame.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/AnnotatorOpenEventHandler.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/CaretChangeHandler.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/FileOpenEventHandler.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/FileSaveAsEventHandler.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/IndexTreeSelectionListener.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/NewTextEventHandler.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/SofaSelectionListener.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TypeSystemFileOpenEventHandler.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/UndoMgr.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XCASFileOpenEventHandler.java
incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XCASSaveHandler.java
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/MainFrame.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/MainFrame.java?view=diff&rev=542182&r1=542181&r2=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/MainFrame.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/MainFrame.java Mon May 28 02:50:27 2007
@@ -146,6 +146,8 @@
import org.apache.uima.tools.cvd.control.XCASFileOpenEventHandler;
import org.apache.uima.tools.cvd.control.XCASSaveHandler;
import org.apache.uima.tools.cvd.control.XCASSaveTSHandler;
+import org.apache.uima.tools.cvd.control.XmiCasFileOpenHandler;
+import org.apache.uima.tools.cvd.control.XmiCasSaveHandler;
import org.apache.uima.util.FileUtils;
import org.apache.uima.util.Level;
import org.apache.uima.util.Logger;
@@ -279,6 +281,10 @@
private JMenuItem xcasReadItem;
private JMenuItem xcasWriteItem;
+
+ private JMenuItem xmiCasReadItem;
+
+ private JMenuItem xmiCasWriteItem;
private JMenuItem typeSystemWriteItem;
@@ -868,6 +874,8 @@
private void createFileMenu() {
this.fileMenu = new JMenu("File");
+
+ // Standard text file menu items.
JMenuItem newTextItem = new JMenuItem("New Text...", KeyEvent.VK_N);
newTextItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
newTextItem.addActionListener(new NewTextEventHandler(this));
@@ -893,6 +901,8 @@
this.recentTextFileMenu.setMnemonic(KeyEvent.VK_U);
this.fileMenu.add(this.recentTextFileMenu);
this.fileMenu.addSeparator();
+
+ // Color preferences
JMenuItem colorPrefsOpenItem = new JMenuItem("Load Color Settings", KeyEvent.VK_L);
colorPrefsOpenItem.addActionListener(new ColorPrefsOpenHandler(this));
this.fileMenu.add(colorPrefsOpenItem);
@@ -900,29 +910,55 @@
colorPrefsSaveItem.addActionListener(new ColorPrefsSaveHandler(this));
this.fileMenu.add(colorPrefsSaveItem);
this.fileMenu.addSeparator();
+
+ // Reading and writing type system files.
this.typeSystemReadItem = new JMenuItem("Read Type System File");
this.typeSystemReadItem.setEnabled(true);
this.typeSystemReadItem.addActionListener(new TypeSystemFileOpenEventHandler(this));
this.fileMenu.add(this.typeSystemReadItem);
this.typeSystemWriteItem = new JMenuItem("Write Type System File");
- this.typeSystemWriteItem.setEnabled(false);
this.typeSystemWriteItem.addActionListener(new XCASSaveTSHandler(this));
this.fileMenu.add(this.typeSystemWriteItem);
this.fileMenu.addSeparator();
- this.xcasWriteItem = new JMenuItem("Write XCAS File", KeyEvent.VK_W);
- this.xcasWriteItem.setEnabled(false);
- this.xcasWriteItem.addActionListener(new XCASSaveHandler(this));
- this.fileMenu.add(this.xcasWriteItem);
+
+ // Reading and writing XMI CAS files.
+ this.xmiCasReadItem = new JMenuItem("Read XMI CAS File");
+ this.xmiCasReadItem.addActionListener(new XmiCasFileOpenHandler(this));
+ this.fileMenu.add(this.xmiCasReadItem);
+ this.xmiCasWriteItem = new JMenuItem("Write XMI CAS File");
+ this.xmiCasWriteItem.addActionListener(new XmiCasSaveHandler(this));
+ this.fileMenu.add(this.xmiCasWriteItem);
+ this.fileMenu.addSeparator();
+
+ // Reading and writing old-style XCAS files.
this.xcasReadItem = new JMenuItem("Read XCAS File", KeyEvent.VK_R);
this.xcasReadItem.addActionListener(new XCASFileOpenEventHandler(this));
- this.xcasReadItem.setEnabled(false);
this.fileMenu.add(this.xcasReadItem);
+ this.xcasWriteItem = new JMenuItem("Write XCAS File", KeyEvent.VK_W);
+ this.xcasWriteItem.addActionListener(new XCASSaveHandler(this));
+ this.fileMenu.add(this.xcasWriteItem);
this.fileMenu.addSeparator();
JMenuItem exit = new JMenuItem("Exit", KeyEvent.VK_X);
exit.addActionListener(new SystemExitHandler(this));
this.fileMenu.add(exit);
+
+ // Disable menu items that can't be executed yet.
+ this.typeSystemWriteItem.setEnabled(false);
+ setEnableCasFileReading(false);
+ setEnableCasFileWriting();
}
+ public final void setEnableCasFileReading(boolean enable) {
+ this.xcasReadItem.setEnabled(enable);
+ this.xmiCasReadItem.setEnabled(enable);
+ }
+
+ public final void setEnableCasFileWriting() {
+ final boolean enable = (this.cas != null);
+ this.xcasWriteItem.setEnabled(enable);
+ this.xmiCasWriteItem.setEnabled(enable);
+ }
+
private final void addCursorOwningComponent(Component comp) {
this.cursorOwningComponents.add(comp);
}
@@ -941,9 +977,6 @@
if (this.cursorCache == null) {
return;
}
- // assert(this.cursorCache != null);
- // assert(this.cursorCache.size() ==
- // this.cursorOwningComponents.size());
for (int i = 0; i < this.cursorOwningComponents.size(); i++) {
Component comp = (Component) this.cursorOwningComponents.get(i);
comp.setCursor((Cursor) this.cursorCache.get(i));
@@ -1250,17 +1283,6 @@
}
public void setFileStatusMessage() {
- // if (this.textFile == null)
- // {
- // fileStatus.setText("(No Text File Loaded)");
- // fileStatus.setToolTipText("No text file loaded.");
- // } else
- // {
- // fileStatus.setText(textFile.getName());
- // fileStatus.setToolTipText(
- // "Currently loaded text file: " + textFile.getAbsolutePath());
- // }
- // statusPanel.revalidate();
Border textBorder;
if (this.textFile == null) {
textBorder = BorderFactory.createTitledBorder(this.textTitleBorder, "New Text Buffer");
@@ -1454,13 +1476,12 @@
// Destroy old AE.
if (this.ae != null) {
+ destroyAe();
this.acdItem.setEnabled(false);
- this.xcasWriteItem.setEnabled(false);
+ setEnableCasFileWriting();
this.tsViewerItem.setEnabled(false);
this.reRunMenu.setEnabled(false);
this.runOnCasMenuItem.setEnabled(false);
- this.ae.destroy();
- this.ae = null;
}
// get Resource Specifier from XML file
@@ -1479,10 +1500,10 @@
this.cas = this.ae.newCAS();
this.acdItem.setEnabled(true);
this.tsViewerItem.setEnabled(true);
- this.xcasWriteItem.setEnabled(true);
- this.xcasReadItem.setEnabled(true);
- this.reRunMenu.setEnabled(true);
this.typeSystemWriteItem.setEnabled(true);
+ setEnableCasFileReading(true);
+ setEnableCasFileWriting();
+ this.reRunMenu.setEnabled(true);
// reset sofa combo box with just the initial view
this.disableSofaListener = true;
@@ -1965,12 +1986,9 @@
this.isDirty = isDirty;
}
- public Action getCopyAction() {
- return this.copyAction;
- }
-
- public Action getCutAction() {
- return this.cutAction;
+ public void setCutCopyEnabled(boolean enable) {
+ this.cutAction.setEnabled(enable);
+ this.copyAction.setEnabled(enable);
}
public Properties getPreferences() {
@@ -2009,8 +2027,8 @@
this.index = index;
}
- public JMenuItem getAllAnnotationViewerItem() {
- return this.allAnnotationViewerItem;
+ public void setAllAnnotationViewerItemEnable(boolean enabled) {
+ this.allAnnotationViewerItem.setEnabled(enabled);
}
public File getFileOpenDir() {
@@ -2029,16 +2047,16 @@
this.textFile = textFile;
}
- public JMenuItem getFileSaveItem() {
- return this.fileSaveItem;
+ public void setSaveTextFileEnable(boolean enabled) {
+ this.fileSaveItem.setEnabled(enabled);
}
public UndoMgr getUndoMgr() {
return this.undoMgr;
}
- public JMenuItem getUndoItem() {
- return this.undoItem;
+ public void setUndoEnabled(boolean enabled) {
+ this.undoItem.setEnabled(enabled);
}
public File getXcasFileOpenDir() {
@@ -2049,54 +2067,35 @@
this.xcasFileOpenDir = xcasFileOpenDir;
}
- public boolean isDisableSofaListener() {
- return this.disableSofaListener;
- }
-
public void setDisableSofaListener(boolean disableSofaListener) {
this.disableSofaListener = disableSofaListener;
}
- public JComboBox getSofaSelectionComboBox() {
- return this.sofaSelectionComboBox;
- }
-
- public void setSofaSelectionComboBox(JComboBox sofaSelectionComboBox) {
- this.sofaSelectionComboBox = sofaSelectionComboBox;
- }
-
- public JPanel getSofaSelectionPanel() {
- return this.sofaSelectionPanel;
- }
-
- public void setSofaSelectionPanel(JPanel sofaSelectionPanel) {
- this.sofaSelectionPanel = sofaSelectionPanel;
- }
-
public void setCas(CAS cas) {
this.cas = cas;
}
- public JMenuItem getRunOnCasMenuItem() {
- return this.runOnCasMenuItem;
+ public void setRunOnCasEnabled() {
+ // Enable the "Run on CAS" menu item when we have both an AE and a CAS.
+ this.runOnCasMenuItem.setEnabled((this.ae != null) && (this.cas != null));
}
- public void setAe(AnalysisEngine ae) {
- this.ae = ae;
- }
-
- public JMenuItem getReRunMenu() {
- return this.reRunMenu;
+ public void destroyAe() {
+ this.cas = null;
+ if (this.ae != null) {
+ this.ae.destroy();
+ this.ae = null;
+ }
}
- public JMenuItem getTsViewerItem() {
- return this.tsViewerItem;
+ public void setRerunEnabled(boolean enabled) {
+ this.reRunMenu.setEnabled(enabled);
}
- public JMenuItem getXcasReadItem() {
- return this.xcasReadItem;
+ public void setTypeSystemViewerEnabled(boolean enabled) {
+ this.tsViewerItem.setEnabled(enabled);
}
-
+
public File getColorSettingsDir() {
return this.colorSettingsDir;
}
@@ -2171,6 +2170,64 @@
public void setCodePagePrefsList(String codePagePrefsList) {
this.codePagePrefsList = codePagePrefsList;
+ }
+
+ /**
+ * @param handler TODO
+ *
+ */
+ public void handleSofas() {
+ // Populate sofa combo box with the names of all text
+ // Sofas in the CAS
+ setDisableSofaListener(true);
+ String currentView = (String) this.sofaSelectionComboBox.getSelectedItem();
+ this.sofaSelectionComboBox.removeAllItems();
+ this.sofaSelectionComboBox.addItem(CAS.NAME_DEFAULT_SOFA);
+ Iterator sofas = ((CASImpl) getCas()).getBaseCAS().getSofaIterator();
+ Feature sofaIdFeat = getCas().getTypeSystem().getFeatureByFullName(
+ CAS.FEATURE_FULL_NAME_SOFAID);
+ boolean nonDefaultSofaFound = false;
+ while (sofas.hasNext()) {
+ SofaFS sofa = (SofaFS) sofas.next();
+ String sofaId = sofa.getStringValue(sofaIdFeat);
+ if (!CAS.NAME_DEFAULT_SOFA.equals(sofaId)) {
+ this.sofaSelectionComboBox.addItem(sofaId);
+ nonDefaultSofaFound = true;
+ }
+ }
+ // reuse last selected view if found in new CAS
+ int newIndex = 0;
+ String newView = CAS.NAME_DEFAULT_SOFA;
+ for (int i = 0; i < this.sofaSelectionComboBox.getItemCount(); i++) {
+ if (currentView.equals(this.sofaSelectionComboBox.getItemAt(i))) {
+ newIndex = i;
+ newView = currentView;
+ break;
+ }
+ }
+ // make sofa selector visible if any text sofa other
+ // than the default was found
+ this.sofaSelectionPanel.setVisible(nonDefaultSofaFound);
+ setCas(getCas().getView(newView));
+ setDisableSofaListener(false);
+
+ this.sofaSelectionComboBox.setSelectedIndex(newIndex);
+ String text = getCas().getDocumentText();
+ if (text == null) {
+ text = getCas().getSofaDataURI();
+ if (text != null) {
+ text = "SofaURI = " + text;
+ } else {
+ if (getCas().getSofaDataArray() != null) {
+ text = "Sofa array with mime type = "
+ + getCas().getSofa().getSofaMime();
+ }
+ }
+ }
+ getTextArea().setText(text);
+ if (text == null) {
+ getTextArea().repaint();
+ }
}
// private void initFocusTraversalPolicy() {
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/AnnotatorOpenEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/AnnotatorOpenEventHandler.java?view=diff&rev=542182&r1=542181&r2=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/AnnotatorOpenEventHandler.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/AnnotatorOpenEventHandler.java Mon May 28 02:50:27 2007
@@ -52,7 +52,7 @@
this.main.setAeDescriptorFile(fileChooser.getSelectedFile());
this.main.loadAEDescriptor(this.main.getAeDescriptorFile());
}
- this.main.getAllAnnotationViewerItem().setEnabled(false);
+ this.main.setAllAnnotationViewerItemEnable(false);
} finally {
this.main.resetCursor();
}
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/CaretChangeHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/CaretChangeHandler.java?view=diff&rev=542182&r1=542181&r2=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/CaretChangeHandler.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/CaretChangeHandler.java Mon May 28 02:50:27 2007
@@ -40,13 +40,7 @@
final int dot = ce.getDot();
final int mark = ce.getMark();
this.main.setCaretStatus(dot, mark);
- if (dot == mark) {
- this.main.getCutAction().setEnabled(false);
- this.main.getCopyAction().setEnabled(false);
- } else {
- this.main.getCutAction().setEnabled(true);
- this.main.getCopyAction().setEnabled(true);
- }
+ this.main.setCutCopyEnabled(dot == mark);
}
}
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/FileOpenEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/FileOpenEventHandler.java?view=diff&rev=542182&r1=542181&r2=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/FileOpenEventHandler.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/FileOpenEventHandler.java Mon May 28 02:50:27 2007
@@ -60,7 +60,7 @@
this.main.loadFile();
time.stop();
this.main.resetTrees();
- this.main.getFileSaveItem().setEnabled(true);
+ this.main.setSaveTextFileEnable(true);
this.main.getUndoMgr().discardAllEdits();
this.main.setFileStatusMessage();
this.main.setStatusbarMessage("Done loading text file " + this.main.getTextFile().getName()
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/FileSaveAsEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/FileSaveAsEventHandler.java?view=diff&rev=542182&r1=542181&r2=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/FileSaveAsEventHandler.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/FileSaveAsEventHandler.java Mon May 28 02:50:27 2007
@@ -55,7 +55,7 @@
if (fileSaved) {
this.main.setDirty(false);
this.main.setTitle();
- this.main.getFileSaveItem().setEnabled(true);
+ this.main.setSaveTextFileEnable(true);
this.main.setFileStatusMessage();
this.main.setStatusbarMessage("Text file " + this.main.getTextFile().getName() + " saved.");
} else {
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/IndexTreeSelectionListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/IndexTreeSelectionListener.java?view=diff&rev=542182&r1=542181&r2=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/IndexTreeSelectionListener.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/IndexTreeSelectionListener.java Mon May 28 02:50:27 2007
@@ -50,7 +50,7 @@
this.main.setAnnotationIndex(label.equals(CAS.STD_ANNOTATION_INDEX));
this.main.setIndex(this.main.getCas().getIndexRepository().getIndex(label, type));
this.main.updateFSTree(label, this.main.getIndex());
- this.main.getAllAnnotationViewerItem().setEnabled(((CASImpl) this.main.getCas())
+ this.main.setAllAnnotationViewerItemEnable(((CASImpl) this.main.getCas())
.isAnnotationType(type));
this.main.getTextArea().getCaret().setVisible(true);
}
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/NewTextEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/NewTextEventHandler.java?view=diff&rev=542182&r1=542181&r2=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/NewTextEventHandler.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/NewTextEventHandler.java Mon May 28 02:50:27 2007
@@ -45,7 +45,7 @@
}
this.main.setTitle();
this.main.resetTrees();
- this.main.getFileSaveItem().setEnabled(false);
+ this.main.setSaveTextFileEnable(false);
this.main.getUndoMgr().discardAllEdits();
this.main.setFileStatusMessage();
this.main.setStatusbarMessage("Text area cleared.");
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/SofaSelectionListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/SofaSelectionListener.java?view=diff&rev=542182&r1=542181&r2=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/SofaSelectionListener.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/SofaSelectionListener.java Mon May 28 02:50:27 2007
@@ -33,30 +33,25 @@
}
public void itemStateChanged(ItemEvent e) {
- if (this.main.isDisableSofaListener()) {
- return;
- }
- if (e.getSource() == this.main.getSofaSelectionComboBox()) {
- // a new sofa was selected. Switch to that view and update
- // display
- String sofaId = (String) e.getItem();
- this.main.setCas(this.main.getCas().getView(sofaId));
- String text = this.main.getCas().getDocumentText();
- if (text == null) {
- text = this.main.getCas().getSofaDataURI();
- if (text != null) {
- text = "SofaURI = " + text;
- } else {
- if (null != this.main.getCas().getSofaDataArray()) {
- text = "Sofa array with mime type = " + this.main.getCas().getSofa().getSofaMime();
- }
+ // a new sofa was selected. Switch to that view and update
+ // display
+ String sofaId = (String) e.getItem();
+ this.main.setCas(this.main.getCas().getView(sofaId));
+ String text = this.main.getCas().getDocumentText();
+ if (text == null) {
+ text = this.main.getCas().getSofaDataURI();
+ if (text != null) {
+ text = "SofaURI = " + text;
+ } else {
+ if (null != this.main.getCas().getSofaDataArray()) {
+ text = "Sofa array with mime type = " + this.main.getCas().getSofa().getSofaMime();
}
}
- this.main.getTextArea().setText(text);
- if (text == null) {
- this.main.getTextArea().repaint();
- }
- this.main.updateIndexTree(true);
}
+ this.main.getTextArea().setText(text);
+ if (text == null) {
+ this.main.getTextArea().repaint();
+ }
+ this.main.updateIndexTree(true);
}
}
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TypeSystemFileOpenEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TypeSystemFileOpenEventHandler.java?view=diff&rev=542182&r1=542181&r2=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TypeSystemFileOpenEventHandler.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TypeSystemFileOpenEventHandler.java Mon May 28 02:50:27 2007
@@ -68,18 +68,15 @@
// map file if there is none.
TypeSystemDescription tsDesc = (TypeSystemDescription) descriptor;
tsDesc.resolveImports();
- if (this.main.getAe() != null) {
- this.main.getAe().destroy();
- this.main.setAe(null);
- }
+ this.main.destroyAe();
this.main.setCas(CasCreationUtils
.createCas(tsDesc, null, new FsIndexDescription[0]));
- this.main.getRunOnCasMenuItem().setEnabled(false);
- this.main.getReRunMenu().setEnabled(false);
+ this.main.setRunOnCasEnabled();
+ this.main.setRerunEnabled(false);
this.main.getTextArea().setText("");
this.main.resetTrees();
- this.main.getTsViewerItem().setEnabled(true);
- this.main.getXcasReadItem().setEnabled(true);
+ this.main.setTypeSystemViewerEnabled(true);
+ this.main.setEnableCasFileReading(true);
time.stop();
this.main.setStatusbarMessage("Done loading type system file in " + time.getTimeSpan() + ".");
} catch (Exception e) {
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/UndoMgr.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/UndoMgr.java?view=diff&rev=542182&r1=542181&r2=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/UndoMgr.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/UndoMgr.java Mon May 28 02:50:27 2007
@@ -44,18 +44,18 @@
public void actionPerformed(ActionEvent arg0) {
undo();
if (!canUndo()) {
- this.main.getUndoItem().setEnabled(false);
+ this.main.setUndoEnabled(false);
}
}
public synchronized boolean addEdit(UndoableEdit arg0) {
- this.main.getUndoItem().setEnabled(true);
+ this.main.setUndoEnabled(true);
return super.addEdit(arg0);
}
public synchronized void discardAllEdits() {
super.discardAllEdits();
- this.main.getUndoItem().setEnabled(false);
+ this.main.setUndoEnabled(false);
}
}
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XCASFileOpenEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XCASFileOpenEventHandler.java?view=diff&rev=542182&r1=542181&r2=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XCASFileOpenEventHandler.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XCASFileOpenEventHandler.java Mon May 28 02:50:27 2007
@@ -23,16 +23,11 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
-import java.util.Iterator;
import javax.swing.JFileChooser;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.Feature;
-import org.apache.uima.cas.SofaFS;
-import org.apache.uima.cas.impl.CASImpl;
import org.apache.uima.cas.impl.XCASDeserializer;
import org.apache.uima.internal.util.Timer;
import org.apache.uima.tools.cvd.MainFrame;
@@ -72,61 +67,11 @@
this.main.getCas().reset();
parser.parse(xcasFile, xcasDeserializer.getXCASHandler(this.main.getCas()));
time.stop();
- // Populate sofa combo box with the names of all text
- // Sofas in the CAS
- this.main.setDisableSofaListener(true);
- String currentView = (String) this.main.getSofaSelectionComboBox().getSelectedItem();
- this.main.getSofaSelectionComboBox().removeAllItems();
- this.main.getSofaSelectionComboBox().addItem(CAS.NAME_DEFAULT_SOFA);
- Iterator sofas = ((CASImpl) this.main.getCas()).getBaseCAS().getSofaIterator();
- Feature sofaIdFeat = this.main.getCas().getTypeSystem().getFeatureByFullName(
- CAS.FEATURE_FULL_NAME_SOFAID);
- boolean nonDefaultSofaFound = false;
- while (sofas.hasNext()) {
- SofaFS sofa = (SofaFS) sofas.next();
- String sofaId = sofa.getStringValue(sofaIdFeat);
- if (!CAS.NAME_DEFAULT_SOFA.equals(sofaId)) {
- this.main.getSofaSelectionComboBox().addItem(sofaId);
- nonDefaultSofaFound = true;
- }
- }
- // reuse last selected view if found in new CAS
- int newIndex = 0;
- String newView = CAS.NAME_DEFAULT_SOFA;
- for (int i = 0; i < this.main.getSofaSelectionComboBox().getItemCount(); i++) {
- if (currentView.equals(this.main.getSofaSelectionComboBox().getItemAt(i))) {
- newIndex = i;
- newView = currentView;
- break;
- }
- }
- // make sofa selector visible if any text sofa other
- // than the default was found
- this.main.getSofaSelectionPanel().setVisible(nonDefaultSofaFound);
- this.main.setCas(this.main.getCas().getView(newView));
- this.main.setDisableSofaListener(false);
-
- this.main.getSofaSelectionComboBox().setSelectedIndex(newIndex);
- String text = this.main.getCas().getDocumentText();
- if (text == null) {
- text = this.main.getCas().getSofaDataURI();
- if (text != null) {
- text = "SofaURI = " + text;
- } else {
- if (this.main.getCas().getSofaDataArray() != null) {
- text = "Sofa array with mime type = "
- + this.main.getCas().getSofa().getSofaMime();
- }
- }
- }
- this.main.getTextArea().setText(text);
- if (text == null) {
- this.main.getTextArea().repaint();
- }
-
+ this.main.handleSofas();
this.main.setTitle("XCAS");
this.main.updateIndexTree(true);
- this.main.getRunOnCasMenuItem().setEnabled(true);
+ this.main.setRunOnCasEnabled();
+ this.main.setEnableCasFileWriting();
this.main.setStatusbarMessage("Done loading XCAS file in " + time.getTimeSpan() + ".");
} catch (Exception e) {
e.printStackTrace();
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XCASSaveHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XCASSaveHandler.java?view=diff&rev=542182&r1=542181&r2=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XCASSaveHandler.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XCASSaveHandler.java Mon May 28 02:50:27 2007
@@ -31,7 +31,6 @@
import javax.swing.JFileChooser;
import org.apache.uima.cas.impl.XCASSerializer;
-import org.apache.uima.internal.util.TimeSpan;
import org.apache.uima.tools.cvd.MainFrame;
import org.apache.uima.util.XMLSerializer;
import org.xml.sax.SAXException;
@@ -58,14 +57,11 @@
File xcasFile = fileChooser.getSelectedFile();
this.main.setXcasFileOpenDir(xcasFile.getParentFile());
try {
- long time = System.currentTimeMillis();
OutputStream outStream = new BufferedOutputStream(new FileOutputStream(xcasFile));
XMLSerializer xmlSerializer = new XMLSerializer(outStream);
XCASSerializer xcasSerializer = new XCASSerializer(this.main.getCas().getTypeSystem());
xcasSerializer.serialize(this.main.getCas(), xmlSerializer.getContentHandler());
outStream.close();
- time = System.currentTimeMillis() - time;
- System.out.println("Time taken: " + new TimeSpan(time));
} catch (IOException e) {
this.main.handleException(e);
} catch (SAXException e) {
Added: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XmiCasFileOpenHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XmiCasFileOpenHandler.java?view=auto&rev=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XmiCasFileOpenHandler.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XmiCasFileOpenHandler.java Mon May 28 02:50:27 2007
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.tools.cvd.control;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+
+import javax.swing.JFileChooser;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.uima.cas.impl.XmiCasDeserializer;
+import org.apache.uima.internal.util.Timer;
+import org.apache.uima.tools.cvd.MainFrame;
+
+/**
+ * Load a CAS from an XMI file.
+ */
+public class XmiCasFileOpenHandler implements ActionListener {
+
+ final MainFrame main;
+
+ // Default constructor, not used.
+ private XmiCasFileOpenHandler() {
+ super();
+ this.main = null;
+ }
+
+ public XmiCasFileOpenHandler(MainFrame main) {
+ super();
+ this.main = main;
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Open XMI CAS file");
+ if (this.main.getXcasFileOpenDir() != null) {
+ fileChooser.setCurrentDirectory(this.main.getXcasFileOpenDir());
+ }
+ int rc = fileChooser.showOpenDialog(this.main);
+ if (rc == JFileChooser.APPROVE_OPTION) {
+ File xmiCasFile = fileChooser.getSelectedFile();
+ if (xmiCasFile.exists() && xmiCasFile.isFile()) {
+ try {
+ this.main.setXcasFileOpenDir(xmiCasFile.getParentFile());
+ Timer time = new Timer();
+ time.start();
+ SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
+ XmiCasDeserializer xmiCasDeserializer = new XmiCasDeserializer(this.main.getCas()
+ .getTypeSystem());
+ this.main.getCas().reset();
+ parser.parse(xmiCasFile, xmiCasDeserializer.getXmiCasHandler(this.main.getCas()));
+ time.stop();
+ this.main.handleSofas();
+
+ this.main.setTitle("XMI CAS");
+ this.main.updateIndexTree(true);
+ this.main.setRunOnCasEnabled();
+ this.main.setEnableCasFileWriting();
+ this.main.setStatusbarMessage("Done loading XMI CAS file in " + time.getTimeSpan() + ".");
+ } catch (Exception e) {
+ e.printStackTrace();
+ this.main.handleException(e);
+ }
+ }
+ }
+ }
+
+}
Added: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XmiCasSaveHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XmiCasSaveHandler.java?view=auto&rev=542182
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XmiCasSaveHandler.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XmiCasSaveHandler.java Mon May 28 02:50:27 2007
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.tools.cvd.control;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.swing.JFileChooser;
+
+import org.apache.uima.cas.impl.XmiCasSerializer;
+import org.apache.uima.tools.cvd.MainFrame;
+import org.apache.uima.util.XMLSerializer;
+import org.xml.sax.SAXException;
+
+/**
+ * Save CAS to disk as XMI.
+ */
+public class XmiCasSaveHandler implements ActionListener {
+
+ private final MainFrame main;
+
+ // Default constructor
+ private XmiCasSaveHandler() {
+ super();
+ this.main = null;
+ }
+
+ public XmiCasSaveHandler(MainFrame main) {
+ super();
+ this.main = main;
+ }
+
+ /* (non-Javadoc)
+ * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+ */
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Save XMI CAS file");
+ if (this.main.getXcasFileOpenDir() != null) {
+ fileChooser.setCurrentDirectory(this.main.getXcasFileOpenDir());
+ }
+ int rc = fileChooser.showSaveDialog(this.main);
+ if (rc == JFileChooser.APPROVE_OPTION) {
+ File xmiCasFile = fileChooser.getSelectedFile();
+ this.main.setXcasFileOpenDir(xmiCasFile.getParentFile());
+ try {
+ OutputStream outStream = new BufferedOutputStream(new FileOutputStream(xmiCasFile));
+ XMLSerializer xmlSerializer = new XMLSerializer(outStream);
+ XmiCasSerializer xmiCasSerializer = new XmiCasSerializer(this.main.getCas().getTypeSystem());
+ xmiCasSerializer.serialize(this.main.getCas(), xmlSerializer.getContentHandler());
+ outStream.close();
+ } catch (IOException e) {
+ this.main.handleException(e);
+ } catch (SAXException e) {
+ this.main.handleException(e);
+ }
+ }
+ }
+
+}