changed related to adding the ../dictionary branch

This commit is contained in:
micha3lp 2006-08-26 01:39:37 +00:00
parent 81dccdb317
commit 6f87bbd844
3 changed files with 106 additions and 78 deletions

View file

@ -18,6 +18,13 @@ import javax.swing.event.ListSelectionListener ;
import javax.swing.event.ListSelectionEvent ;
import java.util.concurrent.locks.ReentrantLock ;
import java.text.StringCharacterIterator ;
import org.thdl.tib.dictionary.TextBody ;
import org.thdl.tib.dictionary.DictionaryEntry ;
import org.thdl.tib.dictionary.DictionaryEntries ;
import org.thdl.tib.dictionary.DictionaryEntryDefinition ;
import org.thdl.tib.dictionary.DictionaryEntryDefinitions ;
import org.thdl.tib.dictionary.Phonetics ;
import java.util.Iterator ;
class DictionaryFrame extends JFrame implements ListSelectionListener
{
@ -270,7 +277,7 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
* @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 )
private void setOriginal ( String text, DefaultStyledDocument realDoc, int startPos, int endPos )
{
AbstractDocument doc = (AbstractDocument)original.getDocument () ;
@ -305,7 +312,7 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
/**
* set the pronounciation field
*/
public void setPronounciation ( String text )
private void setPronounciation ( String text )
{
//
// set the pronounciation field
@ -318,14 +325,14 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
*
* @param text - description as retrieved form TibetanScanner derived objs
*/
public void addDescription ( String text )
private void addDescription ( String key, String desc )
{
//
// add the keyword to entryList. we assume the keyword is anything in the
// dictionary entry that precedes the first dash
//
text = handleSanskrit ( text ) ;
desc = handleSanskrit ( desc ) ;
listLock.lock () ;
@ -342,9 +349,8 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
len = doc.getLength () ;
}
int dashIndex = text.indexOf ( "-" ) ;
String keyword = text.substring ( 0, dashIndex - 1 ) ;
String entry = text.substring ( dashIndex + 1 ) ;
String keyword = key ;
String entry = desc ;
//
// add keyword to the list box
@ -358,7 +364,7 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
//
// add entry to the list box
//
doc.insertString ( len, keyword, attrSet ) ;
doc.insertString ( len, keyword + "\n" , attrSet ) ;
len = doc.getLength () ;
StyleConstants.setBold ( attrSet, true ) ;
@ -374,7 +380,6 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
listLock.unlock () ;
}
}
/**
* called when entryList selection changes
*/
@ -419,6 +424,50 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
}
}
/**
* setData
*
*/
public void setData ( DictionaryEntries de, DefaultStyledDocument doc, int startPos, int endPos )
{
// TODO
String originalText = "" ;
String pronounciationText = "" ;
Iterator it = de.iterator () ;
while ( it.hasNext () )
{
DictionaryEntry entry = (DictionaryEntry)it.next () ;
if ( originalText.length () > 0 )
originalText += " " ;
if ( pronounciationText.length () > 0 )
pronounciationText += " " ;
originalText += entry.getKeyword ().getWylie () ;
pronounciationText += Phonetics.standardToLocalized ( Phonetics.THDL_ENGLISH, entry.getPhonetic () ) ;
String desc = entry.getKeyword () + "\n" ;
String defString = "" ;
DictionaryEntryDefinitions defs = entry.getDefinitions () ;
Iterator defIt = defs.iterator () ;
while ( defIt.hasNext () )
{
DictionaryEntryDefinition def = (DictionaryEntryDefinition) defIt.next () ;
defString += def.toString () ;
defString += "\n" ;
}
addDescription ( entry.getKeyword ().getWylie (), defString ) ;
}
setOriginal ( originalText, doc, startPos, endPos ) ;
setPronounciation ( pronounciationText ) ;
}
/**
* gotoList
* force the focus to the entry list box
@ -569,6 +618,7 @@ class DictionaryFrame extends JFrame implements ListSelectionListener
word = word.replaceAll ( "R", "r\u0323" ) ;
word = word.replaceAll ( "L", "l\u0323" ) ;
word = word.replaceAll ( "z", "s\u0301" ) ;
word = word.replaceAll ( "G", "s\u0303" ) ;
}
return word ;

View file

@ -85,6 +85,10 @@ import org.thdl.tib.input.SettingsServiceProvider;
import org.thdl.tib.input.DictionaryLoadState;
import java.util.Observable ;
import org.thdl.tib.input.GlobalResourceHolder ;
import org.thdl.tib.dictionary.TextBody ;
import org.thdl.tib.dictionary.SimpleTextBody ;
import org.thdl.tib.dictionary.DictionaryEntries ;
import org.thdl.tib.dictionary.DictionaryInterface ;
/**
@ -2048,46 +2052,20 @@ public void paste(int offset)
//
// collect the text the good way
//
boolean [] noSuch = new boolean [] { false } ;
word = doc.getWylie ( startPos, endPos+1, noSuch ) ;
word = word.replaceAll ( "[\\/\\_\\*]", " " ) ;
//
// show dictionary data
//
if ( word.length () > 0 )
{
try
{
TextBody tb = SimpleTextBody.fromWylie ( word ) ;
DictionaryInterface dict = GlobalResourceHolder.getDictionary () ;
DictionaryEntries entries = dict.lookup ( tb ) ;
dictFrame.reset () ;
dictFrame.setOriginal ( word, doc, startPos, endPos ) ;
dictFrame.setPronounciation ( pronounciation.process ( word ) ) ;
}
catch ( Exception e )
{
// TODO
}
TibetanScanner scanner = GlobalResourceHolder.getTibetanScanner () ;
if ( null != scanner )
{
scanner.scanBody ( word ) ;
scanner.finishUp () ;
Word [] words = scanner.getWordArray () ;
for ( int i = 0; i < words.length ; i++ )
{
dictFrame.addDescription ( words [i].toString () ) ;
}
scanner.clearTokens () ;
dictFrame.setData ( entries, doc, startPos, endPos ) ;
dictFrame.setVisible ( true ) ;
dictFrame.requestFocusInWindow () ;
dictFrame.gotoList () ;
}
}
}
private void initDictionarySupport ( Object frame )
{

View file

@ -13,6 +13,8 @@ import org.thdl.tib.scanner.Word ;
import org.thdl.tib.input.SettingsServiceProvider ;
import org.thdl.tib.input.DictionaryLoadState ;
import org.thdl.tib.input.DictionarySettings ;
import org.thdl.tib.dictionary.DictionaryInterface ;
import org.thdl.tib.dictionary.ScannerBasedDictionary ;
import java.awt.GraphicsEnvironment ;
import java.awt.Font ;
@ -32,7 +34,6 @@ public class GlobalResourceHolder
private static Font baseTMWFont [] = null ;
private static Font derivedTMWFont [] = null ;
private static HashMap nameToNumber = null ;
private static TibetanScanner tibetanScanner = null ;
private static SettingsServiceProvider settingsServiceProvider ;
private static DictionarySettings dictionarySettings = null ;
@ -40,6 +41,8 @@ public class GlobalResourceHolder
private static int dictionaryLoadState = DictionaryLoadState.UNDEFINED ;
private static Object dictionaryLoadLock = null ;
private static DictionaryInterface dictionary = null ;
static class Listener implements Observer
{
public static final int DICTIONARY_SETTINGS = 1 ;
@ -80,7 +83,7 @@ public class GlobalResourceHolder
if ( ! newSettings.equal ( GlobalResourceHolder.dictionarySettings ) )
{
GlobalResourceHolder.dictionarySettings.set ( newSettings ) ;
GlobalResourceHolder.tibetanScanner = GlobalResourceHolder.loadDictionaryScanner () ;
GlobalResourceHolder.dictionary = GlobalResourceHolder.loadDictionary () ;
}
}
}
@ -115,8 +118,6 @@ public class GlobalResourceHolder
//
// initialize the dictionary stuff
//
tibetanScanner = null ;
dictionarySettings = new DictionarySettings () ;
dictionaryLoadLock = new Object () ;
}
@ -151,12 +152,21 @@ public class GlobalResourceHolder
}
/**
* loadDictionaryScanner
*
*
*/
protected static TibetanScanner loadDictionaryScanner ()
public static DictionaryInterface getDictionary ()
{
TibetanScanner ts = null ;
return dictionary ;
}
/**
* loadDictionary
*
*/
protected static DictionaryInterface loadDictionary ()
{
DictionaryInterface d = null ;
if ( ! dictionarySettings.isEnabled () )
return null ;
@ -171,12 +181,12 @@ public class GlobalResourceHolder
{
if ( dictionarySettings.isLocal () )
{
ts = new LocalTibetanScanner ( dictionarySettings.getPathOrUrl () ) ;
d = new ScannerBasedDictionary ( new LocalTibetanScanner ( dictionarySettings.getPathOrUrl () ) ) ;
dictionarySettings.setValid ( true ) ;
}
else
{
ts = new RemoteTibetanScanner ( dictionarySettings.getPathOrUrl () ) ;
d = new ScannerBasedDictionary ( new RemoteTibetanScanner ( dictionarySettings.getPathOrUrl () ) ) ;
dictionarySettings.setValid ( true ) ;
}
@ -189,7 +199,7 @@ public class GlobalResourceHolder
}
}
return ts ;
return d ;
}
/*
@ -350,16 +360,6 @@ public class GlobalResourceHolder
return flagIsUsingLocalFonts ;
}
/*
* getTibetanScanner ()
*
* returns the dictionary scanner object or null
*/
public static TibetanScanner getTibetanScanner ()
{
return tibetanScanner ;
}
/**
*
*/