dictionary setting are now grouped in DictionarySettings

This commit is contained in:
micha3lp 2006-08-19 04:43:23 +00:00
parent 7815209c7b
commit eb30452579
2 changed files with 34 additions and 61 deletions

View file

@ -85,7 +85,6 @@ import org.thdl.tib.input.SettingsServiceProvider;
import org.thdl.tib.input.DictionaryLoadState; import org.thdl.tib.input.DictionaryLoadState;
import java.util.Observable ; import java.util.Observable ;
import org.thdl.tib.input.GlobalResourceHolder ; import org.thdl.tib.input.GlobalResourceHolder ;
import org.thdl.tib.input.SettingsChangeListener ;
/** /**
@ -1958,22 +1957,15 @@ public void paste(int offset)
public void onDictionarySettingsChanged () public void onDictionarySettingsChanged ()
{ {
GlobalResourceHolder.getListener ().update ( getObservable (), GlobalResourceHolder.getListener ().update ( getObservable (),
(Object)new Integer ( SettingsChangeListener.DICTIONARY_SETTINGS ) ) ; (Object)new Integer ( GlobalResourceHolder.Listener.DICTIONARY_SETTINGS ) ) ;
if ( null == buttonToggleDict || null == buttonLookupDict ) if ( null == buttonToggleDict || null == buttonLookupDict )
return ; return ;
if ( GlobalResourceHolder.isDictionaryValid () && boolean enableDictionaryButtons = GlobalResourceHolder.getDictionarySettings ().isValid () &&
GlobalResourceHolder.isDictionaryEnabled () ) GlobalResourceHolder.getDictionarySettings ().isEnabled () ;
{ buttonToggleDict.setEnabled ( enableDictionaryButtons ) ;
buttonToggleDict.setEnabled ( true ) ; buttonLookupDict.setEnabled ( enableDictionaryButtons ) ;
buttonLookupDict.setEnabled ( true ) ;
}
else
{
buttonToggleDict.setEnabled ( false ) ;
buttonLookupDict.setEnabled ( false ) ;
}
} }
@ -2177,8 +2169,10 @@ public void paste(int offset)
toolbar.add ( buttonLookupDict ) ; toolbar.add ( buttonLookupDict ) ;
buttonToggleDict.setEnabled ( GlobalResourceHolder.isDictionaryValid () && GlobalResourceHolder.isDictionaryEnabled () ) ; boolean enableDictionaryButtons = GlobalResourceHolder.getDictionarySettings ().isValid () &&
buttonLookupDict.setEnabled ( GlobalResourceHolder.isDictionaryValid () && GlobalResourceHolder.isDictionaryEnabled () ) ; GlobalResourceHolder.getDictionarySettings ().isEnabled () ;
buttonToggleDict.setEnabled ( enableDictionaryButtons ) ;
buttonLookupDict.setEnabled ( enableDictionaryButtons ) ;
} }
} }

View file

@ -10,9 +10,9 @@ import org.thdl.tib.scanner.LocalTibetanScanner ;
import org.thdl.tib.scanner.RemoteTibetanScanner ; import org.thdl.tib.scanner.RemoteTibetanScanner ;
import org.thdl.tib.scanner.Word ; import org.thdl.tib.scanner.Word ;
import org.thdl.tib.input.SettingsChangeListener ;
import org.thdl.tib.input.SettingsServiceProvider ; import org.thdl.tib.input.SettingsServiceProvider ;
import org.thdl.tib.input.DictionaryLoadState ; import org.thdl.tib.input.DictionaryLoadState ;
import org.thdl.tib.input.DictionarySettings ;
import java.awt.GraphicsEnvironment ; import java.awt.GraphicsEnvironment ;
import java.awt.Font ; import java.awt.Font ;
@ -35,17 +35,15 @@ public class GlobalResourceHolder
private static TibetanScanner tibetanScanner = null ; private static TibetanScanner tibetanScanner = null ;
private static SettingsServiceProvider settingsServiceProvider ; private static SettingsServiceProvider settingsServiceProvider ;
private static boolean dictionaryValid = false ; private static DictionarySettings dictionarySettings = null ;
private static boolean dictionaryEnabled = false ;
private static boolean dictionaryLocal = false ;
private static String dictionaryPath = "" ;
private static int dictionaryLoadState = DictionaryLoadState.UNDEFINED ; private static int dictionaryLoadState = DictionaryLoadState.UNDEFINED ;
private static Object dictionaryLoadLock = null ; private static Object dictionaryLoadLock = null ;
//static class Listener implements SettingsChangeListener
static class Listener implements Observer static class Listener implements Observer
{ {
public static final int DICTIONARY_SETTINGS = 1 ;
/** /**
* update * update
* *
@ -64,7 +62,7 @@ public class GlobalResourceHolder
if ( null == GlobalResourceHolder.settingsServiceProvider ) if ( null == GlobalResourceHolder.settingsServiceProvider )
return ; return ;
if ( SettingsChangeListener.DICTIONARY_SETTINGS == setting ) if ( DICTIONARY_SETTINGS == setting )
{ {
// //
// compare with the current settings // compare with the current settings
@ -76,16 +74,13 @@ public class GlobalResourceHolder
String newDictionaryPath = GlobalResourceHolder. String newDictionaryPath = GlobalResourceHolder.
settingsServiceProvider.getDictionarySettingsPath () ; settingsServiceProvider.getDictionarySettingsPath () ;
DictionarySettings newSettings = new DictionarySettings ( newDictionaryEnabled,
newDictionaryLocal,
newDictionaryPath ) ;
if ( newDictionaryEnabled != GlobalResourceHolder.dictionaryEnabled || if ( ! newSettings.equal ( GlobalResourceHolder.dictionarySettings ) )
newDictionaryLocal != GlobalResourceHolder.dictionaryLocal ||
! newDictionaryPath.equals ( GlobalResourceHolder.dictionaryPath ) )
{ {
GlobalResourceHolder.dictionaryEnabled = newDictionaryEnabled ; GlobalResourceHolder.dictionarySettings.set ( newSettings ) ;
GlobalResourceHolder.dictionaryLocal = newDictionaryLocal ;
GlobalResourceHolder.dictionaryPath = newDictionaryPath ;
GlobalResourceHolder.tibetanScanner = GlobalResourceHolder.loadDictionaryScanner () ; GlobalResourceHolder.tibetanScanner = GlobalResourceHolder.loadDictionaryScanner () ;
} }
} }
@ -123,11 +118,7 @@ public class GlobalResourceHolder
// //
tibetanScanner = null ; tibetanScanner = null ;
dictionaryValid = false ; dictionarySettings = new DictionarySettings () ;
dictionaryEnabled = false ;
dictionaryLocal = false ;
dictionaryPath = "" ;
dictionaryLoadLock = new Object () ; dictionaryLoadLock = new Object () ;
} }
@ -160,21 +151,18 @@ public class GlobalResourceHolder
} }
} }
/**
/*
* loadDictionaryScanner * loadDictionaryScanner
* *
*/ */
protected static TibetanScanner loadDictionaryScanner () protected static TibetanScanner loadDictionaryScanner ()
{ {
//return new LocalTibetanScanner ( "F:/tmp/free/free" ) ;
TibetanScanner ts = null ; TibetanScanner ts = null ;
if ( ! dictionaryEnabled ) if ( ! dictionarySettings.isEnabled () )
return null ; return null ;
dictionaryValid = false ; dictionarySettings.setValid ( false ) ;
synchronized ( dictionaryLoadLock ) synchronized ( dictionaryLoadLock )
{ {
@ -182,15 +170,15 @@ public class GlobalResourceHolder
try try
{ {
if ( dictionaryLocal ) if ( dictionarySettings.isLocal () )
{ {
ts = new LocalTibetanScanner ( dictionaryPath ) ; ts = new LocalTibetanScanner ( dictionarySettings.getPathOrUrl () ) ;
dictionaryValid = true ; dictionarySettings.setValid ( true ) ;
} }
else else
{ {
ts = new RemoteTibetanScanner ( dictionaryPath ) ; ts = new RemoteTibetanScanner ( dictionarySettings.getPathOrUrl () ) ;
dictionaryValid = true ; dictionarySettings.setValid ( true ) ;
} }
dictionaryLoadState = DictionaryLoadState.READY ; dictionaryLoadState = DictionaryLoadState.READY ;
@ -395,17 +383,8 @@ public class GlobalResourceHolder
/** /**
* *
*/ */
public static boolean isDictionaryValid () public static DictionarySettings getDictionarySettings ()
{ {
return dictionaryValid ; return dictionarySettings ;
} }
/**
*
*/
public static boolean isDictionaryEnabled ()
{
return dictionaryEnabled ;
}
}; };