org.apache.uima.tools.viewer
Class CasAnnotationViewer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.apache.uima.tools.viewer.CasAnnotationViewer
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.ItemListener, java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.TreeExpansionListener, javax.swing.event.TreeWillExpandListener

public class CasAnnotationViewer
extends javax.swing.JPanel
implements java.awt.event.ActionListener, java.awt.event.MouseListener, javax.swing.event.TreeWillExpandListener, javax.swing.event.TreeExpansionListener, java.awt.event.ItemListener

A Swing component that displays annotations in a text pane with highlighting. There is also a tree view for display details of annotations on which the user clicks. This class extends JPanel and so can be reused within any Swing application.

To launch the viewer, call the setCAS(CAS) method with the CAS to be viewed.

The viewer is configurable via the following methods:

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CasAnnotationViewer()
          Creates a CAS Annotation Viewer.
CasAnnotationViewer(boolean aEntityViewEnabled)
          Deprecated. use the zero-argument constructor and call setEntityViewEnabled(boolean)
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
protected  void addAnnotationToTree(AnnotationFS aAnnotation)
          Adds an annotation to the selected annotations tree.
 void applyBoldfaceToKeywords(java.lang.String[] aWords)
          Causes the specified words to appear in boldface wherever they occur in the document.
 void applyBoldfaceToSpans(int[] aSpans)
          Causes the specified spans to appear in boldface.
 void assignCheckedFromList(java.util.ArrayList aNotChecked)
          Assign initially checked to the specified types, pairing up down the lists
 void assignColorsFromList(java.util.List aColors, java.util.ArrayList aTypeNames)
          Assign colors to the specified types, pairing up down the lists
 void configureViewForXmlFragmentsQuery(java.lang.String aQuery)
          Configures the viewer appropriately for displaying a hit against an XML fragments query.
 void configureViewForXmlFragmentsQuery(java.lang.String aQuery, java.lang.String aTypeNamespace)
          Configures the viewer appropriately for displaying a hit against an XML fragments query.
protected  javax.swing.JTree getSelectedAnnotationTree()
          Gets the selected annotation tree component.
 java.util.ArrayList getUserTypes()
           
 void itemStateChanged(java.awt.event.ItemEvent e)
           
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void setCAS(CAS aCAS)
          Sets the CAS to be viewed.
 void setConsistentColors(boolean aConsistent)
          Sets whether colors will be consistent in all documents viewed using this viewer.
 void setDisplayedTypes(java.lang.String[] aDisplayedTypeNames)
          Set the list of types that will be highlighted in the viewer.
 void setEntityResolver(EntityResolver aEntityResolver)
          Sets the EntityResolver to use when the viewer is in entity mode.
 void setEntityViewEnabled(boolean aEnabled)
          Configures whether the viewer will allow the user to switch to "Entity" view, which highlight entities rather than annotations.
 void setHiddenFeatures(java.lang.String[] aFeatureNames)
          Configures the viewer to hide certain features in the annotation deatail pane.
 void setHiddenTypes(java.lang.String[] aTypeNames)
          Set the list of types that will NOT be highlighted in the viewer.
 void setHideUnselectedCheckboxes(boolean aHideUnselected)
          Sets whether unselected (unchecked) checkboxes will be hidden entirely from the legend.
 void setHighFrequencyTypes(java.lang.String[] aTypeNames)
          Set the list of types that occur most frequently.
 void setInitiallySelectedTypes(java.lang.String[] aTypeNames)
          Configures the initially selected types in the viewer.
 void setRightToLeftTextOrientation(boolean aRightToLeft)
          Sets the text orientation.
 void setSize(java.awt.Dimension d)
           
 void setUserTypes(java.util.ArrayList userTypes)
           
 void treeCollapsed(javax.swing.event.TreeExpansionEvent event)
           
 void treeExpanded(javax.swing.event.TreeExpansionEvent event)
           
 void treeWillCollapse(javax.swing.event.TreeExpansionEvent event)
           
 void treeWillExpand(javax.swing.event.TreeExpansionEvent event)
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CasAnnotationViewer

public CasAnnotationViewer()
Creates a CAS Annotation Viewer.


CasAnnotationViewer

@Deprecated
public CasAnnotationViewer(boolean aEntityViewEnabled)
Deprecated. use the zero-argument constructor and call setEntityViewEnabled(boolean)

Method Detail

getUserTypes

public java.util.ArrayList getUserTypes()
Returns:
Returns the userTypes.

setUserTypes

public void setUserTypes(java.util.ArrayList userTypes)
Parameters:
userTypes - The userTypes to set.

setHighFrequencyTypes

public void setHighFrequencyTypes(java.lang.String[] aTypeNames)
Set the list of types that occur most frequently. This method assigns the most distinguishable colors to these types.

Parameters:
aTypeNames - names of types that are occur frequently. Ideally these should be ordered by frequency, with the most frequent being first.

setDisplayedTypes

public void setDisplayedTypes(java.lang.String[] aDisplayedTypeNames)
Set the list of types that will be highlighted in the viewer. Types not in this list will not appear in the legend and will never be highlighted. If this method is not called, the default is to show all types in the CAS (except those specifically hidden by a call to setHiddenTypes(String[]).

Parameters:
aTypeNames - names of types that are to be highlighted. Null indicates that all types in the CAS should be highlighted.

setHiddenTypes

public void setHiddenTypes(java.lang.String[] aTypeNames)
Set the list of types that will NOT be highlighted in the viewer.

Parameters:
aTypeNames - names of types that are never to be highlighted.

setInitiallySelectedTypes

public void setInitiallySelectedTypes(java.lang.String[] aTypeNames)
Configures the initially selected types in the viewer. If not called, all types will be initially selected.

Parameters:
aTypeNames - array of fully-qualified names of types to be initially selected

setHiddenFeatures

public void setHiddenFeatures(java.lang.String[] aFeatureNames)
Configures the viewer to hide certain features in the annotation deatail pane.

Parameters:
aFeatureName - array of (short) feature names to be hidden

setEntityViewEnabled

public void setEntityViewEnabled(boolean aEnabled)
Configures whether the viewer will allow the user to switch to "Entity" view, which highlight entities rather than annotations. Entity mode is typically only useful if the setEntityResolver(EntityResolver) method has been called with a user-supplied class that can determine which annotations refer to the same entity.

Parameters:
aDisplayEntities - true to enable entity viewing mode, false to allow annotation viewing only. The default is false.

setEntityResolver

public void setEntityResolver(EntityResolver aEntityResolver)
Sets the EntityResolver to use when the viewer is in entity mode. Entity mode must be turned on using the setEntityViewEnabled(boolean) method.

Parameters:
aEntityResolver - user-supplied class that can determine which annotations correspond to the same entity.

setConsistentColors

public void setConsistentColors(boolean aConsistent)
Sets whether colors will be consistent in all documents viewed using this viewer. If set to true, assignments of color to annotation type will persist across documents; if false, colors will be reassigned in each new document. (Note that if high frequency types are set via setHighFrequencyTypes(String[]), the colors for those types will always be consistent, regardless of the value passed to this method.

Parameters:
aConsistent - true (the default) causes colors to be consistent across documents, false allows them to vary

setRightToLeftTextOrientation

public void setRightToLeftTextOrientation(boolean aRightToLeft)
Sets the text orientation. The default is left-to-right, but needs to be set to right-to-left to properly display some languages, most notably Arabic and Hebrew.

Parameters:
aRightToLeft - true to put the viewer in right-to-left mode, false for left-to-right (the default).

setHideUnselectedCheckboxes

public void setHideUnselectedCheckboxes(boolean aHideUnselected)
Sets whether unselected (unchecked) checkboxes will be hidden entirely from the legend. This mode makes for a cleaner legend at the expense of making it more difficult to toggle which types are selected. There's also a button in the GUI that lets the user change this setting.

Parameters:
aConsistent - true (the default) causes colors to be consistent across documents, false allows them to vary

setCAS

public void setCAS(CAS aCAS)
Sets the CAS to be viewed. This must be called before display().

Parameters:
aCAS - the CSA to be viewed

applyBoldfaceToKeywords

public void applyBoldfaceToKeywords(java.lang.String[] aWords)
Causes the specified words to appear in boldface wherever they occur in the document. This is case-insensitive. Call this method after #setCAS(). It wil apply only to the current document, and will be reset on the next call to #setCAS().

Parameters:
aWords - array of words to highlight in boldface.

applyBoldfaceToSpans

public void applyBoldfaceToSpans(int[] aSpans)
Causes the specified spans to appear in boldface. This is case-insensitive. Call this method after #setCAS(). It wil apply only to the current document, and will be reset on the next call to #setCAS().

Parameters:
aSpans - spans to appear in boldface (begin1, end1, begin2, end2, ...)

configureViewForXmlFragmentsQuery

public void configureViewForXmlFragmentsQuery(java.lang.String aQuery,
                                              java.lang.String aTypeNamespace)
Configures the viewer appropriately for displaying a hit against an XML fragments query. This does not use a sophisticated algorithm for determining the location of the document that matched the query. Currently all it does is call setInitiallySelectedTypes(String[]) with the list of types mentioned in the query and #applyBoldfaceToKeyword(String[]) on any keywords mentioned in the query.

Parameters:
aQuery - an XML fragments query
aTypeNamespace - namespace to prepend to the element names in the query in order to form fully-qualified CAS type names. This is optional; if not specified, type namespaces are ignored and any type whose local name matches the query will be selected.

configureViewForXmlFragmentsQuery

public void configureViewForXmlFragmentsQuery(java.lang.String aQuery)
Configures the viewer appropriately for displaying a hit against an XML fragments query. This does not use a sophisticated algorithm for determining the location of the document that matched the query. Currently all it does is call setInitiallySelectedTypes(String[]) with the list of types mentioned in the query and #applyBoldfaceToKeyword(String[]) on any keywords mentioned in the query.

Parameters:
aQuery - an XML fragments query

assignCheckedFromList

public void assignCheckedFromList(java.util.ArrayList aNotChecked)
Assign initially checked to the specified types, pairing up down the lists

Parameters:
aNotChecked - list of types not to be initially checked JMP

assignColorsFromList

public void assignColorsFromList(java.util.List aColors,
                                 java.util.ArrayList aTypeNames)
Assign colors to the specified types, pairing up down the lists

Parameters:
aColors - list of colors
aTypeNames - list of type names JMP

addAnnotationToTree

protected void addAnnotationToTree(AnnotationFS aAnnotation)
Adds an annotation to the selected annotations tree. Annotations in the tree are grouped by type.

Parameters:
aAnnotation - the annotation to add

setSize

public void setSize(java.awt.Dimension d)
Overrides:
setSize in class java.awt.Component
See Also:
Component.setSize(Dimension)

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

treeWillCollapse

public void treeWillCollapse(javax.swing.event.TreeExpansionEvent event)
                      throws javax.swing.tree.ExpandVetoException
Specified by:
treeWillCollapse in interface javax.swing.event.TreeWillExpandListener
Throws:
javax.swing.tree.ExpandVetoException

treeWillExpand

public void treeWillExpand(javax.swing.event.TreeExpansionEvent event)
                    throws javax.swing.tree.ExpandVetoException
Specified by:
treeWillExpand in interface javax.swing.event.TreeWillExpandListener
Throws:
javax.swing.tree.ExpandVetoException

treeCollapsed

public void treeCollapsed(javax.swing.event.TreeExpansionEvent event)
Specified by:
treeCollapsed in interface javax.swing.event.TreeExpansionListener

treeExpanded

public void treeExpanded(javax.swing.event.TreeExpansionEvent event)
Specified by:
treeExpanded in interface javax.swing.event.TreeExpansionListener

itemStateChanged

public void itemStateChanged(java.awt.event.ItemEvent e)
Specified by:
itemStateChanged in interface java.awt.event.ItemListener

getSelectedAnnotationTree

protected javax.swing.JTree getSelectedAnnotationTree()
Gets the selected annotation tree component.

Returns:
the tree that displays annotation details about annotations overlapping the point where the user last clicked in the text.


Copyright © 2010 The Apache Software Foundation. All Rights Reserved.