Updated Branches: refs/heads/develop 502a365b1 -> cfcdd7805
cleaned up button width code Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/cfcdd780 Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/cfcdd780 Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/cfcdd780 Branch: refs/heads/develop Commit: cfcdd78058a4bb3da0633e5e9678d70a9c5d6818 Parents: 502a365 Author: Justin Mclean <[email protected]> Authored: Mon Sep 30 09:55:07 2013 +1000 Committer: Justin Mclean <[email protected]> Committed: Mon Sep 30 09:55:07 2013 +1000 ---------------------------------------------------------------------- installer/src/InstallApacheFlex.mxml | 96 ++++---------------- .../flex/packageflexsdk/util/CalcButtonWidth.as | 61 +++++++++++++ 2 files changed, 81 insertions(+), 76 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/cfcdd780/installer/src/InstallApacheFlex.mxml ---------------------------------------------------------------------- diff --git a/installer/src/InstallApacheFlex.mxml b/installer/src/InstallApacheFlex.mxml index ddd5cf5..d3978d3 100644 --- a/installer/src/InstallApacheFlex.mxml +++ b/installer/src/InstallApacheFlex.mxml @@ -57,11 +57,9 @@ variables are not required because the locations of these pieces are known. import mx.managers.PopUpManager; import mx.utils.StringUtil; - import spark.events.IndexChangeEvent; - import spark.events.TextOperationEvent; - import org.apache.flex.packageflexsdk.model.InstallerComponentVO; import org.apache.flex.packageflexsdk.resource.ViewResourceConstants; + import org.apache.flex.packageflexsdk.util.CalcButtonWidth; import org.apache.flex.packageflexsdk.util.MD5CompareUtil; import org.apache.flex.packageflexsdk.view.UpdaterDialog; import org.apache.flex.packageflexsdk.view.components.AdobeLicense; @@ -76,6 +74,9 @@ variables are not required because the locations of these pieces are known. import org.as3commons.zip.ZipEvent; import org.as3commons.zip.ZipFile; + import spark.events.IndexChangeEvent; + import spark.events.TextOperationEvent; + import ws.tink.spark.controls.StepItem; private var _mirrorURLCGI:String; @@ -218,72 +219,15 @@ variables are not required because the locations of these pieces are known. nativeApplication.addEventListener(InvokeEvent.INVOKE, parseArgs); } - private var _logButtonWidth:Number = 110; - - [Bindable("logButtonWidthChanged")] - public function get logButtonWidth():Number { - return _logButtonWidth; - } + [Bindable] private var _standardButtonWidth:Number = 88; - private var _folderButtonWidth:Number = 225; - - [Bindable("folderButtonWidthChanged")] - public function get folderButtonWidth():Number { - return _folderButtonWidth; - } - - private var _standardButtonWidth:Number = 88; - - [Bindable("buttonWidthChanged")] - public function get standardButtonWidth():Number { - return _standardButtonWidth; - } - - public function computeStandardButtonWidth():void { - // designer set english width at 88 so factor - // in the different between english strings and 88 - var fudgeFactor:Number = 10; - var logFudgeFactor:Number = 3; - var folderFudgeFactor:Number = 17; + public function setButtonWidths():void { + var calc:CalcButtonWidth = new CalcButtonWidth(hiddenButton); - var w:Number; - hiddenButton.label = installLogBtn.label; - hiddenButton.validateNow(); - w = hiddenButton.measuredWidth; - w += logFudgeFactor; - if (_logButtonWidth != w) { - _logButtonWidth = w; - dispatchEvent(new Event("logButtonWidthChanged")); - } + calc.buttonWidth(installLogBtn); + calc.buttonWidth(openApacheFlexFolderBtn); - hiddenButton.label = openApacheFlexFolderBtn.label; - hiddenButton.validateNow(); - w = hiddenButton.measuredWidth; - w += folderFudgeFactor; - if (_folderButtonWidth != w) { - _folderButtonWidth = w; - dispatchEvent(new Event("folderButtonWidthChanged")); - } - - w = 0; - hiddenButton.label = installBtn.label; - hiddenButton.validateNow(); - w = Math.max(w, hiddenButton.measuredWidth); - hiddenButton.label = browseBtn.label; - hiddenButton.validateNow(); - w = Math.max(w, hiddenButton.measuredWidth); - hiddenButton.label = closeBtn.label; - hiddenButton.validateNow(); - w = Math.max(w, hiddenButton.measuredWidth); - hiddenButton.label = nextBtn.label; - hiddenButton.validateNow(); - w = Math.max(w, hiddenButton.measuredWidth); - - w += fudgeFactor; - if (_standardButtonWidth != w) { - _standardButtonWidth = w; - dispatchEvent(new Event("buttonWidthChanged")); - } + _standardButtonWidth = calc.maxButtonWidth([installBtn, browseBtn, closeBtn, nextBtn]); } private function parseArgs(event:InvokeEvent):void { @@ -316,7 +260,7 @@ variables are not required because the locations of these pieces are known. resourceManager.localeChain = [ ViewResourceConstants.DEFAULT_LANGUAGE ]; _viewResourceConstants = ViewResourceConstants.instance; _viewResourceConstants.update(); - computeStandardButtonWidth(); + setButtonWidths(); selectDefaultLanguage(); } @@ -358,7 +302,7 @@ variables are not required because the locations of these pieces are known. resourceManager.addEventListener(Event.CHANGE, _viewResourceConstants.update); _viewResourceConstants.update(); - computeStandardButtonWidth(); + setButtonWidths(); } @@ -1500,7 +1444,7 @@ variables are not required because the locations of these pieces are known. } resourceManager.update(); - computeStandardButtonWidth(); + setButtonWidths(); } override protected function resourcesChanged():void { @@ -2042,7 +1986,7 @@ variables are not required because the locations of these pieces are known. width="100%"/> <s:Button id="directoryBtn" styleName="mainBtnStyle" - width="{standardButtonWidth}" + width="{_standardButtonWidth}" height="32" right="10" label="{_viewResourceConstants.BTN_LABEL_NEXT}" @@ -2071,7 +2015,7 @@ variables are not required because the locations of these pieces are known. change="handleFlexSDXTxtInputChange(event)"/> <s:Button id="browseBtn" styleName="browseBtnStyle" - width="{standardButtonWidth}" + width="{_standardButtonWidth}" height="32" label="{_viewResourceConstants.BTN_LABEL_BROWSE}" click="browseForSDK(event)" @@ -2081,7 +2025,7 @@ variables are not required because the locations of these pieces are known. width="100%"/> <s:Button id="nextBtn" styleName="mainBtnStyle" - width="{standardButtonWidth}" + width="{_standardButtonWidth}" height="32" right="10" label="{_viewResourceConstants.BTN_LABEL_NEXT}" @@ -2102,7 +2046,7 @@ variables are not required because the locations of these pieces are known. width="100%"/> <s:Button id="installBtn" styleName="mainBtnStyle" - width="{standardButtonWidth}" + width="{_standardButtonWidth}" height="32" right="10" label="{_viewResourceConstants.BTN_LABEL_INSTALL}" @@ -2190,7 +2134,7 @@ variables are not required because the locations of these pieces are known. height="21"/> <s:Button id="openApacheFlexFolderBtn" styleName="mainBtnStyle" - width="{folderButtonWidth}" + width="225" height="32" visible="false" includeInLayout="false" @@ -2209,7 +2153,7 @@ variables are not required because the locations of these pieces are known. verticalAlign="middle"> <s:Button id="installLogBtn" styleName="genericBtnStyle" - width="{logButtonWidth}" + width="110" height="32" label="{_viewResourceConstants.BTN_LABEL_INSTALL_LOG}" click="showConsole(event)"/> @@ -2224,7 +2168,7 @@ variables are not required because the locations of these pieces are known. <s:Spacer width="100%"/> <s:Button id="closeBtn" styleName="genericBtnStyle" - width="{standardButtonWidth}" + width="{_standardButtonWidth}" height="32" label="{_viewResourceConstants.BTN_LABEL_CLOSE}" click="closeApplication(event)"/> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/cfcdd780/installer/src/org/apache/flex/packageflexsdk/util/CalcButtonWidth.as ---------------------------------------------------------------------- diff --git a/installer/src/org/apache/flex/packageflexsdk/util/CalcButtonWidth.as b/installer/src/org/apache/flex/packageflexsdk/util/CalcButtonWidth.as new file mode 100644 index 0000000..bf0a371 --- /dev/null +++ b/installer/src/org/apache/flex/packageflexsdk/util/CalcButtonWidth.as @@ -0,0 +1,61 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package org.apache.flex.packageflexsdk.util +{ + import flash.events.Event; + + import spark.components.Button; + + public class CalcButtonWidth + { + protected static var PADDING:int = 20; + + protected var hiddenButton:Button; + + public function CalcButtonWidth(hiddenButton:Button) + { + this.hiddenButton = hiddenButton; + } + + public function buttonWidth(button:Button):int { + var width:int = 0; + + hiddenButton.label = button.label; + hiddenButton.validateNow(); + width = hiddenButton.measuredWidth + PADDING; + + if (button.width != width) { + button.width = width; + } + + return width; + } + + public function maxButtonWidth(buttons:Array):int { + var width:int = 0; + + for each (var button:Button in buttons) { + width = Math.max(width, buttonWidth(button)); + } + + return width; + } + } +} \ No newline at end of file
