gate.gui
Class SyntaxTreeViewer

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 gate.creole.AbstractVisualResource
                      extended by gate.gui.SyntaxTreeViewer
All Implemented Interfaces:
AnnotationVisualResource, Resource, FeatureBearer, NameBearer, VisualResource, ActionListener, MouseListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, Scrollable

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 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:

   
     Syntax tree viewer
     gate.gui.SyntaxTreeViewer
     
     
       
       Sentence
       java.lang.String
       
       java.lang.String
       
     
   
 
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:

  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 [email protected].

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  HashMap buttons
           
protected  AnnotationSet currentSet
           
protected  String displayedString
           
protected  Document document
           
protected  int extraButtonWidth
           
protected  int horizButtonGap
           
protected  boolean laidOut
           
protected  HashMap leaves
           
protected  int maxUnitIncrement
           
static String NODE_CAT_FEATURE_NAME
          The name of the feature that encodes the tree node's category information
static String NODE_CONSISTS_FEATURE_NAME
          The name of the feature that encodes the subtree annotations
protected  HashMap nonTerminals
           
protected  Vector selection
           
protected  String textAnnotationType
           
protected  String tokenType
           
static String TREE_NODE_ANNOTATION_TYPE
          The annotation type used to encode each tree node
protected  AnnotationSet treeAnnotations
           
protected  String treeNodeAnnotationType
           
protected  Annotation utterance
           
protected  boolean utteranceAdded
           
protected  Long utteranceEndOffset
           
protected  Long utteranceStartOffset
           
protected  int vertButtonGap
           
 
Fields inherited from class gate.creole.AbstractVisualResource
features, handle
 
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
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.
protected  STreeNode createParentNode(String text)
          Create a parent node for all selected non-terminal nodes
protected  STreeNode createParentNode(String text, Annotation annot)
          Create a parent node for all selected non-terminal nodes
 void editAnnotation(Annotation ann, AnnotationSet set)
          Used when the viewer/editor has to display/edit an existing annotation
 boolean editingFinished()
          Returns true.
 Annotation getAnnotationCurrentlyEdited()
           
 AnnotationSet getAnnotationSetCurrentlyEdited()
           
 Dimension getPreferredScrollableViewportSize()
           
 int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
           
 boolean getScrollableTracksViewportHeight()
           
 boolean getScrollableTracksViewportWidth()
           
 int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
           
 String getTokenType()
           
 String getTreeNodeAnnotationType()
           
 boolean isActive()
          Checks whether the annotation editor is active (shown on screen and ready to edit annotations.
 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.
protected  void paintComponent(Graphics g)
           
 void setTokenType(String newTokenType)
           
 void setTreeNodeAnnotationType(String newTreeNodeAnnotationType)
           
 boolean supportsCancel()
          Returns true.
 
Methods inherited from class gate.creole.AbstractVisualResource
cleanup, getFeatures, getInitParameterValues, getParameterValue, init, setFeatures, setHandle, setParameterValue, setParameterValues, setTarget
 
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, 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, transferFocusBackward, 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, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gate.VisualResource
setHandle, setTarget
 
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
 

Field Detail

TREE_NODE_ANNOTATION_TYPE

public static final String TREE_NODE_ANNOTATION_TYPE
The annotation type used to encode each tree node

See Also:
Constant Field Values

NODE_CAT_FEATURE_NAME

public static final String NODE_CAT_FEATURE_NAME
The name of the feature that encodes the tree node's category information

See Also:
Constant Field Values

NODE_CONSISTS_FEATURE_NAME

public static final String NODE_CONSISTS_FEATURE_NAME
The name of the feature that encodes the subtree annotations

See Also:
Constant Field Values

laidOut

protected boolean laidOut

horizButtonGap

protected int horizButtonGap

vertButtonGap

protected int vertButtonGap

extraButtonWidth

protected int extraButtonWidth

maxUnitIncrement

protected int maxUnitIncrement

utterance

protected Annotation utterance

utteranceStartOffset

protected Long utteranceStartOffset

utteranceEndOffset

protected Long utteranceEndOffset

currentSet

protected AnnotationSet currentSet

tokenType

protected String tokenType

displayedString

protected String displayedString

treeNodeAnnotationType

protected String treeNodeAnnotationType

textAnnotationType

protected String textAnnotationType

leaves

protected HashMap leaves

nonTerminals

protected HashMap nonTerminals

buttons

protected HashMap buttons

selection

protected Vector selection

treeAnnotations

protected AnnotationSet treeAnnotations

document

protected Document document

utteranceAdded

protected boolean utteranceAdded
Constructor Detail

SyntaxTreeViewer

public SyntaxTreeViewer()
Method Detail

editAnnotation

public void editAnnotation(Annotation ann,
                           AnnotationSet set)
Used when the viewer/editor has to display/edit an existing annotation

Specified by:
editAnnotation in interface AnnotationVisualResource
Parameters:
ann - the annotation to be displayed or edited. If ann is null then the method simply returns
set - the set to which the new annotation belongs.

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
Throws:
GateException

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
Throws:
GateException

supportsCancel

public boolean supportsCancel()
Returns true.

Specified by:
supportsCancel in interface AnnotationVisualResource
Returns:
true iff this editor can rollback changes.

editingFinished

public boolean editingFinished()
Returns true.

Specified by:
editingFinished in interface AnnotationVisualResource
Returns:
true iff the editor has finished editing the current annotation. This might return false for instance when the current annotation does not yet comply with the schema and the editor implementation is designed to enforce schemas.

getAnnotationCurrentlyEdited

public Annotation getAnnotationCurrentlyEdited()
Specified by:
getAnnotationCurrentlyEdited in interface AnnotationVisualResource
Returns:
the annotation currently edited

getAnnotationSetCurrentlyEdited

public AnnotationSet getAnnotationSetCurrentlyEdited()
Specified by:
getAnnotationSetCurrentlyEdited in interface AnnotationVisualResource
Returns:
the annotation set currently edited

isActive

public boolean isActive()
Description copied from interface: AnnotationVisualResource
Checks whether the annotation editor is active (shown on screen and ready to edit annotations.

Specified by:
isActive in interface AnnotationVisualResource
Returns:
true iff the editor is active.

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.

paintComponent

protected void paintComponent(Graphics g)
Overrides:
paintComponent in class JComponent

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

createParentNode

protected STreeNode createParentNode(String text)
Create a parent node for all selected non-terminal nodes


createParentNode

protected STreeNode createParentNode(String text,
                                     Annotation annot)
Create a parent node for all selected non-terminal nodes


setTreeNodeAnnotationType

public void setTreeNodeAnnotationType(String newTreeNodeAnnotationType)

getTreeNodeAnnotationType

public String getTreeNodeAnnotationType()

setTokenType

public void setTokenType(String newTokenType)

getTokenType

public String getTokenType()