## gate.gui
Class SyntaxTreeViewer

    java.lang.Object
      |
      +--java.awt.Component
            |
            +--java.awt.Container
                  |
                  +--javax.swing.JComponent
                        |
                        +--javax.swing.JPanel
                              |
                              +--gate.creole.AbstractVisualResource
                                    |
                                    +--gate.gui.SyntaxTreeViewer

All Implemented Interfaces:
  Accessible, ActionListener, AnnotationVisualResource, EventListener, FeatureBearer, ImageObserver, MenuContainer, MouseListener, NameBearer, Resource, Scrollable, Serializable, VisualResource

public class SyntaxTreeViewer
extends AbstractVisualResource
implements Scrollable, ActionListener, MouseListener, AnnotationVisualResource

The SyntaxTreeViewer is capable of showing and editing utterances (fancy name for sentences) and the attached syntax trees. It works by taking an utterance and all Token annotations and constructs the text. Then it also gets all SyntaxTreeNode annotations and builds and shows the syntac tree for that utterance. The leaves of the tree are the tokens, which constitute the utterance.

It is possible to configure the annotation types that are used by the viewer. The textAnnotationType property specifies the type of annotation which is used to denote the utterance (sentence). In GATE, the value of this property is not set directly, but is derived from the VR configuration information from creole.xml (explained below). The treeNodeAnnotationType is the name of the annotations which encode the SyntaxTreeNodes; default - SyntaxTreeNode. To change when part of GATE, modify the <PARAMETER> setting of the TreeViewer entry in creole.xml. Similarly, one can change which annotation is used for chunking the utterance. By default, it is Token, which is also specified in creole.xml as a parameter in the treeviewer entry. The component assumes that the annotations of type treeNodeAnnotationType have features called: cat with a value String; consists which is a List either empty or with annotation ids of the node's children; and optionally text which contains the text covered by this annotation. The component will work fine even without the last feature. Still when it creates annotations, these will have this feature added.

Newly added tree nodes to the tree are added to the document as annotations and deleted nodes are automatically deleted from the document only after OK is chosen in the dialog. Cancel does not make any changes permanent.

Configuring the viewer in GATE

The viewer is configured in creole.xml. The default entry is:

       <RESOURCE>
         <NAME>Syntax tree viewer</NAME>
         <CLASS>gate.gui.SyntaxTreeViewer</CLASS>

         <GUI>
           <MAIN_VIEWER/>
           <ANNOTATION_TYPE_DISPLAYED>Sentence</ANNOTATION_TYPE_DISPLAYED>
           java.lang.String

           java.lang.String

         </GUI>
       </RESOURCE>

The categories that appear in the menu for manual annotation are determined from SyntaxTreeViewerSchema.xml. If you want to change the default set, you must edit this file and update your Gate jar accordingly (e.g., by recompilation. This does not affect the categories of SyntaxTreeNode annotations, which have been created automatically by some other process, e.g., a parser PR.

If used outside GATE, in order to have appropriate behaviour always put this component inside a scroll pane or something similar that provides scrollers. Example code: <BREAK>

      JScrollPane scroller = new JScrollPane(syntaxTreeViewer1);
      scroller.setPreferredSize(syntaxTreeViewer1.getPreferredSize());
      frame.getContentPane().add(scroller, BorderLayout.CENTER);

The default way is to pass just one annotation of type textAnnotationType which corresponds to the entire sentence or utterance to be annotated with syntax tree information. Then the viewer automatically tokenises it (by obtaining the relevant token annotations) and creates the leaves.

To create a new annotation, use setSpan, instead of setAnnotation.

In either case, you must call setTarget first, because that'll provide the viewer with the document's annotation set, from where it can obtain the token annotations.

If you intend to use the viewer outside GATE and do not understand the API, e-mail gate@dcs.shef.ac.uk.

See Also:
  Serialized Form

Inner classes inherited from class javax.swing.JComponent
`JComponent.AccessibleJComponent`

Fields inherited from class javax.swing.JComponent
`TOOL_TIP_TEXT_KEY, 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
`SyntaxTreeViewer()`

Method Summary
`void` `actionPerformed(ActionEvent e)`
`void` `cancelAction()` Called by the GUI when the user has pressed the "Cancel" button.
`boolean` `canDisplayAnnotationType(String annotationType)` Checks whether this viewer/editor can handle a specific annotation type.
`Dimension` `getPreferredScrollableViewportSize()`
`int` `getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)`
`boolean` `getScrollableTracksViewportHeight()`
`boolean` `getScrollableTracksViewportWidth()`
`int` `getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)`
`String` `getTokenType()`
`void` `mouseClicked(MouseEvent e)`
`void` `mouseEntered(MouseEvent e)`
`void` `mouseExited(MouseEvent e)`
`void` `mousePressed(MouseEvent e)`
`void` `mouseReleased(MouseEvent e)`
`void` `okAction()` Called by the GUI when the user has pressed the "OK" button.
`void` `setAnnotation(Annotation ann)` Used when the viewer/editor has to display/edit an existing annotation
`void` `setSpan(Long startOffset, Long endOffset, String annotType)` Used when the viewer has to create new annotations.
`void` `setTarget(Object target)` Called by the GUI when this viewer/editor has to initialise itself for a specific annotation or text span.
`void` `setTokenType(String newTokenType)`
`void` `setTreeNodeAnnotationType(String newTreeNodeAnnotationType)`

Methods inherited from class gate.creole.AbstractVisualResource
`cleanup, getFeatures, getParameterValue, init, setFeatures, setHandle, setParameterValue, setParameterValues`

Methods inherited from class javax.swing.JPanel
`getAccessibleContext, getUIClassID, updateUI`

Methods inherited from class javax.swing.JComponent

`addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update`

Methods inherited from class java.awt.Container

`add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setLayout, validate`

Methods inherited from class java.awt.Component

`action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, contains, createImage, createImage, dispatchEvent, enable, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface gate.VisualResource
`setHandle`

Methods inherited from interface gate.Resource
`cleanup, getParameterValue, init, setParameterValue, setParameterValues`

Methods inherited from interface gate.util.FeatureBearer
`getFeatures, setFeatures`

Methods inherited from interface gate.util.NameBearer
`getName, setName`

Constructor Detail

### SyntaxTreeViewer

    public SyntaxTreeViewer()

Method Detail

### setTarget

    public void setTarget(Object target)

  Called by the GUI when this viewer/editor has to initialise itself for a specific annotation or text span.
  Specified by:
    `setTarget` in interface `AnnotationVisualResource`
  Overrides:
    `setTarget` in class `AbstractVisualResource`
  Parameters:
    `target` - the object which will always be a `AnnotationSet`

### setAnnotation

    public void setAnnotation(Annotation ann)

  Used when the viewer/editor has to display/edit an existing annotation
  Specified by:
    `setAnnotation` in interface `AnnotationVisualResource`
  Parameters:
    `ann` - the annotation to be displayed or edited. If ann is null then the method simply returns

### setSpan

    public void setSpan(Long startOffset,
                        Long endOffset,
                        String annotType)

  Used when the viewer has to create new annotations.
  Specified by:
    `setSpan` in interface `AnnotationVisualResource`
  Parameters:
    `startOffset` - the start offset of the span covered by the new annotation(s). If is null the method will simply return.
    `endOffset` - the end offset of the span covered by the new annotation(s). If is null the method will simply return.

### okAction

    public void okAction()
                  throws GateException

  Called by the GUI when the user has pressed the "OK" button. This should trigger the saving of the newly created annotation(s)
  Specified by:
    `okAction` in interface `AnnotationVisualResource`

### cancelAction

    public void cancelAction()
                      throws GateException

  Called by the GUI when the user has pressed the "Cancel" button. This should trigger the cleanup operation
  Specified by:
    `cancelAction` in interface `AnnotationVisualResource`

### canDisplayAnnotationType

    public boolean canDisplayAnnotationType(String annotationType)

  Checks whether this viewer/editor can handle a specific annotation type.
  Specified by:
    `canDisplayAnnotationType` in interface `AnnotationVisualResource`
  Parameters:
    `annotationType` - represents the annotation type being questioned.If it is null then the method will return false.
  Returns:
    true if the SchemaAnnotationEditor can handle the annotationType or false otherwise.

### getPreferredScrollableViewportSize

    public Dimension getPreferredScrollableViewportSize()

  Specified by:
    `getPreferredScrollableViewportSize` in interface `Scrollable`

### getScrollableUnitIncrement

    public int getScrollableUnitIncrement(Rectangle visibleRect,
                                          int orientation,
                                          int direction)

  Specified by:
    `getScrollableUnitIncrement` in interface `Scrollable`

### getScrollableBlockIncrement

    public int getScrollableBlockIncrement(Rectangle visibleRect,
                                           int orientation,
                                           int direction)

  Specified by:
    `getScrollableBlockIncrement` in interface `Scrollable`

### getScrollableTracksViewportWidth

    public boolean getScrollableTracksViewportWidth()

  Specified by:
    `getScrollableTracksViewportWidth` in interface `Scrollable`

### getScrollableTracksViewportHeight

    public boolean getScrollableTracksViewportHeight()

  Specified by:
    `getScrollableTracksViewportHeight` in interface `Scrollable`

### actionPerformed

    public void actionPerformed(ActionEvent e)

  Specified by:
    `actionPerformed` in interface `ActionListener`

### mouseClicked

    public void mouseClicked(MouseEvent e)

  Specified by:
    `mouseClicked` in interface `MouseListener`

### mousePressed

    public void mousePressed(MouseEvent e)

  Specified by:
    `mousePressed` in interface `MouseListener`

### mouseReleased

    public void mouseReleased(MouseEvent e)

  Specified by:
    `mouseReleased` in interface `MouseListener`

### mouseEntered

    public void mouseEntered(MouseEvent e)

  Specified by:
    `mouseEntered` in interface `MouseListener`

### mouseExited

    public void mouseExited(MouseEvent e)

  Specified by:
    `mouseExited` in interface `MouseListener`

### setTreeNodeAnnotationType

    public void setTreeNodeAnnotationType(String newTreeNodeAnnotationType)

### setTokenType

    public void setTokenType(String newTokenType)

### getTokenType

    public String getTokenType()