Class TranscriptDocument

java.lang.Object
javax.swing.text.AbstractDocument
javax.swing.text.DefaultStyledDocument
ca.phon.app.session.editor.view.transcript.TranscriptDocument
All Implemented Interfaces:
IExtendable, Serializable, Document, StyledDocument

public class TranscriptDocument extends DefaultStyledDocument implements IExtendable
Text document for a Session that displays the transcript including all tiers, comments, and gems.
See Also:
  • Field Details

    • HEADER_TIER_TRANSCRIPT_ELEMENT_INDEX

      public static int HEADER_TIER_TRANSCRIPT_ELEMENT_INDEX
      Header tier transcript element index
    • TRANSCRIPT_ELEMENT_INDEX_NOT_FOUND

      public static int TRANSCRIPT_ELEMENT_INDEX_NOT_FOUND
      Transcript element index not found
  • Constructor Details

  • Method Details

    • getSession

      public Session getSession()
    • setSession

      public void setSession(Session session)
      Sets the session and reloads the content of the document accordingly
      Parameters:
      session - The session to be displayed
    • setTranscriber

      public void setTranscriber(Transcriber transcriber)
      Set transcriber for the document, this will not reload the document
    • getTranscriber

      public Transcriber getTranscriber()
      Get the transcriber for the document
    • getSingleRecordView

      public boolean getSingleRecordView()
    • setSingleRecordView

      public void setSingleRecordView(boolean singleRecordView)
      Sets whether the document is in "single-record view" and reloads the document if it has changed
      Parameters:
      singleRecordView - whether the document will be in single record view
    • getSingleRecordIndex

      public int getSingleRecordIndex()
    • setSingleRecordIndex

      public void setSingleRecordIndex(int singleRecordIndex)
      Sets the index of the record that will be used in single record mode, and reloads the document if it is currently in single record mode
      Parameters:
      singleRecordIndex - the index of the new record for single record mode
    • updateSingleRecord

      public void updateSingleRecord()
    • getUndoSupport

      public SessionEditUndoSupport getUndoSupport()
    • setUndoSupport

      public void setUndoSupport(SessionEditUndoSupport undoSupport)
    • getEventManager

      public EditorEventManager getEventManager()
    • setEventManager

      public void setEventManager(EditorEventManager eventManager)
    • getSessionFactory

      public SessionFactory getSessionFactory()
    • isBypassDocumentFilter

      public boolean isBypassDocumentFilter()
      Returns whether the next call of remove() from the document will bypass the document filter
      Returns:
      whether the remove will be bypassed
    • setBypassDocumentFilter

      public void setBypassDocumentFilter(boolean bypassDocumentFilter)
      Sets whether the next call of remove() from the document will bypass the document filter
      Parameters:
      bypassDocumentFilter - whether the remove will be bypassed
    • isChatTierNamesShown

      public boolean isChatTierNamesShown()
    • setChatTierNamesShown

      public void setChatTierNamesShown(boolean chatTierNamesShown)
    • getTranscriptStyleContext

      public TranscriptStyleContext getTranscriptStyleContext()
    • getTierText

      public String getTierText(Tier<?> tier, String transcriber)
      Gets the text value of a given tier for a given transcriber
      Parameters:
      tier - the tier that the value will come from
      transcriber - the transcriber whose text will be returned
      Returns:
      the text value of a given tier for a given transcriber (or the regular text for the tier if the transcriber is the validator or null)
    • processBatchUpdates

      public void processBatchUpdates(int offs, List<DefaultStyledDocument.ElementSpec> batch) throws BadLocationException
      Adds the contents of the batch to the document at the specified offset, and sets the global paragraph attributes
      Parameters:
      offs - the offset to insert the batch at
      batch - the batch containing the batch to insert
      Throws:
      BadLocationException
    • findParagraphElementIndexForTier

      public int findParagraphElementIndexForTier(int elementIndex, String tierName)
      Find paragraph element index for given tier
      Parameters:
      elementIndex -
      tierName -
    • findLastParagraphElementIndexForTier

      public int findLastParagraphElementIndexForTier(int elementIndex, String tierName)
      Find final paragraph index for tier including dependent tiers.
      Parameters:
      elementIndex -
      tierName -
      Returns:
      the last paragraph index for the given tier or -1 if not found
    • getParagraphAttributes

      public AttributeSet getParagraphAttributes(int paragraphIdx)
    • findParagraphElementIndexForSessionElementIndex

      public int findParagraphElementIndexForSessionElementIndex(int sessionElementIndex)
      Binary search for the first paragraph element index for the given session element index
      Parameters:
      sessionElementIndex - the session element index
      Returns:
      the first paragraph element index for the given element index or -1 if not found
    • getRangeForSessionElementIndex

      public TranscriptDocument.StartEnd getRangeForSessionElementIndex(int sessionElementIndex)
      Return the range for the given transcript element index
      Parameters:
      sessionElementIndex - the session element index
      Returns:
      the range for the given transcript element index or StartEnd(-1, -1) if not found
    • getRecordStartEnd

      public TranscriptDocument.StartEnd getRecordStartEnd(Record record)
      Return string range for given record
      Parameters:
      record -
      Returns:
      the range for the given record or Range(-1, -1) if not found
    • getRecordStart

      public int getRecordStart(int recordIndex)
      Gets the start of the record with the specified index
      Parameters:
      recordIndex - the index of the record
      Returns:
      the position in the document at the beginning of the records content
    • getRecordEnd

      public int getRecordEnd(Record record)
      Gets the end position of the specified record
      Parameters:
      record - the record whose end is trying to be found
      Returns:
      the position in the document immediately after the final character of the records content (newlines included)
    • getRecordStartEnd

      public TranscriptDocument.StartEnd getRecordStartEnd(int recordIndex)
      Return the range of the given recordIndex
      Parameters:
      recordIndex -
      Returns:
      the range of the given recordIndex
    • getRecordStart

      public int getRecordStart(Record record)
      Gets the start position of the given record
      Parameters:
      record - the record whose start position is trying to be found
      Returns:
      the position in the document at the beginning of the records content
    • getRecordEnd

      public int getRecordEnd(int recordIndex)
      Gets the end position of the record at the specified index
      Parameters:
      recordIndex - the index of the record whose end is trying to be found
      Returns:
      the position in the document immediately after the final character of the records content (newlines included)
    • getCommentLabelStartEnd

      public TranscriptDocument.StartEnd getCommentLabelStartEnd(Comment comment)
      Gets the start/end position of the specified comment label
      Parameters:
      comment - the comment whose start position is trying to be found
      Returns:
      the position in the document at the beginning of the comments label or StartEnd(-1, -1) if not found
    • getCommentContentStartEnd

      public TranscriptDocument.StartEnd getCommentContentStartEnd(Comment comment)
      Return the range for the given comment content
      Parameters:
      comment -
      Returns:
      the range for the given comment content, or StartEnd(-1, -1) if not found
    • getCommentStart

      public int getCommentStart(Comment comment)
      Get the start position of the specified comment including label
      Parameters:
      comment - the comment whose start position is trying to be found
      Returns:
      the position in the document at the beginning of the comment label
    • getCommentContentStart

      public int getCommentContentStart(Comment comment)
      Gets the start position of the specified comment
      Parameters:
      comment - the comment whose start position is trying to be found
      Returns:
      the position in the document at the beginning of the comments content
    • getCommentContentEnd

      public int getCommentContentEnd(Comment comment)
      Gets the end position of the specified comment
      Parameters:
      comment - the comment whose end position is trying to be found
      Returns:
      the position in the document immediately after the final character of the comments content (newlines excluded)
    • getGemStart

      public int getGemStart(Gem gem)
      Gets the start position of the specified gem
      Parameters:
      gem - the gem whose start position is trying to be found
      Returns:
      the position in the document at the beginning of the gem label
    • getGemContentStartEnd

      public TranscriptDocument.StartEnd getGemContentStartEnd(Gem gem)
      Get the range for the given gem's content
      Parameters:
      gem -
      Returns:
      the range for the given gem's content
    • getGemContentStart

      public int getGemContentStart(Gem gem)
      Gets the start position of the specified gem
      Parameters:
      gem - the gem whose start position is trying to be found
      Returns:
      the position in the document at the beginning of the gems content
    • getGemContentEnd

      public int getGemContentEnd(Gem gem)
      Gets the end position of the specified gem
      Parameters:
      gem - the gem whose end position is trying to be found
      Returns:
      the position in the document immediately after the final character of the gems content (newlines excluded)
    • getCommentStartEnd

      public TranscriptDocument.StartEnd getCommentStartEnd(Comment comment)
      Return string range for given comment
      Parameters:
      comment -
      Returns:
      the range for the given comment or Range(-1, -1) if not found
    • getCommentEnd

      public int getCommentEnd(Comment comment)
      Gets the end position of the specified comment
      Parameters:
      comment - the comment whose end position is trying to be found
      Returns:
      the position in the document immediately after the final character of the comments content (newlines included)
    • getGemEnd

      public int getGemEnd(Gem gem)
      Gets the end position of the specified gem
      Parameters:
      gem - the gem whose end position is trying to be found
      Returns:
      the position in the document immediately after the final character of the gems content (newlines included)
    • getTierStartEnd

      public TranscriptDocument.StartEnd getTierStartEnd(int recordIndex, String tierName)
      Get tier start/end
      Parameters:
      tierName -
      Returns:
      the range for the given tier or StartEnd(-1, -1) if not found
    • getTierStart

      public int getTierStart(int recordIndex, String tierName)
      Gets the start position of a tier with the specified name in the record at the specified index
      Parameters:
      recordIndex - the index of the record that contains the tier
      tierName - the name of the tier
      Returns:
      the position in the document at the beginning of the tier label
    • getTierEnd

      public int getTierEnd(int recordIndex, String tierName)
      Gets the end position of a tier with the specified name in the record at the specified index. End includes newline at the end of the tier.
      Parameters:
      recordIndex - the index of the record that contains the tier
      tierName - the name of the tier
      Returns:
      the position in the document immediately after the final character of the tiers content (newlines included)
    • getTierContentStartEnd

      public TranscriptDocument.StartEnd getTierContentStartEnd(int recordIndex, String tierName)
      Get the range of the given tier's content not including the new tier label or newline at end of tier
      Parameters:
      recordIndex -
      tierName -
      Returns:
      the start/end of the given tier's content, (-1, -1) if not found
    • getTierContentStart

      public int getTierContentStart(int recordIndex, String tierName)
      Gets the start position of a tier with the specified name in the record at the specified index
      Parameters:
      recordIndex - the index of the record that contains the tier
      tierName - the name of the tier
      Returns:
      the position in the document at the beginning of the tiers content
    • getTierContentEnd

      public int getTierContentEnd(int recordIndex, String tierName)
      Gets the end position of a tier with the specified name in the record at the specified index. End does not include newline at the end of the tier.
      Parameters:
      recordIndex - the index of the record that contains the tier
      tierName - the name of the tier
      Returns:
      the position in the document immediately after the final character of the tiers content (newlines included)
    • getTierLabelStartEnd

      public TranscriptDocument.StartEnd getTierLabelStartEnd(int recordIndex, String tierName)
      Get the start and end position of the given tier label
      Parameters:
      recordIndex -
      tierName -
      Returns:
      the start and end position of the given tier label or StartEnd(-1, -1) if not found, the position will not include the starting whitespace char(s) or the ending : char
    • getGenericStartEnd

      public TranscriptDocument.StartEnd getGenericStartEnd(Tier<?> genericTier)
      Get the range of the given generic tier (header tier)
      Parameters:
      genericTier -
      Returns:
      the range of the given generic tier or Range(-1, -1) if not found
    • getGenericStartEnd

      public TranscriptDocument.StartEnd getGenericStartEnd(String genericTierName)
      Get the range of the given generic tier (header tier)
      Parameters:
      genericTierName -
      Returns:
      the range of the given generic tier or Range(-1, -1) if not found
    • getGenericContentStartEnd

      public TranscriptDocument.StartEnd getGenericContentStartEnd(Tier<?> genericTier)
      Get the range of the given generic tier content (header tier)
      Parameters:
      genericTier -
      Returns:
      the range of the given generic tier or Range(-1, -1) if not found
    • getGenericContentStartEnd

      public TranscriptDocument.StartEnd getGenericContentStartEnd(String genericTierName)
      Get the range of the given generic tier content (header tier)
      Parameters:
      genericTierName -
      Returns:
      the range of the given generic tier or StartEnd(-1, -1) if not found
    • getGenericContentStart

      public int getGenericContentStart(Tier<?> genericTier)
      Gets the start position of the specified "generic tier"
      Parameters:
      genericTier - a reference to the generic tier whose start position is trying to be found
      Returns:
      the position in the document at the beginning of the generic tiers content
    • getGenericContentEnd

      public int getGenericContentEnd(Tier<?> genericTier)
      Gets the end position of the specified "generic tier"
      Parameters:
      genericTier - a reference to the generic tier whose end position is trying to be found
      Returns:
      the position in the document immediately after the final character of the generic tiers content (newlines excluded)
    • getGenericStart

      public int getGenericStart(String genericTierName)
      Gets the start position of the "generic tier" with the specified name
      Parameters:
      genericTierName - the name of the generic tier whose start position is trying to be found
      Returns:
      the position in the document at the beginning of the generic tiers label
    • getGenericStart

      public int getGenericStart(Tier<?> genericTier)
      Gets the start position of the "generic tier" with the specified name
      Parameters:
      genericTier - the generic tier whose start position is trying to be found
      Returns:
      the position in the document at the beginning of the generic tiers label
    • getGenericContentStart

      public int getGenericContentStart(String genericTierName)
      Gets the start position of the "generic tier" with the specified name
      Parameters:
      genericTierName - the name of the generic tier whose start position is trying to be found
      Returns:
      the position in the document at the beginning of the generic tiers content
    • getGenericEnd

      public int getGenericEnd(Tier<?> genericTier)
      Gets the end position of the specified "generic tier"
      Parameters:
      genericTier - the generic tier whose end position is trying to be found
      Returns:
      the position in the document immediately after the final character of the generic tiers content (newlines included)
    • getGenericEnd

      public int getGenericEnd(String genericTierName)
      Gets the end position of the "generic tier" with the specified name
      Parameters:
      genericTierName - the name of the generic tier whose end position is trying to be found
      Returns:
      the position in the document immediately after the final character of the generic tiers content (newlines included)
    • getGemStartEnd

      public TranscriptDocument.StartEnd getGemStartEnd(Gem gem)
      Return string range for given gem
      Parameters:
      gem -
      Returns:
      the range for the given gem or Range(-1, -1) if not found
    • getGemLabelStartEnd

      public TranscriptDocument.StartEnd getGemLabelStartEnd(Gem gem)
      Return string range for given gem label
      Parameters:
      gem -
      Returns:
      the range for the given gem label or StartEnd(-1, -1) if not found
    • getSegmentBounds

      public TranscriptDocument.StartEnd getSegmentBounds(MediaSegment segment, int includedPos)
      Gets a record containing the start and end of a specified segment assuming the specified position is somewhere between the two
      Parameters:
      segment - the segment that the bounds are being calculated for
      includedPos - a position included in the bounds of the segment
      Returns:
      a record containing the start and end of the segment
    • getCharAtPos

      public Character getCharAtPos(int pos)
      Gets the character at the specified position in the document
      Parameters:
      pos - the position to get the character from
      Returns:
      the character at the specified position
    • getRecordIndex

      public int getRecordIndex(int position)
      Gets the index of the record containing the specified position
      Parameters:
      position - a position in the document in a record
      Returns:
      the index of the record
    • getRecordElementIndex

      public int getRecordElementIndex(int position)
      Gets the element index of the record containing the specified position
      Parameters:
      position - a position in the document in a record
      Returns:
      the element index of the record
    • getTier

      public Tier<?> getTier(int position)
      Gets the tier containing the specified position
      Parameters:
      position - a position in the document in a record
      Returns:
      a reference to the tier
    • getOffsetInContent

      public int getOffsetInContent(int pos)
      Gets the offset from the preceding label of a given position in the document
      Parameters:
      pos - the position that the offset will come from
    • charPosToSessionLocation

      public TranscriptElementLocation charPosToSessionLocation(int charPos)
      Converts a character position in the document into a TranscriptElementLocation object
      Parameters:
      charPos - the position in the document
      Returns:
      the converted session location object
    • sessionLocationToCharPos

      public int sessionLocationToCharPos(TranscriptElementLocation transcriptLocation)
      Converts a session location into a character position in the document
      Parameters:
      transcriptLocation - the session location object
      Returns:
      the converted character position
    • updateGlobalParagraphAttributes

      public void updateGlobalParagraphAttributes()
    • updateParagraphAttributes

      public void updateParagraphAttributes(Element paraEle)
    • deleteTranscriptElement

      public void deleteTranscriptElement(int elementIndex, Transcript.Element elem)
      Deletes a given transcript element from the document
    • onChangeCommentType

      public void onChangeCommentType(Comment comment)
      Updates the displayed type of the given comment in the document
    • onChangeGemType

      public void onChangeGemType(Gem gem)
      Updates the displayed type of the given gem in the document
    • moveRecord

      public void moveRecord(int oldRecordIndex, int newRecordIndex, int oldElementIndex, int newElementIndex)
      Moves a record in the document
      Parameters:
      oldRecordIndex - the existing index of the record
      newRecordIndex - the new index of the record
      oldElementIndex - the existing element index of the record
      newElementIndex - the new element index of the record
    • onChangeSpeaker

      public void onChangeSpeaker(Record record)
      Updates the speaker on the separator / record header
    • onTierDataChanged

      public void onTierDataChanged(Record record, Tier<?> tier)
      Updates the data of the specified tier
      Parameters:
      record - the record that contains the tier
      tier - the tier whose data gets updated
    • addComment

      public void addComment(Comment comment, int transcriptElementIndex)
      Adds a comment to the document and the transcript at the given transcript element index
    • addGem

      public void addGem(Gem gem, int transcriptElementIndex)
    • updateRecord

      public void updateRecord(Record record)
      Update record text in the document
      Parameters:
      record - the record whose media segment is being updated
    • addRecord

      public void addRecord(Record addedRecord, int elementIndex)
      Adds a record to the document
      Parameters:
      addedRecord - the record that gets added
    • deleteRecord

      public void deleteRecord(int elementIndex, int recordIndex, Record removedRecord)
      Removes a record from the document
      Parameters:
      removedRecord - the record that gets removed
    • addTier

      public void addTier(String tierName, int tierIndex, Function<Record,Tier<?>> tierSupplier)
      Insert tier at given tier view index for all records using the provided supplier
      Parameters:
      tierName -
      tierSupplier -
    • removeTier

      public void removeTier(String tierName)
      Remove tier from all records
      Parameters:
      tierName -
    • setTierItemViewLocked

      public void setTierItemViewLocked(String tierName, boolean locked)
      Sets whether a TierViewItem with the provided name is locked
      Parameters:
      tierName - the name of the tier that will be locked or unlocked
      locked - whether the tier will be locked or unlocked
    • getDocumentProperty

      public Object getDocumentProperty(String key)
      Gets the object associated with a given key from the document properties
      Parameters:
      key - the key to get the object with the object
      Returns:
      the object associated with the key (null if no object is present)
    • getDocumentPropertyOrDefault

      public Object getDocumentPropertyOrDefault(String key, Object defaultValue)
      Gets the object associated with a given key from the document properties and returns a given default value if none is present
      Parameters:
      key - the key to get the object with the object
      defaultValue - the object to be returned if there is no object associated with the key
      Returns:
      the object associated with the key or the default if no object is present
    • putDocumentProperty

      public void putDocumentProperty(String key, Object value)
      Adds a given key-value pair to the document properties
      Parameters:
      key - the kek
      value - the value
    • addDocumentPropertyChangeListener

      public void addDocumentPropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
      Adds a property change listener that responds to changes in the document property with the given key / name
      Parameters:
      propertyName - the name / key of the property that will be listened to
      propertyChangeListener - the listener that contains some behavior that will happen when the property changes
    • removeDocumentPropertyChangeListener

      public void removeDocumentPropertyChangeListener(PropertyChangeListener propertyChangeListener)
      Removes a document property change listener
      Parameters:
      propertyChangeListener - the listener that was listening for changes in a document property
    • containsNotEditableAttribute

      public boolean containsNotEditableAttribute(AttributeSet attrs)
      Checks if the provided attribute set contains any attributes that are currently considered "not editable"
      Parameters:
      attrs - the attribute set that will be checked
      Returns:
      whether there were any "not editable" attributes
    • addNotEditableAttribute

      public void addNotEditableAttribute(String attributeKey)
      Adds the given attribute to the set of "not editable" attributes
      Parameters:
      attributeKey - the attribute that will be added to the set
    • removeNotEditableAttribute

      public void removeNotEditableAttribute(String attributeKey)
      Removes the given attribute from the set of "not editable" attributes
      Parameters:
      attributeKey - the attribute that will be removed from the set
    • isPopulating

      public boolean isPopulating()
      Determine if the document is currently being populated
    • reload

      public void reload()
      Empties the document and repopulates it with up-to-date data
    • getInsertionHooks

      public List<InsertionHook> getInsertionHooks()
    • addInsertionHook

      public void addInsertionHook(InsertionHook hook)
    • removeInsertionHook

      public boolean removeInsertionHook(InsertionHook hook)
    • getExtensions

      public Set<Class<?>> getExtensions()
      Description copied from interface: IExtendable
      Return all extension types supported
      Specified by:
      getExtensions in interface IExtendable
    • getExtension

      public <T> T getExtension(Class<T> cap)
      Description copied from interface: IExtendable
      Get the requested extension if available.
      Specified by:
      getExtension in interface IExtendable
      Returns:
      the capability object or null if the cability is not available
    • putExtension

      public <T> T putExtension(Class<T> cap, T impl)
      Description copied from interface: IExtendable
      Add a new extension.
      Specified by:
      putExtension in interface IExtendable
      Parameters:
      cap - the extension to add
      Returns:
      the added extension implementation
    • removeExtension

      public <T> T removeExtension(Class<T> cap)
      Description copied from interface: IExtendable
      Remove a capability.
      Specified by:
      removeExtension in interface IExtendable
      Parameters:
      cap - the capability to remove