KickJava   Java API By Example, From Geeks To Geeks.

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


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.Graphics JavaDoc;
24
25 /**
26  * This Sprite represents an animated rounded rectangle. It can optionally be filled.
27  *
28  * @author Eric Lafortune
29  */

30 public class RectangleSprite implements Sprite
31 {
32     private boolean filled;
33     private VariableColor color;
34     private VariableInt x;
35     private VariableInt y;
36     private VariableInt width;
37     private VariableInt height;
38     private VariableInt arcWidth;
39     private VariableInt arcHeight;
40
41
42     /**
43      * Creates a new rectangular RectangleSprite.
44      * @param filled specifies whether the rectangle should be filled.
45      * @param color the variable color of the rectangle.
46      * @param x the variable x-coordinate of the upper-left corner of the rectangle.
47      * @param y the variable y-coordinate of the upper-left corner of the rectangle.
48      * @param width the variable width of the rectangle.
49      * @param height the variable height of the rectangle.
50      */

51     public RectangleSprite(boolean filled,
52                            VariableColor color,
53                            VariableInt x,
54                            VariableInt y,
55                            VariableInt width,
56                            VariableInt height)
57     {
58         this(filled, color, x, y, width, height, new ConstantInt(0), new ConstantInt(0));
59     }
60
61
62     /**
63      * Creates a new RectangleSprite with rounded corners.
64      * @param filled specifies whether the rectangle should be filled.
65      * @param color the variable color of the rectangle.
66      * @param x the variable x-coordinate of the upper-left corner of the rectangle.
67      * @param y the variable y-coordinate of the upper-left corner of the rectangle.
68      * @param width the variable width of the rectangle.
69      * @param height the variable height of the rectangle.
70      * @param arcwWidth the variable width of the corner arcs.
71      * @param arcwHeight the variable height of the corner arcs.
72      */

73     public RectangleSprite(boolean filled,
74                            VariableColor color,
75                            VariableInt x,
76                            VariableInt y,
77                            VariableInt width,
78                            VariableInt height,
79                            VariableInt arcWidth,
80                            VariableInt arcHeight)
81     {
82         this.filled = filled;
83         this.color = color;
84         this.x = x;
85         this.y = y;
86         this.width = width;
87         this.height = height;
88         this.arcWidth = arcWidth;
89         this.arcHeight = arcHeight;
90     }
91
92     // Implementation for Sprite.
93

94     public void paint(Graphics JavaDoc graphics, long time)
95     {
96         graphics.setColor(color.getColor(time));
97
98         int xt = x.getInt(time);
99         int yt = y.getInt(time);
100         int w = width.getInt(time);
101         int h = height.getInt(time);
102         int aw = arcWidth.getInt(time);
103         int ah = arcHeight.getInt(time);
104
105         if (filled)
106         {
107             graphics.fillRoundRect(xt, yt, w, h, aw, ah);
108         }
109         else
110         {
111             graphics.drawRoundRect(xt, yt, w, h, aw, ah);
112         }
113     }
114 }
115
Popular Tags