Index: lams_common/src/flash/org/lamsfoundation/lams/common/PreferencesDialog.as =================================================================== diff -u --- lams_common/src/flash/org/lamsfoundation/lams/common/PreferencesDialog.as (revision 0) +++ lams_common/src/flash/org/lamsfoundation/lams/common/PreferencesDialog.as (revision be5225130a3e8822d923e0a3fa3594dbbe4dcfa8) @@ -0,0 +1,300 @@ +import mx.controls.* +import mx.utils.* +import mx.managers.* +import mx.events.* + +import org.lamsfoundation.lams.common.ws.* +import org.lamsfoundation.lams.common.util.* +import org.lamsfoundation.lams.common.dict.* +import org.lamsfoundation.lams.common.style.* +import org.lamsfoundation.lams.common.* +import org.lamsfoundation.lams.authoring.* + +/* +* Preferences Dialog window for editing user preferences +* @author DI +*/ +class PreferencesDialog extends MovieClip implements Dialog{ + + //References to components + clips + private var _container:MovieClip; //The container window that holds the dialog + private var cfg:Config; //local config reference + + private var ok_btn:Button; //OK+Cancel buttons + private var cancel_btn:Button; + + private var panel:MovieClip; //The underlaying panel base + + private var lang_cb:ComboBox; //Theme + language labels + private var theme_cb:ComboBox; + + private var lang_lbl:Label; //Theme + language labels + private var theme_lbl:Label; + + + private var fm:FocusManager; //Reference to focus manager + private var themeManager:ThemeManager; //Theme manager + + private var currentLanguage:String; //Language and theme settings for current and new + private var newLanguage:String; + + private var currentTheme:String; + private var newTheme:String; + + //Dimensions for resizing + private var xOkOffset:Number; + private var yOkOffset:Number; + private var xCancelOffset:Number; + private var yCancelOffset:Number; + + //These are defined so that the compiler can 'see' the events that are added at runtime by EventDispatcher + private var dispatchEvent:Function; + public var addEventListener:Function; + public var removeEventListener:Function; + + + /** + * constructor + */ + function PreferencesDialog(){ + //Set up this class to use the Flash event delegation model + EventDispatcher.initialize(this); + + //set up local confi reference + cfg = Config.getInstance(); + + //Create a clip that will wait a frame before dispatching init to give components time to setup + this.onEnterFrame = init; + } + + /** + * Called a frame after movie attached to allow components to initialise + */ + private function init():Void{ + //Delete the enterframe dispatcher + delete this.onEnterFrame; + + //Store current language for rollback if needed + currentLanguage = newLanguage = String(cfg.getItem('language')); + currentTheme = newTheme = String(cfg.getItem('theme')); + + //set the reference to the StyleManager + themeManager = ThemeManager.getInstance(); + + //Set the text for buttons + ok_btn.label = Dictionary.getValue(5); + cancel_btn.label = Dictionary.getValue(6); + + //Set the labels + lang_lbl.text = Dictionary.getValue(7); + theme_lbl.text = Dictionary.getValue(8); + + //get focus manager + set focus to OK button, focus manager is available to all components through getFocusManager + fm = _container.getFocusManager(); + fm.enabled = true; + + //EVENTS + //Add event listeners for ok, cancel and close buttons + ok_btn.addEventListener('click',Delegate.create(this, ok)); + cancel_btn.addEventListener('click',Delegate.create(this, cancel)); + //Assign Click (close button) and resize handlers + _container.addEventListener('click',this); + _container.addEventListener('size',this); + + //work out offsets from bottom RHS of panel + xOkOffset = panel._width - ok_btn._x; + yOkOffset = panel._height - ok_btn._y; + xCancelOffset = panel._width - cancel_btn._x; + yCancelOffset = panel._height - cancel_btn._y; + + //Register as listener with StyleManager and set Styles + themeManager.addEventListener('themeChanged',this); + setStyles(); + + //Populate themes and languages combo + //Languages is an array containing objects with label and data properties + var languages = cfg.getItem('languages'); + lang_cb.dataProvider = languages; + //Select current language + var language = cfg.getItem('language'); + //Go through all options to find current language index and select it in combo + for(var i=0;i