 import flash.display.NativeWindowDisplayState;
 import flash.events.Event;
 import flash.events.MouseEvent;
-import flash.events.NativeWindowDisplayStateEvent;
 import flash.geom.Rectangle;
 import flash.system.Capabilities;
 import flash.text.TextFormat;
 import flash.text.TextFormatAlign;
+
 import mx.controls.Button;
-import mx.core.WindowedApplication;
 import mx.core.IFlexDisplayObject;
 import mx.core.IUITextField;
 import mx.core.IWindow;
-import mx.core.mx_internal;
 import mx.core.UIComponent;
 import mx.core.UITextField;
-import mx.styles.CSSStyleDeclaration;
+import mx.core.mx_internal;
 import mx.styles.ISimpleStyleClient;
 import mx.styles.IStyleClient;
-import mx.styles.StyleManager;
 
 use namespace mx_internal;
 

        titleTextField.text = _title;
        titleTextField.validateNow();

        var charWidth:Number = titleTextField.getLineMetrics(0).width /
                               titleTextField.length;

        if (titleAlign == "left")
        {
            if (buttonAlign == "left")
            {
                titleTextField.setActualSize(
                    width - leftOffset - rightOffset - 2 -
                    Math.max((closeButton.x + closeButton.measuredWidth),
                    (minimizeButton.x + minimizeButton.measuredWidth),
                    (maximizeButton.x + maximizeButton.measuredWidth)),
                    measureChromeText(titleTextField).height +
                    UITextField.TEXT_HEIGHT_PADDING);

                titleTextField.move(
                    leftOffset +
                    Math.max((closeButton.x + closeButton.measuredWidth),
                    (minimizeButton.x + minimizeButton.measuredWidth),
                    (maximizeButton.x + maximizeButton.measuredWidth)),
                    (height - (measureChromeText(titleTextField).height +
                    UITextField.TEXT_HEIGHT_PADDING))/2);


        else // titleAlign is center
        {
            var tf:TextFormat = new TextFormat();
            tf.align = TextFormatAlign.LEFT;
            titleTextField.setTextFormat(tf);

            var titleX:Number;
            var textWidth:Number = titleTextField.getLineMetrics( 0 ).width;
            titleTextField.truncateToFit();
            
            if (buttonAlign == "left")
            {
                titleTextField.setActualSize(
                    width - rightOffset - buttonsX - 2,
                    measureChromeText(titleTextField).height +
                    UITextField.TEXT_HEIGHT_PADDING);

                titleX = Math.max(buttonsX, (width - leftOffset - rightOffset - textWidth)/2);
                
                titleTextField.move(titleX,
                    (height - (measureChromeText(titleTextField).height +
                    UITextField.TEXT_HEIGHT_PADDING))/2);
            }
            else
            {
                titleTextField.setActualSize(
                    width - leftOffset - rightOffset -
                    (width - buttonsX) - 2,
                    measureChromeText(titleTextField).height +
                    UITextField.TEXT_HEIGHT_PADDING);

                titleX = Math.max(0, Math.min(buttonsX - textWidth - 2, (width - leftOffset - rightOffset - textWidth)/2));
                
                titleTextField.move(
                    titleX,
                    (height - (measureChromeText(titleTextField).height +
                    UITextField.TEXT_HEIGHT_PADDING))/2);
            }
        }
    }
