Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

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