<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Li Guoliang &#187; UI</title>
	<atom:link href="http://liguoliang.com/tag/ui/feed/" rel="self" type="application/rss+xml" />
	<link>http://liguoliang.com</link>
	<description>ActionScript Flex Java JEE PHP...</description>
	<lastBuildDate>Mon, 21 May 2012 17:04:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Flex: 检查/撤销Datagrid编辑数据 Validate/revert editable Datagrid input value</title>
		<link>http://liguoliang.com/2011/validaterevert-editable-datagrid-input-value/</link>
		<comments>http://liguoliang.com/2011/validaterevert-editable-datagrid-input-value/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 13:42:11 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[DataGrid]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[itemEditor]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2011/flex-%e6%a3%80%e6%9f%a5%e6%92%a4%e9%94%80datagrid%e7%bc%96%e8%be%91%e6%95%b0%e6%8d%ae-validaterevert-editable-datagrid-input-value/</guid>
		<description><![CDATA[Requirement: We want to validate user input in editable datagrid, and revert the original value(undo) if necessary.
Solution: Handle the ‘itemEditEnd’<p class='read-more'><a href='http://liguoliang.com/2011/validaterevert-editable-datagrid-input-value/'>More...</a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<p>Requirement: We want to validate user input in editable datagrid, and revert the original value(undo) if necessary.</p>
<p>Solution: Handle the ‘itemEditEnd’ Event dispatched by the datagrid.</p>
<p>Codes:</p>
<pre class="java" name="code">	/**
	 * validate user input, revert the original value if necessary.
	 */
	protected function datagirdTest_itemEditEndHandler(event:DataGridEvent):void {
		if(event.dataField != "Name") { // chech the field;
			return;
		}
		var input:String = (datagirdTest.itemEditorInstance as TextInput).text; // get the user input data.
		if(input == null || input == "") {
			event.preventDefault(); // prevent default behavior
			// var filed:String = (datagirdTest.columns[event.columnIndex] as DataGridColumn).editorDataField;
			// trace(datagirdTest.itemEditorInstance[filed]);
			(datagirdTest.itemEditorInstance as TextInput).text = (event.itemRenderer.data as XML).Name;// Undo: revert the original data by the selected item.
			Alert.show(errorMesg);
			return;
		}
	}
</pre>
<p>Screen caputre: </p>
</p>
<p><a href="http://liguoliang.com/wp-content/uploads/2011/12/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://liguoliang.com/wp-content/uploads/2011/12/image_thumb.png" width="512" height="406"></a> </p>
<p>User input is empty, we got the Event, prevent the default behavior, and revert the value form the modeling.</p>
<p>Ref:</p>
<p>1. itemEditEnd called multiple times <a title="http://forums.adobe.com/message/2459209" href="http://forums.adobe.com/message/2459209">http://forums.adobe.com/message/2459209</a><br />2. Using cell editing events&nbsp; &#8211; <a title="http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_7.html" href="http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_7.html">http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_7.html</a></p>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2011/validaterevert-editable-datagrid-input-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex小技巧: 设定Visiable = flase后重新排列UI</title>
		<link>http://liguoliang.com/2009/flex%e5%b0%8f%e6%8a%80%e5%b7%a7-%e8%ae%be%e5%ae%9avisiable-flase%e5%90%8e%e9%87%8d%e6%96%b0%e6%8e%92%e5%88%97ui/</link>
		<comments>http://liguoliang.com/2009/flex%e5%b0%8f%e6%8a%80%e5%b7%a7-%e8%ae%be%e5%ae%9avisiable-flase%e5%90%8e%e9%87%8d%e6%96%b0%e6%8e%92%e5%88%97ui/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 06:51:40 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[visiable]]></category>

		<guid isPermaLink="false">http://liguoliang.com/2009/02/788/</guid>
		<description><![CDATA[初始化完成后:
<a href="http://liguoliang.com/wp-content/uploads/2009/02/image7.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="275" alt="image" src="http://liguoliang.com/wp-content/uploads/2009/02/image-thumb7.png" width="567" border="0" /></a> 
点击左侧目录后:
<a href="http://liguoliang.com/wp-content/uploads/2009/02/image8.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="348" alt="image" src="http://liguoliang.com/wp-content/uploads/2009/02/image-thumb8.png" width="631" border="0" /></a> 
&#160;
具体实现:
初始化时:
		//Main - Maincontent
		vboxMainRightcontent = new VBox();
		empListContainer = new MainContent();
		empListC<p class='read-more'><a href='http://liguoliang.com/2009/flex%e5%b0%8f%e6%8a%80%e5%b7%a7-%e8%ae%be%e5%ae%9avisiable-flase%e5%90%8e%e9%87%8d%e6%96%b0%e6%8e%92%e5%88%97ui/'>More...</a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<p>初始化完成后:</p>
<p><a href="http://liguoliang.com/wp-content/uploads/2009/02/image7.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="275" alt="image" src="http://liguoliang.com/wp-content/uploads/2009/02/image-thumb7.png" width="567" border="0" /></a> </p>
<p>点击左侧目录后:</p>
<p><a href="http://liguoliang.com/wp-content/uploads/2009/02/image8.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="348" alt="image" src="http://liguoliang.com/wp-content/uploads/2009/02/image-thumb8.png" width="631" border="0" /></a> </p>
<p>&#160;</p>
<p>具体实现:</p>
<p>初始化时:</p>
<pre class="java" name="code">		//Main - Maincontent
		vboxMainRightcontent = new VBox();
		empListContainer = new MainContent();
		empListContainer.visible = false;
		vboxMainRightcontent.addChild(empListContainer);
		//----------------------------加入button 测试 invilidate...----------
		testButton.label = &quot;我是来测试的&quot;;
		vboxMainRightcontent.addChild(testButton);
		empListContainer.explicitHeight = 0;//注意此处, 设置为0方可不占用界面中的场地, 注意在visable设置为true之后还要进行相应的调整
		empListContainer.explicitWidth = 0;</pre>
<p>左侧目录被点击后: </p>
<pre class="java" name="code">
//---------------------------------Listeners------------------------
	//Listener - onListChange
	private function onDepListChange(e:ListEvent):void {
		_empListContainer.visible = _treeDepCat.selectedItem != null;

		if(_empListContainer.visible) {
		        _empListContainer.explicitHeight = undefined;//将explicitHeight复原, 否则虽然已经visable, 但其宽高都是0 仍无法可见.
		       _empListContainer.explicitWidth = undefined;
		}else {
			_empListContainer.explicitHeight = 0;
			_empListContainer.explicitWidth = 0;
		}</pre>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2009/flex%e5%b0%8f%e6%8a%80%e5%b7%a7-%e8%ae%be%e5%ae%9avisiable-flase%e5%90%8e%e9%87%8d%e6%96%b0%e6%8e%92%e5%88%97ui/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>文件属性设置UI设计 &#8211; 初探Flex中自定义组件 Custom UI Component Example: Unix File Permission Setting</title>
		<link>http://liguoliang.com/2008/%e6%96%87%e4%bb%b6%e5%b1%9e%e6%80%a7%e8%ae%be%e7%bd%aeui%e8%ae%be%e8%ae%a1-%e5%88%9d%e6%8e%a2flex%e4%b8%ad%e8%87%aa%e5%ae%9a%e4%b9%89%e7%bb%84%e4%bb%b6-custom-ui-component-example-unix-file-permiss/</link>
		<comments>http://liguoliang.com/2008/%e6%96%87%e4%bb%b6%e5%b1%9e%e6%80%a7%e8%ae%be%e7%bd%aeui%e8%ae%be%e8%ae%a1-%e5%88%9d%e6%8e%a2flex%e4%b8%ad%e8%87%aa%e5%ae%9a%e4%b9%89%e7%bb%84%e4%bb%b6-custom-ui-component-example-unix-file-permiss/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 14:04:13 +0000</pubDate>
		<dc:creator>Guoliang</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Custom Component]]></category>
		<category><![CDATA[Example]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://myxju.com/?p=18</guid>
		<description><![CDATA[<p>[小站博客均为原创, 转载请保留以下信息:</p>
<p>作者:<a href="http://liguoliang.com" target="_blank">http://liguoliang.com</a> 欢迎访问:Adobe上海用户组: <a href="http://riashanghai.com " target="_blank">http://riashanghai.com </a>]</p>
<h2>一:目标</h2>
<p>设计一个自定义组件,可以通过该UI初步读取或设置文件属性.<br />
</p><p class='read-more'><a href='http://liguoliang.com/2008/%e6%96%87%e4%bb%b6%e5%b1%9e%e6%80%a7%e8%ae%be%e7%bd%aeui%e8%ae%be%e8%ae%a1-%e5%88%9d%e6%8e%a2flex%e4%b8%ad%e8%87%aa%e5%ae%9a%e4%b9%89%e7%bb%84%e4%bb%b6-custom-ui-component-example-unix-file-permiss/'>More...</a></p><p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></description>
			<content:encoded><![CDATA[<p>[小站博客均为原创, 转载请保留以下信息:</p>
<p>作者:<a href="http://liguoliang.com" target="_blank">http://liguoliang.com</a> 欢迎访问:Adobe上海用户组: <a href="http://riashanghai.com " target="_blank">http://riashanghai.com </a>]</p>
<h2>一:目标</h2>
<p>设计一个自定义组件,可以通过该UI初步读取或设置文件属性.<br />
<span id="more-18"></span></p>
<h2>二:设计</h2>
<p>概要设计:</p>
<p>* 1.界面使用checkbox.分别对应Ower,Group,Public的Read,Write,Excute权限<br />
* 2.定义变量<br />
* 3.定义get set函数,定义checkbox状态与permission的转换函数,相关Event;</p>
<p>详细设计:</p>
<p>命名:</p>
<p>组件名称:PermissionUI;</p>
<p>各checkbox命名:checkOwnerRead, checkOwnerWrite, checkOwerExecute, checkGroupRead, &#8230;, checkPublicExecute.</p>
<p>变量命名:private _permission;</p>
<p>函数命名: 初始化函数:private function init(); public function set permission(); public function get permission(); checkbox状态转换[permissioncheckbox状态改变响应函数]:private function checkHandler();permission转换为checkbox状态函数 public function permissionToCheck();</p>
<p>代码:</p>
<p>1.初始化:</p>
<pre class="java">/**
* 初始化Array与Dictionary,Array用于存放所有的checkbox,Dictionary为以checkbox为Key,以checkbox对应Permission为值的Dictionary;
* 用于在checkbox与permission之间的转换,即SET与GET函数中通过Permission转换为Checkbox状态与将checkbox状态转换为Permission;
*
* 注意Array中存放的并非为各个checkbox的id[即其变量名称],而是对象,也就是说Array中存放的是9个checkbox.同时Dict中的Key也是checkbox;
*/
private function inint():void{
_checkBoxArray = [checkOwerRead,checkOwerWrite,checkOwerExecute,checkGroupRead,checkGroupWrite,checkGroupExecute,
checkPublicRead,checkPublicWrite,checkPublicExecute];
_checkBoxAndPermissionDict = new Dictionary();
_checkBoxAndPermissionDict[checkOwerRead] = 400;
_checkBoxAndPermissionDict[checkOwerWrite] = 200;
_checkBoxAndPermissionDict[checkOwerExecute] = 100;
_checkBoxAndPermissionDict[checkGroupRead] = 40;
_checkBoxAndPermissionDict[checkGroupWrite] = 20;
_checkBoxAndPermissionDict[checkGroupExecute] = 10;
_checkBoxAndPermissionDict[checkPublicRead] = 4;
_checkBoxAndPermissionDict[checkPublicWrite] = 2;
_checkBoxAndPermissionDict[checkPublicExecute] = 1;
}</pre>
<p>2.get函数</p>
<pre class="java">/**
* 定义Get函数,并设定为Bindable,以便在set之后立即改变permission的值
*/

[Bindable]
public  function get permission():int {
trace("get method is called");
return _permission;
}</pre>
<p>3.set函数:</p>
<pre class="java">/**
* SET函数.通过传来的_permission值确定各个checkbox的选定状态;
* 调用函数permissionTocheck()来完成任务
*/

public function set permission(permission_:int):void {
_permission = permission_;
trace("set method called");
trace(_permission);
permissionToCheck();
}</pre>
<p>4.checkbox状态转换[permissioncheckbox状态改变响应函数]:</p>
<pre class="java">/**
* 定义checkHandler函数,在checkbox状态改变时将其状态转换为permission值.
* 如果permission值改变,广播该事件,以便相关Bindable的值改变.
* 如果将_permission = _value变为permission = _value,则call一次set函数,导致checkbox的一次更新;
* 但后果就是因checkbox状态改变而导致permission改变,但因为调用了set函数,checkbox状态将更新一次.
* 即:因checkbox引起的改变又引起了checkbox的改变.
* 如果不使用propertyChangeEvent,则会引起死循环.
*
* 该函数通过循环checkBoxArray,遍历每一个checkbox,检查其是否被选中,如果被选中,则临时变量_value增加该checkbox在_checkBoxAndPermissionDict中对应的value.
* 达到通过判断checkbox选定状态,来确定_permission值的目的;
*/
public function checkHandler():int {
var _value:int = 0;
var i:int;
if (_checkBoxArray == null || _checkBoxAndPermissionDict == null){
inint();
}
for(i=0; i&lt;_checkBoxArray.length; i++){
if (_checkBoxArray[i].selected == true){
_value += _checkBoxAndPermissionDict[_checkBoxArray[i]];
}
}

trace("Current Permission is " + _permission);
var _old:int = _permission;
_permission = _value;
// dispatch PropertyChanged Event,以便于Binding.定义的_old用于存放最初的permission值.
//_permission为最新的值.如有不同则dispatch,便于更新TestPermission的数据,完成get方法.
this.dispatchEvent(mx.events.PropertyChangeEvent.createUpdateEvent(this,"permission",_old,_permission));
return _permission;
}</pre>
<p>5.permission转换为checkbox状态函数:</p>
<pre class="java">/**
* 通过遍历每个checkbox,判断临时变量temp[值为set函数的参数]与checkbox在Dict中对应值得大小来确定该checkbox是否选定,
* 因为Dict中的每个value都是从大到小排列的,如果temp大于某checkbox的对应value,则可以确定该checkbox需要选定.
* 同时,为了配合前端的手动修改,会通过直接修改permission而不是通过checkbox来修改permission,
* 必须应该每个checkbox在选定之前取消选定,否则前面选定的checkbox在permission手动修改之后仍旧保持选定状态.该语句置于for循环之内,
* 保证每次判断或是操作checkbox之前取消其选定状态.
*/
public function permissionToCheck():void {
var i:int;
var temp:int = _permission;
if (_checkBoxArray == null || _checkBoxAndPermissionDict == null){
inint();
}
for (i = 0; i&lt;_checkBoxArray.length; i++){
_checkBoxArray[i].selected = false;
if (temp &gt;=  _checkBoxAndPermissionDict[_checkBoxArray[i]]){
_checkBoxArray[i].selected = true;
temp -= _checkBoxAndPermissionDict[_checkBoxArray[i]];
}
}
trace("permission to check ");
}</pre>
<h2>三:测试</h2>
<p>编写测试:</p>
<pre class="java">&lt;![CDATA[
import com.Check;
[Bindable]
public var testPermissionUI:PermissionUI = new PermissionUI();
/**
* 初始化.
* 新建一个PermissionUI,放置于(20,20);
* 使用时可以将permission初始化为某获取文件权限的函数的返回值.
* 此处测试为707,同时将初始值在permissionTextInput中显示.
*/
public function onCreationComplete():void {
testPermissionUI.x = 20;
testPermissionUI.y = 20;
addChild(testPermissionUI);
testPermissionUI.permission = 707;

}
/**
* 用户手动修改permission的时候调用该函数,然后使用set permission,使用给出的permission确定各个checkbox的状态.
*/
public function setPermission():void{
testPermissionUI.permission = int(permissionTextInput.text);
}</pre>
<h2>四:抓图</h2>
<p><img src="http://www.javaplusflex.com/sites/default/files/2008-8-17%200-58-26_2.jpg" alt="" width="390" height="305" /></p>
<h2>五:出现问题及解决方法</h2>
<p>1.MXML中自定义组件的使用.</p>
<p>由于对自定义组件理解不够深入,导致在测试时拖入permissionUI时无法使用,于是新建一个permissionUI,但仍旧无法运行.原因是拖入的自定义组件虽然显示并没有真正使用,而通过new permissionUI()创建的组件因为没有add,导致没有显示出来.应将自定义组件当作普通组件一样使用,拉入后应添加ID,以在函数中使用.也可通过AS代码中new来实例化,但必须通过addchild()使之显示于容器中.</p>
<p>2.对象与String,ID</p>
<p>在最开始的_checkBoxArray设计中,我使用了</p>
<p>_checkBoxArray = ["checkOwerRead","checkOwerWrite","checkOwerExecute","checkGroupRead","checkGroupWrite","checkGroupExecute",<br />
"checkPublicRead","checkPublicWrite","checkPublicExecute"];</p>
<p>在后续使用中使用了_checkBoxArray[i].selected</p>
<p>误以为只要名字与对应ID相同,便可对checkbox进行操作,但实际情况是作为string的checkOwerRead,是不具有 selected的属性的,只有作为checkbox才能使用该属性,将上述数组中的string元素换为checkbox元素即可.因为数组中是可以存放Object的,且Dictionary中key可以为任意类型.这是与HashMap不同的,HashMap的Key只能为String类型.</p>
<p>3.算法设计.</p>
<p>checkbox与int转换的最初思路:</p>
<p>1.checkbox&#8211;&gt;int:分别判断checkbox是否被点击,如果checkOwnerRead被点击,则int自加400,如果是checkOwnerWrite被选中,则int再自增200,以此类推.</p>
<p>2.int&#8211;&gt;checkbox:将int每一位分离出来,如果第一位为7,则Owner列全部选中,如果为6,则选中Read跟Write,如果为5,则选中Excute与Read,以此类推,实现非常复杂.</p>
<p>但如果使用Array与Dictionary组合,则会极大减少工作量.</p>
<p>1.checkbox&#8211;&gt;int:通过遍历checkBoxArray中每个checkbox,检查其是否被选中,如果被选中,则int增加checkBoxAndPermissionDict中对应的value.</p>
<p>2.int&#8211;&gt;checkbox:通过遍历每个checkbox,判断int与checkbox在中checkBoxAndPermissionDict对应值得大小来确定该checkbox是否选定.</p>
<p>4.测试时手动输入属性的实现</p>
<p>最开始时仅仅将input中的输入数值赋给permission,调用了set函数,但并不能有效完成任务.通过分析发现,因为之前初始化的 permission以将部分checkbox选中,新set的值在permissionToCheck()时,只会将应该选定但没有选定的 checkbox选中,但已经选定的checkbox不会变化,于是在permissionToCheck()的for循环中加入了:</p>
<p>_checkBoxArray[i].selected = false;</p>
<p>由于该语句置于for循环之内,保证每次判断或是操作checkbox之前取消其选定状态.</p>
<h2>六:相关知识点总结</h2>
<p>1.Bindable</p>
<p>2.自定义事件</p>
<p>3.Array Dictionary</p>
<p><p>

----------Post from: <a href="http://liguoliang.com">@LiGuoliang.com, 欢迎回来~</a>----------</p></p>
]]></content:encoded>
			<wfw:commentRss>http://liguoliang.com/2008/%e6%96%87%e4%bb%b6%e5%b1%9e%e6%80%a7%e8%ae%be%e7%bd%aeui%e8%ae%be%e8%ae%a1-%e5%88%9d%e6%8e%a2flex%e4%b8%ad%e8%87%aa%e5%ae%9a%e4%b9%89%e7%bb%84%e4%bb%b6-custom-ui-component-example-unix-file-permiss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

