KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > swing > animate > IntroPage


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.mc4j.console.swing.animate;
18
19 import com.jgoodies.animation.Animations;
20 import com.jgoodies.animation.Animation;
21 import com.jgoodies.animation.AbstractAnimation;
22 import com.jgoodies.animation.Animator;
23 import com.jgoodies.animation.animations.BasicTextAnimation;
24 import com.jgoodies.animation.animations.BasicTextAnimations;
25 import com.jgoodies.animation.animations.FanAnimation;
26 import com.jgoodies.animation.components.BasicTextLabel;
27 import com.jgoodies.animation.components.FanComponent;
28
29 import javax.swing.*;
30 import java.awt.*;
31 import java.awt.geom.AffineTransform JavaDoc;
32 import java.net.URL JavaDoc;
33
34 import org.openide.util.Utilities;
35
36 /**
37  * @author Greg Hinkle (ghinkle@users.sourceforge.net), Oct 6, 2004
38  * @version $Revision: 492 $($Author: ghinkl $ / $Date: 2004-10-13 01:03:28 -0400 (Wed, 13 Oct 2004) $)
39  */

40
41 public final class IntroPage extends JPanel{
42
43     // UI Components
44
private BasicTextLabel label1;
45     private BasicTextLabel label2;
46     private FanComponent fan;
47     private TransformablePanel logoPanel;
48
49     /**
50      * Refers to the animation that is used in this page.
51      */

52     private Animation animation;
53     private static final Color MC4J_COLOR = Color.decode("0x87ADCB");
54
55     public static void main(String JavaDoc[] args) {
56         JFrame frame = new JFrame();
57         frame.setContentPane(new IntroPage());
58         frame.setSize(350, 300);
59         frame.setTitle("MC4J intro");
60         frame.setDefaultCloseOperation(3);
61         locateOnScreenCenter(frame);
62         frame.setVisible(true);
63     }
64
65     private static void locateOnScreenCenter(Component component) {
66         Dimension paneSize = component.getSize();
67         Dimension screenSize = component.getToolkit().getScreenSize();
68         component.setLocation(
69             (screenSize.width - paneSize.width) / 2,
70             (screenSize.height - paneSize.height) / 2);
71     }
72
73     public IntroPage() {
74         buildContent();
75         Animator animator = new Animator(animation(), 30);
76         animator.start();
77     }
78
79
80     /**
81      * Returns the intro animation.
82      *
83      * @return the intro animation
84      */

85     public Animation animation() {
86         return animation;
87     }
88
89
90     /**
91      * Creates and configures the UI components.
92      */

93     private void initComponents() {
94         Font font = getAnimationFont();
95         label1 = new BasicTextLabel(" ");
96         label1.setFont(font.deriveFont(Font.BOLD,18));
97         label1.setOpaque(false);
98
99         label2 = new BasicTextLabel(" ");
100         label2.setFont(font.deriveFont(Font.BOLD,18));
101         label2.setOpaque(false);
102
103         fan = new FanComponent(3,MC4J_COLOR);
104
105         logoPanel = new TransformablePanel();
106     }
107
108     /**
109      * Builds this intro panel with two overlayed labels in the center.
110      *
111      */

112     public void buildContent() {
113         initComponents();
114         animation = createAnimation();
115
116         setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
117         setOpaque(false);
118
119         add(label1);
120         add(label2);
121
122         // Seems a bit slow
123
// add(fan);
124
}
125
126     // Animation Creation ***************************************************
127

128     /**
129      * Creates and answers a composed animation for the intro.
130      *
131      * @return the composed animation
132      */

133     private Animation createAnimation() {
134         Animation one =
135             BasicTextAnimation.defaultFade(
136                 label1,
137                 2500,
138                 "Welcome to MC4J",
139                 MC4J_COLOR);
140
141         Animation twoA =
142             BasicTextAnimation.defaultFade(
143                 label1,
144                 2500,
145                 "JMX application management",
146                 Color.darkGray);
147         Animation twoB =
148             BasicTextAnimation.defaultFade(
149                 label2,
150                 4000,
151                 "and monitoring",
152                 Color.darkGray);
153
154         Animation two = Animations.parallel(twoA, twoB);
155
156         Animation three =
157             BasicTextAnimation.defaultScale(
158                 label1, 2000,
159                 "for all major servers",
160                 Color.blue);
161
162
163         Animation fourA =
164             Animations.sequential(
165                 new Animation[] {
166                     BasicTextAnimation.defaultFade(
167                         label1,
168                         1000,
169                         "WebLogic",
170                         Color.decode("0xAD170F")),
171                     Animations.pause(1000),
172                     BasicTextAnimation.defaultFade(
173                         label1,
174                         1000,
175                         "Oracle OC4J",
176                         Color.decode("0xFF0000")),
177                     Animations.pause(1000),
178                     BasicTextAnimation.defaultFade(
179                         label1,
180                         1000,
181                         "Pramati",
182                         Color.decode("0xD6E0E0")),
183                     Animations.pause(1000),
184                     BasicTextAnimation.defaultFade(
185                         label1,
186                         1000,
187                         "Geronimo",
188                         Color.decode("0xCCCCCC")),
189                     Animations.pause(1000)
190                 });
191
192         Animation fourB =
193             Animations.sequential(
194                 new Animation[] {
195                     Animations.pause(1000),
196                     BasicTextAnimation.defaultFade(
197                         label2,
198                         1000,
199                         "WebSphere",
200                         Color.decode("0x006699")),
201                     Animations.pause(1000),
202                     BasicTextAnimation.defaultFade(
203                         label2,
204                         1000,
205                         "JBoss",
206                         Color.decode("0xF28423")),
207                     Animations.pause(1000),
208                     BasicTextAnimation.defaultFade(
209                         label2,
210                         1000,
211                         "Tomcat",
212                         Color.decode("0x525D76")),
213                     Animations.pause(1000),
214                     BasicTextAnimation.defaultFade(
215                         label2,
216                         1000,
217                         "JS2E 1.5",
218                         Color.decode("0x594FBF")),
219                     Animations.pause(1000)
220                 });
221
222         Animation four = Animations.parallel(fourA,fourB);
223
224
225         Animation five =
226             BasicTextAnimations.defaultSpace(
227                 label1,label2,2000,4000,"Customizable Dashboards",Color.darkGray);
228
229         Animation six =
230             BasicTextAnimations.defaultSpace(
231                 label1,label2,2000,4000,"Live graphs",Color.darkGray);
232
233
234         Animation fanAnimation =
235             FanAnimation.defaultFan(fan,8000);
236
237         Animation all =
238             Animations.repeat(10f,
239                 Animations.sequential(
240                     new Animation[] {
241                         Animations.pause(500),
242                         one,
243                         Animations.pause(500),
244                         two,
245                         three,
246                         Animations.pause(500),
247                         four,
248                         Animations.pause(500),
249                         five,
250                         Animations.pause(500),
251                         six,
252                         Animations.pause(3000),
253                         }));
254
255         Animation base =
256             Animations.parallel(
257                 Animations.repeat(50f,fanAnimation),
258                 all);
259
260 // base = Animations.parallel(
261
// Animations.repeat(50f, new LogoAnimation(5000,logoPanel)),
262
// base);
263

264         return base;
265     }
266
267     // Helper Code **********************************************************
268

269     /**
270      * Looks up and answer a <code>Font</code> used for the animations.
271      * Tries to get a bold <i>Tahoma</i> on Windows.
272      *
273      * @return the font used for the animation
274      */

275     private Font getAnimationFont() {
276         return new Font("Tahoma", Font.BOLD, 18);
277     }
278
279     public static class TransformablePanel extends JPanel {
280         private AffineTransform JavaDoc currentTransform;
281         public void setTransform(AffineTransform JavaDoc transform) {
282             this.currentTransform = transform;
283         }
284
285         double angle;
286         public void setAngle(double angle) {
287             this.angle = angle;
288         }
289
290         private AlphaComposite slightAlpha =
291             AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f);
292         protected void paintChildren(Graphics g) {
293 // AffineTransform baseTransform = ((Graphics2D)g).getTransform();
294
// ((Graphics2D)g).rotate(angle);
295
((Graphics2D)g).setComposite(slightAlpha);
296             super.paintChildren(g);
297 // ((Graphics2D)g).setTransform(baseTransform);
298
}
299     }
300
301
302     public static class LogoAnimation extends AbstractAnimation {
303
304         private TransformablePanel target;
305         private Image image;
306
307         public LogoAnimation(long l, TransformablePanel target) {
308             super(l);
309             this.target = target;
310
311             URL JavaDoc url = getClass().getClassLoader().getResource("images/FullLogo.gif");
312             image = Toolkit.getDefaultToolkit().createImage(url);
313             target.add(new JLabel(new ImageIcon(image)));
314         }
315
316         protected void applyEffect(long l) {
317             AffineTransform JavaDoc transform = AffineTransform.getRotateInstance(l * 0.05);
318
319             target.setAngle(l * 0.05);
320         }
321     }
322
323 }
Popular Tags