チェンジセット 548

差分発生行の前後
無視リスト:
コミット日時:
2008/05/31 11:56:21 (6 ヶ月前)
コミッタ:
yossy
ログメッセージ:

Thread(soumen): 進捗状況通知機構追加

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/Thread/branches/soumen/Thread.as3proj

    r543 r548  
    1919    <class path="samples\urlloader" /> 
    2020    <class path="samples\tweener" /> 
     21    <class path="samples\progress" /> 
    2122  </classpaths> 
    2223  <!-- Build options --> 
     
    6667  <!-- Class files to compile (other referenced classes will automatically be included) --> 
    6768  <compileTargets> 
    68     <compile path="samples\tweener\Sample2.as" /> 
     69    <compile path="samples\progress\Sample.as" /> 
    6970  </compileTargets> 
    7071  <!-- Paths to exclude from the Project Explorer tree --> 
  • as3/Thread/branches/soumen/src/org/libspark/thread/threads/display/LoaderThread.as

    r537 r548  
    3131        import flash.events.Event; 
    3232        import flash.events.IOErrorEvent; 
     33        import flash.events.ProgressEvent; 
    3334        import flash.net.URLRequest; 
    3435        import flash.system.LoaderContext; 
    3536        import flash.errors.IOError; 
     37        import org.libspark.thread.utils.IProgress; 
     38        import org.libspark.thread.utils.IProgressNotifier; 
     39        import org.libspark.thread.utils.Progress; 
    3640         
    3741        import org.libspark.thread.Thread; 
     
    5256         * @author      yossy:beinteractive 
    5357         */ 
    54         public class LoaderThread extends Thread 
     58        public class LoaderThread extends Thread implements IProgressNotifier 
    5559        { 
    5660                /** 
     
    6670                        _context = context; 
    6771                        _loader = loader != null ? loader : new Loader(); 
     72                        _progress = new Progress(); 
    6873                } 
    6974                 
     
    7176                private var _context:LoaderContext; 
    7277                private var _loader:Loader; 
     78                private var _progress:Progress; 
    7379                 
    7480                /** 
     
    106112                 
    107113                /** 
     114                 * @inheritDoc 
     115                 */ 
     116                public function get progress():IProgress 
     117                { 
     118                        return _progress; 
     119                } 
     120                 
     121                /** 
    108122                 * 実行 
    109123                 *  
     
    114128                        // イベントハンドラを設定 
    115129                        // Note: イベントハンドラを設定した場合、自動的に wait がかかる 
    116                         event(_loader.contentLoaderInfo, Event.COMPLETE, completeHandler); 
    117                         event(_loader.contentLoaderInfo, IOErrorEvent.IO_ERROR, ioErrorHandler); 
     130                        events(); 
    118131                         
    119132                        // 割り込みハンドラを設定 
     
    125138                 
    126139                /** 
    127                  * Event.COMPLETEハンドラ 
     140                 * イベントハンドラの登録 
     141                 *  
     142                 * @private 
     143                 */ 
     144                private function events():void 
     145                { 
     146                        event(_loader.contentLoaderInfo, Event.COMPLETE, completeHandler); 
     147                        event(_loader.contentLoaderInfo, ProgressEvent.PROGRESS, progressHandler); 
     148                        event(_loader.contentLoaderInfo, IOErrorEvent.IO_ERROR, ioErrorHandler); 
     149                } 
     150                 
     151                /** 
     152                 * まだ開始を通知していなければ通知する 
     153                 *  
     154                 * @private 
     155                 */ 
     156                private function notifyStartIfNeeded(total:Number):void 
     157                { 
     158                        if (!_progress.isStarted) { 
     159                                _progress.start(total); 
     160                        } 
     161                } 
     162                 
     163                /** 
     164                 * ProgressEvent.PROGRESS ハンドラ 
     165                 */ 
     166                private function progressHandler(e:ProgressEvent):void 
     167                { 
     168                        // 必要であれば開始を通知 
     169                        notifyStartIfNeeded(e.bytesTotal); 
     170                         
     171                        // 進捗を通知 
     172                        _progress.progress(e.bytesLoaded); 
     173                         
     174                        // 割り込みハンドラを設定 
     175                        interrupted(interruptedHandler); 
     176                         
     177                        // 再びイベント待ち 
     178                        events(); 
     179                } 
     180                 
     181                /** 
     182                 * Event.COMPLETE ハンドラ 
    128183                 */ 
    129184                private function completeHandler(e:Event):void 
    130185                { 
    131                         // 何もしない → スレッドが終了する 
    132                 } 
    133                  
    134                 /** 
    135                  * IOErrorEvent.IO_ERRORハンドラ 
     186                        // 必要であれば開始を通知 (問題が発生しなければ通常 progressHandler で通知される) 
     187                        notifyStartIfNeeded(0); 
     188                         
     189                        // 完了を通知 
     190                        _progress.complete(); 
     191                         
     192                        // ここでスレッド終了 
     193                } 
     194                 
     195                /** 
     196                 * IOErrorEvent.IO_ERROR ハンドラ 
    136197                 */ 
    137198                private function ioErrorHandler(e:IOErrorEvent):void 
    138199                { 
     200                        // 必要であれば開始を通知 (問題が発生しなければ通常 progressHandler で通知される) 
     201                        notifyStartIfNeeded(0); 
     202                         
     203                        // 失敗を通知 
     204                        _progress.fail(); 
     205                         
    139206                        // IOError をスロー 
    140207                        throw new IOError(e.text); 
     
    146213                private function interruptedHandler():void 
    147214                { 
     215                        // 必要であれば開始を通知 (問題が発生しなければ通常 progressHandler で通知される) 
     216                        notifyStartIfNeeded(0); 
     217                         
    148218                        // ロードをキャンセル 
    149219                        _loader.close(); 
     220                         
     221                        // キャンセルを通知 
     222                        _progress.cancel(); 
    150223                } 
    151224        } 
  • as3/Thread/branches/soumen/src/org/libspark/thread/threads/net/URLLoaderThread.as

    r535 r548  
    2828package org.libspark.thread.threads.net 
    2929{ 
     30        import flash.events.ProgressEvent; 
    3031        import org.libspark.thread.Thread; 
     32        import org.libspark.thread.utils.IProgress; 
     33        import org.libspark.thread.utils.IProgressNotifier; 
     34        import org.libspark.thread.utils.Progress; 
    3135         
    3236        import flash.net.URLLoader; 
     
    5559         * @author      yossy:beinteractive 
    5660         */ 
    57         public class URLLoaderThread extends Thread 
     61        public class URLLoaderThread extends Thread implements IProgressNotifier 
    5862        { 
    5963                /** 
     
    6771                        _request = request; 
    6872                        _loader = loader != null ? loader : new URLLoader(); 
     73                        _progress = new Progress(); 
    6974                } 
    7075                 
    7176                private var _request:URLRequest; 
    7277                private var _loader:URLLoader; 
    73                 private var _error:Error
     78                private var _progress:Progress
    7479                 
    7580                /** 
     
    97102                 
    98103                /** 
     104                 * @inheritDoc 
     105                 */ 
     106                public function get progress():IProgress 
     107                { 
     108                        return _progress; 
     109                } 
     110                 
     111                /** 
    99112                 * ロード処理をキャンセルします 
    100113                 */ 
     
    112125                        // イベントハンドラを設定 
    113126                        // Note: イベントハンドラを設定した場合、自動的に wait がかかる 
     127                        events(); 
     128                         
     129                        // 割り込みハンドラを設定 
     130                        interrupted(interruptedHandler); 
     131                         
     132                        // ロード開始 
     133                        _loader.load(_request); 
     134                } 
     135                 
     136                /** 
     137                 * イベントハンドラの登録 
     138                 *  
     139                 * @private 
     140                 */ 
     141                private function events():void 
     142                { 
    114143                        event(_loader, Event.COMPLETE, completeHandler); 
     144                        event(_loader, ProgressEvent.PROGRESS, progressHandler); 
    115145                        event(_loader, IOErrorEvent.IO_ERROR, ioErrorHandler); 
    116146                        event(_loader, SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); 
     147                } 
     148                 
     149                /** 
     150                 * まだ開始を通知していなければ通知する 
     151                 *  
     152                 * @private 
     153                 */ 
     154                private function notifyStartIfNeeded(total:Number):void 
     155                { 
     156                        if (!_progress.isStarted) { 
     157                                _progress.start(total); 
     158                        } 
     159                } 
     160                 
     161                /** 
     162                 * ProgressEvent.PROGRESS ハンドラ 
     163                 */ 
     164                private function progressHandler(e:ProgressEvent):void 
     165                { 
     166                        // 必要であれば開始を通知 
     167                        notifyStartIfNeeded(e.bytesTotal); 
     168                         
     169                        // 進捗を通知 
     170                        _progress.progress(e.bytesLoaded); 
    117171                         
    118172                        // 割り込みハンドラを設定 
    119173                        interrupted(interruptedHandler); 
    120174                         
    121                         // ロード開始 
    122                         _loader.load(_request); 
    123                 } 
    124                  
    125                 /** 
    126                  * Event.COMPLETEハンドラ 
     175                        // 再びイベント待ち 
     176                        events(); 
     177                } 
     178                 
     179                /** 
     180                 * Event.COMPLETE ハンドラ 
    127181                 */ 
    128182                private function completeHandler(e:Event):void 
    129183                { 
    130                         // 何もしない → スレッドが終了する 
    131                 } 
    132                  
    133                 /** 
    134                  * IOErrorEvent.IO_ERRORハンドラ 
     184                        // 必要であれば開始を通知 (問題が発生しなければ通常 progressHandler で通知される) 
     185                        notifyStartIfNeeded(0); 
     186                         
     187                        // 完了を通知 
     188                        _progress.complete(); 
     189                         
     190                        // ここでスレッド終了 
     191                } 
     192                 
     193                /** 
     194                 * IOErrorEvent.IO_ERROR ハンドラ 
    135195                 */ 
    136196                private function ioErrorHandler(e:IOErrorEvent):void 
    137197                { 
     198                        // 必要であれば開始を通知 (問題が発生しなければ通常 progressHandler で通知される) 
     199                        notifyStartIfNeeded(0); 
     200                         
     201                        // 失敗を通知 
     202                        _progress.fail(); 
     203                         
    138204                        // IOError をスロー 
    139205                        throw new IOError(e.text); 
     
    141207                 
    142208                /** 
    143                  * SecurityErrorEvent.SECURITY_ERRORハンドラ 
     209                 * SecurityErrorEvent.SECURITY_ERROR ハンドラ 
    144210                 */ 
    145211                private function securityErrorHandler(e:SecurityErrorEvent):void 
    146212                { 
     213                        // 必要であれば開始を通知 (問題が発生しなければ通常 progressHandler で通知される) 
     214                        notifyStartIfNeeded(0); 
     215                         
     216                        // 失敗を通知 
     217                        _progress.fail(); 
     218                         
    147219                        // SecurityError をスロー 
    148220                        throw new SecurityError(e.text); 
     
    154226                private function interruptedHandler():void 
    155227                { 
     228                        // 必要であれば開始を通知 (問題が発生しなければ通常 progressHandler で通知される) 
     229                        notifyStartIfNeeded(0); 
     230                         
    156231                        // ロードをキャンセル 
    157232                        _loader.close(); 
     233                         
     234                        // キャンセルを通知 
     235                        _progress.cancel(); 
    158236                } 
    159237        }