added comments in the code

This commit is contained in:
micha3lp 2006-08-13 18:09:33 +00:00
parent 6a30083f11
commit 7d1529ef4b

View file

@ -39,7 +39,8 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
// //
// entryList contains MyListElement-s instead of just String-s // entryList contains MyListElement-s instead of just String-s
// (we want a number to be associated with each element to store the position within description) // (we want a number to be associated with each element to store
// the position within description)
// //
class MyListElement class MyListElement
{ {
@ -113,7 +114,8 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
closeButton = new JButton ( "Close" ) ; closeButton = new JButton ( "Close" ) ;
closeButton.setMnemonic ( 'c' ) ; closeButton.setMnemonic ( 'c' ) ;
closeButton.addActionListener ( new ActionListener () { public void actionPerformed ( ActionEvent e ) { closeWindow () ; } } ) ; closeButton.addActionListener ( new ActionListener ()
{ public void actionPerformed ( ActionEvent e ) { closeWindow () ; } } ) ;
original.setEditable ( false ) ; original.setEditable ( false ) ;
pronounciation.setEditable ( false ) ; pronounciation.setEditable ( false ) ;
@ -220,7 +222,7 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
} }
/** /**
* * close the window
*/ */
void closeWindow () void closeWindow ()
{ {
@ -252,6 +254,8 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
/** /**
* isEmpty * isEmpty
*
* @return true if the dict frame does not display any data
*/ */
public boolean isEmpty () public boolean isEmpty ()
{ {
@ -261,9 +265,10 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
/** /**
* set the original * set the original
* *
* text - has the Wylie roman text * @param text - has the Wylie roman text
* realDoc - ref to the actual document being edited * @param realDoc - ref to the actual document being edited
* startPos, endPos - location of the text in the actual document being edited * @param startPos
* @param endPos - location of the text in the actual document being edited
*/ */
public void setOriginal ( String text, DefaultStyledDocument realDoc, int startPos, int endPos ) public void setOriginal ( String text, DefaultStyledDocument realDoc, int startPos, int endPos )
{ {
@ -310,6 +315,8 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
/** /**
* add a dictionary entry * add a dictionary entry
*
* @param text - description as retrieved form TibetanScanner derived objs
*/ */
public void addDescription ( String text ) public void addDescription ( String text )
{ {
@ -412,25 +419,54 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
} }
} }
/**
* gotoList
* force the focus to the entry list box
*
*/
public void gotoList () public void gotoList ()
{ {
entryList.requestFocusInWindow () ; entryList.requestFocusInWindow () ;
entryList.setSelectedIndex ( 0 ) ; entryList.setSelectedIndex ( 0 ) ;
} }
/**
* handleSanskrit
* converts the dictionary entry text so that romanized Sanskrit leters are
* displayed correctly (long a vs A etc)
*
* @param inText - text as retrieved from TibetanScanner
* @return converted text
*/
protected String handleSanskrit ( String inText ) protected String handleSanskrit ( String inText )
{ {
String outText = "" ; String outText = "" ;
StringCharacterIterator it = new StringCharacterIterator ( inText ) ; StringCharacterIterator it = new StringCharacterIterator ( inText ) ;
//
// we have three states
//
final int DEFAULT = 0 ; final int DEFAULT = 0 ;
final int INBRACES = 1 ; final int INBRACES = 1 ;
final int INWORD = 2 ; final int INWORD = 2 ;
//
// state is the current state
// word is the recently collected piece of text
// wasBraces is true if we are just after a {XX} sequence was encountered
//
int state = DEFAULT ; int state = DEFAULT ;
String word = "" ; String word = "" ;
boolean wasBraces = false ; boolean wasBraces = false ;
//
// loop through the entire text, find whatever is likely to be a Sanskrit word
//
// the decision whether a word could be Sanskrit is based on two criteria:
// 1. if it appears immediately after a {XX} sequence it's assumed to be Sanskrit
// 2. otherwise if it contains a sequence of <lowercase><uppercase>
// in which case uppercase is likely to be a letter that needs conversion
//
for ( char c = it.first (); c != StringCharacterIterator.DONE; c = it.next () ) for ( char c = it.first (); c != StringCharacterIterator.DONE; c = it.next () )
{ {
switch ( state ) switch ( state )
@ -474,6 +510,9 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
} }
else else
{ {
//
// looks like a Sanskrit word, let's convert it
//
outText += processSanskrit ( word, wasBraces ) + c ; outText += processSanskrit ( word, wasBraces ) + c ;
word = "" ; word = "" ;
state = DEFAULT ; state = DEFAULT ;
@ -487,7 +526,14 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
} }
/** /**
* isLikelyToBeSanskrit
* *
* the criterion is :
* the word contains a sequence of <lowercase><uppercase>
*
* @param word
* @return true is word is likely to be Sanskrit
*
*/ */
protected boolean isLikelyToBeSanskrit ( String word ) protected boolean isLikelyToBeSanskrit ( String word )
{ {
@ -498,7 +544,11 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
} }
/** /**
* processSanskrit
* *
* @param word
* @param forceSanskrit
* @return converted word
*/ */
protected String processSanskrit ( String word, boolean forceSanskrit ) protected String processSanskrit ( String word, boolean forceSanskrit )
{ {