diff --git a/source/org/thdl/tib/input/DictionarySettings.java b/source/org/thdl/tib/input/DictionarySettings.java index 0fad106..7d6e862 100644 --- a/source/org/thdl/tib/input/DictionarySettings.java +++ b/source/org/thdl/tib/input/DictionarySettings.java @@ -14,10 +14,10 @@ public class DictionarySettings public DictionarySettings () { - boolean dictionaryValid = false ; - boolean dictionaryEnabled = false ; - boolean dictionaryLocal = false ; - String dictionaryPath = "" ; + dictionaryValid = false ; + dictionaryEnabled = false ; + dictionaryLocal = false ; + dictionaryPath = "" ; } public DictionarySettings ( boolean valid, boolean enabled, boolean local, String pathOrUrl ) @@ -36,6 +36,14 @@ public class DictionarySettings dictionaryPath = pathOrUrl ; } + public static DictionarySettings cloneDs ( DictionarySettings ds ) + { + return new DictionarySettings ( ds.dictionaryValid, + ds.dictionaryEnabled, + ds.dictionaryLocal, + ds.dictionaryPath ) ; + } + public boolean equal ( DictionarySettings ds ) { return ( ds.isEnabled () == this.isEnabled () && diff --git a/source/org/thdl/tib/input/DuffPane.java b/source/org/thdl/tib/input/DuffPane.java index e4f8c02..f25ac37 100644 --- a/source/org/thdl/tib/input/DuffPane.java +++ b/source/org/thdl/tib/input/DuffPane.java @@ -252,9 +252,10 @@ public class DuffPane extends TibetanPane * The current dictionary information * @TODO these three fields should be one class */ - private boolean dictionaryEnabled = false ; - private boolean dictionaryLocal = false ; - private String dictionaryPath ; + //private boolean dictionaryEnabled = false ; + //private boolean dictionaryLocal = false ; + //private String dictionaryPath ; + private DictionarySettings dictionarySettings = null ; private Hashtable actions; @@ -448,9 +449,9 @@ public class DuffPane extends TibetanPane "Serif"); romanFontSize = defaultRomanFontSize(); - dictionaryEnabled = defaultDictionarySettingsEnabled () ; - dictionaryLocal = defaultDictionarySettingsLocal () ; - dictionaryPath = defaultDictionarySettingsPath () ; + dictionarySettings = new DictionarySettings ( defaultDictionarySettingsEnabled (), + defaultDictionarySettingsLocal (), + defaultDictionarySettingsPath () ) ; onDictionarySettingsChanged () ; newDocument(); @@ -835,19 +836,9 @@ public class DuffPane extends TibetanPane /** * //MP add comment */ - public boolean getDictionarySettingsEnabled () + public DictionarySettings getDictionarySettings () { - return dictionaryEnabled ; - } - - public boolean getDictionarySettingsLocal () - { - return dictionaryLocal ; - } - - public String getDictionarySettingsPath () - { - return dictionaryPath ; + return dictionarySettings ; } /** @@ -867,9 +858,9 @@ public class DuffPane extends TibetanPane */ public void setDictionarySettings ( boolean enabled, boolean local, String path ) { - dictionaryEnabled = enabled ; - dictionaryLocal = local ; - dictionaryPath = path ; + dictionarySettings.setEnabled ( enabled ) ; + dictionarySettings.setLocal ( local ) ; + dictionarySettings.setPathOrUrl ( path ) ; onDictionarySettingsChanged () ; } @@ -1961,7 +1952,7 @@ public void paste(int offset) public void onDictionarySettingsChanged () { GlobalResourceHolder.getListener ().update ( getObservable (), - (Object)new Integer ( GlobalResourceHolder.Listener.DICTIONARY_SETTINGS ) ) ; + dictionarySettings ) ; if ( null == buttonToggleDict || null == buttonLookupDict ) return ; @@ -2088,14 +2079,18 @@ public void paste(int offset) { public void keyPressed ( KeyEvent ke ) { - if ( KeyEvent.VK_F12 == ke.getKeyCode () ) - { - toggleDictionaryFrame () ; - } - else if ( KeyEvent.VK_F11 == ke.getKeyCode () ) - { - lookupDictionary () ; - } + boolean dictEnabled = buttonLookupDict.isEnabled () && + buttonToggleDict.isEnabled () ; + + + if ( dictEnabled && KeyEvent.VK_F12 == ke.getKeyCode () ) + { + toggleDictionaryFrame () ; + } + else if ( dictEnabled && KeyEvent.VK_F11 == ke.getKeyCode () ) + { + lookupDictionary () ; + } } } ) ; diff --git a/source/org/thdl/tib/input/GlobalResourceHolder.java b/source/org/thdl/tib/input/GlobalResourceHolder.java index 5675c39..95dc6fd 100644 --- a/source/org/thdl/tib/input/GlobalResourceHolder.java +++ b/source/org/thdl/tib/input/GlobalResourceHolder.java @@ -53,32 +53,25 @@ public class GlobalResourceHolder */ public void update ( Observable o, Object arg ) { - onSettingsChange ( ((Integer)arg).intValue () ) ; + onSettingsChange ( arg ) ; } /** * onSettingsChange * */ - public void onSettingsChange ( int setting ) + public void onSettingsChange ( Object arg ) { if ( null == GlobalResourceHolder.settingsServiceProvider ) return ; - if ( DICTIONARY_SETTINGS == setting ) + if ( arg instanceof DictionarySettings ) { // // compare with the current settings // - boolean newDictionaryEnabled = GlobalResourceHolder. - settingsServiceProvider.getDictionarySettingsEnabled () ; - boolean newDictionaryLocal = GlobalResourceHolder. - settingsServiceProvider.getDictionarySettingsLocal () ; - String newDictionaryPath = GlobalResourceHolder. - settingsServiceProvider.getDictionarySettingsPath () ; - - DictionarySettings newSettings = new DictionarySettings ( newDictionaryEnabled, - newDictionaryLocal, - newDictionaryPath ) ; + DictionarySettings newSettings = + DictionarySettings.cloneDs ( GlobalResourceHolder. + settingsServiceProvider.getDictionarySettings () ) ; if ( ! newSettings.equal ( GlobalResourceHolder.dictionarySettings ) ) { diff --git a/source/org/thdl/tib/input/PreferenceWindow.java b/source/org/thdl/tib/input/PreferenceWindow.java index 2e6f969..b4fe181 100644 --- a/source/org/thdl/tib/input/PreferenceWindow.java +++ b/source/org/thdl/tib/input/PreferenceWindow.java @@ -80,9 +80,10 @@ public class PreferenceWindow implements ActionListener, ItemListener GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] fontNames = genv.getAvailableFontFamilyNames(); - valDictionaryEnabled = dp.getDictionarySettingsEnabled () ; - valDictionaryLocal = dp.getDictionarySettingsLocal () ; - valDictionaryPath = dp.getDictionarySettingsPath () ; + DictionarySettings ds = dp.getDictionarySettings () ; + valDictionaryEnabled = ds.isEnabled () ; + valDictionaryLocal = ds.isLocal () ; + valDictionaryPath = ds.getPathOrUrl () ; JPanel tibetanPanel; @@ -355,9 +356,10 @@ public class PreferenceWindow implements ActionListener, ItemListener /** This returns only when the user has closed the dialog */ public void show() { - valDictionaryEnabled = dp.getDictionarySettingsEnabled () ; - valDictionaryLocal = dp.getDictionarySettingsLocal () ; - valDictionaryPath = dp.getDictionarySettingsPath () ; + DictionarySettings ds = dp.getDictionarySettings () ; + valDictionaryEnabled = ds.isEnabled () ; + valDictionaryLocal = ds.isLocal () ; + valDictionaryPath = ds.getPathOrUrl () ; updateDictionaryGui () ; pane.setOptionType ( JOptionPane.OK_CANCEL_OPTION ) ; diff --git a/source/org/thdl/tib/input/SettingsServiceProvider.java b/source/org/thdl/tib/input/SettingsServiceProvider.java index 92539d1..c6debed 100644 --- a/source/org/thdl/tib/input/SettingsServiceProvider.java +++ b/source/org/thdl/tib/input/SettingsServiceProvider.java @@ -25,10 +25,13 @@ import java.util.Observable ; * * @author Edward Garrett, Tibetan and Himalayan Digital Library */ public interface SettingsServiceProvider -{ +{ + /* boolean getDictionarySettingsEnabled () ; boolean getDictionarySettingsLocal () ; - String getDictionarySettingsPath () ; + String getDictionarySettingsPath () ; + */ + DictionarySettings getDictionarySettings () ; Observable getObservable () ; } // interface SettingsServiceProvider