if (rc == JFileChooser.APPROVE_OPTION) {
File xcasFile = fileChooser.getSelectedFile();
if (xcasFile.exists() && xcasFile.isFile()) {
try {
MainFrame.this.xcasFileOpenDir = xcasFile.getParentFile();
Timer time = new Timer();
time.start();
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
XCASDeserializer xcasDeserializer = new XCASDeserializer(MainFrame.this.cas
.getTypeSystem());
MainFrame.this.cas.reset();
parser.parse(xcasFile, xcasDeserializer.getXCASHandler(MainFrame.this.cas));
time.stop();
// Populate sofa combo box with the names of all text
// Sofas in the CAS
MainFrame.this.disableSofaListener = true;
String currentView = (String) MainFrame.this.sofaSelectionComboBox.getSelectedItem();
MainFrame.this.sofaSelectionComboBox.removeAllItems();
MainFrame.this.sofaSelectionComboBox.addItem(CAS.NAME_DEFAULT_SOFA);
Iterator sofas = ((CASImpl) MainFrame.this.cas).getBaseCAS().getSofaIterator();
Feature sofaIdFeat = MainFrame.this.cas.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)) {
MainFrame.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 < MainFrame.this.sofaSelectionComboBox.getItemCount(); i++) {
if (currentView.equals(MainFrame.this.sofaSelectionComboBox.getItemAt(i))) {
newIndex = i;
newView = currentView;
break;
}
}
// make sofa selector visible if any text sofa other
// than the default was found
MainFrame.this.sofaSelectionPanel.setVisible(nonDefaultSofaFound);
MainFrame.this.cas = MainFrame.this.cas.getView(newView);
MainFrame.this.disableSofaListener = false;
MainFrame.this.sofaSelectionComboBox.setSelectedIndex(newIndex);
String text = MainFrame.this.cas.getDocumentText();
if (text == null) {
text = MainFrame.this.cas.getSofaDataURI();
if (text != null) {
text = "SofaURI = " + text;
} else {
if (null != MainFrame.this.cas.getSofaDataArray()) {
text = "Sofa array with mime type = "
+ MainFrame.this.cas.getSofa().getSofaMime();
}
}
}
MainFrame.this.textArea.setText(text);
if (text == null) {
MainFrame.this.textArea.repaint();
}
MainFrame.this.setTitle("XCAS");
MainFrame.this.updateIndexTree(true);
MainFrame.this.runOnCasMenuItem.setEnabled(true);
setStatusbarMessage("Done loading XCAS file in " + time.getTimeSpan() + ".");
} catch (Exception e) {
e.printStackTrace();
handleException(e);
}
}