1 2 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 |