gate.gui
Class AnnotationEditor

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--gate.creole.AbstractVisualResource
                                |
                                +--gate.gui.AnnotationEditor
All Implemented Interfaces:
Accessible, FeatureBearer, ImageObserver, MenuContainer, Resource, Serializable, VisualResource

public class AnnotationEditor
extends AbstractVisualResource

This class implements a viewer/editor for the annotations on a document. As a viewer, this visual resource will display all the annotations found on the document. The editor needs to have some data about annotation types in order to allow the editing of annotations. This data comes from the AnnotationSchema objects that are loaded in the Gate system at a given moment. If there are no such objects the editing of annotations will be restricted to a very crude method allowing the user to add any type of annotations having any features with any String values.

See Also:
Serialized Form

Inner Class Summary
protected  class AnnotationEditor.AnnotationsTableModel
          A custom table model used to render a table containing the annotations from a set of annotation sets.
 class AnnotationEditor.CustomLabelView
          Fixes the 4406598 bug in swing text components.
 class AnnotationEditor.CustomStyledEditorKit
          Fixes the 4406598 bug in swing text components.
 class AnnotationEditor.CustomStyledViewFactory
          Fixes the 4406598 bug in swing text components.
(package private)  class AnnotationEditor.DelayedListener
          Used to process a bunch of events after they happened.
protected  class AnnotationEditor.DeleteSelectedAnnotationsAction
           
protected  class AnnotationEditor.EditAnnotationAction
          The action that is fired when the user wants to edit an annotation.
protected  class AnnotationEditor.NewAnnotationPopupItem
          The menu items used for creating a new annotation from the right click popup menu.
protected  class AnnotationEditor.NewCustomAnnotationPopupItem
          The menu items used for creating a new custom annotation from the right click popup menu.
(package private)  class AnnotationEditor.NodeRenderer
          Displays an entry in the right hand side tree.
(package private)  class AnnotationEditor.Range
          Describes a range in the data structure.
protected  class AnnotationEditor.SelectAnnotationPopupItem
          The popup menu items used to select annotations at right click.
(package private)  class AnnotationEditor.SelectionBlinker
          This class handles the blinking for the selected annotations in the text display.
 class AnnotationEditor.TypeData
          Holds the GUI metadata for a given annotation type.
 
Inner classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent, JComponent.ActionStandin, JComponent.IntVector, JComponent.KeyboardState
 
Inner classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.AWTTreeLock
 
Field Summary
protected  AnnotationEditDialog annotationEditDialog
          The dialog used for editing/adding annotations
protected  XJTable annotationsTable
          The table placed below the text display used for showing annotations
protected  AnnotationEditor.AnnotationsTableModel annotationsTableModel
          Model for the annotations table
protected  ColorGenerator colGenerator
          A random colour generator used to generate initial default colours for highlighting various types of annotations.
protected  List data
          holds the data for the annotations table: a list of Annotation objects
private  Document document
          The Document currently displayed.
private  boolean editable
          Should this component bahave as an editor as well as an viewer
protected  AnnotationEditor.DelayedListener eventHandler
          The listener for the evnts coming from the document (annotations and annotation sets added or removed).
private  boolean filtersVisible
          Should the right hand side tree be visible.
protected  Highlighter highlighter
          The highlighter used to help the user select annotations that overlap and for highligting in the text the annotations selected in the lower table.
protected  JSplitPane leftSplit
           
protected  Object lock
          Object used to sychronise all the various threads involved in GUI updating;
protected  JProgressBar progressBar
          The progress bar used during updating the text
protected  Box progressBox
          A box containing a JProgressBar used to keep the user entertained while the text display is being updated
private  PropertyChangeSupport propertyChangeListeners
           
protected  List ranges
          a list containing AnnotationEditor.Range objects.
protected  Highlighter selectionHighlighter
          This highlighter is actually used as a data structure.
protected  TextAttributesChooser styleChooser
          The dialog used for editing the styles used to highlight annotations
protected  JTree stylesTree
          The right hand side tree with all the annotation sets and types of annotations
protected  DefaultTreeModel stylesTreeModel
          The model for the styles tree
protected  DefaultMutableTreeNode stylesTreeRoot
          The root for the styles tree
protected  JScrollPane stylesTreeScroll
          Scroller for the styles tree
protected  JScrollPane tableScroll
          Scroller for the annotations table
private  boolean tableVisible
          Should the table be visible
protected  JTextPane textPane
          The text display.
protected  JScrollPane textScroll
          Scroller used for the text diaplay
private  boolean textVisible
          Should the text be visible
protected  Map typeDataMap
          A composed map used to get the metadata for an annotation type starting from the annotation set name and the type name.
 
Fields inherited from class gate.creole.AbstractVisualResource
features
 
Fields inherited from class javax.swing.JPanel
defaultLayout, uiClassID
 
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
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
AnnotationEditor()
          Default constructor.
 
Method Summary
protected  void addAnnotationSet(AnnotationSet as, int progressStart, int progressEnd)
          Used to register with the GUI a new annotation set on the current document.
 void addPropertyChangeListener(PropertyChangeListener l)
           
 void addPropertyChangeListener(String propertyName, PropertyChangeListener l)
           
protected  Set getAnnotationSchemas()
          Gets all the AnnotationSchema objects currently loaded in the system.
 Document getDocument()
          Gets the currently displayed document
protected  AnnotationEditor.TypeData getTypeData(String setName, String type)
          Gets the data related to a given annotation type.
protected  void initGuiComponents()
          Builds all the graphical components
protected  void initListeners()
          Initialises all the listeners that this component has to register with other classes.
protected  void initLocalData()
          Initialises the local variables to their default values
 boolean isEditable()
          Is the editor functionality enabled
 boolean isFiltersVisible()
          Is the right hand side tree shown?
 boolean isTableVisible()
          Is the annotations table shown?
 boolean isTextVisible()
          Is the text display shown?
static void main(String[] args)
          Test code
 void removePropertyChangeListener(PropertyChangeListener l)
           
protected  void selectAnnotation(String set, Annotation ann)
          Updates the GUI when the user has selected an annotation e.g.
 void setDocument(Document newDocument)
          Sets the document to be displayed
 void setEditable(boolean newEditable)
          Should the editor functionality of this component be enabled
 void setFiltersVisible(boolean newFiltersVisible)
          If set to true the right hand side tree will be displayed.
 void setTableVisible(boolean newTableVisible)
          If set to true the annotations table will be shown.
 void setTextVisible(boolean newTextVisible)
          If set to true the text display will be shown.
protected  void showHighlights(Set annotations, AttributeSet style)
          Repaints the highlighting for annotation types in the text display.
protected  void this_documentChanged()
          Updates this component when the underlying document is changed.
protected  void updateTreeSize()
          Updates the size of the styles tree so it gets all the width it needs
 
Methods inherited from class gate.creole.AbstractVisualResource
getFeatures, init, setFeatures
 
Methods inherited from class javax.swing.JPanel
, getAccessibleContext, getUIClassID, paramString, updateUI, writeObject
 
Methods inherited from class javax.swing.JComponent
_paintImmediately, addAncestorListener, addNotify, 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, paintComponent, 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, 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
 
Methods inherited from interface gate.util.FeatureBearer
getName, setName
 

Field Detail

propertyChangeListeners

private transient PropertyChangeSupport propertyChangeListeners

document

private Document document
The Document currently displayed.

colGenerator

protected ColorGenerator colGenerator
A random colour generator used to generate initial default colours for highlighting various types of annotations.

textPane

protected JTextPane textPane
The text display.

textScroll

protected JScrollPane textScroll
Scroller used for the text diaplay

annotationsTable

protected XJTable annotationsTable
The table placed below the text display used for showing annotations

annotationsTableModel

protected AnnotationEditor.AnnotationsTableModel annotationsTableModel
Model for the annotations table

tableScroll

protected JScrollPane tableScroll
Scroller for the annotations table

leftSplit

protected JSplitPane leftSplit

stylesTree

protected JTree stylesTree
The right hand side tree with all the annotation sets and types of annotations

stylesTreeScroll

protected JScrollPane stylesTreeScroll
Scroller for the styles tree

stylesTreeRoot

protected DefaultMutableTreeNode stylesTreeRoot
The root for the styles tree

stylesTreeModel

protected DefaultTreeModel stylesTreeModel
The model for the styles tree

styleChooser

protected TextAttributesChooser styleChooser
The dialog used for editing the styles used to highlight annotations

annotationEditDialog

protected AnnotationEditDialog annotationEditDialog
The dialog used for editing/adding annotations

progressBox

protected Box progressBox
A box containing a JProgressBar used to keep the user entertained while the text display is being updated

progressBar

protected JProgressBar progressBar
The progress bar used during updating the text

highlighter

protected Highlighter highlighter
The highlighter used to help the user select annotations that overlap and for highligting in the text the annotations selected in the lower table.

selectionHighlighter

protected Highlighter selectionHighlighter
This highlighter is actually used as a data structure. It is used to keep the data for the selected annotations; the actual highlighting will be done by the highlighter as using two different highlighters on the same text component is looking for trouble.

data

protected List data
holds the data for the annotations table: a list of Annotation objects

ranges

protected List ranges
a list containing AnnotationEditor.Range objects. These are the ranges in the data structure. A range is a bunch of annotations belonging to the same annotation set that are contiguous in the data structure.

typeDataMap

protected Map typeDataMap
A composed map used to get the metadata for an annotation type starting from the annotation set name and the type name. Annotation set name -> Annotation type -> AnnotationEditor.TypeData Maps from String to Map to AnnotationEditor.TypeData.

eventHandler

protected AnnotationEditor.DelayedListener eventHandler
The listener for the evnts coming from the document (annotations and annotation sets added or removed). In order to keep the display updated in an efficient manner these events are processed in groups after a short delay and not one by one as they occur. This is based on the assumption that these kinds of events tend to occur in groups (e.g. when a processing resource runs over a document it is likely to generate more than one new annotation).

lock

protected Object lock
Object used to sychronise all the various threads involved in GUI updating;

tableVisible

private boolean tableVisible
Should the table be visible

textVisible

private boolean textVisible
Should the text be visible

filtersVisible

private boolean filtersVisible
Should the right hand side tree be visible. That tree is used to select what types of annotations are visible in the text display, hence the name filters.

editable

private boolean editable
Should this component bahave as an editor as well as an viewer
Constructor Detail

AnnotationEditor

public AnnotationEditor()
Default constructor. Creats all the components and initialises all the internal data to default values where possible.
Method Detail

main

public static void main(String[] args)
Test code

initListeners

protected void initListeners()
Initialises all the listeners that this component has to register with other classes.

initLocalData

protected void initLocalData()
Initialises the local variables to their default values

initGuiComponents

protected void initGuiComponents()
Builds all the graphical components

updateTreeSize

protected void updateTreeSize()
Updates the size of the styles tree so it gets all the width it needs

getAnnotationSchemas

protected Set getAnnotationSchemas()
Gets all the AnnotationSchema objects currently loaded in the system.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Overrides:
removePropertyChangeListener in class JComponent

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Overrides:
addPropertyChangeListener in class JComponent

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener l)
Overrides:
addPropertyChangeListener in class JComponent

setDocument

public void setDocument(Document newDocument)
Sets the document to be displayed
Parameters:
newDocument - a Document

getDocument

public Document getDocument()
Gets the currently displayed document
Returns:
a Document

setTableVisible

public void setTableVisible(boolean newTableVisible)
If set to true the annotations table will be shown. The default value is true

isTableVisible

public boolean isTableVisible()
Is the annotations table shown?

setTextVisible

public void setTextVisible(boolean newTextVisible)
If set to true the text display will be shown. Default value is true

isTextVisible

public boolean isTextVisible()
Is the text display shown?

setFiltersVisible

public void setFiltersVisible(boolean newFiltersVisible)
If set to true the right hand side tree will be displayed. Default value is true

isFiltersVisible

public boolean isFiltersVisible()
Is the right hand side tree shown?

this_documentChanged

protected void this_documentChanged()
Updates this component when the underlying document is changed. This method is only triggered when the document is changed to a new one and not when the internal data from the document changes. For the document internal events {@see #DelayedListener}.

addAnnotationSet

protected void addAnnotationSet(AnnotationSet as,
                                int progressStart,
                                int progressEnd)
Used to register with the GUI a new annotation set on the current document.

getTypeData

protected AnnotationEditor.TypeData getTypeData(String setName,
                                                String type)
Gets the data related to a given annotation type. An annotation type is uniquely identified by the name of its AnnotationSet and the name of the type. For the default annotation set of a document (which has no name) the "<Default>" value is used. Once a AnnotationEditor.TypeData value has been obtained it can be used to change the way the respective type of annotations are displayed.
Parameters:
setName - a String, the name of the annotation set
type - a String, the name of the type.
Returns:
a AnnotationEditor.TypeData value

showHighlights

protected void showHighlights(Set annotations,
                              AttributeSet style)
Repaints the highlighting for annotation types in the text display.

selectAnnotation

protected void selectAnnotation(String set,
                                Annotation ann)
Updates the GUI when the user has selected an annotation e.g. by using the right click popup. That basically means make the appropiate type of annotations visible in case it isn't already.

setEditable

public void setEditable(boolean newEditable)
Should the editor functionality of this component be enabled

isEditable

public boolean isEditable()
Is the editor functionality enabled