unified the dictionary settings - all in DictionarySettings now, will add synchronization soon for potential delayed loading
This commit is contained in:
parent
de3e9a1dd0
commit
f0576e5c94
5 changed files with 56 additions and 55 deletions
|
@ -14,10 +14,10 @@ public class DictionarySettings
|
||||||
|
|
||||||
public DictionarySettings ()
|
public DictionarySettings ()
|
||||||
{
|
{
|
||||||
boolean dictionaryValid = false ;
|
dictionaryValid = false ;
|
||||||
boolean dictionaryEnabled = false ;
|
dictionaryEnabled = false ;
|
||||||
boolean dictionaryLocal = false ;
|
dictionaryLocal = false ;
|
||||||
String dictionaryPath = "" ;
|
dictionaryPath = "" ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DictionarySettings ( boolean valid, boolean enabled, boolean local, String pathOrUrl )
|
public DictionarySettings ( boolean valid, boolean enabled, boolean local, String pathOrUrl )
|
||||||
|
@ -36,6 +36,14 @@ public class DictionarySettings
|
||||||
dictionaryPath = pathOrUrl ;
|
dictionaryPath = pathOrUrl ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DictionarySettings cloneDs ( DictionarySettings ds )
|
||||||
|
{
|
||||||
|
return new DictionarySettings ( ds.dictionaryValid,
|
||||||
|
ds.dictionaryEnabled,
|
||||||
|
ds.dictionaryLocal,
|
||||||
|
ds.dictionaryPath ) ;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean equal ( DictionarySettings ds )
|
public boolean equal ( DictionarySettings ds )
|
||||||
{
|
{
|
||||||
return ( ds.isEnabled () == this.isEnabled () &&
|
return ( ds.isEnabled () == this.isEnabled () &&
|
||||||
|
|
|
@ -252,9 +252,10 @@ public class DuffPane extends TibetanPane
|
||||||
* The current dictionary information
|
* The current dictionary information
|
||||||
* @TODO these three fields should be one class
|
* @TODO these three fields should be one class
|
||||||
*/
|
*/
|
||||||
private boolean dictionaryEnabled = false ;
|
//private boolean dictionaryEnabled = false ;
|
||||||
private boolean dictionaryLocal = false ;
|
//private boolean dictionaryLocal = false ;
|
||||||
private String dictionaryPath ;
|
//private String dictionaryPath ;
|
||||||
|
private DictionarySettings dictionarySettings = null ;
|
||||||
|
|
||||||
private Hashtable actions;
|
private Hashtable actions;
|
||||||
|
|
||||||
|
@ -448,9 +449,9 @@ public class DuffPane extends TibetanPane
|
||||||
"Serif");
|
"Serif");
|
||||||
romanFontSize = defaultRomanFontSize();
|
romanFontSize = defaultRomanFontSize();
|
||||||
|
|
||||||
dictionaryEnabled = defaultDictionarySettingsEnabled () ;
|
dictionarySettings = new DictionarySettings ( defaultDictionarySettingsEnabled (),
|
||||||
dictionaryLocal = defaultDictionarySettingsLocal () ;
|
defaultDictionarySettingsLocal (),
|
||||||
dictionaryPath = defaultDictionarySettingsPath () ;
|
defaultDictionarySettingsPath () ) ;
|
||||||
onDictionarySettingsChanged () ;
|
onDictionarySettingsChanged () ;
|
||||||
|
|
||||||
newDocument();
|
newDocument();
|
||||||
|
@ -835,19 +836,9 @@ public class DuffPane extends TibetanPane
|
||||||
/**
|
/**
|
||||||
* //MP add comment
|
* //MP add comment
|
||||||
*/
|
*/
|
||||||
public boolean getDictionarySettingsEnabled ()
|
public DictionarySettings getDictionarySettings ()
|
||||||
{
|
{
|
||||||
return dictionaryEnabled ;
|
return dictionarySettings ;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getDictionarySettingsLocal ()
|
|
||||||
{
|
|
||||||
return dictionaryLocal ;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDictionarySettingsPath ()
|
|
||||||
{
|
|
||||||
return dictionaryPath ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -867,9 +858,9 @@ public class DuffPane extends TibetanPane
|
||||||
*/
|
*/
|
||||||
public void setDictionarySettings ( boolean enabled, boolean local, String path )
|
public void setDictionarySettings ( boolean enabled, boolean local, String path )
|
||||||
{
|
{
|
||||||
dictionaryEnabled = enabled ;
|
dictionarySettings.setEnabled ( enabled ) ;
|
||||||
dictionaryLocal = local ;
|
dictionarySettings.setLocal ( local ) ;
|
||||||
dictionaryPath = path ;
|
dictionarySettings.setPathOrUrl ( path ) ;
|
||||||
|
|
||||||
onDictionarySettingsChanged () ;
|
onDictionarySettingsChanged () ;
|
||||||
}
|
}
|
||||||
|
@ -1961,7 +1952,7 @@ public void paste(int offset)
|
||||||
public void onDictionarySettingsChanged ()
|
public void onDictionarySettingsChanged ()
|
||||||
{
|
{
|
||||||
GlobalResourceHolder.getListener ().update ( getObservable (),
|
GlobalResourceHolder.getListener ().update ( getObservable (),
|
||||||
(Object)new Integer ( GlobalResourceHolder.Listener.DICTIONARY_SETTINGS ) ) ;
|
dictionarySettings ) ;
|
||||||
|
|
||||||
if ( null == buttonToggleDict || null == buttonLookupDict )
|
if ( null == buttonToggleDict || null == buttonLookupDict )
|
||||||
return ;
|
return ;
|
||||||
|
@ -2088,11 +2079,15 @@ public void paste(int offset)
|
||||||
{
|
{
|
||||||
public void keyPressed ( KeyEvent ke )
|
public void keyPressed ( KeyEvent ke )
|
||||||
{
|
{
|
||||||
if ( KeyEvent.VK_F12 == ke.getKeyCode () )
|
boolean dictEnabled = buttonLookupDict.isEnabled () &&
|
||||||
|
buttonToggleDict.isEnabled () ;
|
||||||
|
|
||||||
|
|
||||||
|
if ( dictEnabled && KeyEvent.VK_F12 == ke.getKeyCode () )
|
||||||
{
|
{
|
||||||
toggleDictionaryFrame () ;
|
toggleDictionaryFrame () ;
|
||||||
}
|
}
|
||||||
else if ( KeyEvent.VK_F11 == ke.getKeyCode () )
|
else if ( dictEnabled && KeyEvent.VK_F11 == ke.getKeyCode () )
|
||||||
{
|
{
|
||||||
lookupDictionary () ;
|
lookupDictionary () ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,32 +53,25 @@ public class GlobalResourceHolder
|
||||||
*/
|
*/
|
||||||
public void update ( Observable o, Object arg )
|
public void update ( Observable o, Object arg )
|
||||||
{
|
{
|
||||||
onSettingsChange ( ((Integer)arg).intValue () ) ;
|
onSettingsChange ( arg ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* onSettingsChange
|
* onSettingsChange
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void onSettingsChange ( int setting )
|
public void onSettingsChange ( Object arg )
|
||||||
{
|
{
|
||||||
if ( null == GlobalResourceHolder.settingsServiceProvider )
|
if ( null == GlobalResourceHolder.settingsServiceProvider )
|
||||||
return ;
|
return ;
|
||||||
if ( DICTIONARY_SETTINGS == setting )
|
if ( arg instanceof DictionarySettings )
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// compare with the current settings
|
// compare with the current settings
|
||||||
//
|
//
|
||||||
boolean newDictionaryEnabled = GlobalResourceHolder.
|
DictionarySettings newSettings =
|
||||||
settingsServiceProvider.getDictionarySettingsEnabled () ;
|
DictionarySettings.cloneDs ( GlobalResourceHolder.
|
||||||
boolean newDictionaryLocal = GlobalResourceHolder.
|
settingsServiceProvider.getDictionarySettings () ) ;
|
||||||
settingsServiceProvider.getDictionarySettingsLocal () ;
|
|
||||||
String newDictionaryPath = GlobalResourceHolder.
|
|
||||||
settingsServiceProvider.getDictionarySettingsPath () ;
|
|
||||||
|
|
||||||
DictionarySettings newSettings = new DictionarySettings ( newDictionaryEnabled,
|
|
||||||
newDictionaryLocal,
|
|
||||||
newDictionaryPath ) ;
|
|
||||||
|
|
||||||
if ( ! newSettings.equal ( GlobalResourceHolder.dictionarySettings ) )
|
if ( ! newSettings.equal ( GlobalResourceHolder.dictionarySettings ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -80,9 +80,10 @@ public class PreferenceWindow implements ActionListener, ItemListener
|
||||||
GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||||
String[] fontNames = genv.getAvailableFontFamilyNames();
|
String[] fontNames = genv.getAvailableFontFamilyNames();
|
||||||
|
|
||||||
valDictionaryEnabled = dp.getDictionarySettingsEnabled () ;
|
DictionarySettings ds = dp.getDictionarySettings () ;
|
||||||
valDictionaryLocal = dp.getDictionarySettingsLocal () ;
|
valDictionaryEnabled = ds.isEnabled () ;
|
||||||
valDictionaryPath = dp.getDictionarySettingsPath () ;
|
valDictionaryLocal = ds.isLocal () ;
|
||||||
|
valDictionaryPath = ds.getPathOrUrl () ;
|
||||||
|
|
||||||
|
|
||||||
JPanel tibetanPanel;
|
JPanel tibetanPanel;
|
||||||
|
@ -355,9 +356,10 @@ public class PreferenceWindow implements ActionListener, ItemListener
|
||||||
/** This returns only when the user has closed the dialog */
|
/** This returns only when the user has closed the dialog */
|
||||||
public void show()
|
public void show()
|
||||||
{
|
{
|
||||||
valDictionaryEnabled = dp.getDictionarySettingsEnabled () ;
|
DictionarySettings ds = dp.getDictionarySettings () ;
|
||||||
valDictionaryLocal = dp.getDictionarySettingsLocal () ;
|
valDictionaryEnabled = ds.isEnabled () ;
|
||||||
valDictionaryPath = dp.getDictionarySettingsPath () ;
|
valDictionaryLocal = ds.isLocal () ;
|
||||||
|
valDictionaryPath = ds.getPathOrUrl () ;
|
||||||
updateDictionaryGui () ;
|
updateDictionaryGui () ;
|
||||||
|
|
||||||
pane.setOptionType ( JOptionPane.OK_CANCEL_OPTION ) ;
|
pane.setOptionType ( JOptionPane.OK_CANCEL_OPTION ) ;
|
||||||
|
|
|
@ -26,9 +26,12 @@ import java.util.Observable ;
|
||||||
* @author Edward Garrett, Tibetan and Himalayan Digital Library */
|
* @author Edward Garrett, Tibetan and Himalayan Digital Library */
|
||||||
public interface SettingsServiceProvider
|
public interface SettingsServiceProvider
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
boolean getDictionarySettingsEnabled () ;
|
boolean getDictionarySettingsEnabled () ;
|
||||||
boolean getDictionarySettingsLocal () ;
|
boolean getDictionarySettingsLocal () ;
|
||||||
String getDictionarySettingsPath () ;
|
String getDictionarySettingsPath () ;
|
||||||
|
*/
|
||||||
|
|
||||||
|
DictionarySettings getDictionarySettings () ;
|
||||||
Observable getObservable () ;
|
Observable getObservable () ;
|
||||||
} // interface SettingsServiceProvider
|
} // interface SettingsServiceProvider
|
||||||
|
|
Loading…
Reference in a new issue