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/02/02 10:44:55 UTC
svn commit: r502554 [2/2] -
/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/annot_view/MainFrame.java
Modified: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/annot_view/MainFrame.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/annot_view/MainFrame.java?view=diff&rev=502554&r1=502553&r2=502554
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/annot_view/MainFrame.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/annot_view/MainFrame.java Fri Feb 2 01:44:52 2007
@@ -154,2970 +154,2964 @@
*/
public class MainFrame extends JFrame {
- private static final long serialVersionUID = -1357410768440678886L;
+ private static final long serialVersionUID = -1357410768440678886L;
- private class FocusIRAction extends AbstractAction implements Action {
+ private class FocusIRAction extends AbstractAction implements Action {
- private static final long serialVersionUID = -8128067676842119411L;
+ private static final long serialVersionUID = -8128067676842119411L;
- public void actionPerformed(ActionEvent arg0) {
- // Only available in 1.4.
- // MainFrame.this.indexTree.requestFocusInWindow();
- MainFrame.this.indexTree.requestFocus();
- }
+ public void actionPerformed(ActionEvent arg0) {
+ // Only available in 1.4.
+ // MainFrame.this.indexTree.requestFocusInWindow();
+ MainFrame.this.indexTree.requestFocus();
+ }
- }
+ }
- private class FocusFSAction extends AbstractAction implements Action {
+ private class FocusFSAction extends AbstractAction implements Action {
- private static final long serialVersionUID = -8330075846211434833L;
+ private static final long serialVersionUID = -8330075846211434833L;
- public void actionPerformed(ActionEvent arg0) {
- // Only available in 1.4.
- // MainFrame.this.fsTree.requestFocusInWindow();
- MainFrame.this.fsTree.requestFocus();
- }
+ public void actionPerformed(ActionEvent arg0) {
+ // Only available in 1.4.
+ // MainFrame.this.fsTree.requestFocusInWindow();
+ MainFrame.this.fsTree.requestFocus();
+ }
- }
+ }
- private class FocusTextAction extends AbstractAction implements Action {
+ private class FocusTextAction extends AbstractAction implements Action {
- private static final long serialVersionUID = -4867535661038776033L;
+ private static final long serialVersionUID = -4867535661038776033L;
- public void actionPerformed(ActionEvent arg0) {
- // Only available in 1.4.
- // MainFrame.this.textArea.requestFocusInWindow();
- MainFrame.this.textArea.requestFocus();
- }
+ public void actionPerformed(ActionEvent arg0) {
+ // Only available in 1.4.
+ // MainFrame.this.textArea.requestFocusInWindow();
+ MainFrame.this.textArea.requestFocus();
+ }
- }
+ }
- private class TextChangedListener implements DocumentListener {
+ private class TextChangedListener implements DocumentListener {
- public void changedUpdate(DocumentEvent arg0) {
- // Do nothing.
- }
+ public void changedUpdate(DocumentEvent arg0) {
+ // Do nothing.
+ }
- public void insertUpdate(DocumentEvent arg0) {
- removeUpdate(arg0);
- }
+ public void insertUpdate(DocumentEvent arg0) {
+ removeUpdate(arg0);
+ }
- /*
+ /*
* (non-Javadoc)
*
* @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
*/
- public void removeUpdate(DocumentEvent arg0) {
- if (!MainFrame.this.isDirty) {
- MainFrame.this.isDirty = true;
- setTitle();
- if (MainFrame.this.cas != null) {
- setStatusbarMessage("Text changed, CAS removed.");
- }
- resetTrees();
- }
- }
+ public void removeUpdate(DocumentEvent arg0) {
+ if (!MainFrame.this.isDirty) {
+ MainFrame.this.isDirty = true;
+ setTitle();
+ if (MainFrame.this.cas != null) {
+ setStatusbarMessage("Text changed, CAS removed.");
+ }
+ resetTrees();
+ }
+ }
- }
+ }
- private class TextFocusHandler implements FocusListener {
+ private class TextFocusHandler implements FocusListener {
- /*
+ /*
* (non-Javadoc)
*
* @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
*/
- public void focusGained(FocusEvent e) {
- MainFrame.this.textArea.getCaret().setVisible(true);
- }
+ public void focusGained(FocusEvent e) {
+ MainFrame.this.textArea.getCaret().setVisible(true);
+ }
- /*
+ /*
* (non-Javadoc)
*
* @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
*/
- public void focusLost(FocusEvent e) {
- // Does nothing
- }
-
- }
-
- private static class TreeFocusHandler implements FocusListener {
-
- private JTree tree;
-
- private TreeFocusHandler(JTree tree) {
- super();
- this.tree = tree;
- }
-
- public void focusGained(FocusEvent arg0) {
- TreePath selPath = this.tree.getSelectionPath();
- if (selPath == null) {
- selPath = new TreePath(new Object[] { this.tree.getModel().getRoot() });
- this.tree.setSelectionPath(selPath);
- }
- }
-
- public void focusLost(FocusEvent arg0) {
- // Do nothing.
- }
-
- }
-
- private class PopupHandler implements ActionListener {
-
- private final int node;
-
- private PopupHandler(int n) {
- super();
- this.node = n;
- }
-
- public void actionPerformed(ActionEvent e) {
- FSTreeModel treeModel = (FSTreeModel) MainFrame.this.fsTree.getModel();
- TreePath path = treeModel.pathToNode(this.node);
- MainFrame.this.fsTree.setSelectionPath(path);
- MainFrame.this.fsTree.scrollPathToVisible(path);
- }
-
- }
-
- private class CaretChangeHandler implements CaretListener {
-
- public void caretUpdate(CaretEvent ce) {
- final int dot = ce.getDot();
- final int mark = ce.getMark();
- setCaretStatus(dot, mark);
- if (dot == mark) {
- MainFrame.this.cutAction.setEnabled(false);
- MainFrame.this.copyAction.setEnabled(false);
- } else {
- MainFrame.this.cutAction.setEnabled(true);
- MainFrame.this.copyAction.setEnabled(true);
- }
- }
-
- }
-
- private class PopupListener extends MouseAdapter {
-
- public void mousePressed(MouseEvent e) {
- maybeShowPopup(e);
- }
-
- public void mouseReleased(MouseEvent e) {
- maybeShowPopup(e);
- }
-
- private void maybeShowPopup(MouseEvent e) {
- if (e.isPopupTrigger()) {
- showTextPopup(e.getX(), e.getY());
- }
- }
- }
-
- private class TextContextMenuAction extends AbstractAction {
-
- private static final long serialVersionUID = -5518456467913617514L;
-
- public void actionPerformed(ActionEvent arg0) {
- Point caretPos = MainFrame.this.textArea.getCaret().getMagicCaretPosition();
- if (caretPos == null) {
- // No idea why this is needed. Bug in JTextArea, or my poor
- // understanding of the magics of carets. The point is null when
- // the
- // text area is first focused.
- showTextPopup(0, 0);
- } else {
- showTextPopup(caretPos.x, caretPos.y);
- }
- }
-
- }
-
- private class IndexPopupListener extends MouseAdapter {
-
- public void mousePressed(MouseEvent e) {
- maybeShowPopup(e);
- }
-
- public void mouseReleased(MouseEvent e) {
- maybeShowPopup(e);
- }
-
- private void maybeShowPopup(MouseEvent e) {
- if (e.isPopupTrigger()) {
- DefaultMutableTreeNode node = (DefaultMutableTreeNode) MainFrame.this.indexTree
- .getLastSelectedPathComponent();
- if (node == null) {
- return;
- }
- Object userObject = node.getUserObject();
- String annotTitle = null;
- boolean isAnnotation = true;
- if (userObject instanceof IndexTreeNode) {
- IndexTreeNode iNode = (IndexTreeNode) userObject;
- if (!iNode.getName().equals(CAS.STD_ANNOTATION_INDEX)) {
- isAnnotation = false;
- }
- annotTitle = iNode.getType().getName();
- } else if (userObject instanceof TypeTreeNode) {
- TypeTreeNode tNode = (TypeTreeNode) userObject;
- if (!tNode.getLabel().equals(CAS.STD_ANNOTATION_INDEX)) {
- isAnnotation = false;
- }
- annotTitle = tNode.getType().getName();
- } else {
- isAnnotation = false;
- }
- JPopupMenu menu = new JPopupMenu();
- JMenuItem item = null;
- if (isAnnotation) {
- item = new JMenuItem("Show annotations: " + annotTitle);
- item.addActionListener(new ShowAnnotatedTextHandler());
- } else {
- item = new JMenuItem("No annotations selected");
- }
- menu.add(item);
- menu.show(e.getComponent(), e.getX(), e.getY());
- }
- }
- }
-
- // private class IndexPopupHandler implements ActionListener {
- //
- // public void actionPerformed(ActionEvent event) {
- // DefaultMutableTreeNode node =
- // (DefaultMutableTreeNode) indexTree.getLastSelectedPathComponent();
- // if (node == null) {
- // return;
- // }
- // Object userObject = node.getUserObject();
- // String label = null;
- // Type type = null;
- // if (userObject instanceof IndexTreeNode) {
- // IndexTreeNode indexNode = (IndexTreeNode) userObject;
- // label = indexNode.getName();
- // type = indexNode.getType();
- // } else if (userObject instanceof TypeTreeNode) {
- // TypeTreeNode typeNode = (TypeTreeNode) userObject;
- // label = typeNode.getLabel();
- // type = typeNode.getType();
- // } else {
- // return;
- // }
- // indexLabel = label;
- // isAnnotIndex = label.equals(CAS.STD_ANNOTATION_INDEX);
- // index = cas.getIndexRepository().getIndex(label, type);
- // String title = indexLabel + " [" + index.getType().getName() + "]";
- // MultiAnnotViewerFrame f = new MultiAnnotViewerFrame(title);
- // f.addWindowListener(new CloseAnnotationViewHandler());
- // FSIterator it = index.iterator();
- // final String text = cas.getDocumentText();
- // System.out.println("Creating extents.");
- // AnnotationExtent[] extents =
- // MultiMarkup.createAnnotationMarkups(it, text.length(), styleMap);
- // System.out.println("Initializing text frame.");
- // f.init(text, extents, getDimension(MainFrame.annotViewSizePref));
- // System.out.println("Done.");
- // }
- //
- // }
-
- private class MainFrameClosing extends WindowAdapter {
-
- public void windowClosing(WindowEvent e) {
- try {
- setStatusbarMessage("Saving preferences.");
- saveProgramPreferences();
- if (MainFrame.this.ae != null) {
- MainFrame.this.ae.destroy();
- }
- } catch (IOException ioe) {
- handleException(ioe);
- }
- System.exit(0);
- }
+ public void focusLost(FocusEvent e) {
+ // Does nothing
+ }
+
+ }
+
+ private static class TreeFocusHandler implements FocusListener {
+
+ private JTree tree;
+
+ private TreeFocusHandler(JTree tree) {
+ super();
+ this.tree = tree;
+ }
+
+ public void focusGained(FocusEvent arg0) {
+ TreePath selPath = this.tree.getSelectionPath();
+ if (selPath == null) {
+ selPath = new TreePath(new Object[] { this.tree.getModel().getRoot() });
+ this.tree.setSelectionPath(selPath);
+ }
+ }
+
+ public void focusLost(FocusEvent arg0) {
+ // Do nothing.
+ }
+
+ }
+
+ private class PopupHandler implements ActionListener {
+
+ private final int node;
+
+ private PopupHandler(int n) {
+ super();
+ this.node = n;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ FSTreeModel treeModel = (FSTreeModel) MainFrame.this.fsTree.getModel();
+ TreePath path = treeModel.pathToNode(this.node);
+ MainFrame.this.fsTree.setSelectionPath(path);
+ MainFrame.this.fsTree.scrollPathToVisible(path);
+ }
+
+ }
+
+ private class CaretChangeHandler implements CaretListener {
+
+ public void caretUpdate(CaretEvent ce) {
+ final int dot = ce.getDot();
+ final int mark = ce.getMark();
+ setCaretStatus(dot, mark);
+ if (dot == mark) {
+ MainFrame.this.cutAction.setEnabled(false);
+ MainFrame.this.copyAction.setEnabled(false);
+ } else {
+ MainFrame.this.cutAction.setEnabled(true);
+ MainFrame.this.copyAction.setEnabled(true);
+ }
+ }
+
+ }
+
+ private class PopupListener extends MouseAdapter {
+
+ public void mousePressed(MouseEvent e) {
+ maybeShowPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ maybeShowPopup(e);
+ }
+
+ private void maybeShowPopup(MouseEvent e) {
+ if (e.isPopupTrigger()) {
+ showTextPopup(e.getX(), e.getY());
+ }
+ }
+ }
+
+ private class TextContextMenuAction extends AbstractAction {
+
+ private static final long serialVersionUID = -5518456467913617514L;
+
+ public void actionPerformed(ActionEvent arg0) {
+ Point caretPos = MainFrame.this.textArea.getCaret().getMagicCaretPosition();
+ if (caretPos == null) {
+ // No idea why this is needed. Bug in JTextArea, or my poor
+ // understanding of the magics of carets. The point is null when
+ // the
+ // text area is first focused.
+ showTextPopup(0, 0);
+ } else {
+ showTextPopup(caretPos.x, caretPos.y);
+ }
+ }
+
+ }
+
+ private class IndexPopupListener extends MouseAdapter {
+
+ public void mousePressed(MouseEvent e) {
+ maybeShowPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ maybeShowPopup(e);
+ }
+
+ private void maybeShowPopup(MouseEvent e) {
+ if (e.isPopupTrigger()) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) MainFrame.this.indexTree
+ .getLastSelectedPathComponent();
+ if (node == null) {
+ return;
+ }
+ Object userObject = node.getUserObject();
+ String annotTitle = null;
+ boolean isAnnotation = true;
+ if (userObject instanceof IndexTreeNode) {
+ IndexTreeNode iNode = (IndexTreeNode) userObject;
+ if (!iNode.getName().equals(CAS.STD_ANNOTATION_INDEX)) {
+ isAnnotation = false;
+ }
+ annotTitle = iNode.getType().getName();
+ } else if (userObject instanceof TypeTreeNode) {
+ TypeTreeNode tNode = (TypeTreeNode) userObject;
+ if (!tNode.getLabel().equals(CAS.STD_ANNOTATION_INDEX)) {
+ isAnnotation = false;
+ }
+ annotTitle = tNode.getType().getName();
+ } else {
+ isAnnotation = false;
+ }
+ JPopupMenu menu = new JPopupMenu();
+ JMenuItem item = null;
+ if (isAnnotation) {
+ item = new JMenuItem("Show annotations: " + annotTitle);
+ item.addActionListener(new ShowAnnotatedTextHandler());
+ } else {
+ item = new JMenuItem("No annotations selected");
+ }
+ menu.add(item);
+ menu.show(e.getComponent(), e.getX(), e.getY());
+ }
+ }
+ }
+
+ // private class IndexPopupHandler implements ActionListener {
+ //
+ // public void actionPerformed(ActionEvent event) {
+ // DefaultMutableTreeNode node =
+ // (DefaultMutableTreeNode) indexTree.getLastSelectedPathComponent();
+ // if (node == null) {
+ // return;
+ // }
+ // Object userObject = node.getUserObject();
+ // String label = null;
+ // Type type = null;
+ // if (userObject instanceof IndexTreeNode) {
+ // IndexTreeNode indexNode = (IndexTreeNode) userObject;
+ // label = indexNode.getName();
+ // type = indexNode.getType();
+ // } else if (userObject instanceof TypeTreeNode) {
+ // TypeTreeNode typeNode = (TypeTreeNode) userObject;
+ // label = typeNode.getLabel();
+ // type = typeNode.getType();
+ // } else {
+ // return;
+ // }
+ // indexLabel = label;
+ // isAnnotIndex = label.equals(CAS.STD_ANNOTATION_INDEX);
+ // index = cas.getIndexRepository().getIndex(label, type);
+ // String title = indexLabel + " [" + index.getType().getName() + "]";
+ // MultiAnnotViewerFrame f = new MultiAnnotViewerFrame(title);
+ // f.addWindowListener(new CloseAnnotationViewHandler());
+ // FSIterator it = index.iterator();
+ // final String text = cas.getDocumentText();
+ // System.out.println("Creating extents.");
+ // AnnotationExtent[] extents =
+ // MultiMarkup.createAnnotationMarkups(it, text.length(), styleMap);
+ // System.out.println("Initializing text frame.");
+ // f.init(text, extents, getDimension(MainFrame.annotViewSizePref));
+ // System.out.println("Done.");
+ // }
+ //
+ // }
+
+ private class MainFrameClosing extends WindowAdapter {
+
+ public void windowClosing(WindowEvent e) {
+ try {
+ setStatusbarMessage("Saving preferences.");
+ saveProgramPreferences();
+ if (MainFrame.this.ae != null) {
+ MainFrame.this.ae.destroy();
+ }
+ } catch (IOException ioe) {
+ handleException(ioe);
+ }
+ System.exit(0);
+ }
- }
+ }
- /**
+ /**
* Change the display of the FSTree if a type in an index is selected.
*/
- private class IndexTreeSelectionListener implements TreeSelectionListener {
+ private class IndexTreeSelectionListener implements TreeSelectionListener {
- /**
+ /**
* @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
*/
- public void valueChanged(TreeSelectionEvent arg0) {
- // System.out.println("Tree selection value changed");
- DefaultMutableTreeNode node = (DefaultMutableTreeNode) MainFrame.this.indexTree
- .getLastSelectedPathComponent();
- if (node == null) {
- return;
- }
- Object userObject = node.getUserObject();
- String label = null;
- Type type = null;
- if (userObject instanceof IndexTreeNode) {
- IndexTreeNode indexNode = (IndexTreeNode) userObject;
- label = indexNode.getName();
- type = indexNode.getType();
- } else if (userObject instanceof TypeTreeNode) {
- TypeTreeNode typeNode = (TypeTreeNode) userObject;
- label = typeNode.getLabel();
- type = typeNode.getType();
- } else {
- return;
- }
- MainFrame.this.indexLabel = label;
- MainFrame.this.isAnnotIndex = label.equals(CAS.STD_ANNOTATION_INDEX);
- MainFrame.this.index = MainFrame.this.cas.getIndexRepository().getIndex(label, type);
- updateFSTree(label, MainFrame.this.index);
- MainFrame.this.allAnnotViewerItem.setEnabled(((CASImpl) MainFrame.this.cas)
- .isAnnotationType(type));
- MainFrame.this.textArea.getCaret().setVisible(true);
- }
+ public void valueChanged(TreeSelectionEvent arg0) {
+ // System.out.println("Tree selection value changed");
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) MainFrame.this.indexTree
+ .getLastSelectedPathComponent();
+ if (node == null) {
+ return;
+ }
+ Object userObject = node.getUserObject();
+ String label = null;
+ Type type = null;
+ if (userObject instanceof IndexTreeNode) {
+ IndexTreeNode indexNode = (IndexTreeNode) userObject;
+ label = indexNode.getName();
+ type = indexNode.getType();
+ } else if (userObject instanceof TypeTreeNode) {
+ TypeTreeNode typeNode = (TypeTreeNode) userObject;
+ label = typeNode.getLabel();
+ type = typeNode.getType();
+ } else {
+ return;
+ }
+ MainFrame.this.indexLabel = label;
+ MainFrame.this.isAnnotIndex = label.equals(CAS.STD_ANNOTATION_INDEX);
+ MainFrame.this.index = MainFrame.this.cas.getIndexRepository().getIndex(label, type);
+ updateFSTree(label, MainFrame.this.index);
+ MainFrame.this.allAnnotViewerItem.setEnabled(((CASImpl) MainFrame.this.cas)
+ .isAnnotationType(type));
+ MainFrame.this.textArea.getCaret().setVisible(true);
+ }
- }
+ }
- private class FSTreeSelectionListener implements TreeSelectionListener {
+ private class FSTreeSelectionListener implements TreeSelectionListener {
- /**
+ /**
* @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
*/
- public void valueChanged(TreeSelectionEvent event) {
- // System.out.println("");
- FSTreeNode protoNode = (FSTreeNode) MainFrame.this.fsTree.getLastSelectedPathComponent();
- if (!(protoNode instanceof FSNode)) {
- return;
- }
- FSNode node = (FSNode) protoNode;
- if (node == null) {
- return;
- }
- // Remeber start of current selection.
- final int currentSelStart = MainFrame.this.textArea.getSelectionStart();
- if (node.isAnnotation()) {
- if (null != MainFrame.this.cas.getDocumentText()) {
- MainFrame.this.textArea.setSelectionStart(node.getStart());
- MainFrame.this.textArea.setSelectionEnd(node.getEnd());
- // System.out.println(
- // "Setting selection from " + node.getStart() + " to " +
- // node.getEnd());
- MainFrame.this.textArea.getCaret().setSelectionVisible(true);
- }
- } else {
- MainFrame.this.textArea.setSelectionEnd(currentSelStart);
- }
-
- }
-
- }
-
- private class FileOpenEventHandler implements ActionListener {
-
- private FileOpenEventHandler() {
- super();
- }
+ public void valueChanged(TreeSelectionEvent event) {
+ // System.out.println("");
+ FSTreeNode protoNode = (FSTreeNode) MainFrame.this.fsTree.getLastSelectedPathComponent();
+ if (!(protoNode instanceof FSNode)) {
+ return;
+ }
+ FSNode node = (FSNode) protoNode;
+ if (node == null) {
+ return;
+ }
+ // Remeber start of current selection.
+ final int currentSelStart = MainFrame.this.textArea.getSelectionStart();
+ if (node.isAnnotation()) {
+ if (null != MainFrame.this.cas.getDocumentText()) {
+ MainFrame.this.textArea.setSelectionStart(node.getStart());
+ MainFrame.this.textArea.setSelectionEnd(node.getEnd());
+ // System.out.println(
+ // "Setting selection from " + node.getStart() + " to " +
+ // node.getEnd());
+ MainFrame.this.textArea.getCaret().setSelectionVisible(true);
+ }
+ } else {
+ MainFrame.this.textArea.setSelectionEnd(currentSelStart);
+ }
+
+ }
+
+ }
+
+ private class FileOpenEventHandler implements ActionListener {
+
+ private FileOpenEventHandler() {
+ super();
+ }
- /**
+ /**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
- public void actionPerformed(ActionEvent event) {
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setDialogTitle("Open text file");
- fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
- if (MainFrame.this.fileOpenDir != null) {
- fileChooser.setCurrentDirectory(MainFrame.this.fileOpenDir);
- }
- int rc = fileChooser.showOpenDialog(MainFrame.this);
- if (rc == JFileChooser.APPROVE_OPTION) {
- MainFrame.this.textFile = fileChooser.getSelectedFile();
- if (MainFrame.this.textFile.exists() && MainFrame.this.textFile.isFile()) {
- MainFrame.this.fileOpenDir = MainFrame.this.textFile.getParentFile();
- }
- Timer time = new Timer();
- time.start();
- loadFile();
- time.stop();
- resetTrees();
- MainFrame.this.fileSaveItem.setEnabled(true);
- MainFrame.this.undoMgr.discardAllEdits();
- setFileStatusMessage();
- setStatusbarMessage("Done loading text file " + MainFrame.this.textFile.getName() + " in "
- + time.getTimeSpan() + ".");
- }
- }
- }
-
- private class NewTextEventHandler implements ActionListener {
-
- private NewTextEventHandler() {
- super();
- }
-
- public void actionPerformed(ActionEvent event) {
- MainFrame.this.textFile = null;
- MainFrame.this.textArea.setText("");
- if (MainFrame.this.isDirty) {
- MainFrame.this.isDirty = false;
- }
- setTitle();
- resetTrees();
- MainFrame.this.fileSaveItem.setEnabled(false);
- MainFrame.this.undoMgr.discardAllEdits();
- setFileStatusMessage();
- setStatusbarMessage("Text area cleared.");
- }
-
- }
-
- private class LoadRecentTextFileEventHandler implements ActionListener {
-
- private final String fileName;
-
- private LoadRecentTextFileEventHandler(String fileName) {
- super();
- this.fileName = fileName;
- }
-
- public void actionPerformed(ActionEvent e) {
- loadTextFile(new File(this.fileName));
- }
-
- }
-
- private class LoadRecentDescFileEventHandler implements ActionListener {
-
- private final String fileName;
-
- private LoadRecentDescFileEventHandler(String fileName) {
- super();
- this.fileName = fileName;
- }
-
- public void actionPerformed(ActionEvent e) {
- loadAEDescriptor(new File(this.fileName));
- }
-
- }
-
- private class FileSaveAsEventHandler implements ActionListener {
-
- private FileSaveAsEventHandler() {
- super();
- }
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Open text file");
+ fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ if (MainFrame.this.fileOpenDir != null) {
+ fileChooser.setCurrentDirectory(MainFrame.this.fileOpenDir);
+ }
+ int rc = fileChooser.showOpenDialog(MainFrame.this);
+ if (rc == JFileChooser.APPROVE_OPTION) {
+ MainFrame.this.textFile = fileChooser.getSelectedFile();
+ if (MainFrame.this.textFile.exists() && MainFrame.this.textFile.isFile()) {
+ MainFrame.this.fileOpenDir = MainFrame.this.textFile.getParentFile();
+ }
+ Timer time = new Timer();
+ time.start();
+ loadFile();
+ time.stop();
+ resetTrees();
+ MainFrame.this.fileSaveItem.setEnabled(true);
+ MainFrame.this.undoMgr.discardAllEdits();
+ setFileStatusMessage();
+ setStatusbarMessage("Done loading text file " + MainFrame.this.textFile.getName() + " in "
+ + time.getTimeSpan() + ".");
+ }
+ }
+ }
+
+ private class NewTextEventHandler implements ActionListener {
+
+ private NewTextEventHandler() {
+ super();
+ }
+
+ public void actionPerformed(ActionEvent event) {
+ MainFrame.this.textFile = null;
+ MainFrame.this.textArea.setText("");
+ if (MainFrame.this.isDirty) {
+ MainFrame.this.isDirty = false;
+ }
+ setTitle();
+ resetTrees();
+ MainFrame.this.fileSaveItem.setEnabled(false);
+ MainFrame.this.undoMgr.discardAllEdits();
+ setFileStatusMessage();
+ setStatusbarMessage("Text area cleared.");
+ }
+
+ }
+
+ private class LoadRecentTextFileEventHandler implements ActionListener {
+
+ private final String fileName;
+
+ private LoadRecentTextFileEventHandler(String fileName) {
+ super();
+ this.fileName = fileName;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ loadTextFile(new File(this.fileName));
+ }
+
+ }
+
+ private class LoadRecentDescFileEventHandler implements ActionListener {
+
+ private final String fileName;
+
+ private LoadRecentDescFileEventHandler(String fileName) {
+ super();
+ this.fileName = fileName;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ loadAEDescriptor(new File(this.fileName));
+ }
+
+ }
+
+ private class FileSaveAsEventHandler implements ActionListener {
+
+ private FileSaveAsEventHandler() {
+ super();
+ }
- /**
+ /**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
- public void actionPerformed(ActionEvent event) {
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setDialogTitle("Save file as...");
- fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
- fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
- if (MainFrame.this.fileOpenDir != null) {
- fileChooser.setCurrentDirectory(MainFrame.this.fileOpenDir);
- }
- int rc = fileChooser.showSaveDialog(MainFrame.this);
- if (rc == JFileChooser.APPROVE_OPTION) {
- File tmp = MainFrame.this.textFile;
- MainFrame.this.textFile = fileChooser.getSelectedFile();
- boolean fileSaved = saveFile();
- if (fileSaved) {
- MainFrame.this.isDirty = false;
- setTitle();
- MainFrame.this.fileSaveItem.setEnabled(true);
- setFileStatusMessage();
- setStatusbarMessage("Text file " + MainFrame.this.textFile.getName() + " saved.");
- } else {
- MainFrame.this.textFile = tmp;
- }
- }
- }
-
- }
-
- private class FileSaveEventHandler implements ActionListener {
-
- private FileSaveEventHandler() {
- super();
- }
-
- public void actionPerformed(ActionEvent event) {
- saveFile();
- setStatusbarMessage("Text file " + MainFrame.this.textFile.getName() + " saved.");
- }
-
- }
-
- private class XCASFileOpenEventHandler implements ActionListener {
-
- private XCASFileOpenEventHandler() {
- super();
- }
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Save file as...");
+ fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
+ if (MainFrame.this.fileOpenDir != null) {
+ fileChooser.setCurrentDirectory(MainFrame.this.fileOpenDir);
+ }
+ int rc = fileChooser.showSaveDialog(MainFrame.this);
+ if (rc == JFileChooser.APPROVE_OPTION) {
+ File tmp = MainFrame.this.textFile;
+ MainFrame.this.textFile = fileChooser.getSelectedFile();
+ boolean fileSaved = saveFile();
+ if (fileSaved) {
+ MainFrame.this.isDirty = false;
+ setTitle();
+ MainFrame.this.fileSaveItem.setEnabled(true);
+ setFileStatusMessage();
+ setStatusbarMessage("Text file " + MainFrame.this.textFile.getName() + " saved.");
+ } else {
+ MainFrame.this.textFile = tmp;
+ }
+ }
+ }
+
+ }
+
+ private class FileSaveEventHandler implements ActionListener {
+
+ private FileSaveEventHandler() {
+ super();
+ }
+
+ public void actionPerformed(ActionEvent event) {
+ saveFile();
+ setStatusbarMessage("Text file " + MainFrame.this.textFile.getName() + " saved.");
+ }
+
+ }
+
+ private class XCASFileOpenEventHandler implements ActionListener {
+
+ private XCASFileOpenEventHandler() {
+ super();
+ }
- /**
+ /**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
- public void actionPerformed(ActionEvent event) {
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setDialogTitle("Open XCAS file");
- if (MainFrame.this.xcasFileOpenDir != null) {
- fileChooser.setCurrentDirectory(MainFrame.this.xcasFileOpenDir);
- }
- int rc = fileChooser.showOpenDialog(MainFrame.this);
- 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);
- }
- }
- }
- }
-
- }
-
- private class TypeSystemFileOpenEventHandler implements ActionListener {
-
- private TypeSystemFileOpenEventHandler() {
- super();
- }
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Open XCAS file");
+ if (MainFrame.this.xcasFileOpenDir != null) {
+ fileChooser.setCurrentDirectory(MainFrame.this.xcasFileOpenDir);
+ }
+ int rc = fileChooser.showOpenDialog(MainFrame.this);
+ 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);
+ }
+ }
+ }
+ }
+
+ }
+
+ private class TypeSystemFileOpenEventHandler implements ActionListener {
+
+ private TypeSystemFileOpenEventHandler() {
+ super();
+ }
- /**
+ /**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
- public void actionPerformed(ActionEvent event) {
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setDialogTitle("Open Type System File");
- if (MainFrame.this.xcasFileOpenDir != null) {
- fileChooser.setCurrentDirectory(MainFrame.this.xcasFileOpenDir);
- }
- int rc = fileChooser.showOpenDialog(MainFrame.this);
- if (rc == JFileChooser.APPROVE_OPTION) {
- File tsFile = fileChooser.getSelectedFile();
- if (tsFile.exists() && tsFile.isFile()) {
- try {
- MainFrame.this.xcasFileOpenDir = tsFile.getParentFile();
- Timer time = new Timer();
- time.start();
- Object descriptor = UIMAFramework.getXMLParser().parse(new XMLInputSource(tsFile));
- // instantiate CAS to get type system. Also build style
- // map file if there is none.
- TypeSystemDescription tsDesc = (TypeSystemDescription) descriptor;
- tsDesc.resolveImports();
- if (MainFrame.this.ae != null) {
- MainFrame.this.ae.destroy();
- MainFrame.this.ae = null;
- }
- MainFrame.this.cas = CasCreationUtils
- .createCas(tsDesc, null, new FsIndexDescription[0]);
- MainFrame.this.runOnCasMenuItem.setEnabled(false);
- MainFrame.this.reRunMenu.setEnabled(false);
- MainFrame.this.textArea.setText("");
- MainFrame.this.resetTrees();
- MainFrame.this.tsViewerItem.setEnabled(true);
- MainFrame.this.xcasReadItem.setEnabled(true);
- time.stop();
- setStatusbarMessage("Done loading type system file in " + time.getTimeSpan() + ".");
- } catch (Exception e) {
- e.printStackTrace();
- handleException(e);
- }
- }
- }
- }
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Open Type System File");
+ if (MainFrame.this.xcasFileOpenDir != null) {
+ fileChooser.setCurrentDirectory(MainFrame.this.xcasFileOpenDir);
+ }
+ int rc = fileChooser.showOpenDialog(MainFrame.this);
+ if (rc == JFileChooser.APPROVE_OPTION) {
+ File tsFile = fileChooser.getSelectedFile();
+ if (tsFile.exists() && tsFile.isFile()) {
+ try {
+ MainFrame.this.xcasFileOpenDir = tsFile.getParentFile();
+ Timer time = new Timer();
+ time.start();
+ Object descriptor = UIMAFramework.getXMLParser().parse(new XMLInputSource(tsFile));
+ // instantiate CAS to get type system. Also build style
+ // map file if there is none.
+ TypeSystemDescription tsDesc = (TypeSystemDescription) descriptor;
+ tsDesc.resolveImports();
+ if (MainFrame.this.ae != null) {
+ MainFrame.this.ae.destroy();
+ MainFrame.this.ae = null;
+ }
+ MainFrame.this.cas = CasCreationUtils
+ .createCas(tsDesc, null, new FsIndexDescription[0]);
+ MainFrame.this.runOnCasMenuItem.setEnabled(false);
+ MainFrame.this.reRunMenu.setEnabled(false);
+ MainFrame.this.textArea.setText("");
+ MainFrame.this.resetTrees();
+ MainFrame.this.tsViewerItem.setEnabled(true);
+ MainFrame.this.xcasReadItem.setEnabled(true);
+ time.stop();
+ setStatusbarMessage("Done loading type system file in " + time.getTimeSpan() + ".");
+ } catch (Exception e) {
+ e.printStackTrace();
+ handleException(e);
+ }
+ }
+ }
+ }
- }
+ }
- private class ColorPrefsOpenHandler implements ActionListener {
+ private class ColorPrefsOpenHandler implements ActionListener {
- /**
+ /**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
- public void actionPerformed(ActionEvent event) {
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setDialogTitle("Load color preferences file");
- fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
- if (MainFrame.this.colorSettingsDir != null) {
- fileChooser.setCurrentDirectory(MainFrame.this.colorSettingsDir);
- }
- int rc = fileChooser.showOpenDialog(MainFrame.this);
- if (rc == JFileChooser.APPROVE_OPTION) {
- File file = fileChooser.getSelectedFile();
- if (file.exists() && file.isFile()) {
- MainFrame.this.colorSettingsDir = file.getParentFile();
- MainFrame.this.colorSettingFile = file;
- try {
- loadColorPreferences(MainFrame.this.colorSettingFile);
- } catch (IOException e) {
- handleException(e);
- // e.printStackTrace();
- // JOptionPane.showMessageDialog(
- // MainFrame.this,
- // e.getMessage(),
- // "I/O Error",
- // JOptionPane.ERROR_MESSAGE);
- }
- }
- }
- }
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Load color preferences file");
+ fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ if (MainFrame.this.colorSettingsDir != null) {
+ fileChooser.setCurrentDirectory(MainFrame.this.colorSettingsDir);
+ }
+ int rc = fileChooser.showOpenDialog(MainFrame.this);
+ if (rc == JFileChooser.APPROVE_OPTION) {
+ File file = fileChooser.getSelectedFile();
+ if (file.exists() && file.isFile()) {
+ MainFrame.this.colorSettingsDir = file.getParentFile();
+ MainFrame.this.colorSettingFile = file;
+ try {
+ loadColorPreferences(MainFrame.this.colorSettingFile);
+ } catch (IOException e) {
+ handleException(e);
+ // e.printStackTrace();
+ // JOptionPane.showMessageDialog(
+ // MainFrame.this,
+ // e.getMessage(),
+ // "I/O Error",
+ // JOptionPane.ERROR_MESSAGE);
+ }
+ }
+ }
+ }
- }
+ }
- private class ColorPrefsSaveHandler implements ActionListener {
+ private class ColorPrefsSaveHandler implements ActionListener {
- /**
+ /**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
- public void actionPerformed(ActionEvent event) {
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setDialogTitle("Save color preferences");
- if (MainFrame.this.colorSettingsDir != null) {
- fileChooser.setCurrentDirectory(MainFrame.this.colorSettingsDir);
- }
- int rc = fileChooser.showSaveDialog(MainFrame.this);
- if (rc == JFileChooser.APPROVE_OPTION) {
- File prefFile = fileChooser.getSelectedFile();
- MainFrame.this.colorSettingsDir = prefFile.getParentFile();
- try {
- saveColorPreferences(prefFile);
- } catch (IOException e) {
- handleException(e);
- }
- }
- }
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Save color preferences");
+ if (MainFrame.this.colorSettingsDir != null) {
+ fileChooser.setCurrentDirectory(MainFrame.this.colorSettingsDir);
+ }
+ int rc = fileChooser.showSaveDialog(MainFrame.this);
+ if (rc == JFileChooser.APPROVE_OPTION) {
+ File prefFile = fileChooser.getSelectedFile();
+ MainFrame.this.colorSettingsDir = prefFile.getParentFile();
+ try {
+ saveColorPreferences(prefFile);
+ } catch (IOException e) {
+ handleException(e);
+ }
+ }
+ }
- }
+ }
- private class XCASSaveHandler implements ActionListener {
+ private class XCASSaveHandler implements ActionListener {
- /**
+ /**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
- public void actionPerformed(ActionEvent event) {
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setDialogTitle("Save XCAS file");
- if (MainFrame.this.xcasFileOpenDir != null) {
- fileChooser.setCurrentDirectory(MainFrame.this.xcasFileOpenDir);
- }
- int rc = fileChooser.showSaveDialog(MainFrame.this);
- if (rc == JFileChooser.APPROVE_OPTION) {
- File xcasFile = fileChooser.getSelectedFile();
- MainFrame.this.xcasFileOpenDir = xcasFile.getParentFile();
- try {
- long time = System.currentTimeMillis();
- OutputStream outStream = new BufferedOutputStream(new FileOutputStream(xcasFile));
- XMLSerializer xmlSerializer = new XMLSerializer(outStream);
- XCASSerializer xcasSerializer = new XCASSerializer(MainFrame.this.cas.getTypeSystem());
- xcasSerializer.serialize(MainFrame.this.cas, xmlSerializer.getContentHandler());
- outStream.close();
- time = System.currentTimeMillis() - time;
- System.out.println("Time taken: " + new TimeSpan(time));
- } catch (IOException e) {
- handleException(e);
- } catch (SAXException e) {
- handleException(e);
- }
- }
- }
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Save XCAS file");
+ if (MainFrame.this.xcasFileOpenDir != null) {
+ fileChooser.setCurrentDirectory(MainFrame.this.xcasFileOpenDir);
+ }
+ int rc = fileChooser.showSaveDialog(MainFrame.this);
+ if (rc == JFileChooser.APPROVE_OPTION) {
+ File xcasFile = fileChooser.getSelectedFile();
+ MainFrame.this.xcasFileOpenDir = xcasFile.getParentFile();
+ try {
+ long time = System.currentTimeMillis();
+ OutputStream outStream = new BufferedOutputStream(new FileOutputStream(xcasFile));
+ XMLSerializer xmlSerializer = new XMLSerializer(outStream);
+ XCASSerializer xcasSerializer = new XCASSerializer(MainFrame.this.cas.getTypeSystem());
+ xcasSerializer.serialize(MainFrame.this.cas, xmlSerializer.getContentHandler());
+ outStream.close();
+ time = System.currentTimeMillis() - time;
+ System.out.println("Time taken: " + new TimeSpan(time));
+ } catch (IOException e) {
+ handleException(e);
+ } catch (SAXException e) {
+ handleException(e);
+ }
+ }
+ }
- }
+ }
- private class XCASSaveTSHandler implements ActionListener {
+ private class XCASSaveTSHandler implements ActionListener {
- /**
+ /**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
- public void actionPerformed(ActionEvent event) {
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setDialogTitle("Save type system file");
- if (MainFrame.this.xcasFileOpenDir != null) {
- fileChooser.setCurrentDirectory(MainFrame.this.xcasFileOpenDir);
- }
- int rc = fileChooser.showSaveDialog(MainFrame.this);
- if (rc == JFileChooser.APPROVE_OPTION) {
- File tsFile = fileChooser.getSelectedFile();
- MainFrame.this.xcasFileOpenDir = tsFile.getParentFile();
- try {
- OutputStream outStream = new BufferedOutputStream(new FileOutputStream(tsFile));
- TypeSystem2Xml.typeSystem2Xml(MainFrame.this.cas.getTypeSystem(), outStream);
- outStream.close();
- } catch (IOException e) {
- handleException(e);
- } catch (SAXException e) {
- handleException(e);
- }
- }
- }
-
- }
-
- private class SystemExitHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent event) {
- try {
- saveProgramPreferences();
- } catch (IOException e) {
- handleException(e);
- }
- System.exit(0);
- }
-
- }
-
- private class AnnotatorOpenEventHandler implements ActionListener {
-
- private MainFrame frame;
-
- private AnnotatorOpenEventHandler(MainFrame frame) {
- super();
- this.frame = frame;
- }
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Save type system file");
+ if (MainFrame.this.xcasFileOpenDir != null) {
+ fileChooser.setCurrentDirectory(MainFrame.this.xcasFileOpenDir);
+ }
+ int rc = fileChooser.showSaveDialog(MainFrame.this);
+ if (rc == JFileChooser.APPROVE_OPTION) {
+ File tsFile = fileChooser.getSelectedFile();
+ MainFrame.this.xcasFileOpenDir = tsFile.getParentFile();
+ try {
+ OutputStream outStream = new BufferedOutputStream(new FileOutputStream(tsFile));
+ TypeSystem2Xml.typeSystem2Xml(MainFrame.this.cas.getTypeSystem(), outStream);
+ outStream.close();
+ } catch (IOException e) {
+ handleException(e);
+ } catch (SAXException e) {
+ handleException(e);
+ }
+ }
+ }
+
+ }
+
+ private class SystemExitHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent event) {
+ try {
+ saveProgramPreferences();
+ } catch (IOException e) {
+ handleException(e);
+ }
+ System.exit(0);
+ }
+
+ }
+
+ private class AnnotatorOpenEventHandler implements ActionListener {
+
+ private MainFrame frame;
+
+ private AnnotatorOpenEventHandler(MainFrame frame) {
+ super();
+ this.frame = frame;
+ }
- /**
+ /**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
- public void actionPerformed(ActionEvent event) {
- try {
- JFileChooser fileChooser = new JFileChooser();
- fileChooser.setDialogTitle("Load AE specifier file");
- fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
- if (MainFrame.this.annotOpenDir != null) {
- fileChooser.setCurrentDirectory(MainFrame.this.annotOpenDir);
- }
- int rc = fileChooser.showOpenDialog(this.frame);
- if (rc == JFileChooser.APPROVE_OPTION) {
- MainFrame.this.aeDescriptorFile = fileChooser.getSelectedFile();
- loadAEDescriptor(MainFrame.this.aeDescriptorFile);
- }
- MainFrame.this.allAnnotViewerItem.setEnabled(false);
- } finally {
- resetCursor();
- }
- }
-
- }
-
- private class SofaSelectionListener implements ItemListener {
-
- public void itemStateChanged(ItemEvent e) {
- if (MainFrame.this.disableSofaListener) {
- return;
- }
- if (e.getSource() == MainFrame.this.sofaSelectionComboBox) {
- // a new sofa was selected. Switch to that view and update
- // display
- String sofaId = (String) e.getItem();
- MainFrame.this.cas = MainFrame.this.cas.getView(sofaId);
- 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.updateIndexTree(true);
- }
- }
- }
-
- public void loadAEDescriptor(File descriptorFile) {
- setWaitCursor();
- if (descriptorFile.exists() && descriptorFile.isFile()) {
- this.annotOpenDir = descriptorFile.getParentFile();
- }
- Timer time = new Timer();
- time.start();
- boolean success = false;
- try {
- success = setupAE(descriptorFile);
- } catch (Exception e) {
- handleException(e);
- } catch (NoClassDefFoundError e) {
- // We don't want to catch all errors, but some are ok.
- handleException(e);
- }
- time.stop();
- addRecentDescFile(descriptorFile);
- if (!success) {
- setStatusbarMessage("Failed to load AE specifier: " + descriptorFile.getName());
- this.reRunMenu.setText("Run AE");
- setAEStatusMessage();
- resetCursor();
- return;
- }
- if (this.ae != null) {
- String annotName = this.ae.getAnalysisEngineMetaData().getName();
- this.reRunMenu.setText("Run " + annotName);
- this.reRunMenu.setEnabled(true);
- this.runOnCasMenuItem.setText("Run " + annotName + " on CAS");
- setAEStatusMessage();
- setStatusbarMessage("Done loading AE " + annotName + " in " + time.getTimeSpan() + ".");
- }
- resetCursor();
- }
+ public void actionPerformed(ActionEvent event) {
+ try {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Load AE specifier file");
+ fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
+ if (MainFrame.this.annotOpenDir != null) {
+ fileChooser.setCurrentDirectory(MainFrame.this.annotOpenDir);
+ }
+ int rc = fileChooser.showOpenDialog(this.frame);
+ if (rc == JFileChooser.APPROVE_OPTION) {
+ MainFrame.this.aeDescriptorFile = fileChooser.getSelectedFile();
+ loadAEDescriptor(MainFrame.this.aeDescriptorFile);
+ }
+ MainFrame.this.allAnnotViewerItem.setEnabled(false);
+ } finally {
+ resetCursor();
+ }
+ }
+
+ }
+
+ private class SofaSelectionListener implements ItemListener {
+
+ public void itemStateChanged(ItemEvent e) {
+ if (MainFrame.this.disableSofaListener) {
+ return;
+ }
+ if (e.getSource() == MainFrame.this.sofaSelectionComboBox) {
+ // a new sofa was selected. Switch to that view and update
+ // display
+ String sofaId = (String) e.getItem();
+ MainFrame.this.cas = MainFrame.this.cas.getView(sofaId);
+ 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.updateIndexTree(true);
+ }
+ }
+ }
+
+ public void loadAEDescriptor(File descriptorFile) {
+ setWaitCursor();
+ if (descriptorFile.exists() && descriptorFile.isFile()) {
+ this.annotOpenDir = descriptorFile.getParentFile();
+ }
+ Timer time = new Timer();
+ time.start();
+ boolean success = false;
+ try {
+ success = setupAE(descriptorFile);
+ } catch (Exception e) {
+ handleException(e);
+ } catch (NoClassDefFoundError e) {
+ // We don't want to catch all errors, but some are ok.
+ handleException(e);
+ }
+ time.stop();
+ addRecentDescFile(descriptorFile);
+ if (!success) {
+ setStatusbarMessage("Failed to load AE specifier: " + descriptorFile.getName());
+ this.reRunMenu.setText("Run AE");
+ setAEStatusMessage();
+ resetCursor();
+ return;
+ }
+ if (this.ae != null) {
+ String annotName = this.ae.getAnalysisEngineMetaData().getName();
+ this.reRunMenu.setText("Run " + annotName);
+ this.reRunMenu.setEnabled(true);
+ this.runOnCasMenuItem.setText("Run " + annotName + " on CAS");
+ setAEStatusMessage();
+ setStatusbarMessage("Done loading AE " + annotName + " in " + time.getTimeSpan() + ".");
+ }
+ resetCursor();
+ }
- private class AnnotatorRerunEventHandler implements ActionListener {
+ private class AnnotatorRerunEventHandler implements ActionListener {
- /**
+ /**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
- public void actionPerformed(ActionEvent event) {
- runAE(true);
- }
- }
+ public void actionPerformed(ActionEvent event) {
+ runAE(true);
+ }
+ }
- private class AnnotatorRunOnCasEventHandler implements ActionListener {
+ private class AnnotatorRunOnCasEventHandler implements ActionListener {
- /**
+ /**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
- public void actionPerformed(ActionEvent event) {
- runAE(false);
- }
- }
-
- public void runAE(boolean doCasReset) {
- setStatusbarMessage("Running Annotator.");
- Timer timer = new Timer();
- timer.start();
- if (this.ae == null) {
- JOptionPane.showMessageDialog(this, "No AE loaded.", "Error", JOptionPane.ERROR_MESSAGE);
- return;
- }
- internalRunAE(doCasReset);
- timer.stop();
- setStatusbarMessage("Done running AE " + this.ae.getAnalysisEngineMetaData().getName() + " in "
- + timer.getTimeSpan() + ".");
- updateIndexTree(true);
- this.allAnnotViewerItem.setEnabled(false);
- this.isDirty = false;
- this.runOnCasMenuItem.setEnabled(true);
- }
-
- // Get the size of the window so we can save it for later use.
- private class CloseTypeSystemHandler extends WindowAdapter implements WindowListener {
-
- public void windowClosing(WindowEvent event) {
- JComponent tsContentPane = (JComponent) ((JFrame) event.getComponent()).getContentPane();
- final int x = tsContentPane.getWidth();
- final int y = tsContentPane.getHeight();
- MainFrame.this.prefs.setProperty(tsWindowSizePref + widthSuffix, Integer.toString(x));
- MainFrame.this.prefs.setProperty(tsWindowSizePref + heightSuffix, Integer.toString(y));
- }
-
- }
-
- private class CloseAnnotationViewHandler extends WindowAdapter implements WindowListener {
-
- public void windowClosing(WindowEvent event) {
- JComponent tsContentPane = (JComponent) ((JFrame) event.getComponent()).getContentPane();
- final int x = tsContentPane.getWidth();
- final int y = tsContentPane.getHeight();
- MainFrame.this.prefs.setProperty(annotViewSizePref + widthSuffix, Integer.toString(x));
- MainFrame.this.prefs.setProperty(annotViewSizePref + heightSuffix, Integer.toString(y));
- }
-
- }
-
- private class CloseLogViewHandler extends WindowAdapter implements WindowListener {
-
- public void windowClosing(WindowEvent event) {
- JComponent contentPane = (JComponent) ((JFrame) event.getComponent()).getContentPane();
- final int x = contentPane.getWidth();
- final int y = contentPane.getHeight();
- MainFrame.this.prefs.setProperty(logViewSizePref + widthSuffix, Integer.toString(x));
- MainFrame.this.prefs.setProperty(logViewSizePref + heightSuffix, Integer.toString(y));
- }
+ public void actionPerformed(ActionEvent event) {
+ runAE(false);
+ }
+ }
+
+ public void runAE(boolean doCasReset) {
+ setStatusbarMessage("Running Annotator.");
+ Timer timer = new Timer();
+ timer.start();
+ if (this.ae == null) {
+ JOptionPane.showMessageDialog(this, "No AE loaded.", "Error", JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ internalRunAE(doCasReset);
+ timer.stop();
+ setStatusbarMessage("Done running AE " + this.ae.getAnalysisEngineMetaData().getName() + " in "
+ + timer.getTimeSpan() + ".");
+ updateIndexTree(true);
+ this.allAnnotViewerItem.setEnabled(false);
+ this.isDirty = false;
+ this.runOnCasMenuItem.setEnabled(true);
+ }
+
+ // Get the size of the window so we can save it for later use.
+ private class CloseTypeSystemHandler extends WindowAdapter implements WindowListener {
+
+ public void windowClosing(WindowEvent event) {
+ JComponent tsContentPane = (JComponent) ((JFrame) event.getComponent()).getContentPane();
+ final int x = tsContentPane.getWidth();
+ final int y = tsContentPane.getHeight();
+ MainFrame.this.prefs.setProperty(tsWindowSizePref + widthSuffix, Integer.toString(x));
+ MainFrame.this.prefs.setProperty(tsWindowSizePref + heightSuffix, Integer.toString(y));
+ }
+
+ }
+
+ private class CloseAnnotationViewHandler extends WindowAdapter implements WindowListener {
+
+ public void windowClosing(WindowEvent event) {
+ JComponent tsContentPane = (JComponent) ((JFrame) event.getComponent()).getContentPane();
+ final int x = tsContentPane.getWidth();
+ final int y = tsContentPane.getHeight();
+ MainFrame.this.prefs.setProperty(annotViewSizePref + widthSuffix, Integer.toString(x));
+ MainFrame.this.prefs.setProperty(annotViewSizePref + heightSuffix, Integer.toString(y));
+ }
+
+ }
+
+ private class CloseLogViewHandler extends WindowAdapter implements WindowListener {
+
+ public void windowClosing(WindowEvent event) {
+ JComponent contentPane = (JComponent) ((JFrame) event.getComponent()).getContentPane();
+ final int x = contentPane.getWidth();
+ final int y = contentPane.getHeight();
+ MainFrame.this.prefs.setProperty(logViewSizePref + widthSuffix, Integer.toString(x));
+ MainFrame.this.prefs.setProperty(logViewSizePref + heightSuffix, Integer.toString(y));
+ }
- }
+ }
- private class ShowTypesystemHandler implements ActionListener {
+ private class ShowTypesystemHandler implements ActionListener {
- /**
+ /**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
- public void actionPerformed(ActionEvent event) {
- if (MainFrame.this.cas == null) {
- return;
- }
- org.apache.uima.tools.annot_view.ts_editor.MainFrame tsFrame = new org.apache.uima.tools.annot_view.ts_editor.MainFrame();
- tsFrame.addWindowListener(new CloseTypeSystemHandler());
- JComponent tsContentPane = (JComponent) tsFrame.getContentPane();
- MainFrame.this.setPreferredSize(tsContentPane, tsWindowSizePref);
- tsFrame.setTypeSystem(MainFrame.this.cas.getTypeSystem());
- tsFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
- tsFrame.pack();
- tsFrame.setVisible(true);
- }
-
- }
-
- private class SetDataPathHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent arg0) {
- String result = (String) JOptionPane.showInputDialog(MainFrame.this, "Specify the data path",
- "Set data path", JOptionPane.PLAIN_MESSAGE, null, null, MainFrame.this.dataPathName);
-
- if (result != null) {
- MainFrame.this.setDataPath(result);
- }
- }
-
- }
-
- public void setDataPath(String dataPath) {
- this.dataPathName = dataPath;
- }
-
- private class SetCodePageHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent e) {
- JRadioButtonMenuItem item = (JRadioButtonMenuItem) e.getSource();
- MainFrame.this.codePage = item.getText();
- }
-
- }
-
- private class RemoveCodePageHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent e) {
- String cp = ((JMenuItem) e.getSource()).getText();
- if (MainFrame.this.codePage.equals(cp)) {
- MainFrame.this.codePage = null;
- }
- MainFrame.this.codePages.remove(cp);
- resetCPMenu();
- }
-
- }
-
- private class SetLanguageHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent e) {
- JRadioButtonMenuItem item = (JRadioButtonMenuItem) e.getSource();
- MainFrame.this.language = item.getText();
- }
-
- }
-
- private class RemoveLanguageHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent e) {
- String lang = ((JMenuItem) e.getSource()).getText();
- if (MainFrame.this.language.equals(lang)) {
- MainFrame.this.language = null;
- }
- MainFrame.this.languages.remove(lang);
- resetLangMenu();
- }
-
- }
-
- private class RestoreLangDefaultsHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent e) {
- MainFrame.this.language = null;
- MainFrame.this.languagePrefsList = null;
- createLanguages();
- resetLangMenu();
- }
-
- }
-
- private class RestoreCPDefaultsHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent e) {
- MainFrame.this.codePage = null;
- MainFrame.this.codePagePrefsList = null;
- createCodePages();
- resetCPMenu();
- }
-
- }
-
- private class ShowAnnotatedTextHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent event) {
- String title = MainFrame.this.indexLabel + " - " + MainFrame.this.index.getType().getName();
- MultiAnnotViewerFrame f = new MultiAnnotViewerFrame(title);
- f.addWindowListener(new CloseAnnotationViewHandler());
- FSIterator it = MainFrame.this.index.iterator();
- final String text = MainFrame.this.cas.getDocumentText();
- System.out.println("Creating extents.");
- AnnotationExtent[] extents = MultiMarkup.createAnnotationMarkups(it, text.length(),
- MainFrame.this.styleMap);
- System.out.println("Initializing text frame.");
- f.init(text, extents, getDimension(MainFrame.annotViewSizePref));
- System.out.println("Done.");
- }
-
- }
-
- private class ShowAnnotationCustomizerHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent event) {
- AnnotationDisplayCustomizationFrame acd = new AnnotationDisplayCustomizationFrame(
- "Customize Annotation Display");
- acd.init(MainFrame.this.styleMap, MainFrame.this.cas);
- acd.pack();
- acd.setVisible(true);
- }
-
- }
-
- private class AddCPHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent arg0) {
- String input = JOptionPane.showInputDialog(MainFrame.this, "Add new code page option");
- if (input != null && input.length() > 0) {
- addCodePage(input);
- }
- }
-
- }
-
- private class AddLangHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent arg0) {
- String input = JOptionPane.showInputDialog(MainFrame.this, "Add new language");
- if (input != null && input.length() > 0) {
- addLanguage(input);
- }
- }
-
- }
-
- private class AboutHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent e) {
- String javaVersion = System.getProperty("java.version");
- String javaVendor = System.getProperty("java.vendor");
- javaVendor = (javaVendor == null) ? "<Unknown>" : javaVendor;
- String versionInfo = null;
- if (javaVersion == null) {
- versionInfo = "Running on an old version of Java";
- } else {
- versionInfo = "Running Java " + javaVersion + " from " + javaVendor;
- }
- String msg = "CVD (CAS Visual Debugger)\n" + "Apache UIMA Version "
- + UIMAFramework.getVersionString() + "\n"
- + "Copyright 2006 The Apache Software Foundation\n" + versionInfo + "\n";
- Icon icon = Images.getImageIcon(Images.UIMA_LOGO_SMALL);
- if (icon == null) {
- JOptionPane.showMessageDialog(MainFrame.this, msg, "About CVD",
- JOptionPane.INFORMATION_MESSAGE);
- } else {
- JOptionPane.showMessageDialog(MainFrame.this, msg, "About CVD",
- JOptionPane.INFORMATION_MESSAGE, icon);
- }
- }
-
- }
-
-// private static class WindowClosingMouseListener implements MouseListener {
-//
-// private JWindow window;
-//
-// private WindowClosingMouseListener(JWindow window) {
-// this.window = window;
-// }
-//
-// public void mouseClicked(MouseEvent e) {
-// this.window.dispose();
-// }
-//
-// public void mousePressed(MouseEvent e) {
-// // does nothing
-// }
-//
-// public void mouseReleased(MouseEvent e) {
-// // does nothing
-// }
-//
-// public void mouseEntered(MouseEvent e) {
-// // does nothing
-// }
-//
-// public void mouseExited(MouseEvent e) {
-// // does nothing
-// }
-//
-// }
-
- private class AboutUimaHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent e) {
- AboutDialog dialog = new AboutDialog(MainFrame.this, "About UIMA");
- dialog.setVisible(true);
- }
- }
-
- private class ManualHandler implements ActionListener {
-
- class Hyperactive implements HyperlinkListener {
-
- public void hyperlinkUpdate(HyperlinkEvent e) {
- if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
- JEditorPane pane = (JEditorPane) e.getSource();
- if (e instanceof HTMLFrameHyperlinkEvent) {
- HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
- HTMLDocument doc = (HTMLDocument) pane.getDocument();
- doc.processHTMLFrameHyperlinkEvent(evt);
- } else {
- try {
- pane.setPage(e.getURL());
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- }
- }
- }
-
- public void actionPerformed(ActionEvent event) {
- try {
- String manFileName = "tools/tools.html";
- JFrame manFrame = new JFrame("CVD Manual");
- JEditorPane editorPane = new JEditorPane();
- editorPane.setEditable(false);
- editorPane.addHyperlinkListener(new Hyperactive());
- URL manURL = ClassLoader.getSystemResource(manFileName);
- if (manURL == null) {
- String manpath = System.getProperty(Gladis.MAN_PATH_PROPERTY, null);
- if (manpath != null) {
- File manDir = new File(manpath);
- File manFile = new File(manDir, manFileName);
- if (manFile.exists()) {
- manURL = manFile.toURL();
- }
- }
- }
- if (manURL == null) {
- String msg = "Can't find manual. The manual is loaded via the classpath,\n" +
- "so make sure the manual folder is in the classpath.";
- JOptionPane.showMessageDialog(MainFrame.this, msg, "Error loading manual",
- JOptionPane.ERROR_MESSAGE);
- return;
- }
- editorPane.setPage(manURL);
- JScrollPane scrollPane = new JScrollPane(editorPane);
- scrollPane.setPreferredSize(new Dimension(700, 800));
- manFrame.setContentPane(scrollPane);
- manFrame.pack();
- manFrame.setVisible(true);
- URL cvdLinkUrl = new URL(manURL.toString() + "#ugr.tools.cvd");
- HyperlinkEvent e = new HyperlinkEvent(editorPane, HyperlinkEvent.EventType.ACTIVATED, cvdLinkUrl);
- editorPane.fireHyperlinkUpdate(e);
- } catch (Exception e) {
- handleException(e);
- }
- }
-
- }
-
- private class HelpHandler implements ActionListener {
-
- public void actionPerformed(ActionEvent event) {
- String msg = "There is currently no online help."
- + "\nPlease find documentation on CVD and UIMA"
- + "\nin the doc directory of the UIMA installation";
- JOptionPane.showMessageDialog(MainFrame.this, msg, "Help", JOptionPane.INFORMATION_MESSAGE);
- }
-
- }
-
- private class UndoMgr extends UndoManager implements ActionListener {
-
- private static final long serialVersionUID = 7677701629555379146L;
-
- public void actionPerformed(ActionEvent arg0) {
- undo();
- if (!canUndo()) {
- MainFrame.this.undoItem.setEnabled(false);
- }
- }
-
- public synchronized boolean addEdit(UndoableEdit arg0) {
- MainFrame.this.undoItem.setEnabled(true);
- return super.addEdit(arg0);
- }
+ public void actionPerformed(ActionEvent event) {
+ if (MainFrame.this.cas == null) {
+ return;
+ }
+ org.apache.uima.tools.annot_view.ts_editor.MainFrame tsFrame = new org.apache.uima.tools.annot_view.ts_editor.MainFrame();
+ tsFrame.addWindowListener(new CloseTypeSystemHandler());
+ JComponent tsContentPane = (JComponent) tsFrame.getContentPane();
+ MainFrame.this.setPreferredSize(tsContentPane, tsWindowSizePref);
+ tsFrame.setTypeSystem(MainFrame.this.cas.getTypeSystem());
+ tsFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+ tsFrame.pack();
+ tsFrame.setVisible(true);
+ }
+
+ }
+
+ private class SetDataPathHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent arg0) {
+ String result = (String) JOptionPane.showInputDialog(MainFrame.this, "Specify the data path",
+ "Set data path", JOptionPane.PLAIN_MESSAGE, null, null, MainFrame.this.dataPathName);
+
+ if (result != null) {
+ MainFrame.this.setDataPath(result);
+ }
+ }
+
+ }
+
+ public void setDataPath(String dataPath) {
+ this.dataPathName = dataPath;
+ }
+
+ private class SetCodePageHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent e) {
+ JRadioButtonMenuItem item = (JRadioButtonMenuItem) e.getSource();
+ MainFrame.this.codePage = item.getText();
+ }
+
+ }
+
+ private class RemoveCodePageHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent e) {
+ String cp = ((JMenuItem) e.getSource()).getText();
+ if (MainFrame.this.codePage.equals(cp)) {
+ MainFrame.this.codePage = null;
+ }
+ MainFrame.this.codePages.remove(cp);
+ resetCPMenu();
+ }
+
+ }
+
+ private class SetLanguageHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent e) {
+ JRadioButtonMenuItem item = (JRadioButtonMenuItem) e.getSource();
+ MainFrame.this.language = item.getText();
+ }
+
+ }
+
+ private class RemoveLanguageHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent e) {
+ String lang = ((JMenuItem) e.getSource()).getText();
+ if (MainFrame.this.language.equals(lang)) {
+ MainFrame.this.language = null;
+ }
+ MainFrame.this.languages.remove(lang);
+ resetLangMenu();
+ }
+
+ }
+
+ private class RestoreLangDefaultsHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent e) {
+ MainFrame.this.language = null;
+ MainFrame.this.languagePrefsList = null;
+ createLanguages();
+ resetLangMenu();
+ }
+
+ }
+
+ private class RestoreCPDefaultsHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent e) {
+ MainFrame.this.codePage = null;
+ MainFrame.this.codePagePrefsList = null;
+ createCodePages();
+ resetCPMenu();
+ }
+
+ }
+
+ private class ShowAnnotatedTextHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent event) {
+ String title = MainFrame.this.indexLabel + " - " + MainFrame.this.index.getType().getName();
+ MultiAnnotViewerFrame f = new MultiAnnotViewerFrame(title);
+ f.addWindowListener(new CloseAnnotationViewHandler());
+ FSIterator it = MainFrame.this.index.iterator();
+ final String text = MainFrame.this.cas.getDocumentText();
+ System.out.println("Creating extents.");
+ AnnotationExtent[] extents = MultiMarkup.createAnnotationMarkups(it, text.length(),
+ MainFrame.this.styleMap);
+ System.out.println("Initializing text frame.");
+ f.init(text, extents, getDimension(MainFrame.annotViewSizePref));
+ System.out.println("Done.");
+ }
+
+ }
+
+ private class ShowAnnotationCustomizerHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent event) {
+ AnnotationDisplayCustomizationFrame acd = new AnnotationDisplayCustomizationFrame(
+ "Customize Annotation Display");
+ acd.init(MainFrame.this.styleMap, MainFrame.this.cas);
+ acd.pack();
+ acd.setVisible(true);
+ }
+
+ }
+
+ private class AddCPHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent arg0) {
+ String input = JOptionPane.showInputDialog(MainFrame.this, "Add new code page option");
+ if (input != null && input.length() > 0) {
+ addCodePage(input);
+ }
+ }
+
+ }
+
+ private class AddLangHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent arg0) {
+ String input = JOptionPane.showInputDialog(MainFrame.this, "Add new language");
+ if (input != null && input.length() > 0) {
+ addLanguage(input);
+ }
+ }
+
+ }
+
+ private class AboutHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent e) {
+ String javaVersion = System.getProperty("java.version");
+ String javaVendor = System.getProperty("java.vendor");
+ javaVendor = (javaVendor == null) ? "<Unknown>" : javaVendor;
+ String versionInfo = null;
+ if (javaVersion == null) {
+ versionInfo = "Running on an old version of Java";
+ } else {
+ versionInfo = "Running Java " + javaVersion + " from " + javaVendor;
+ }
+ String msg = "CVD (CAS Visual Debugger)\n" + "Apache UIMA Version "
+ + UIMAFramework.getVersionString() + "\n"
+ + "Copyright 2006 The Apache Software Foundation\n" + versionInfo + "\n";
+ Icon icon = Images.getImageIcon(Images.UIMA_LOGO_SMALL);
+ if (icon == null) {
+ JOptionPane.showMessageDialog(MainFrame.this, msg, "About CVD",
+ JOptionPane.INFORMATION_MESSAGE);
+ } else {
+ JOptionPane.showMessageDialog(MainFrame.this, msg, "About CVD",
+ JOptionPane.INFORMATION_MESSAGE, icon);
+ }
+ }
+
+ }
+
+ // private static class WindowClosingMouseListener implements MouseListener {
+ //
+ // private JWindow window;
+ //
+ // private WindowClosingMouseListener(JWindow window) {
+ // this.window = window;
+ // }
+ //
+ // public void mouseClicked(MouseEvent e) {
+ // this.window.dispose();
+ // }
+ //
+ // public void mousePressed(MouseEvent e) {
+ // // does nothing
+ // }
+ //
+ // public void mouseReleased(MouseEvent e) {
+ // // does nothing
+ // }
+ //
+ // public void mouseEntered(MouseEvent e) {
+ // // does nothing
+ // }
+ //
+ // public void mouseExited(MouseEvent e) {
+ // // does nothing
+ // }
+ //
+ // }
+
+ private class AboutUimaHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent e) {
+ AboutDialog dialog = new AboutDialog(MainFrame.this, "About UIMA");
+ dialog.setVisible(true);
+ }
+ }
+
+ private class ManualHandler implements ActionListener {
+
+ class Hyperactive implements HyperlinkListener {
+
+ public void hyperlinkUpdate(HyperlinkEvent e) {
+ if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
+ JEditorPane pane = (JEditorPane) e.getSource();
+ if (e instanceof HTMLFrameHyperlinkEvent) {
+ HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
+ HTMLDocument doc = (HTMLDocument) pane.getDocument();
+ doc.processHTMLFrameHyperlinkEvent(evt);
+ } else {
+ try {
+ pane.setPage(e.getURL());
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+ public void actionPerformed(ActionEvent event) {
+ try {
+ String manFileName = "tools/tools.html";
+ JFrame manFrame = new JFrame("CVD Manual");
+ JEditorPane editorPane = new JEditorPane();
+ editorPane.setEditable(false);
+ editorPane.addHyperlinkListener(new Hyperactive());
+ URL manURL = ClassLoader.getSystemResource(manFileName);
+ if (manURL == null) {
+ String manpath = System.getProperty(Gladis.MAN_PATH_PROPERTY, null);
+ if (manpath != null) {
+ File manDir = new File(manpath);
+ File manFile = new File(manDir, manFileName);
+ if (manFile.exists()) {
+ manURL = manFile.toURL();
+ }
+ }
+ }
+ if (manURL == null) {
+ String msg = "Can't find manual. The manual is loaded via the classpath,\n"
+ + "so make sure the manual folder is in the classpath.";
+ JOptionPane.showMessageDialog(MainFrame.this, msg, "Error loading manual",
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
+ editorPane.setPage(manURL);
+ JScrollPane scrollPane = new JScrollPane(editorPane);
+ scrollPane.setPreferredSize(new Dimension(700, 800));
+ manFrame.setContentPane(scrollPane);
+ manFrame.pack();
+ manFrame.setVisible(true);
+ URL cvdLinkUrl = new URL(manURL.toString() + "#ugr.tools.cvd");
+ HyperlinkEvent e = new HyperlinkEvent(editorPane, HyperlinkEvent.EventType.ACTIVATED,
+ cvdLinkUrl);
+ editorPane.fireHyperlinkUpdate(e);
+ } catch (Exception e) {
+ handleException(e);
+ }
+ }
+
+ }
+
+ private class HelpHandler implements ActionListener {
+
+ public void actionPerformed(ActionEvent event) {
+ String msg = "There is currently no online help."
+ + "\nPlease find documentation on CVD and UIMA"
+ + "\nin the doc directory of the UIMA installation";
+ JOptionPane.showMessageDialog(MainFrame.this, msg, "Help", JOptionPane.INFORMATION_MESSAGE);
+ }
+
+ }
+
+ private class UndoMgr extends UndoManager implements ActionListener {
+
+ private static final long serialVersionUID = 7677701629555379146L;
+
+ public void actionPerformed(ActionEvent arg0) {
+ undo();
+ if (!canUndo()) {
+ MainFrame.this.undoItem.setEnabled(false);
+ }
+ }
+
+ public synchronized boolean addEdit(UndoableEdit arg0) {
+ MainFrame.this.undoItem.setEnabled(true);
+ return super.addEdit(arg0);
+ }
- /*
+ /*
* (non-Javadoc)
*
* @see javax.swing.undo.UndoManager#discardAllEdits()
*/
- public synchronized void discardAllEdits() {
- super.discardAllEdits();
- MainFrame.this.undoItem.setEnabled(false);
- }
+ public synchronized void discardAllEdits() {
+ super.discardAllEdits();
+ MainFrame.this.undoItem.setEnabled(false);
+ }
- }
-
- private static final String loggerPropertiesFileName = "org/apache/uima/tools/annot_view/Logger.properties";
+ }
- private static final String defaultText =
- // "Load a text file and/or edit text here.";
- "Load or edit text here.";
+ private static final String loggerPropertiesFileName = "org/apache/uima/tools/annot_view/Logger.properties";
- private static final String titleText = "CAS Visual Debugger (CVD)";
+ private static final String defaultText =
+ // "Load a text file and/or edit text here.";
+ "Load or edit text here.";
- static final String htmlGrayColor = "<font color=#808080>";
+ private static final String titleText = "CAS Visual Debugger (CVD)";
- private static final String indexReposRootLabel = "<html><b>CAS Index Repository</b></html>";
+ static final String htmlGrayColor = "<font color=#808080>";
- private static final String noIndexReposLabel = "<html><b>" + htmlGrayColor
- + "CAS Index Repository</b></html>";
+ private static final String indexReposRootLabel = "<html><b>CAS Index Repository</b></html>";
- // private static final String noIndexReposLabel = indexReposRootLabel;
+ private static final String noIndexReposLabel = "<html><b>" + htmlGrayColor
+ + "CAS Index Repository</b></html>";
- // The content areas.
- protected JTextArea textArea;
+ // private static final String noIndexReposLabel = indexReposRootLabel;
- private JTree indexTree;
+ // The content areas.
+ protected JTextArea textArea;
- private JTree fsTree;
+ private JTree indexTree;
- private JPanel statusPanel;
+ private JTree fsTree;
- private JTextField statusBar;
+ private JPanel statusPanel;
- private JTextField fileStatus;
+ private JTextField statusBar;
- private JTextField aeStatus;
+ private JTextField fileStatus;
- private JTextField caretStatus;
+ private JTextField aeStatus;
- private Border textTitleBorder;
+ private JTextField caretStatus;
- // Dirty flag for the editor.
- private boolean isDirty;
+ private Border textTitleBorder;
- // The scroll panels.
- private JScrollPane textScrollPane;
+ // Dirty flag for the editor.
+ private boolean isDirty;
- private JScrollPane indexTreeScrollPane;
+ // The scroll panels.
+ private JScrollPane textScrollPane;
- private JScrollPane fsTreeScrollPane;
+ private JScrollPane indexTreeScrollPane;
- // Menus
- protected JMenu fileMenu = null;
+ private JScrollPane fsTreeScrollPane;
- private JMenuItem fileSaveItem = null;
+ // Menus
+ protected JMenu fileMenu = null;
- private JMenu editMenu;
+ private JMenuItem fileSaveItem = null;
- private JMenuItem undoItem;
+ private JMenu editMenu;
- private UndoMgr undoMgr;
+ private JMenuItem undoItem;
- private Action cutAction;
+ private UndoMgr undoMgr;
- private Action copyAction;
+ private Action cutAction;
- private JMenuItem allAnnotViewerItem;
+ private Action copyAction;
- private JMenuItem acdItem;
+ private JMenuItem allAnnotViewerItem;
- private JMenuItem tsViewerItem;
+ private JMenuItem acdItem;
- private JMenuItem reRunMenu;
+ private JMenuItem tsViewerItem;
- private JMenuItem runOnCasMenuItem;
+ private JMenuItem reRunMenu;
- private JPopupMenu textPopup;
+ private JMenuItem runOnCasMenuItem;
- private JMenuItem xcasReadItem;
+ private JPopupMenu textPopup;
- private JMenuItem xcasWriteItem;
+ private JMenuItem xcasReadItem;
- private JMenuItem typeSystemWriteItem;
+ private JMenuItem xcasWriteItem;
- private JMenuItem typeSystemReadItem;
+ private JMenuItem typeSystemWriteItem;
- private JMenu recentTextFileMenu;
+ private JMenuItem typeSystemReadItem;
- private JMenu recentDescFileMenu;
+ private JMenu recentTextFileMenu;
- // Code page support
- private String codePagePrefsList = null;
+ private JMenu recentDescFileMenu;
- private ArrayList codePages = null;
+ // Code page support
+ private String codePagePrefsList = null;
- private String codePage = null;
+ private ArrayList codePages = null;
- private JMenu cpMenu;
+ private String codePage = null;
- private ButtonGroup cpButtons;
+ private JMenu cpMenu;
- private static final String defaultCodePages = "US-ASCII,ISO-8859-1,UTF-8,UTF-16BE,UTF-16LE,UTF-16";
+ private ButtonGroup cpButtons;
- // Language support
- private String languagePrefsList = null;
+ private static final String defaultCodePages = "US-ASCII,ISO-8859-1,UTF-8,UTF-16BE,UTF-16LE,UTF-16";
- // private String defaultLanguagePref = null;
- private ArrayList languages = null;
+ // Language support
+ private String languagePrefsList = null;
- private JMenu langMenu;
+ // private String defaultLanguagePref = null;
+ private ArrayList languages = null;
- private ButtonGroup langButtons;
+ private JMenu langMenu;
- private static final String LANGUAGE_DEFAULT = "en";
+ private ButtonGroup langButtons;
- private String language;
+ private static final String LANGUAGE_DEFAULT = "en";
- private static final String defaultLanguages = "de,en,fr,ja,ko-kr,pt-br,zh-cn,zh-tw,x-unspecified";
+ private String language;
- protected File textFile = null;
+ private static final String defaultLanguages = "de,en,fr,ja,ko-kr,pt-br,zh-cn,zh-tw,x-unspecified";
- private File fileOpenDir = null;
+ protected File textFile = null;
- private File annotOpenDir = null;
+ private File fileOpenDir = null;
- private File xcasFileOpenDir = null;
+ private File annotOpenDir = null;
- private File colorSettingsDir = null;
+ private File xcasFileOpenDir = null;
- // Selected index
- private String indexLabel = null;
+ private File colorSettingsDir = null;
- private FSIndex index = null;
+ // Selected index
+ private String indexLabel = null;
- private boolean isAnnotIndex = false;
+ private FSIndex index = null;
- // private ArrayList runConfigs;
+ private boolean isAnnotIndex = false;
- protected CAS cas = null;
+ // private ArrayList runConfigs;
- private File aeDescriptorFile = null;
+ protected CAS cas = null;
- private AnalysisEngine ae = null;
+ private File aeDescriptorFile = null;
- private File logFile = null;
+ private AnalysisEngine ae = null;
- private PrintStream logStream = null;
+ private File logFile = null;
- private Logger log = null;
+ // private PrintStream logStream = null;
- private File colorSettingFile;
+ private Logger log = null;
- private static final Color selectionColor = Color.orange;
+ private File colorSettingFile;
- private Properties prefs;
+ private static final Color selectionColor = Color.orange;
- private static final String textDirPref = "dir.open.text";
+ private Properties prefs;
- private static final String aeDirPref = "dir.open.tae";
+ private static final String textDirPref = "dir.open.text";
- private static final String xcasDirPref = "dir.open.xcas";
+ private static final String aeDirPref = "dir.open.tae";
- private static final String textSizePref = "textArea.size";
+ private static final String xcasDirPref = "dir.open.xcas";
[... 2983 lines stripped ...]