Home | History | Annotate | Download | only in splash
      1 /*
      2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
      3  *             of Java bytecode.
      4  *
      5  * Copyright (c) 2002-2009 Eric Lafortune (eric (at) 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 
     25 /**
     26  * This Sprite represents a text.
     27  *
     28  * @author Eric Lafortune
     29  */
     30 public class TextSprite implements Sprite
     31 {
     32     private final VariableString[] text;
     33     private final VariableInt      spacing;
     34     private final VariableInt      x;
     35     private final VariableInt      y;
     36 
     37 
     38     /**
     39      * Creates a new TextSprite containing a single line of text.
     40      * @param text  the variable text string.
     41      * @param x     the variable x-coordinate of the lower-left corner of the text.
     42      * @param y     the variable y-coordinate of the lower-left corner of the text.
     43      */
     44     public TextSprite(VariableString text,
     45                       VariableInt    x,
     46                       VariableInt    y)
     47     {
     48         this(new VariableString[] { text }, new ConstantInt(0), x, y);
     49     }
     50 
     51 
     52     /**
     53      * Creates a new TextSprite containing a multiple lines of text.
     54      * @param text    the variable text strings.
     55      * @param spacing the variable spacing between the lines of text.
     56      * @param x       the variable x-coordinate of the lower-left corner of the
     57      *                first line of text.
     58      * @param y       the variable y-coordinate of the lower-left corner of the
     59      *                first line of text.
     60      */
     61     public TextSprite(VariableString[] text,
     62                       VariableInt      spacing,
     63                       VariableInt      x,
     64                       VariableInt      y)
     65     {
     66 
     67         this.text    = text;
     68         this.spacing = spacing;
     69         this.x       = x;
     70         this.y       = y;
     71     }
     72 
     73 
     74     // Implementation for Sprite.
     75 
     76     public void paint(Graphics graphics, long time)
     77     {
     78 
     79         int xt = x.getInt(time);
     80         int yt = y.getInt(time);
     81 
     82         int spacingt = spacing.getInt(time);
     83 
     84         for (int index = 0; index < text.length; index++)
     85         {
     86             graphics.drawString(text[index].getString(time), xt, yt + index * spacingt);
     87         }
     88     }
     89 }
     90