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 124a900ed95e14a3424d167d59e5a8952f97b120) @@ -0,0 +1,155 @@ +import mx.controls.* +import mx.utils.* +import mx.managers.* +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.* + +/* +* 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 ok_btn:Button; //OK+Cancel buttons + private var cancel_btn:Button; + private var panel:MovieClip; //The underlaying panel base + + private var fm:FocusManager; //Reference to focus manager + private var themeManager:ThemeManager; //Theme manager + + //Dimensions for resizing + private var xOkOffset:Number; + private var yOkOffset:Number; + private var xCancelOffset:Number; + private var yCancelOffset:Number; + + /** + * constructor + */ + function preferencesDialog(){ + //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; + + //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); + + //get focus manager + set focus to OK button, focus manager is available to all components through getFocusManager + fm = _container.getFocusManager(); + fm.enabled = true; + + + //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)); + //Tie parent click event (generated on clicking close button) to this instance + _container.addEventListener('click',this); + //Register for LFWindow size events + _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(); + } + + /** + * Event fired by StyleManager class to notify listeners that Theme has changed + * it is up to listeners to then query Style Manager for relevant style info + */ + public function themeChanged(event:Object):Void{ + if(event.type=='themeChanged') { + //Theme has changed so update objects to reflect new styles + setStyles(); + }else { + Debugger.log('themeChanged event broadcast with an object.type not equal to "themeChanged"',Debugger.CRITICAL,'themeChanged','org.lamsfoundation.lams.WorkspaceDialog'); + } + } + + /** + * Called on initialisation and themeChanged event handler + */ + private function setStyles(){ + //LFWindow, goes first to prevent being overwritten with inherited styles. + var styleObj = themeManager.getStyleObject('LFWindow'); + _container.setStyle('styleName',styleObj); + + //Get the button style from the style manager and apply to both buttons + styleObj = themeManager.getStyleObject('button'); + ok_btn.setStyle('styleName',styleObj); + cancel_btn.setStyle('styleName',styleObj); + + //Apply combo style + styleObj = themeManager.getStyleObject('combo'); + //languageCombo.setStyle('styleName',styleObj); + } + + /** + * Called by the cancel button + */ + private function cancel(){ + trace('Cancel'); + //close parent window + _container.deletePopUp(); + } + + /** + * Called by the OK button + */ + private function ok(){ + trace('OK'); + //If validation successful commit + close parent window + } + + /** + * Event dispatched by parent container when close button clicked + */ + public function click(e:Object):Void{ + trace('WorkspaceDialog.click'); + e.target.deletePopUp(); + } + + + /** + * Main resize method, called by scrollpane container/parent + */ + public function setSize(w:Number,h:Number):Void{ + //Debugger.log('setSize',Debugger.GEN,'setSize','org.lamsfoundation.lams.common.ws.WorkspaceDialog'); + //Size the panel + panel.setSize(w,h); + + //Buttons + ok_btn.move(w-xOkOffset,h-yOkOffset); + cancel_btn.move(w-xCancelOffset,h-yCancelOffset); + } + + //Gets+Sets + /** + * set the container refernce to the window holding the dialog + */ + function set container(value:MovieClip){ + _container = value; + } + +} \ No newline at end of file