Source code: javax/microedition/lcdui/ImageStringItem.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 import com.barteo.emulator.device.DeviceFactory;
23
24
25 class ImageStringItem extends Item
26 {
27
28 Image img;
29 StringComponent stringComponent;
30
31
32 public ImageStringItem(String label, Image img, String text)
33 {
34 super(label);
35 stringComponent = new StringComponent(text);
36 setImage(img);
37 }
38
39
40 public Image getImage()
41 {
42 return img;
43 }
44
45
46 public void setImage(Image img)
47 {
48 this.img = img;
49 if (this.img != null) {
50 stringComponent.setWidth(
51 DeviceFactory.getDevice().getDeviceDisplay().getWidth() - img.getWidth() - 2);
52 }
53 }
54
55
56 public String getText()
57 {
58 return stringComponent.getText();
59 }
60
61
62 public void setText(String text)
63 {
64 stringComponent.setText(text);
65 }
66
67
68 int getHeight()
69 {
70 if (img != null && img.getHeight() > stringComponent.getHeight()) {
71 return img.getHeight();
72 } else {
73 return stringComponent.getHeight();
74 }
75 }
76
77
78 void invertPaint(boolean state)
79 {
80 stringComponent.invertPaint(state);
81 }
82
83
84 int paint(Graphics g)
85 {
86 if (stringComponent == null) {
87 return 0;
88 }
89
90 if (img != null) {
91 g.drawImage(img, 0, 0, Graphics.LEFT | Graphics.TOP);
92 g.translate(img.getWidth() + 2, 0);
93 }
94
95 int y = stringComponent.paint(g);
96
97 if (img != null) {
98 g.translate(-img.getWidth() - 2, 0);
99 }
100
101 return y;
102 }
103
104 }