Source code: javax/microedition/lcdui/StringItem.java
1 /*
2 * MicroEmulator
3 * Copyright (C) 2001 Bartek Teodorczyk <barteo@it.pl>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 package javax.microedition.lcdui;
21
22
23 public class StringItem extends Item
24 {
25
26 StringComponent stringComponent;
27
28
29 public StringItem(String label, String text)
30 {
31 super(label);
32 stringComponent = new StringComponent(text);
33 }
34
35
36 public String getText()
37 {
38 return stringComponent.getText();
39 }
40
41
42 public void setLabel(String label)
43 {
44 super.setLabel(label);
45 }
46
47
48 public void setText(String text)
49 {
50 stringComponent.setText(text);
51 }
52
53
54 int getHeight()
55 {
56 return super.getHeight() + stringComponent.getHeight();
57 }
58
59
60 int paint(Graphics g)
61 {
62 super.paintContent(g);
63
64 g.translate(0, super.getHeight());
65 stringComponent.paint(g);
66 g.translate(0, -super.getHeight());
67
68 return getHeight();
69 }
70
71
72 int traverse(int gameKeyCode, int top, int bottom, boolean action)
73 {
74 Font f = Font.getDefaultFont();
75
76 if (gameKeyCode == Canvas.UP) {
77 if (top > 0) {
78 if ((top % f.getHeight()) == 0) {
79 return -f.getHeight();
80 } else {
81 return -(top % f.getHeight());
82 }
83 } else {
84 return Item.OUTOFITEM;
85 }
86 }
87 if (gameKeyCode == Canvas.DOWN) {
88 if (bottom < getHeight()) {
89 if (getHeight() - bottom < f.getHeight()) {
90 return getHeight() - bottom;
91 } else {
92 return f.getHeight();
93 }
94 } else {
95 return Item.OUTOFITEM;
96 }
97 }
98
99 return 0;
100 }
101
102 }