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

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

001: //package com.s_cradle.improve.client;
002: 
003: import javax.microedition.lcdui.Graphics;
004: import javax.microedition.lcdui.Canvas;
005: import java.util.Enumeration;
006: import java.util.Hashtable;
007: 
008: /**
009:  * Copyright (C) 2003 Sophia Cradle, Inc.
010:  *
011:  * 友達リストを表現する Menu です。
012:  *
013:  * @author Masaru Yoshimura
014:  */
015: public class C/*BuddyListMenu*/ extends Z/*Task*//*Menu*/ {
016:     //downsize 定数展開
017:     /** 描画用定数 */
018:     //private static final int TICKER_HEIGHT = 18;
019:     //private static final int IMAGES_INTERVAL = 30;
020: 
021:     //private static final int IMAGE_ARROW_VERTICAL_WIDTH = 7;
022:     //private static final int IMAGE_ARROW_VERTICAL_HEIGHT = 4;
023:     //private static final int IMAGE_ARROW_VERTICAL_IMAGES_INTERVAL = 8;
024:     //private static final int IMAGE_ARROW_VERTICAL_DOWN_INTERVAL = 4;
025: 
026:     /** 子メニュー */
027:     private Z/*Task*//*Menu*/ translate/*menu*/;
028: 
029:     /** フォーカスされているBuddy*/
030:     private A/*Buddy*/ StackMap/*cursorBuddy*/;
031: 
032:     private int[] Code/*idata2*/ = new int[2];
033:     //private int delta;
034:     //private int field;
035: 
036:     /**
037:      * コンストラクタ
038:      */
039:     public C/*BuddyListMenu*/() {
040:         //super(null,null);
041:         Z/*initializeMenu*/(null,null);
042:         Code/*idata2*/[0]/*delta*/ = 0;
043:     }
044: 
045:     /**
046:      * 描画
047:      */
048:     public void I/*draw*/(Graphics g, int width_, int height_){
049:         g.translate(0, 18/*TICKER_HEIGHT*/+1);
050:         StackMap/*draw3DRect*/(g, 0, 0, width_, height_-g.getTranslateY(),
051:                   (153<<16) | (153<<8) | 255/*ImproveAbstractCanvas.LIST_BG_COLOR*/,
                                                                 0x00EEEEFF, 0x00000080);
052: 
053:         Code/*idata2*/[1]/*field*/ = (height_-g.getTranslateY())/18;
054: 
055:         if(Z/*idata*/[0]/*cursor*/ - Code/*idata2*/[0]/*delta*/ < 0){
056:             Code/*idata2*/[0]/*delta*/ = Z/*idata*/[0]/*cursor*/;
057:         }
058:         if(Z/*idata*/[0]/*cursor*/-Code/*idata2*/[0]/*delta*/ >= Code/*
                                                                   data2*/[1]/*field*/){
059:             Code/*idata2*/[0]/*delta*/ = Z/*idata*/[0]/*cursor*/-Code/*
                                                                  idata2*/[1]/*field*/+1;
060:         }
061:         if(Z/*idata*/[0]/*cursor*/ >= I/*ImproveMIDlet*/.Code/*buddyList*/.size()){
062:             Z/*idata*/[0]/*cursor*/ = I/*ImproveMIDlet*/.Code/*buddyList*/.size()-1;
063:             if(Z/*idata*/[0]/*cursor*/ < 0){
064:                 Z/*idata*/[0]/*cursor*/ = 0;
065:             }
066:         }
067: 
068:         boolean up = (Code/*idata2*/[0]/*delta*/>0);
069:         boolean down = (I/*ImproveMIDlet*/.Code/*buddyList*/.size()-Code/*
                                   idata2*/[0]/*delta*/-Code/*idata2*/[1]/*field*/ > 0);
070: 
071:         int temp=0,position=0;
072:         for(Enumeration e=I/*ImproveMIDlet*/.Code/*buddyList*/.elements();
                                                                 e.hasMoreElements();){
073:             A/*Buddy*/ buddy = (A/*Buddy*/)e.nextElement();
074:             if( temp < Code/*idata2*/[0]/*delta*/ ){
075:                 temp++;
076:             } else{
077:                 buddy.StackMap/*draw*/(g,width_,17/*COLUMN_HEIGHT*/ *position,(
                   (position+Code/*idata2*/[0]/*delta*/)==Z/*idata*/[0]/*cursor*/),false);
078:                 if((position+Code/*idata2*/[0]/*delta*/) == Z/*idata*/[0]/*cursor*/){
079:                     StackMap/*cursorBuddy*/ = buddy;
080:                 }
081:                 position++;
082:                 if( 17/*COLUMN_HEIGHT*/ *(position+1) + ((up || down) ?
083:                         4/*IMAGE_ARROW_VERTICAL_HEIGHT*/+
084:                         4/*IMAGE_ARROW_VERTICAL_DOWN_INTERVAL*/ : 0) >
085:                         height_-g.getTranslateY()){
086:                     position--;
087:                     break;
088:                 }
089:             }
090:         }
091:         if( up ){
092:             g.drawImage(I/*ImproveMIDlet*//*ResourceManager*/.Code/*getImage*/(
                                                           0/*ResourceManager.IMAGE_UP*/),
093:                         (width_-7/*IMAGE_ARROW_VERTICAL_WIDTH*/ *2-8/*
                                                IMAGE_ARROW_VERTICAL_IMAGES_INTERVAL*/)/2,
094:                         height_-g.getTranslateY()-4/*
                    IMAGE_ARROW_VERTICAL_HEIGHT*/-4/*IMAGE_ARROW_VERTICAL_DOWN_INTERVAL*/,
095:                         g.TOP | g.LEFT);
096:         }
097:         if( down ){
098:             g.drawImage(
  I/*ImproveMIDlet*//*ResourceManager*/.Code/*getImage*/(1/*ResourceManager.IMAGE_DOWN*/),
099:                         (width_+8/*IMAGE_ARROW_VERTICAL_IMAGES_INTERVAL*/)/2,
100:                         height_-g.getTranslateY()-4/*
                    IMAGE_ARROW_VERTICAL_HEIGHT*/-4/*IMAGE_ARROW_VERTICAL_DOWN_INTERVAL*/,
101:                         g.TOP | g.LEFT);
102:         }
103: 
104:         g.translate(0, -(18/*TICKER_HEIGHT*/+1));
105: 
106:         if(translate/*menu*/ != null){
107:             translate/*menu*/.I/*draw*/(g,width_,height_);
108:         }
109:     }
110: 
111: 
112:     /**
113:      * キーハンドラ
114:      */
115:     protected Z/*Task*//*Menu*/ StackMap/*processFireKeyRelease*/() {
116:         if(StackMap/*cursorBuddy*/ != null){
117:             if( 
    StackMap/*cursorBuddy*/.Code/*idata*/[1]/*attribute*/ == 0/*Buddy.ATTRIBUTE_HIM*/ ){
118:                 return new J/*MainMenu*/(StackMap/*cursorBuddy*/);
119:             } else{
120:                 return new G/*FriendMenu*/(StackMap/*cursorBuddy*/);
121:             }
122:         } else{
123:             System.out.println("error in BuddyListMenu.processFireKeyRelease!");
124:             return null;
125:         }
126:     }
127: 
128:     /**
129:      * キーハンドラ
130:      */
131:     public Z/*Task*//*Menu*/ A/*processKeyRelease*/(int gameAction, int keyCode){
132:         if( translate/*menu*/ != null ){
133:             translate/*menu*/ = translate/*menu*/.A/*processKeyRelease*/(
                                                                      gameAction,keyCode);
134:         } else{
135:             switch( gameAction ){
136:                 case Canvas.FIRE:
137:                     translate/*menu*/ =  StackMap/*processFireKeyRelease*/();
138:                     break;
139:                 case Canvas.DOWN:
140:                     if( Z/*idata*/[0]/*cursor*/+1 < I/*
                                      ImproveMIDlet*/.Code/*buddyList*/.size() ){
141:                         Z/*idata*/[0]/*cursor*/++;
142:                         StackMap/*cursorBuddy*/ = null;
143:                     }
144:                     break;
145:                 case Canvas.UP:
146:                     if( Z/*idata*/[0]/*cursor*/ > 0 ){
147:                         Z/*idata*/[0]/*cursor*/--;
148:                         StackMap/*cursorBuddy*/ = null;
149:                     }
150:                     break;
151:                 case Canvas.RIGHT:
152:                     if( StackMap/*
               cursorBuddy*/ != null && StackMap/*cursorBuddy*/.L/*messageBox*/ != null ){
153:                         I/*ImproveMIDlet*/.Code/*setCurrent*/(
                                       new M/*MessagingCanvas*/(StackMap/*cursorBuddy*/));
154:                         return null;
155:                     }
156:                     break;
157:                 default:
158:                     break;
159:             }
160:         }
161: 
162:         return this;
163:     }
164: }