KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > gui > splash > TextSprite


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.gui.splash;
22
23 import java.awt.*;
24 import java.awt.geom.Rectangle2D JavaDoc;
25 import java.awt.image.BufferedImage JavaDoc;
26
27 /**
28  * This Sprite represents a text.
29  *
30  * @author Eric Lafortune
31  */

32 public class TextSprite implements Sprite
33 {
34     private VariableString[] text;
35     private VariableInt spacing;
36     private VariableInt x;
37     private VariableInt y;
38
39
40     /**
41      * Creates a new TextSprite containing a single line of text.
42      * @param text the variable text string.
43      * @param x the variable x-coordinate of the lower-left corner of the text.
44      * @param y the variable y-coordinate of the lower-left corner of the text.
45      */

46     public TextSprite(VariableString text,
47                       VariableInt x,
48                       VariableInt y)
49     {
50         this(new VariableString[] { text }, new ConstantInt(0), x, y);
51     }
52
53
54     /**
55      * Creates a new TextSprite containing a multiple lines of text.
56      * @param text the variable text strings.
57      * @param spacing the variable spacing between the lines of text.
58      * @param x the variable x-coordinate of the lower-left corner of the
59      * first line of text.
60      * @param y the variable y-coordinate of the lower-left corner of the
61      * first line of text.
62      */

63     public TextSprite(VariableString[] text,
64                       VariableInt spacing,
65                       VariableInt x,
66                       VariableInt y)
67     {
68
69         this.text = text;
70         this.spacing = spacing;
71         this.x = x;
72         this.y = y;
73     }
74
75
76     // Implementation for Sprite.
77

78     public void paint(Graphics graphics, long time)
79     {
80
81         int xt = x.getInt(time);
82         int yt = y.getInt(time);
83
84         int spacingt = spacing.getInt(time);
85
86         for (int index = 0; index < text.length; index++)
87         {
88             graphics.drawString(text[index].getString(time), xt, yt + index * spacingt);
89         }
90     }
91 }
92
Popular Tags