View Javadoc

1   /*
2    *  MicroEmulator
3    *  Copyright (C) 2001 Bartek Teodorczyk <barteo@barteo.net>
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  public class StringItem extends Item {
23  
24  	StringComponent stringComponent;
25  
26  	public StringItem(String label, String text) {
27  		this(label, text, PLAIN);
28  	}
29  	
30  	public StringItem(String label, String text, int appearanceMode) {
31  		super(label);
32  		stringComponent = new StringComponent(text);
33  		// TODO apperanceMode
34  	}
35  	
36  	public int getAppearanceMode() {
37      	// TODO implement
38  		return Item.PLAIN;
39  	}
40  	
41  	public Font getFont() {
42      	// TODO implement
43  		return Font.getDefaultFont();
44  	}
45  	
46  	public void setFont(Font font) {
47      	// TODO implement
48  	}
49  
50  	public void setPreferredSize(int width, int height) {
51      	// TODO implement
52  	}
53  	
54  	public String getText() {
55  		return stringComponent.getText();
56  	}
57  
58  	public void setText(String text) {
59  		stringComponent.setText(text);
60  		repaint();
61  	}
62  
63  	int getHeight() {
64  		return super.getHeight() + stringComponent.getHeight();
65  	}
66  
67  	int paint(Graphics g) {
68  		super.paintContent(g);
69  
70  		g.translate(0, super.getHeight());
71  		stringComponent.paint(g);
72  		g.translate(0, -super.getHeight());
73  
74  		return getHeight();
75  	}
76  
77  	int traverse(int gameKeyCode, int top, int bottom, boolean action) {
78  		Font f = Font.getDefaultFont();
79  
80  		if (gameKeyCode == Canvas.UP) {
81  			if (top > 0) {
82  				if ((top % f.getHeight()) == 0) {
83  					return -f.getHeight();
84  				} else {
85  					return -(top % f.getHeight());
86  				}
87  			} else {
88  				return Item.OUTOFITEM;
89  			}
90  		}
91  		if (gameKeyCode == Canvas.DOWN) {
92  			if (bottom < getHeight()) {
93  				if (getHeight() - bottom < f.getHeight()) {
94  					return getHeight() - bottom;
95  				} else {
96  					return f.getHeight();
97  				}
98  			} else {
99  				return Item.OUTOFITEM;
100 			}
101 		}
102 
103 		return 0;
104 	}
105 
106 }