KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > microedition > lcdui > List


1
2 /*
3  * MicroEmulator
4  * Copyright (C) 2001 Bartek Teodorczyk <barteo@it.pl>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contributor(s):
21  * 3GLab
22  */

23  
24 package javax.microedition.lcdui;
25
26
27 public class List extends Screen implements Choice
28 {
29
30   public static final Command SELECT_COMMAND = new Command("", Command.SCREEN, 0);
31   
32   ChoiceGroup choiceGroup;
33   
34   
35   public List(String title, int listType)
36   {
37     super(title);
38     
39         choiceGroup = new ChoiceGroup(null, listType);
40         choiceGroup.setOwner(this);
41         choiceGroup.setFocus(true);
42   }
43   
44   
45     public List(String title, int listType, String[] stringElements, Image[] imageElements)
46     {
47     super(title);
48     
49     choiceGroup = new ChoiceGroup(null, listType, stringElements, imageElements);
50     choiceGroup.setOwner(this);
51         choiceGroup.setFocus(true);
52     }
53                         
54
55   public int append(String stringPart, Image imagePart)
56   {
57     return choiceGroup.append(stringPart, imagePart);
58   }
59     
60
61   public void delete(int elementNum)
62   {
63     choiceGroup.delete(elementNum);
64   }
65     
66
67   public Image getImage(int elementNum)
68   {
69     return choiceGroup.getImage(elementNum);
70   }
71     
72
73   public int getSelectedFlags(boolean[] selectedArray_return)
74   {
75     return choiceGroup.getSelectedFlags(selectedArray_return);
76   }
77     
78
79   public int getSelectedIndex()
80   {
81     return choiceGroup.getSelectedIndex();
82   }
83     
84   
85   public String getString(int elementNum)
86   {
87     return choiceGroup.getString(elementNum);
88   }
89     
90   
91   public void insert(int elementNum, String stringPart, Image imagePart)
92   {
93     choiceGroup.insert(elementNum, stringPart, imagePart);
94   }
95     
96   
97   public boolean isSelected(int elementNum)
98   {
99     return choiceGroup.isSelected(elementNum);
100   }
101     
102   
103   public void set(int elementNum, String stringPart, Image imagePart) {
104     choiceGroup.set(elementNum, stringPart, imagePart);
105   }
106     
107   
108   public void setSelectedFlags(boolean[] selectedArray)
109   {
110     choiceGroup.setSelectedFlags(selectedArray);
111   }
112     
113   
114   public void setSelectedIndex(int elementNum, boolean selected)
115   {
116     choiceGroup.setSelectedIndex(elementNum, selected);
117   }
118     
119   
120   void keyPressed(int keyCode)
121   {
122     if(Display.getGameAction(keyCode) == Canvas.FIRE
123         && choiceGroup.select() && super.listener != null
124         && choiceGroup.choiceType == Choice.IMPLICIT) {
125       super.listener.commandAction(SELECT_COMMAND, this);
126     } else {
127       super.keyPressed(keyCode);
128     }
129   }
130
131   
132   int paintContent(Graphics g)
133   {
134     return choiceGroup.paint(g);
135   }
136   
137   
138   public int size()
139   {
140     return choiceGroup.size();
141   }
142
143   
144   int traverse(int gameKeyCode, int top, int bottom)
145   {
146         int traverse = choiceGroup.traverse(gameKeyCode, top, bottom, true);
147         if (traverse == Item.OUTOFITEM) {
148             return 0;
149         } else {
150         return traverse;
151         }
152   }
153   
154 }
155
Popular Tags