gate.gui
Class SyntaxTreeViewer
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--javax.swing.JComponent
|
+--javax.swing.JPanel
|
+--gate.gui.SyntaxTreeViewer
- All Implemented Interfaces:
- Accessible, ActionListener, EventListener, ImageObserver, MenuContainer, MouseListener, Scrollable, Serializable
- public class SyntaxTreeViewer
- extends JPanel
- implements Scrollable, ActionListener, MouseListener
The SyntaxTreeViewer works by getting an annotation set of all annotations
that need to be displayed (both text and tree nodes) as an AnnotationSet
property called treeAnnotations. The types of annotations used by the viewer
can be configured although it also has default values.
The textAnnotationType property specifies the type
of annotation which is used to get the text from (e.g. token, utterance);
default value - utterance. The treeNodeAnnotationType is the name of the
annotations which encode the SyntaxTreeNodes; default - SyntaxTreeNode. The
component assumes that the annotations of type treeNodeAnnotationType have
features called: cat with a value String; consists which is a Vector either
empty or with annotation ids of the node's children; and 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 automatically added to the document
as annotations (the document is obtained automatically from the annotation
set passed to the viewer with setAnnotations).
Deleted nodes are automatically deleted from the document
annotations too.
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);
To get an idea how to use the component, look at the main function which
is also the test for this bean.
The trick of using the viewer is that it needs to be constructed first,
then shown, and only after that set the annotations. This is due to painting
and size issues.
Example code:
final SyntaxTreeViewer syntaxTreeViewer1 = new SyntaxTreeViewer
("SyntaxTreeNode");
//if we need GATE Unicode support
syntaxTreeViewer1.setUnicodeSupportEnabled(true);
frame.show(); //show the frame that contains the tree viewer
...
//finally set the annotations on the tree viewer
syntaxTreeViewer1.setTreeAnnotations(annots);
When more than one annotations of type textAnnotationType (e.g., tokens) are
passed to the viewer in setTreeAnnotations, these annotations are treated as
separate leafs which together constitute the text to be annotated.
For example, if the three tokens - this, is, silly - are passed to the
viewer, it will take their offsets and corresponding texts and add them
to the viewer as separate leafs separated by spaces - this is silly.
This functionality however has not been tested extensively and I suspect
it might not work properly.
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 and
creates the leaves.
This is well-tested and is the usual way.
- See Also:
- Serialized Form
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 |
SyntaxTreeViewer
public SyntaxTreeViewer(String annotType)
main
public static void main(String[] args)
throws Exception
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
setTreeAnnotations
public void setTreeAnnotations(AnnotationSet newTreeAnnotations)
setTreeNodeAnnotationType
public void setTreeNodeAnnotationType(String newTreeNodeAnnotationType)
setTextAnnotationType
public void setTextAnnotationType(String newTextAnnotationType)