J2ME 技術的學習與實踐者

          導航

          <2008年3月>
          2425262728291
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          統計

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          [導入]OpenBaseMovil Action <--> View <--> Controller


          網站: JavaEye  作者: iwinyeah  鏈接:http://iwinyeah.javaeye.com/blog/172974  發表時間: 2008年03月17日

          聲明:本文系JavaEye網站發布的原創博客文章,未經作者書面許可,嚴禁任何網站轉載本文,否則必將追究法律責任!

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

          請看View的基類的代碼節選
          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是屏幕相關的命令
                  }
                  else
                  {
                      item.addCommand( command ); // 該Action是數據項相關的命令
                      if( action.isDefaultAction() )
                      {
                          item.setDefaultCommand( command );
                      }
                  }
              }
          
              //...省略
          
              // 用戶按下相應的命令鍵后,觸發執行與其關聯的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 );
                      }
                  }
              }
          
              // 用戶在某個指定了命令的Item按下了命令按鈕時觸發執行與其關聯的Action
              public void commandAction( final Command command, final Item item )
              {
                  if( !handleAction( command ) )
                  {
                      AbstractController.commandAction( this, command );
                  }
              }
          
              // 根據所觸發的命令查找關聯的Action,并新它發送到Controller進行處理
              public boolean handleAction( final Command command )
              {
                  if( activeActions.containsKey( command ) )
                  {
                      final Action action = (Action) activeActions.get( command );
                      // 以Action代碼為參數生成ControllerEvent并傳遞到controller處理
                      final ControllerEvent event = new ControllerEvent(
                              action.getCode(),
                              this
                      );
                      controller.handle( event );
                      return true;
                  }
                  else
                  {
                      return false;
                  }
              }
          
              //...省略
          
          }
          

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


          JavaEye推薦




          文章來源:http://iwinyeah.javaeye.com/blog/172974

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

          View <--> Controller" trackback:ping="http://www.aygfsteel.com/iwinyeah/services/trackbacks/187974.aspx" /> -->
          主站蜘蛛池模板: 琼结县| 定南县| 曲松县| 平武县| 旬阳县| 名山县| 伽师县| 温州市| 会泽县| 个旧市| 军事| 富平县| 常山县| 清镇市| 舞阳县| 隆安县| 丘北县| 土默特右旗| 于田县| 大竹县| 高陵县| 金门县| 文安县| 沐川县| 土默特左旗| 平安县| 来安县| 小金县| 新巴尔虎右旗| 唐山市| 桑植县| 姜堰市| 信阳市| 监利县| 海南省| 岚皋县| 潞西市| 玛曲县| 仙居县| 革吉县| 河曲县|