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/18 14:16:11 UTC
svn commit: r539414 [2/2] - in
/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd:
./ control/
Added: 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=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/IndexTreeSelectionListener.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/IndexTreeSelectionListener.java Fri May 18 05:16:09 2007
@@ -0,0 +1,58 @@
+package org.apache.uima.tools.cvd.control;
+
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.tools.cvd.IndexTreeNode;
+import org.apache.uima.tools.cvd.MainFrame;
+import org.apache.uima.tools.cvd.TypeTreeNode;
+
+/**
+ * Change the display of the FSTree if a type in an index is selected.
+ */
+public class IndexTreeSelectionListener implements TreeSelectionListener {
+
+ private final MainFrame main;
+
+ public IndexTreeSelectionListener(MainFrame frame) {
+ this.main = frame;
+ }
+
+ /**
+ * @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) this.main.getIndexTree()
+ .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;
+ }
+ this.main.setIndexLabel(label);
+ 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())
+ .isAnnotationType(type));
+ this.main.getTextArea().getCaret().setVisible(true);
+ }
+
+}
\ No newline at end of file
Added: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/LoadRecentDescFileEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/LoadRecentDescFileEventHandler.java?view=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/LoadRecentDescFileEventHandler.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/LoadRecentDescFileEventHandler.java Fri May 18 05:16:09 2007
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.uima.tools.cvd.MainFrame;
+
+public class LoadRecentDescFileEventHandler implements ActionListener {
+
+ private final MainFrame main;
+ private final String fileName;
+
+ public LoadRecentDescFileEventHandler(MainFrame frame, String fileName) {
+ super();
+ this.main = frame;
+ this.fileName = fileName;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ this.main.loadAEDescriptor(new File(this.fileName));
+ }
+
+}
\ No newline at end of file
Added: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/LoadRecentTextFileEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/LoadRecentTextFileEventHandler.java?view=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/LoadRecentTextFileEventHandler.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/LoadRecentTextFileEventHandler.java Fri May 18 05:16:09 2007
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.uima.tools.cvd.MainFrame;
+
+public class LoadRecentTextFileEventHandler implements ActionListener {
+
+ private final MainFrame main;
+ private final String fileName;
+
+ public LoadRecentTextFileEventHandler(MainFrame frame, String fileName) {
+ super();
+ this.main = frame;
+ this.fileName = fileName;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ this.main.loadTextFile(new File(this.fileName));
+ }
+
+}
\ No newline at end of file
Added: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/MainFrameClosing.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/MainFrameClosing.java?view=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/MainFrameClosing.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/MainFrameClosing.java Fri May 18 05:16:09 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.IOException;
+
+import org.apache.uima.tools.cvd.MainFrame;
+
+/**
+ * Save preferences on closing CVD.
+ */
+public class MainFrameClosing extends WindowAdapter {
+
+ private final MainFrame main;
+
+ public MainFrameClosing(MainFrame frame) {
+ this.main = frame;
+ }
+
+ public void windowClosing(WindowEvent e) {
+ try {
+ this.main.setStatusbarMessage("Saving preferences.");
+ this.main.saveProgramPreferences();
+ if (this.main.getAe() != null) {
+ this.main.getAe().destroy();
+ }
+ } catch (IOException ioe) {
+ this.main.handleException(ioe);
+ }
+ System.exit(0);
+ }
+
+}
\ No newline at end of file
Added: 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=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/NewTextEventHandler.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/NewTextEventHandler.java Fri May 18 05:16:09 2007
@@ -0,0 +1,54 @@
+/*
+ * 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 org.apache.uima.tools.cvd.MainFrame;
+
+/**
+ * Clear text area.
+ */
+public class NewTextEventHandler implements ActionListener {
+
+ private final MainFrame main;
+
+ public NewTextEventHandler(MainFrame frame) {
+ super();
+ this.main = frame;
+ }
+
+ public void actionPerformed(ActionEvent event) {
+ this.main.setTextFile(null);
+ this.main.getTextArea().setText("");
+ if (this.main.isDirty()) {
+ this.main.setDirty(false);
+ }
+ this.main.setTitle();
+ this.main.resetTrees();
+ this.main.getFileSaveItem().setEnabled(false);
+ this.main.getUndoMgr().discardAllEdits();
+ this.main.setFileStatusMessage();
+ this.main.setStatusbarMessage("Text area cleared.");
+ }
+
+}
\ No newline at end of file
Added: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/PopupHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/PopupHandler.java?view=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/PopupHandler.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/PopupHandler.java Fri May 18 05:16:09 2007
@@ -0,0 +1,52 @@
+/*
+ * 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 javax.swing.tree.TreePath;
+
+import org.apache.uima.tools.cvd.FSTreeModel;
+import org.apache.uima.tools.cvd.MainFrame;
+
+/**
+ * Action handler for text pop-up menu items. Select chosen annotation in FS tree, make visible.
+ */
+public class PopupHandler implements ActionListener {
+
+ private final MainFrame main;
+
+ private final int node;
+
+ public PopupHandler(MainFrame frame, int n) {
+ super();
+ this.main = frame;
+ this.node = n;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ FSTreeModel treeModel = (FSTreeModel) this.main.getFsTree().getModel();
+ TreePath path = treeModel.pathToNode(this.node);
+ this.main.getFsTree().setSelectionPath(path);
+ this.main.getFsTree().scrollPathToVisible(path);
+ }
+
+}
\ No newline at end of file
Added: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/PopupListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/PopupListener.java?view=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/PopupListener.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/PopupListener.java Fri May 18 05:16:09 2007
@@ -0,0 +1,52 @@
+/*
+ * 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.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import org.apache.uima.tools.cvd.MainFrame;
+
+/**
+ * Handle text pop-up (mouse) events. The actual logic for creating the text pop-up menu is not
+ * here.
+ */
+public class PopupListener extends MouseAdapter {
+
+ private final MainFrame main;
+
+ public PopupListener(MainFrame frame) {
+ this.main = frame;
+ }
+
+ public void mousePressed(MouseEvent e) {
+ maybeShowPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ maybeShowPopup(e);
+ }
+
+ private void maybeShowPopup(MouseEvent e) {
+ if (e.isPopupTrigger()) {
+ this.main.showTextPopup(e.getX(), e.getY());
+ }
+ }
+}
\ No newline at end of file
Added: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/ShowAnnotatedTextHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/ShowAnnotatedTextHandler.java?view=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/ShowAnnotatedTextHandler.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/ShowAnnotatedTextHandler.java Fri May 18 05:16:09 2007
@@ -0,0 +1,57 @@
+/*
+ * 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 org.apache.uima.cas.FSIterator;
+import org.apache.uima.tools.cvd.AnnotationExtent;
+import org.apache.uima.tools.cvd.MainFrame;
+import org.apache.uima.tools.cvd.MultiAnnotViewerFrame;
+import org.apache.uima.tools.cvd.MultiMarkup;
+
+/**
+ * Show the multi-annotation text window. Is anybody even using this? This is handled much better in
+ * the DocumentAnalyzer.
+ */
+public class ShowAnnotatedTextHandler implements ActionListener {
+
+ private final MainFrame main;
+
+ public ShowAnnotatedTextHandler(MainFrame frame) {
+ this.main = frame;
+ }
+
+ public void actionPerformed(ActionEvent event) {
+ String title = this.main.getIndexLabel() + " - " + this.main.getIndex().getType().getName();
+ MultiAnnotViewerFrame f = new MultiAnnotViewerFrame(title);
+ f.addWindowListener(new CloseAnnotationViewHandler(this.main));
+ FSIterator it = this.main.getIndex().iterator();
+ final String text = this.main.getCas().getDocumentText();
+ System.out.println("Creating extents.");
+ AnnotationExtent[] extents = MultiMarkup.createAnnotationMarkups(it, text.length(), this.main
+ .getStyleMap());
+ System.out.println("Initializing text frame.");
+ f.init(text, extents, this.main.getDimension(MainFrame.annotViewSizePref));
+ System.out.println("Done.");
+ }
+
+}
\ No newline at end of file
Added: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TextChangedListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TextChangedListener.java?view=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TextChangedListener.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TextChangedListener.java Fri May 18 05:16:09 2007
@@ -0,0 +1,64 @@
+/*
+ * 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 javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+
+import org.apache.uima.tools.cvd.MainFrame;
+
+/**
+ * Listener for changes in text frame. When the text is changed, the CAS is removed as the text from
+ * the CAS does no longer correspond to the text that is displayed in the frame, hence annotation
+ * offsets are no longer correct.
+ */
+public class TextChangedListener implements DocumentListener {
+
+ private final MainFrame main;
+
+ public TextChangedListener(MainFrame frame) {
+ this.main = frame;
+ }
+
+ public void changedUpdate(DocumentEvent arg0) {
+ // Do nothing.
+ }
+
+ 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 (!this.main.isDirty()) {
+ this.main.setDirty(true);
+ this.main.setTitle();
+ if (this.main.getCas() != null) {
+ this.main.setStatusbarMessage("Text changed, CAS removed.");
+ }
+ this.main.resetTrees();
+ }
+ }
+
+}
\ No newline at end of file
Added: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TextContextMenuAction.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TextContextMenuAction.java?view=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TextContextMenuAction.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TextContextMenuAction.java Fri May 18 05:16:09 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.Point;
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+
+import org.apache.uima.tools.cvd.MainFrame;
+
+/**
+ * Text pop-up action (for keyboard accessibility).
+ */
+public class TextContextMenuAction extends AbstractAction {
+
+ private final MainFrame main;
+
+ public TextContextMenuAction(MainFrame frame) {
+ this.main = frame;
+ }
+
+ private static final long serialVersionUID = -5518456467913617514L;
+
+ public void actionPerformed(ActionEvent arg0) {
+ Point caretPos = this.main.getTextArea().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.
+ this.main.showTextPopup(0, 0);
+ } else {
+ this.main.showTextPopup(caretPos.x, caretPos.y);
+ }
+ }
+
+}
\ No newline at end of file
Added: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TextFocusHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TextFocusHandler.java?view=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TextFocusHandler.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TextFocusHandler.java Fri May 18 05:16:09 2007
@@ -0,0 +1,55 @@
+/*
+ * 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.FocusEvent;
+import java.awt.event.FocusListener;
+
+import org.apache.uima.tools.cvd.MainFrame;
+
+public class TextFocusHandler implements FocusListener {
+
+ private final MainFrame main;
+
+ public TextFocusHandler(MainFrame frame) {
+ this.main = frame;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent)
+ */
+ public void focusGained(FocusEvent e) {
+ // Need to make the caret visible when gaining focus. Sometimes this happens automatically, but
+ // not always. Not sure if there is a better way to do this.
+ this.main.getTextArea().getCaret().setVisible(true);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent)
+ */
+ public void focusLost(FocusEvent e) {
+ // Does nothing
+ }
+
+}
\ No newline at end of file
Added: incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TreeFocusHandler.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TreeFocusHandler.java?view=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TreeFocusHandler.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/TreeFocusHandler.java Fri May 18 05:16:09 2007
@@ -0,0 +1,50 @@
+/*
+ * 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.FocusEvent;
+import java.awt.event.FocusListener;
+
+import javax.swing.JTree;
+import javax.swing.tree.TreePath;
+
+public class TreeFocusHandler implements FocusListener {
+
+ private JTree tree;
+
+ public 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.
+ }
+
+}
\ No newline at end of file
Added: 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=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/UndoMgr.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/UndoMgr.java Fri May 18 05:16:09 2007
@@ -0,0 +1,61 @@
+/*
+ * 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 javax.swing.undo.UndoManager;
+import javax.swing.undo.UndoableEdit;
+
+import org.apache.uima.tools.cvd.MainFrame;
+
+/**
+ * Undo manager for text area.
+ */
+public class UndoMgr extends UndoManager implements ActionListener {
+
+ private final MainFrame main;
+
+ public UndoMgr(MainFrame frame) {
+ this.main = frame;
+ }
+
+ private static final long serialVersionUID = 7677701629555379146L;
+
+ public void actionPerformed(ActionEvent arg0) {
+ undo();
+ if (!canUndo()) {
+ this.main.getUndoItem().setEnabled(false);
+ }
+ }
+
+ public synchronized boolean addEdit(UndoableEdit arg0) {
+ this.main.getUndoItem().setEnabled(true);
+ return super.addEdit(arg0);
+ }
+
+ public synchronized void discardAllEdits() {
+ super.discardAllEdits();
+ this.main.getUndoItem().setEnabled(false);
+ }
+
+}
\ No newline at end of file
Added: 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=auto&rev=539414
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XCASFileOpenEventHandler.java (added)
+++ incubator/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/cvd/control/XCASFileOpenEventHandler.java Fri May 18 05:16:09 2007
@@ -0,0 +1,139 @@
+/*
+ * 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 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;
+
+/**
+ * Load an XCAS file.
+ */
+public class XCASFileOpenEventHandler implements ActionListener {
+
+ private final MainFrame main;
+
+ public XCASFileOpenEventHandler(MainFrame frame) {
+ super();
+ this.main = frame;
+ }
+
+ /**
+ * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
+ */
+ public void actionPerformed(ActionEvent event) {
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle("Open XCAS file");
+ if (this.main.getXcasFileOpenDir() != null) {
+ fileChooser.setCurrentDirectory(this.main.getXcasFileOpenDir());
+ }
+ int rc = fileChooser.showOpenDialog(this.main);
+ if (rc == JFileChooser.APPROVE_OPTION) {
+ File xcasFile = fileChooser.getSelectedFile();
+ if (xcasFile.exists() && xcasFile.isFile()) {
+ try {
+ this.main.setXcasFileOpenDir(xcasFile.getParentFile());
+ Timer time = new Timer();
+ time.start();
+ SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
+ XCASDeserializer xcasDeserializer = new XCASDeserializer(this.main.getCas()
+ .getTypeSystem());
+ 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.setTitle("XCAS");
+ this.main.updateIndexTree(true);
+ this.main.getRunOnCasMenuItem().setEnabled(true);
+ this.main.setStatusbarMessage("Done loading XCAS file in " + time.getTimeSpan() + ".");
+ } catch (Exception e) {
+ e.printStackTrace();
+ this.main.handleException(e);
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file