This Component is a java class which can be to used to spin a text with the specified angle. This can be used in any screens in Blackberry where a text needs a spin.
public class StringSpinner extends MainScreen {
// Font of the text to be displayed
private Font myFont;
// Horizontal position of drawing the text
private int xOffset;
// Vertical position of drawing the text
private int yOffset;
// Angle to which the text is to be tilted
private int theta;
// Text to spin
private String textToSpin;
/**
* Constructor
* @param textToSpin text to be displayed
*/
public StringSpinner(final String textToSpin) {
xOffset = Display.getWidth() / 2;
yOffset = Display.getHeight() / 2;
this.textToSpin= textToSpin;
// execute in a new thread
new Thread() {
public void run() {
// repeat the loop
while(true) {
theta += 5;
theta %= 360;
// call paint method to draw text
invalidate();
try {
// call thread to sleep for 25 milliseconds
Thread.sleep(25);
}
catch (InterruptedException ignore) {
ignore.printStackTrace();
}
}
}
}.start();
}
/*
* @see net.rim.device.api.ui.Screen#paint(net.rim.device.api.ui.Graphics)
*/
public void paint(Graphics graphics) {
int thetaFixed = Fixed32.toFP(theta);
int cell_11 = Fixed32.cosd(thetaFixed);
int cell_12 = -Fixed32.sind(thetaFixed);
int cell_21 = Fixed32.sind(thetaFixed);
int cell_22 = Fixed32.cosd(thetaFixed);
// Define a transform for the text font
int[] transform = new int[] {
cell_11, cell_12,
cell_21, cell_22,
0, 0
};
// set the font for the given transform
myFont = Font.getDefault().derive(Font.PLAIN, 14, Ui.UNITS_px, Font.ANTIALIAS_STANDARD, 0, transform);
graphics.setFont(myFont);
// call graphics to draw text with given horizontal and vertical positions
graphics.drawText(textToSpin, xOffset, yOffset);
}
}