KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > animation > examples > intro > IntroPage


1 /*
2  * Copyright (c) 2001-2004 JGoodies Karsten Lentzsch. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * o Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * o Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * o Neither the name of JGoodies Karsten Lentzsch nor the names of
15  * its contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.jgoodies.animation.examples.intro;
32
33 import java.awt.Color JavaDoc;
34 import java.awt.Font JavaDoc;
35
36 import javax.swing.JPanel JavaDoc;
37
38 import com.jgoodies.animation.Animation;
39 import com.jgoodies.animation.Animations;
40 import com.jgoodies.animation.animations.BasicTextAnimation;
41 import com.jgoodies.animation.animations.BasicTextAnimations;
42 import com.jgoodies.animation.components.BasicTextLabel;
43
44 /**
45  * Builds a page that consists of two <code>BasicTextLabel</code>s
46  * that render an intro animation.
47  *
48  * @author Karsten Lentzsch
49  * @version $Revision: 1.3 $
50  *
51  * @see Animation
52  * @see BasicTextLabel
53  */

54
55 public final class IntroPage {
56
57     // UI Components
58
private BasicTextLabel label1;
59     private BasicTextLabel label2;
60     
61     /**
62      * Refers to the animation that is used in this page.
63      */

64     private Animation animation;
65
66
67     // API ******************************************************************
68

69     /**
70      * Returns the intro animation.
71      *
72      * @return the intro animation
73      */

74     public Animation animation() {
75         return animation;
76     }
77     
78
79     // Building *************************************************************
80

81     /**
82      * Creates and configures the UI components.
83      */

84     private void initComponents() {
85         Font JavaDoc font = getAnimationFont();
86         label1 = new BasicTextLabel(" ");
87         label1.setFont(font);
88         label1.setBounds(0, 0, 350, 100);
89         label1.setOpaque(false);
90
91         label2 = new BasicTextLabel(" ");
92         label2.setFont(font);
93         label2.setBounds(0, 0, 350, 100);
94         label2.setOpaque(false);
95     }
96     
97     /**
98      * Builds this intro panel with two overlayed labels in the center.
99      *
100      * @return the panel that contains the two overlayed labels
101      */

102     public JPanel JavaDoc build() {
103         initComponents();
104         animation = createAnimation();
105         
106         JPanel JavaDoc panel = new JPanel JavaDoc(null);
107         panel.setBounds(0, 0, 350, 100);
108         panel.setBackground(Color.white);
109         
110         panel.add(label1);
111         panel.add(label2);
112
113         return panel;
114     }
115
116     // Animation Creation ***************************************************
117

118     /**
119      * Creates and answers a composed animation for the intro.
120      *
121      * @return the composed animation
122      */

123     private Animation createAnimation() {
124         Animation welcome =
125             BasicTextAnimation.defaultFade(
126                 label1,
127                 2500,
128                 "Welcome To",
129                 Color.darkGray);
130
131         Animation theJGoodiesAnimation =
132             BasicTextAnimation.defaultFade(
133                 label1,
134                 3000,
135                 "The JGoodies Animation",
136                 Color.darkGray);
137
138         Animation description =
139             BasicTextAnimations.defaultFade(
140                 label1,
141                 label2,
142                 2000,
143                 -100,
144                 "An open source framework|" +
145                 "for time-based|real-time animations|in Java.",
146                 Color.darkGray);
147
148         Animation features =
149             BasicTextAnimations.defaultFade(
150                 label1,
151                 label2,
152                 3000,
153                 500,
154                 "Main Features:",
155                 Color.darkGray);
156
157         Animation featureList =
158             BasicTextAnimations.defaultFade(
159                 label1,
160                 label2,
161                 1750,
162                 0,
163                 "Seamless|flexible|and powerful integration|with Java.|" +
164                 "small library size",
165                 Color.darkGray);
166
167         Animation all =
168             Animations.sequential(
169                 new Animation[] {
170                     Animations.pause(1000),
171                     welcome,
172                     Animations.pause(1000),
173                     theJGoodiesAnimation,
174                     Animations.pause(1000),
175                     description,
176                     Animations.pause(1000),
177                     features,
178                     Animations.pause(1000),
179                     featureList,
180                     Animations.pause(1500),
181                     });
182
183         return all;
184     }
185     
186     // Helper Code **********************************************************
187

188     /**
189      * Looks up and answer a <code>Font</code> used for the animations.
190      * Tries to get a bold <i>Tahoma</i> on Windows.
191      *
192      * @return the font used for the animation
193      */

194     private Font JavaDoc getAnimationFont() {
195         return new Font JavaDoc("Tahoma", Font.BOLD, 18);
196     }
197
198 }
Popular Tags