ホーム > デベロッパ > J2ME / MIDP プログラミング > 実機に載せよう

第4回:実機に載せよう(ダウンサイズ)

001: //package com.s_cradle.improve.client;
002: 
003: import java.io.*;
004: //import com.s_cradle.improve.Constants;
005: import java.util.*;
006: import javax.microedition.lcdui.Canvas;
007: import javax.microedition.lcdui.Displayable;
008: 
009: /**
010:  * Copyright (C) 2003 Sophia Cradle, Inc.
011:  *
012:  * オペレーション polling を使ったタスクを行うクラスです。
013:  *
014:  * @author Masaru Yoshimura
015:  */
016: public class N/*PollingTask*/ extends Z/*Task*/{
017:     //downsize 定数展開
018:     /*
019:     private static final String TICKERMESSAGE_ATTACKED = "から攻撃されました!";
020:     private static final String MESSAGE_ATTACKED = "攻撃されました。";
021:     */
022: 
023:     private Vector[] StackMap/*vectors*/ = new Vector[2];
024: 
025:     //private Vector newList;
026:     //private Vector messages;
027: 
028:     private static final String[] Code/*ITEMS*/ = new String[]{
029:         "account"/*Constants.PARAMETER_ACCOUNT*/, "password"/*
                                                        Constants.PARAMETER_PASSWORD*/};
030: 
031:     /**
032:      * コンストラクタ。タスクで使う値(アカウント,パスワード)を引数にとる。
033:      */
034:     public N/*PollingTask*/(String[] strs1) {
035:         StackMap/*initializeTask*//*super*/(6/*TASK_POLLING*/,Code/*
                 ITEMS*/,new String[]{D/*strs*/[0]/*account*/,D/*strs*/[1]/*password*/});
036:         StackMap/*vectors*/[0]/*newList*/ = new Vector();
037:         StackMap/*vectors*/[1]/*messages*/ = new Vector();
038:     }
039: 
040:     /**
041:      * 失敗時の処理
042:      */
043:     protected void Z/*processFailed*/() {
044:     }
045: 
046:     /**
047:      * 返値を読んだ後の処理
048:      */
049:     protected void Code/*processAfterReturnValue*/(
                          int result, DataInputStream input) throws java.io.IOException {
050:         Vector oldList = I/*ImproveMIDlet*/.Code/*buddyList*/;
051: 
052:         short userNumber = (short)(result >> 16);
053:         short messageNumber = (short)result;
054: 
055:         //downsize アルゴリズム
056:         if(userNumber > 0){
057:             A/*Buddy*/ buddy = new A/*Buddy*/(input);
058:             buddy.Code/*idata*/[1]/*attribute*/ = 0/*Buddy.ATTRIBUTE_HIM*/;
059:             StackMap/*vectors*/[0]/*newList*/.addElement(buddy);
060:         }
061:         for (short i=1; i<userNumber; i++) {
062:             StackMap/*vectors*/[0]/*newList*/.addElement(new A/*Buddy*/(input));
063:         }
064: 
065:         for (short i=0; i<messageNumber; i++) {
066:             StackMap/*vectors*/[1]/*messages*/.addElement(new K/*Message*/(input));
067:         }
068: 
069:         I/*ImproveMIDlet*/.I/*callSerially*/(new Runnable(){
070:             public void run(){
071:                 Vector oldList = I/*ImproveMIDlet*/.Code/*buddyList*/;
072:                 Vector buddyList = new Vector();
073:                 Hashtable hush = new Hashtable();
074: 
075:                 for(Enumeration e=StackMap/*vectors*/[0]/*
                                             newList*/.elements();e.hasMoreElements();){
076:                     A/*Buddy*/ newBuddy = (A/*Buddy*/)e.nextElement();
077:                     if( oldList.indexOf(newBuddy) >= 0 ){
078:                        A/*Buddy*/ oldBuddy = (
                                A/*Buddy*/)oldList.elementAt(oldList.indexOf(newBuddy));
079:                         oldBuddy.StackMap/*update*/(newBuddy);
080:                         buddyList.addElement(oldBuddy);
081:                         hush.put(oldBuddy.StackMap/*etc*/[0]/*account*/,oldBuddy);
082:                     } else{
083:                         buddyList.addElement(newBuddy);
084:                         hush.put(newBuddy.StackMap/*etc*/[0]/*account*/,newBuddy);
085:                     }
086:                 }
087: 
088:                 for(Enumeration e=StackMap/*vectors*/[1]/*
                                           messages*/.elements();e.hasMoreElements();){
089:                     K/*Message*/ m = (K/*Message*/)e.nextElement();
090:                     A/*Buddy*/ buddy = (
                                    A/*Buddy*/)hush.get(m.Code/*strs2*/[0]/*account*/);
091: 
092:                     //downsize アルゴリズム
093:                     if(buddy != null){
094:                         if(buddy.L/*messageBox*/ == null){
095:                             new M/*MessagingCanvas*/(buddy);
096:                         }
097:                         if( m.StackMap/*idata1*/[1]/*from*/ == 0/*m.FROM_ME*/){
098:                             buddy.L/*messageBox*/.Code/*addMessage*/(
                             m.Code/*strs2*/[1]/*content*/,8/*MessageBox.MESSAGE_MINE*/);
099:                         } else if(
                                   m.StackMap/*idata1*/[1]/*from*/ == 1/*m.FROM_OTHER*/){
100:                             if( 
                  m.StackMap/*idata1*/[0]/*type*/ == 1/*Constants.MESSAGE_TYPE_NORMAL*/){
101:                                 buddy.L/*messageBox*/.Code/*addMessage*/(
                            m.Code/*strs2*/[1]/*content*/,9/*MessageBox.MESSAGE_OTHER*/);
102:                             } else if(
                  m.StackMap/*idata1*/[0]/*type*/ == 2/*Constants.MESSAGE_TYPE_ATTACK*/){
103:                                 I/*ImproveMIDlet*/.StackMap/*
             listCanvas*/.I/*ticker*/.Code/*insert*/(
                        1/*Ticker.LEVEL_NORMAL*/,m.Code/*strs2*/[0]/*
                             account*/+"から攻撃されました!"/*TICKERMESSAGE_ATTACKED*/);
104:                                 buddy.L/*messageBox*/.Code/*addMessage*/(
                   "攻撃されました。"/*MESSAGE_ATTACKED*/,9/*MessageBox.MESSAGE_OTHER*/);
105:                             }
106:                         }
107:                     }
108:                 }
109: 
110:                 I/*ImproveMIDlet*/.Code/*buddyList*/ = buddyList;
111:                 Displayable d = I/*ImproveMIDlet*/.StackMap/*getCurrent*/();
112:                 if( d instanceof Canvas ){
113:                     ((Canvas)d).repaint();
114:                 }
115:                 StackMap/*vectors*/[0]/*newList*/ = new Vector();
116:                 StackMap/*vectors*/[1]/*messages*/ = new Vector();
117:             }
118:         });
119:     }
120: 
121:     /**
122:      * 自分の投げたメッセージを追加する。
123:      */
124:     public void Code/*addOwnMessage*/(String target,String content){
125:         StackMap/*vectors*/[1]/*messages*/.addElement(
                                                     new K/*Message*/(target,content));
126:     }
127: }