Class CasAnnotationViewer

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class CasAnnotationViewer extends JPanel
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:

  • setConsistentColors(boolean) - if set to true (default), the color assigned to any annotation type will be the same across all documents. If set to false, colors may vary across documents.
  • setDisplayedTypes(String[]) - specifies a set of types that will be highlighted in the viewer's text pane.
  • setHiddenTypes(String[]) - specifies a set of types that will NOT be highlighted in the viewer's text pane.
  • setHiddenFeatures(String[]) - specifies a set of features that will never shown in the viewer's annotation details tree.
  • setHighFrequencyTypes(String[]) - this can be used to specify a set of types that occur frequently. These types will the be assigned the most distinguishable colors.
  • setInitiallySelectedTypes(String[]) - this can be used to specify a set of types that will initially be selected (i.e. have their checkboxes checked) in the viewer. The default is for all types to be initially selected.
  • setRightToLeftTextOrientation(boolean) - switches the text pane from left-to-right (default) to right-to-left mode. This is needed to support languages such as Arabic and Hebrew, which are read from right to left.
See Also:
  • Constructor Details

    • CasAnnotationViewer

      public CasAnnotationViewer()
      Creates a CAS Annotation Viewer.
    • CasAnnotationViewer

      @Deprecated public CasAnnotationViewer(boolean aEntityViewEnabled)
      Deprecated.
      use the zero-argument constructor
      Instantiates a new cas annotation viewer.
      Parameters:
      aEntityViewEnabled - the a entity view enabled
  • Method Details

    • getUserTypes

      public List<String> getUserTypes()
      Gets the user types.
      Returns:
      Returns the userTypes.
    • setUserTypes

      public void setUserTypes(List<String> userTypes)
      Sets the user types.
      Parameters:
      userTypes - The userTypes to set.
    • setHighFrequencyTypes

      public void setHighFrequencyTypes(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(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:
      aDisplayedTypeNames - names of types that are to be highlighted. Null indicates that all types in the CAS should be highlighted.
    • setHiddenTypes

      public void setHiddenTypes(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(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(String[] aFeatureNames)
      Configures the viewer to hide certain features in the annotation deatail pane.
      Parameters:
      aFeatureNames - array of (short) feature names to be hidden
    • setEntityResolver

      public void setEntityResolver(EntityResolver aEntityResolver)
      Sets the EntityResolver to use when the viewer is in entity mode.
      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:
      aHideUnselected - the new hide unselected checkboxes
    • 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(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(CAS). It wil apply only to the current document, and will be reset on the next call to setCAS(CAS).
      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(CAS). It wil apply only to the current document, and will be reset on the next call to setCAS(CAS).
      Parameters:
      aSpans - spans to appear in boldface (begin1, end1, begin2, end2, ...)
    • configureViewForXmlFragmentsQuery

      public void configureViewForXmlFragmentsQuery(String aQuery, 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 applyBoldfaceToKeywords(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(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 applyBoldfaceToKeywords(String[]) on any keywords mentioned in the query.
      Parameters:
      aQuery - an XML fragments query
    • assignCheckedFromList

      public void assignCheckedFromList(List<String> 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(List<Color> aColors, List<String> 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(Dimension d)
      Sets the size.
      Overrides:
      setSize in class Component
      Parameters:
      d - the new size
      See Also:
    • getSelectedAnnotationTree

      protected 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.