Class TermTool

java.lang.Object
  |
  +--TermTool
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, javax.swing.event.ListSelectionListener, SaturationListener, TextUpdateListener

public class TermTool
extends java.lang.Object
implements java.awt.event.ActionListener, javax.swing.event.ListSelectionListener, SaturationListener, TextUpdateListener

The TermTool is responsible for manipulating terminological information.

Version:
$2007-05-01 03:19:56 mdh$
Author:
Malcolm D. Hyman

Inner Class Summary
 class TermTool.LemmaChangeListener
          This class listens for modifications to the lemmata choosers in the SaturationMeter.
 
Constructor Summary
TermTool(int colorID)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent evt)
          This method handles the action commands generated by buttons.
 boolean addClickedWord(java.lang.String word, int num, java.lang.String xpath, java.lang.String lang)
          Adds a word clicked in the ContentRenderPane to the list of parts that constitute a full instance of a term.
 void addInstance(java.lang.String word, int number, java.lang.String xpath, org.w3c.dom.Node container, java.lang.String lang, ContentRenderPane content)
          Starts the process of adding a new term instance.
 void addTerm()
          Presents a dialog whereby the user may add a new term (not a new term instance -- that's addInstance().
protected  org.w3c.dom.Node addTermToDOM(java.lang.String name, int parts, java.lang.String translation, java.lang.String lang)
          Adds a new term in the DOM.
protected  void addTermToList(java.lang.String name, int parts, java.lang.String translation, java.lang.String lang, java.lang.String comments)
           
 void cancelEdit()
          Cancels any edit that is in progress.
 void cleanup()
          Cleans up the term tool, in particular by pushing any edits to comments.
 void clearFilter()
          Clears filter on term list.
 void copyTerm()
          Copies the selected term (with instances) to another termlist.
 java.lang.String describe()
          Returns a name/description for this TermTool.
 void dispose()
           
 boolean dropInParts(java.io.Reader reader)
          Allows term instances to be added in batch via drag-and-drop.
 boolean editInProgress()
          Returns true if the user is in the process of editing a term instance.
 void editInstance(org.w3c.dom.Element instance, java.lang.String xpath, org.w3c.dom.Node container, java.lang.String lang, ContentRenderPane content, boolean preselected, boolean clearFilter)
          Displays an existing term instance in the term editor.
 void editTerm()
          Presents a dialog whereby the user may edit an existing term (not a term instance).
 void extendMorphology(java.lang.String variant, java.lang.String basic, java.lang.String lang)
           
 void filterTermList()
          Filter term list.
 javax.swing.JPanel getChooserPanel()
          Returns the term chooser widget panel.
 int getColorID()
          Returns the color ID for highlighting terms in this list.
 org.w3c.dom.Document getDocument()
          Returns the termlist document.
 TermTool.LemmaChangeListener getLemmaChangeListener()
          Returns the LemmaChangeListener.
 java.io.File getSaveFile()
          Returns the File to which this URL should be saved.
 java.lang.String getSelectedViewLang()
          Returns the selected view language.
 TermInfo getTermInfo(java.lang.String term)
          Returns the TermInfoobject for a named term.
 org.w3c.dom.Document getTermList()
          Returns XML termlist document.
 javax.swing.JList getTermSelector()
          Returns the term selector component.
 java.net.URL getTermURL()
          Returns the URL used for loading terms.
 void hashInstances(ArborPanel panel)
          Builds a hash that maps DOM nodes to instance elements in the termlist; we'll want to get them quickly when rendering, etc.
 void initAddTermWidgets()
          Initially creates the widgets for the "Add term" dialog.
 void initChooserWidgets()
          Initially creates the widgets for the term chooser dialog.
 boolean isDirty()
          Returns true if the termlist (DOM) is "dirty" -- that is, if any changes have been made.
static boolean isDragInProgress()
          Returns true if a drag involving a TermTool is in progress.
 boolean isFinished()
          Returns true if this object is no longer to be used.
 boolean isInternalContentRenderPane(ContentRenderPane p)
          Returns true if the ContentRenderPane is the internal ContentRenderPane of the editor.
 void multipleSelectionMode(int[] indices)
          Enters multiple-selection mode.
 void parseTermList(ArborAgent agent)
          Parses an XML termlist.
 void playConfirmationSound()
          Plays the sound associated with confirmation of adding a term.
 void redrawTerms()
          Redraws list of terms in editor.
 void refreshTermList()
          Refreshes the list of terms in the term selector.
 void rename()
          Renames the term editor (if it is visible).
 void saturationChanged(SaturationEvent evt)
          This method is part of the SaturationListener interface.
 void seedTermList(java.lang.String loc)
          Loads a list of candidate ("seed") terms from a URl (in string form).
 void serialize(java.io.File file)
          Generates an XML file from the termlist in the DOM.
 boolean serverMode()
          Determines whether we're in server mode (terms from online DB).
 void setAvailableLangs()
          Updates the choices in the picker (combo box) that allows the user to examine candidate terms in the available languages.
 void setDirty(boolean value)
          Sets or clears the "dirty" property of the termlist.
static void setDragInProgress(boolean value)
          Sets global dragInProgress status.
 void setEditInProgress(boolean value)
          Sets the flag that indicates whether the user is in the process of editing a term instance.
 void setLocator(java.lang.String locator)
          Sets the text locator.
 void setSelectLang(java.lang.String lang)
          Sets the value of selectLang.
 void setTermSelectorLanguage(java.lang.String lang)
          Ensures that the term selector displays candidate terms for the given language.
 void setTermTypeMask()
          Sets the term type mask.
 void setTermURL(java.net.URL termURL)
          Sets the URL used for loading terms.
 void showEditor()
          Displays the modeless frame that allows the user to edit term instances.
 void showInstances()
          Displays a new frame containing passages in the current text where the selected technical term is instantiated.
 void showOther()
          Allows the users to view all term instances not in the selected text.
 void showSelectedInstanceInContext()
          Shows the currently selected instance.
 boolean termsLoaded()
          Indicates whether terms have been loaded.
 void textsUpdated(TextUpdateEvent evt)
          Required by the TextUpdateListener interface.
 void valueChanged(javax.swing.event.ListSelectionEvent evt)
          This method is part of the ListSelectionListener interface.
 void view()
          Displays the Term Editor frame.
protected  void zapPart(int num)
          Removes part num from the accumulated instance parts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TermTool

public TermTool(int colorID)
Method Detail

describe

public java.lang.String describe()
Returns a name/description for this TermTool.
Returns:
human-readable name

getSaveFile

public java.io.File getSaveFile()
Returns the File to which this URL should be saved.
Returns:
save file

getColorID

public int getColorID()
Returns the color ID for highlighting terms in this list.
Returns:
highlight color ID

initChooserWidgets

public void initChooserWidgets()
Initially creates the widgets for the term chooser dialog.

rename

public void rename()
Renames the term editor (if it is visible).

getChooserPanel

public javax.swing.JPanel getChooserPanel()
Returns the term chooser widget panel.
Returns:
chooser widget panel

setTermTypeMask

public void setTermTypeMask()
Sets the term type mask.

setTermURL

public void setTermURL(java.net.URL termURL)
Sets the URL used for loading terms.
Parameters:
termURL - URL for loading terms

getTermURL

public java.net.URL getTermURL()
Returns the URL used for loading terms.
Returns:
URL for loading terms

setLocator

public void setLocator(java.lang.String locator)
Sets the text locator.
Parameters:
locator - text locator

parseTermList

public void parseTermList(ArborAgent agent)
Parses an XML termlist.
Parameters:
agent - ArborAgent

hashInstances

public void hashInstances(ArborPanel panel)
Builds a hash that maps DOM nodes to instance elements in the termlist; we'll want to get them quickly when rendering, etc.
Parameters:
panel - ArborPanel

playConfirmationSound

public void playConfirmationSound()
Plays the sound associated with confirmation of adding a term.

addInstance

public void addInstance(java.lang.String word,
                        int number,
                        java.lang.String xpath,
                        org.w3c.dom.Node container,
                        java.lang.String lang,
                        ContentRenderPane content)
Starts the process of adding a new term instance.
Parameters:
word - word in term (e.g., "naturam")
number - number in container
xpath - XPath expression
container - container in document
lang - language code as per ISO 639
content - content pane in which word occurs

editInstance

public void editInstance(org.w3c.dom.Element instance,
                         java.lang.String xpath,
                         org.w3c.dom.Node container,
                         java.lang.String lang,
                         ContentRenderPane content,
                         boolean preselected,
                         boolean clearFilter)
Displays an existing term instance in the term editor.
Parameters:
instance - instance element in termlist
xpath - XPath expression
container - container in document
lang - language code as per ISO 639
content - content pane in which word occurs
preselected - instance is already selected in termSelector
clearFilter - should any active filter be cleared?

multipleSelectionMode

public void multipleSelectionMode(int[] indices)
Enters multiple-selection mode. In this mode, all instances are rendered in the internal ContentRenderPane, but there is no SaturationMeter.
Parameters:
indices - selected indices

termsLoaded

public boolean termsLoaded()
Indicates whether terms have been loaded.
Returns:
true if terms have been loaded

addTermToDOM

protected org.w3c.dom.Node addTermToDOM(java.lang.String name,
                                        int parts,
                                        java.lang.String translation,
                                        java.lang.String lang)
Adds a new term in the DOM.
Parameters:
name - term
parts - number of parts
translation - translation(s)
lang - language code as per ISO 639
Returns:
added term node

textsUpdated

public void textsUpdated(TextUpdateEvent evt)
Required by the TextUpdateListener interface.
Specified by:
textsUpdated in interface TextUpdateListener

showEditor

public void showEditor()
Displays the modeless frame that allows the user to edit term instances.

showInstances

public void showInstances()
Displays a new frame containing passages in the current text where the selected technical term is instantiated.

showOther

public void showOther()
Allows the users to view all term instances not in the selected text. New master texts are opened as necessary, providing Arboreal can resolve the locators.

showSelectedInstanceInContext

public void showSelectedInstanceInContext()
Shows the currently selected instance.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent evt)
This method handles the action commands generated by buttons.
Specified by:
actionPerformed in interface java.awt.event.ActionListener

filterTermList

public void filterTermList()
Filter term list.

clearFilter

public void clearFilter()
Clears filter on term list.

copyTerm

public void copyTerm()
Copies the selected term (with instances) to another termlist.

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent evt)
This method is part of the ListSelectionListener interface.
Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener

saturationChanged

public void saturationChanged(SaturationEvent evt)
This method is part of the SaturationListener interface.
Specified by:
saturationChanged in interface SaturationListener

seedTermList

public void seedTermList(java.lang.String loc)
Loads a list of candidate ("seed") terms from a URl (in string form).
Parameters:
loc - URL source

setTermSelectorLanguage

public void setTermSelectorLanguage(java.lang.String lang)
Ensures that the term selector displays candidate terms for the given language.
Parameters:
lang - language code as per ISO 639

refreshTermList

public void refreshTermList()
Refreshes the list of terms in the term selector.

editInProgress

public boolean editInProgress()
Returns true if the user is in the process of editing a term instance.
Returns:
true if an edit is currently in progress

setEditInProgress

public void setEditInProgress(boolean value)
Sets the flag that indicates whether the user is in the process of editing a term instance.
Parameters:
value - true if an edit is currently in progress

addClickedWord

public boolean addClickedWord(java.lang.String word,
                              int num,
                              java.lang.String xpath,
                              java.lang.String lang)
Adds a word clicked in the ContentRenderPane to the list of parts that constitute a full instance of a term. Each term expects a certain number of parts; when that many parts have been added, the term is considered saturated, and may be added to the database.
Parameters:
word - a variant form from the text
num - instance number of the variant relative to container
xpath - XPath expression
lang - language code as per ISO 639
Returns:
true if word was added, otherwise false

zapPart

protected void zapPart(int num)
Removes part num from the accumulated instance parts.
Parameters:
num - part number

dropInParts

public boolean dropInParts(java.io.Reader reader)
Allows term instances to be added in batch via drag-and-drop.
Parameters:
reader - reader containing term instances in XML fragment form
Returns:
true if instances successfully added

initAddTermWidgets

public void initAddTermWidgets()
Initially creates the widgets for the "Add term" dialog.

addTerm

public void addTerm()
Presents a dialog whereby the user may add a new term (not a new term instance -- that's addInstance().
See Also:
addInstance(java.lang.String, int, java.lang.String, org.w3c.dom.Node, java.lang.String, ContentRenderPane)

addTermToList

protected void addTermToList(java.lang.String name,
                             int parts,
                             java.lang.String translation,
                             java.lang.String lang,
                             java.lang.String comments)

editTerm

public void editTerm()
Presents a dialog whereby the user may edit an existing term (not a term instance).
See Also:
editInstance(org.w3c.dom.Element, java.lang.String, org.w3c.dom.Node, java.lang.String, ContentRenderPane, boolean, boolean)

cancelEdit

public void cancelEdit()
Cancels any edit that is in progress.

serialize

public void serialize(java.io.File file)
Generates an XML file from the termlist in the DOM.
Parameters:
file - file to which XML is written

isDirty

public boolean isDirty()
Returns true if the termlist (DOM) is "dirty" -- that is, if any changes have been made.
Returns:
true if changes made

setDirty

public void setDirty(boolean value)
Sets or clears the "dirty" property of the termlist.
Parameters:
value - true if terms regarded as dirty

redrawTerms

public void redrawTerms()
Redraws list of terms in editor.

dispose

public void dispose()

isFinished

public boolean isFinished()
Returns true if this object is no longer to be used.
Returns:
true if TermTool finished

cleanup

public void cleanup()
Cleans up the term tool, in particular by pushing any edits to comments.

serverMode

public boolean serverMode()
Determines whether we're in server mode (terms from online DB).
Returns:
true if in server mode

getDocument

public org.w3c.dom.Document getDocument()
Returns the termlist document.
Returns:
termlist

view

public void view()
Displays the Term Editor frame.

setAvailableLangs

public void setAvailableLangs()
Updates the choices in the picker (combo box) that allows the user to examine candidate terms in the available languages.

getSelectedViewLang

public java.lang.String getSelectedViewLang()
Returns the selected view language.
Returns:
selected view language

extendMorphology

public void extendMorphology(java.lang.String variant,
                             java.lang.String basic,
                             java.lang.String lang)

getTermSelector

public javax.swing.JList getTermSelector()
Returns the term selector component.
Returns:
term component.

getTermList

public org.w3c.dom.Document getTermList()
Returns XML termlist document.
Returns:
XML termlist document

setSelectLang

public void setSelectLang(java.lang.String lang)
Sets the value of selectLang.
Parameters:
lang - value of selectLang

getTermInfo

public TermInfo getTermInfo(java.lang.String term)
Returns the TermInfoobject for a named term.
Parameters:
term - term name
Returns:
TermInfo object

getLemmaChangeListener

public TermTool.LemmaChangeListener getLemmaChangeListener()
Returns the LemmaChangeListener.
Returns:
lemma change listener

isInternalContentRenderPane

public boolean isInternalContentRenderPane(ContentRenderPane p)
Returns true if the ContentRenderPane is the internal ContentRenderPane of the editor.
Returns:
true if internal ContentRenderPane

setDragInProgress

public static void setDragInProgress(boolean value)
Sets global dragInProgress status.
Parameters:
value - true if a drag is in progress

isDragInProgress

public static boolean isDragInProgress()
Returns true if a drag involving a TermTool is in progress.
Returns:
true if a drag is in progress