J2ME 技術(shù)的學(xué)習(xí)與實(shí)踐者

          [導(dǎo)入]OpenBaseMovil Action <--> View <--> Controller


          網(wǎng)站: JavaEye  作者: iwinyeah  鏈接:http://iwinyeah.javaeye.com/blog/172974  發(fā)表時(shí)間: 2008年03月17日

          聲明:本文系JavaEye網(wǎng)站發(fā)布的原創(chuàng)博客文章,未經(jīng)作者書面許可,嚴(yán)禁任何網(wǎng)站轉(zhuǎn)載本文,否則必將追究法律責(zé)任!

          Action: 規(guī)定了與用戶交互的View可以觸發(fā)的動(dòng)作,在某個(gè)View新建之后顯示之前,應(yīng)先為其指定具體的Action,當(dāng)用戶按下了相應(yīng)的Command按鈕之后,View將該Command對(duì)應(yīng)的Action發(fā)送到該View的Controller進(jìn)行處理。
          //
          public class Action{
              String name; // 名稱 
              Command command; // 命令 
              int code; // 代碼 (將由該View的傳遞到其Controller使用)
              Item item; // 數(shù)據(jù)項(xiàng) 
              boolean defaultAction; // 是否是默認(rèn)的Action 
              //...省略
          }
          
          

          請(qǐng)看View的基類的代碼節(jié)選
          public abstract class AbstractView{
          
              //...省略
          
              // 為該View增加Action
              public void addAction( final Action action, final boolean active )
              {
                  if( !actions.containsKey( action.getName() ) )
                  {
                      // 將Action存入Actions表中
                      actions.put( action.getName(), action );
                      if( active )
                      {
                          activateAction( action );
                      }
                  }
              }
          
              // 使Action生效可用
              private void activateAction( final Action action )
              {
                  final Command command = action.getCommand();
                  activeActions.put( command, action );
                  final Item item = action.getItem();
                  if( item == null )
                  {
                      addCommand( command ); // 該Action是屏幕相關(guān)的命令
                  }
                  else
                  {
                      item.addCommand( command ); // 該Action是數(shù)據(jù)項(xiàng)相關(guān)的命令
                      if( action.isDefaultAction() )
                      {
                          item.setDefaultCommand( command );
                      }
                  }
              }
          
              //...省略
          
              // 用戶按下相應(yīng)的命令鍵后,觸發(fā)執(zhí)行與其關(guān)聯(lián)的Action
              public void commandAction(
                      final Command       command,
                      final Displayable   displayable
              )
              {
                  if( !handleAction( command ) )
                  {
                      if( displayable instanceof Choice )
                      {
                          AbstractController.commandAction(
                                  this,
                                  command,
                                  (Choice) displayable
                          );
                      }
                      else
                      {
                          AbstractController.commandAction( this, command );
                      }
                  }
              }
          
              // 用戶在某個(gè)指定了命令的Item按下了命令按鈕時(shí)觸發(fā)執(zhí)行與其關(guān)聯(lián)的Action
              public void commandAction( final Command command, final Item item )
              {
                  if( !handleAction( command ) )
                  {
                      AbstractController.commandAction( this, command );
                  }
              }
          
              // 根據(jù)所觸發(fā)的命令查找關(guān)聯(lián)的Action,并新它發(fā)送到Controller進(jìn)行處理
              public boolean handleAction( final Command command )
              {
                  if( activeActions.containsKey( command ) )
                  {
                      final Action action = (Action) activeActions.get( command );
                      // 以Action代碼為參數(shù)生成ControllerEvent并傳遞到controller處理
                      final ControllerEvent event = new ControllerEvent(
                              action.getCode(),
                              this
                      );
                      controller.handle( event );
                      return true;
                  }
                  else
                  {
                      return false;
                  }
              }
          
              //...省略
          
          }
          

          本文的討論也很精彩,瀏覽討論>>


          JavaEye推薦




          文章來(lái)源:http://iwinyeah.javaeye.com/blog/172974

          posted on 2008-03-17 14:06 iwinyeah 閱讀(356) 評(píng)論(0)  編輯  收藏 所屬分類: OpenBaseMovil 資料

          View <--> Controller" trackback:ping="http://www.aygfsteel.com/iwinyeah/services/trackbacks/187974.aspx" /> -->

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 新乡市| 浑源县| 山阴县| 咸丰县| 吴旗县| 固始县| 神池县| 奉贤区| 洱源县| 繁峙县| 色达县| 通山县| 治县。| 江山市| 青浦区| 阿坝| 喀喇| 新乐市| 大港区| 巴楚县| 德阳市| 武平县| 五家渠市| 石林| 双牌县| 南城县| 称多县| 阿坝县| 木兰县| 丰原市| 桑植县| 香格里拉县| 沿河| 通榆县| 揭阳市| 洛南县| 临夏县| 锡林浩特市| 平昌县| 黑水县| 大关县|