KickJava   Java API By Example, From Geeks To Geeks.

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


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 import com.barteo.emulator.device.DeviceFactory;
27
28
29 public class Ticker
30 {
31
32   static int PAINT_TIMEOUT = 250;
33   static int PAINT_MOVE = 5;
34   static int PAINT_GAP = 10;
35   
36   Ticker instance = null;
37
38   String text;
39   int textPos = 0;
40   int resetTextPosTo = -1;
41
42
43   public Ticker(String str)
44   {
45     if (str == null) {
46       throw new NullPointerException();
47     }
48     instance = this;
49     
50     text = str;
51   }
52
53
54   public String getString()
55   {
56     return text;
57   }
58
59
60   public void setString(String str)
61   {
62     if (str == null) {
63       throw new NullPointerException();
64     }
65     text = str;
66   }
67   
68
69   int getHeight()
70   {
71     return Font.getDefaultFont().getHeight();
72   }
73   
74   
75   int paintContent(Graphics g)
76   {
77         Font f = Font.getDefaultFont();
78     
79     synchronized (instance) {
80       int stringWidth = f.stringWidth(text) + PAINT_GAP;
81       g.drawString(text, textPos, 0, Graphics.LEFT | Graphics.TOP);
82       int xPos = textPos + stringWidth;
83       while (xPos < DeviceFactory.getDevice().getDeviceDisplay().getWidth()) {
84         g.drawString(text, xPos, 0, Graphics.LEFT | Graphics.TOP);
85         xPos += stringWidth;
86       }
87       if (textPos + stringWidth < 0) {
88         resetTextPosTo = textPos + stringWidth;
89       }
90     }
91     
92     return f.getHeight();
93   }
94   
95 }
96
Popular Tags