KickJava   Java API By Example, From Geeks To Geeks.

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


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  
21 package javax.microedition.lcdui;
22
23
24 public class StringItem extends Item
25 {
26
27   StringComponent stringComponent;
28
29
30   public StringItem(String label, String text)
31   {
32     super(label);
33     stringComponent = new StringComponent(text);
34   }
35
36
37     public String getText()
38     {
39         return stringComponent.getText();
40     }
41
42
43   public void setLabel(String label)
44   {
45     super.setLabel(label);
46   }
47
48
49     public void setText(String text)
50     {
51         stringComponent.setText(text);
52     }
53
54
55     int getHeight()
56     {
57         return super.getHeight() + stringComponent.getHeight();
58     }
59
60
61   int paint(Graphics g)
62   {
63         super.paintContent(g);
64
65         g.translate(0, super.getHeight());
66         stringComponent.paint(g);
67         g.translate(0, -super.getHeight());
68
69         return getHeight();
70   }
71
72
73     int traverse(int gameKeyCode, int top, int bottom, boolean action)
74     {
75         Font f = Font.getDefaultFont();
76
77         if (gameKeyCode == Canvas.UP) {
78             if (top > 0) {
79                 if ((top % f.getHeight()) == 0) {
80                     return -f.getHeight();
81                 } else {
82                     return -(top % f.getHeight());
83                 }
84             } else {
85                 return Item.OUTOFITEM;
86             }
87         }
88         if (gameKeyCode == Canvas.DOWN) {
89             if (bottom < getHeight()) {
90                 if (getHeight() - bottom < f.getHeight()) {
91                     return getHeight() - bottom;
92                 } else {
93                     return f.getHeight();
94                 }
95             } else {
96                 return Item.OUTOFITEM;
97             }
98         }
99
100         return 0;
101     }
102
103 }
104
Popular Tags