Changeset 21457 for lang/actionscript

Show
Ignore:
Timestamp:
10/17/08 01:48:52 (3 months ago)
Author:
genms
Message:

チャンクあたりのボタン数を変更できるようにした
ページ数が変わったとき、現在のチャンクの場所が変になるのを修正

Location:
lang/actionscript/PagingChunk/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/actionscript/PagingChunk/trunk/PagingChunk.as3proj

    r4489 r21457  
    5252    <!-- example: <element path="..." /> --> 
    5353  </rslPaths> 
     54  <!-- Intrinsic Libraries --> 
     55  <intrinsics> 
     56    <!-- example: <element path="..." /> --> 
     57  </intrinsics> 
    5458  <!-- Assets to embed into the output SWF --> 
    5559  <library> 
     
    7175  <options> 
    7276    <option showHiddenPaths="False" /> 
    73     <option testMovie="NewTab" /> 
     77    <option testMovie="NewWindow" /> 
    7478  </options> 
    7579</project> 
  • lang/actionscript/PagingChunk/trunk/genms/controls/PagingChunk.mxml

    r4489 r21457  
    1515        <mx:Script> 
    1616        <![CDATA[ 
     17        import flash.display.SimpleButton; 
    1718        import flash.events.Event; 
    1819        import genms.controls.PagingChunkEvent; 
     
    3536         
    3637        public function set pageNum(n:int):void { 
    37                 unmarkCurrentPage(); 
    38                  
     38                if (n <= 0) { 
     39                        return; 
     40                } 
     41                 
     42                unmarkCurrentPage(); 
     43 
    3944                _pageNum = n; 
    40                 _chunkNum = int((_pageNum - 1) / 10) + 1; 
    41  
    42                 if (_currentChunk > _chunkNum) { 
    43                         _currentChunk = _chunkNum; 
    44                 } 
    45                  
     45                 
     46                refreshChunkNum(); 
     47                refreshCurrentChunk(); 
    4648                refreshButton(); 
    4749                markCurrentPage(); 
     
    6466        } 
    6567         
    66 /*       
    67         public function set currentChunk(n:int):void { 
    68                 _currentChunk = n; 
    69                 refreshButton(); 
    70         } 
    71 */ 
    72  
     68        //---- 
     69        // buttonNum 
     70        private var _buttonNum:int = 10; 
     71         
     72        /** 
     73         * チャンクあたりのボタン数 
     74         */ 
     75        public function get buttonNum():int { 
     76                return _buttonNum; 
     77        } 
     78 
     79        public function set buttonNum(n:int):void { 
     80                if (n <= 0) { 
     81                        return; 
     82                } 
     83                 
     84                unmarkCurrentPage(); 
     85 
     86                _buttonNum = n; 
     87                 
     88                refreshChunkNum(); 
     89                refreshCurrentChunk(); 
     90                createNumberButton(); 
     91                refreshButton(); 
     92                markCurrentPage(); 
     93        } 
     94         
    7395        //---- 
    7496        // currentPage 
     
    83105         
    84106        public function set currentPage(page:int):void { 
     107                if (page <= 0 || page > _pageNum) { 
     108                        return; 
     109                } 
     110                 
    85111                unmarkCurrentPage(); 
    86112 
    87113                _currentPage = page; 
    88                  
    89                 var check:int = isCurrentPageInCurrentChunk(); 
    90                 if (check < 0) { 
    91                         _currentChunk--; 
    92                 } 
    93                 else if (check > 0) { 
    94                         _currentChunk++; 
    95                 } 
    96                  
    97                 refreshButton(); 
    98114 
    99115                var e:PagingChunkEvent = new PagingChunkEvent(PagingChunkEvent.CHANGE_PAGE); 
     
    101117                dispatchEvent(e); 
    102118                 
    103                 markCurrentPage(); 
     119                refreshCurrentChunk(); 
     120                refreshButton(); 
     121                markCurrentPage(); 
     122        } 
     123         
     124        /** 
     125         * チャンク数を再計算 
     126         */ 
     127        private function refreshChunkNum():void { 
     128                if (_pageNum == 0) { 
     129                        _chunkNum = 0; 
     130                } 
     131                else { 
     132                        _chunkNum = int((_pageNum - 1) / buttonNum) + 1; 
     133                } 
     134        } 
     135         
     136        /** 
     137         * 現在のチャンクを再計算 
     138         */ 
     139        private function refreshCurrentChunk():void { 
     140                if (_pageNum == 0) { 
     141                        _chunkNum = 0; 
     142                } 
     143                else { 
     144                        _currentChunk = int((_currentPage - 1) / buttonNum) + 1; 
     145                } 
    104146        } 
    105147         
     
    109151        private function refreshButton():void { 
    110152                var i:int; 
    111                  
     153/* 
     154trace("pageNum: " + pageNum); 
     155trace("buttonNum: " + buttonNum); 
     156trace("chunkNum: " + _chunkNum); 
     157trace("currentPage: " + currentPage); 
     158trace("currentChunk: " + currentChunk); 
     159*/ 
    112160                // Page移動ボタンのenabled 
    113161                backPageButton.enabled = (currentPage > 1); 
     
    115163 
    116164                // Chunk移動ボタンのenabled 
    117                 firstChunkButton.enabled = (_currentChunk >= 2); 
    118                 backChunkButton.enabled = (_currentChunk >= 2); 
    119                 nextChunkButton.enabled = (_currentChunk <= _chunkNum - 1); 
    120                 lastChunkButton.enabled = (_currentChunk <= _chunkNum - 1); 
     165                firstChunkButton.enabled = (currentChunk >= 2); 
     166                backChunkButton.enabled = (currentChunk >= 2); 
     167                nextChunkButton.enabled = (currentChunk <= _chunkNum - 1); 
     168                lastChunkButton.enabled = (currentChunk <= _chunkNum - 1); 
    121169                 
    122170                // 数字ボタンのvisible 
    123171                if (_chunkNum == 0) { 
    124                         for (i=1; i<=10; i++) { 
     172                        for (i = 0; i < buttonNum; i++) { 
    125173                                numberButtons[i].visible = false; 
    126174                        } 
    127175                } 
    128176                else if (_currentChunk == _chunkNum) { 
    129                         var lastChunkButtonNo:int = _pageNum % 10; 
     177                        var lastChunkButtonNo:int = pageNum - (buttonNum * (currentChunk - 1)); 
    130178                         
    131                         for (i=1; i<=lastChunkButtonNo; i++) { 
     179                        for (i = 0; i < lastChunkButtonNo; i++) { 
    132180                                numberButtons[i].visible = true; 
    133181                        } 
    134182 
    135                         for (i=lastChunkButtonNo+1; i<=10; i++) { 
     183                        for (i = lastChunkButtonNo; i < buttonNum; i++) { 
    136184                                numberButtons[i].visible = false; 
    137185                        } 
    138186                } 
    139187                else { 
    140                         for (i=1; i<=10; i++) { 
     188                        for (i = 0; i < buttonNum; i++) { 
    141189                                numberButtons[i].visible = true; 
    142190                        } 
     
    144192 
    145193                // 数字ボタンのlabel 
    146                 for (i=1; i<=10; i++) { 
    147                         numberButtons[i].label = (_currentChunk - 1) * 10 + i; 
     194                for (i = 0; i < buttonNum; i++) { 
     195                        numberButtons[i].label = (_currentChunk - 1) * buttonNum + i + 1; 
    148196                } 
    149197        } 
     
    154202        private function markCurrentPage():void { 
    155203                if (isCurrentPageInCurrentChunk() == 0) { 
    156                         var no:int = currentPage - (_currentChunk - 1) * 10; 
    157                         numberButtons[no].selected = true; 
     204                        var no:int = currentPage - (_currentChunk - 1) * buttonNum; 
     205                        numberButtons[no - 1].selected = true; 
    158206                } 
    159207        } 
     
    164212        private function unmarkCurrentPage():void { 
    165213                if (isCurrentPageInCurrentChunk() == 0) { 
    166                         var no:int = currentPage - (_currentChunk - 1) * 10; 
    167                         numberButtons[no].selected = false; 
     214                        var no:int = currentPage - (_currentChunk - 1) * buttonNum; 
     215                        numberButtons[no - 1].selected = false; 
    168216                } 
    169217        } 
     
    174222         */ 
    175223        private function isCurrentPageInCurrentChunk():int { 
    176                 if (currentPage < (_currentChunk - 1) * 10 + 1) { 
     224                if (currentPage < (_currentChunk - 1) * buttonNum + 1) { 
    177225                        return -1; 
    178226                } 
    179                 else if (currentPage > (_currentChunk - 1) * 10 + 10) { 
     227                else if (currentPage > (_currentChunk - 1) * buttonNum + buttonNum) { 
    180228                        return 1; 
    181229                } 
     
    184232                } 
    185233        } 
     234 
     235        /** 
     236         * 数字ボタンを作成 
     237         */ 
     238        private function createNumberButton():void { 
     239                var i:int; 
     240         
     241                for (i = 0; i < numberButtons.length; i++) { 
     242                        removeChild(numberButtons[i]); 
     243                } 
     244                numberButtons = new Array(); 
     245 
     246                for (i = 0; i < buttonNum; i++) { 
     247                        var button:Button = new Button(); 
     248                        button.name = "b" + (i + 1).toString(); 
     249                        button.percentWidth = 100; 
     250                        button.percentHeight = 100; 
     251                        button.toggle = true; 
     252                        button.styleName = "pcButton"; 
     253                        button.addEventListener(MouseEvent.CLICK, function(event:Event):void  
     254                                { 
     255                                        numberButtonClickHandler(event, event.target.name.substr(1)); 
     256                                } 
     257                        ); 
     258                         
     259                        addChildAt(button, 4 + i); 
     260                        numberButtons[i] = button; 
     261                } 
     262        } 
    186263         
    187264        /** 
     
    190267         */ 
    191268        private function onCreationCompleteHandler(event:Event):void { 
    192                 numberButtons[1] = b1; 
    193                 numberButtons[2] = b2; 
    194                 numberButtons[3] = b3; 
    195                 numberButtons[4] = b4; 
    196                 numberButtons[5] = b5; 
    197                 numberButtons[6] = b6; 
    198                 numberButtons[7] = b7; 
    199                 numberButtons[8] = b8; 
    200                 numberButtons[9] = b9; 
    201                 numberButtons[10] = b10; 
    202                  
     269                createNumberButton(); 
    203270                refreshButton(); 
    204271        } 
     
    297364                unmarkCurrentPage(); 
    298365 
    299                 var newCurrentPage:int = (_currentChunk - 1) * 10 + page; 
     366                var newCurrentPage:int = (_currentChunk - 1) * buttonNum + page; 
    300367 
    301368                var e:PagingChunkEvent = new PagingChunkEvent(PagingChunkEvent.NUMBER_BUTTON_CLICK); 
     
    305372                currentPage = newCurrentPage; 
    306373 
    307                 refreshButton(); 
    308374                markCurrentPage(); 
    309375        } 
     
    314380        <mx:Button id="backChunkButton" label="&lt;" width="100%" height="100%" styleName="pcButton" click="backChunkButtonClickHandler(event);"/> 
    315381        <mx:Spacer width="5"/> 
    316         <mx:Button id="backPageButton" label="前へ" click="backPageButtonClickHandler(event);"/> 
    317         <mx:Button id="b1" label="1" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 1);"/> 
    318         <mx:Button id="b2" label="2" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 2);"/> 
    319         <mx:Button id="b3" label="3" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 3);"/> 
    320         <mx:Button id="b4" label="4" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 4);"/> 
    321         <mx:Button id="b5" label="5" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 5);"/> 
    322         <mx:Button id="b6" label="6" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 6);"/> 
    323         <mx:Button id="b7" label="7" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 7);"/> 
    324         <mx:Button id="b8" label="8" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 8);"/> 
    325         <mx:Button id="b9" label="9" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 9);"/> 
    326         <mx:Button id="b10" label="10" width="100%" height="100%" toggle="true" styleName="pcButton" click="numberButtonClickHandler(event, 10);"/> 
    327         <mx:Button id="nextPageButton" label="次へ" click="nextPageButtonClickHandler(event);"/> 
     382        <mx:Button id="backPageButton" label="前へ" width="100%" click="backPageButtonClickHandler(event);"/> 
     383        <mx:Button id="nextPageButton" label="次へ" width="100%" click="nextPageButtonClickHandler(event);"/> 
    328384        <mx:Spacer width="5"/> 
    329385        <mx:Button id="nextChunkButton" label="&gt;" width="100%" height="100%" styleName="pcButton" click="nextChunkButtonClickHandler(event);"/> 
  • lang/actionscript/PagingChunk/trunk/test.mxml

    r4489 r21457  
    1 <?xml version="1.0"?> 
    2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:genms.controls="genms.controls.*" creationComplete="pagingChunk.pageNum = 46;"> 
     1<?xml version="1.0"?> 
     2<mx:Application  
     3        xmlns:mx="http://www.adobe.com/2006/mxml"  
     4        xmlns:genms.controls="genms.controls.*"  
     5        width="800" 
     6        height="600" 
     7        creationComplete="pagingChunk.pageNum = 46;" 
     8> 
     9        <mx:Script> 
     10        <![CDATA[ 
     11                private function apply():void { 
     12                        pagingChunk.pageNum = int(pageNum.text); 
     13                        pagingChunk.buttonNum = int(buttonNum.text); 
     14                        pagingChunk.currentPage = int(currentPage.text); 
     15                } 
     16        ]]> 
     17        </mx:Script> 
     18         
    319        <genms.controls:PagingChunk id="pagingChunk" width="100%" numberButtonClick="textArea.text += event.page + '\n';"/> 
     20 
     21        <mx:Spacer height="50"/> 
    422         
    5         <mx:TextArea id="textArea" width="200" height="300"/> 
    6         <mx:Button label="clear" click="textArea.text = '';"/> 
     23        <mx:HBox> 
     24                <mx:Panel title="テスト表示" height="400"> 
     25                        <mx:TextArea id="textArea" width="250" height="100%"/> 
     26                        <mx:Button label="clear" click="textArea.text = '';"/> 
     27                </mx:Panel> 
     28                 
     29                <mx:Panel title="プロパティ変更" height="400"> 
     30                        <mx:Form defaultButton="{applyButton}"> 
     31                                <mx:FormItem label="ページ数"> 
     32                                        <mx:TextInput id="pageNum" text="46" /> 
     33                                </mx:FormItem> 
     34                                <mx:FormItem label="チャンクあたりのボタン数"> 
     35                                        <mx:TextInput id="buttonNum" text="10" /> 
     36                                </mx:FormItem> 
     37                                <mx:FormItem label="現在のページ"> 
     38                                        <mx:TextInput id="currentPage" text="1" /> 
     39                                </mx:FormItem> 
     40                                <mx:FormItem> 
     41                                        <mx:Button id="applyButton" label="適用" click="apply();" /> 
     42                                </mx:FormItem> 
     43                        </mx:Form> 
     44                </mx:Panel> 
     45        </mx:HBox> 
    746</mx:Application>