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
Fields inherited from class javax.swing.JComponent |
_bounds, accessibleContext, actionMap, ACTIONMAP_CREATED, alignmentX, alignmentY, ANCESTOR_INPUTMAP_CREATED, ANCESTOR_USING_BUFFER, ancestorInputMap, ancestorNotifier, autoscroller, border, changeSupport, clientProperties, CREATED_DOUBLE_BUFFER, flags, FOCUS_INPUTMAP_CREATED, focusInputMap, HAS_FOCUS, htmlKey, htmlView, inputVerifier, IS_DOUBLE_BUFFERED, IS_OPAQUE, IS_PAINTING_TILE, IS_PRINTING, IS_PRINTING_ALL, KEY_EVENTS_ENABLED, KEYBOARD_BINDINGS_KEY, listenerList, maximumSize, minimumSize, NEXT_FOCUS, paintImmediatelyClip, paintingChild, preferredSize, readObjectCallbacks, REQUEST_FOCUS_DISABLED, tmpRect, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, verifyInputWhenFocusTarget, vetoableChangeSupport, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, WHEN_IN_FOCUSED_WINDOW_BINDINGS, WIF_INPUTMAP_CREATED, windowInputMap |
Fields inherited from class java.awt.Container |
component, containerListener, containerSerializedDataVersion, dbg, dispatcher, layoutMgr, listeningBoundsChildren, listeningChildren, maxSize, ncomponents, printing, printingThreads, serialVersionUID |
Fields inherited from class java.awt.Component |
actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, graphicsConfig, hasFocus, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowClosingException, windowListenerK, x, y |
Method Summary |
void |
actionPerformed(ActionEvent e)
|
private void |
addLines(STreeNode newNode)
|
private void |
annotations2Trees()
Converts the annotations into treeNodes and sets the displayedString
correctly. |
private void |
clearAll()
Clear all buttons and tree nodes created because component is being
re-initialised. |
private void |
clearSelection()
|
private int |
createButton4Node(STreeNode node,
int buttonX,
int buttonY)
Returns the X position where another button can start if necessary. |
private JButton |
createCentralButton(STreeNode newNode)
|
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 |
private void |
drawLines(Graphics g)
|
private void |
fillCategoriesMenu()
|
private STreeNode |
findLeaf(Node start,
Node end)
|
Dimension |
getPreferredScrollableViewportSize()
|
int |
getScrollableBlockIncrement(Rectangle visibleRect,
int orientation,
int direction)
|
boolean |
getScrollableTracksViewportHeight()
|
boolean |
getScrollableTracksViewportWidth()
|
int |
getScrollableUnitIncrement(Rectangle visibleRect,
int orientation,
int direction)
|
private void |
jbInit()
|
static void |
main(String[] args)
|
void |
mouseClicked(MouseEvent e)
|
void |
mouseEntered(MouseEvent e)
|
void |
mouseExited(MouseEvent e)
|
void |
mousePressed(MouseEvent e)
|
void |
mouseReleased(MouseEvent e)
|
protected void |
paintComponent(Graphics g)
|
private JButton |
processChildrenAnnots(Annotation annot,
HashMap processed)
|
private void |
recalculateLines()
|
private void |
recalculateLines(STreeNode node)
recalculates all lines from that node to all its children |
(package private) void |
removeNode(JButton button)
|
private void |
removeNodesAbove(STreeNode node)
|
private void |
resetChildren(STreeNode node)
|
(package private) void |
selectNode(MouseEvent e)
|
private void |
setMenuCommands(JPopupMenu menu,
String command)
Sets the action commands of all menu items to the specified command |
void |
setTextAnnotationType(String newTextAnnotationType)
|
void |
setTreeAnnotations(AnnotationSet newTreeAnnotations)
|
void |
setTreeNodeAnnotationType(String newTreeNodeAnnotationType)
|
private void |
shiftButtonsDown(int offset)
|
private void |
showRightClickPopup(MouseEvent e)
|
(package private) void |
this_propertyChange(PropertyChangeEvent e)
|
private void |
tokens2Tree(AnnotationSet tokens)
Converts the given tokens into a set of leaf nodes
this needs testing as I've never used it |
private void |
utterances2Trees()
Converts the given utterances into a set of leaf nodes for annotation |
Methods inherited from class javax.swing.JComponent |
_paintImmediately, addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, adjustPaintFlags, alwaysOnTop, checkIfChildObscuredBySibling, clearFocusOwners, componentInputMapChanged, computeVisibleRect, computeVisibleRect, compWriteObjectNotify, contains, createToolTip, disable, enable, enableSerialization, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperties, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getCreatedDoubleBuffer, getDebugGraphicsOptions, getFlag, getGraphics, getHeight, getInputMap, 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, paintBorder, paintChildren, paintImmediately, paintImmediately, paintWithBuffer, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyBindings, processKeyBindingsForAllComponents, processKeyEvent, processMouseMotionEvent, putClientProperty, readObject, rectangleIsObscured, rectangleIsObscuredBySibling, registerKeyboardAction, registerKeyboardAction, registerWithKeyboardManager, registerWithKeyboardManager, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setCreatedDoubleBuffer, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFlag, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPaintingChild, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, unregisterWithKeyboardManager, unregisterWithKeyboardManager, update |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, adjustListeningChildren, applyOrientation, checkGD, countComponents, createChildHierarchyEvents, createHierarchyEvents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, findComponentAt, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getLayout, getMouseEventTarget, getWindow, initIDs, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, nextFocus, numListening, paintComponents, paintHeavyweightComponents, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, printComponents, printHeavyweightComponents, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, remove, remove, removeAll, removeContainerListener, setFocusOwner, setLayout, transferFocus, validate, validateTree |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, areInputMethodsEnabled, bounds, checkImage, checkImage, checkWindowClosingException, coalesceEvents, constructComponentName, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getAccessibleIndexInParent, getAccessibleStateSet, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getToolkit, getToolkitImpl, getTreeLock, getWindowForObject, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isEnabledImpl, isLightweight, isRecursivelyVisible, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resetGC, 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 |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait |
DEBUG
private static final boolean DEBUG
- Debug flag
laidOut
private boolean laidOut
horizButtonGap
private int horizButtonGap
vertButtonGap
private int vertButtonGap
extraButtonWidth
private int extraButtonWidth
maxUnitIncrement
private int maxUnitIncrement
borderLayout1
BorderLayout borderLayout1
popup
JPopupMenu popup
buttonBackground
Color buttonBackground
selectedNodeColor
Color selectedNodeColor
lines
HashSet lines
utterance
private Annotation utterance
utteranceOffset
private int utteranceOffset
displayedString
private String displayedString
treeNodeAnnotationType
private String treeNodeAnnotationType
textAnnotationType
private String textAnnotationType
leaves
private HashMap leaves
nonTerminals
private HashMap nonTerminals
buttons
private HashMap buttons
selection
private Vector selection
treeAnnotations
private AnnotationSet treeAnnotations
document
private Document document
unicodeSupportEnabled
private boolean unicodeSupportEnabled
SyntaxTreeViewer
private SyntaxTreeViewer()
SyntaxTreeViewer
public SyntaxTreeViewer(String annotType)
SyntaxTreeViewer
private SyntaxTreeViewer(String annotType,
boolean unicodeSupport)
jbInit
private void jbInit()
throws Exception
main
public static void main(String[] args)
throws Exception
paintComponent
protected void paintComponent(Graphics g)
- Overrides:
paintComponent
in class JComponent
drawLines
private void drawLines(Graphics g)
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
this_propertyChange
void this_propertyChange(PropertyChangeEvent e)
clearAll
private void clearAll()
- Clear all buttons and tree nodes created because component is being
re-initialised. Not sure it works perfectly.
annotations2Trees
private void annotations2Trees()
- Converts the annotations into treeNodes and sets the displayedString
correctly.
processChildrenAnnots
private JButton processChildrenAnnots(Annotation annot,
HashMap processed)
findLeaf
private STreeNode findLeaf(Node start,
Node end)
utterances2Trees
private void utterances2Trees()
- Converts the given utterances into a set of leaf nodes for annotation
tokens2Tree
private void tokens2Tree(AnnotationSet tokens)
- Converts the given tokens into a set of leaf nodes
this needs testing as I've never used it
createButton4Node
private int createButton4Node(STreeNode node,
int buttonX,
int buttonY)
- Returns the X position where another button can start if necessary.
To be used to layout only the leaf buttons. All others must be created
central to their children using createCentralButton.
createCentralButton
private JButton createCentralButton(STreeNode newNode)
shiftButtonsDown
private void shiftButtonsDown(int offset)
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
showRightClickPopup
private void showRightClickPopup(MouseEvent e)
addLines
private void addLines(STreeNode newNode)
clearSelection
private void clearSelection()
fillCategoriesMenu
private void fillCategoriesMenu()
setMenuCommands
private void setMenuCommands(JPopupMenu menu,
String command)
- Sets the action commands of all menu items to the specified command
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
selectNode
void selectNode(MouseEvent e)
removeNode
void removeNode(JButton button)
resetChildren
private void resetChildren(STreeNode node)
removeNodesAbove
private void removeNodesAbove(STreeNode node)
recalculateLines
private void recalculateLines()
recalculateLines
private void recalculateLines(STreeNode node)
- recalculates all lines from that node to all its children
setTreeAnnotations
public void setTreeAnnotations(AnnotationSet newTreeAnnotations)
setTreeNodeAnnotationType
public void setTreeNodeAnnotationType(String newTreeNodeAnnotationType)
setTextAnnotationType
public void setTextAnnotationType(String newTextAnnotationType)