001: /*
002: * Copyright (c) 2001-2006 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.animation.tutorial.intro;
032:
033: import java.awt.Color;
034: import java.awt.Font;
035: import java.awt.event.ActionEvent;
036:
037: import javax.swing.*;
038:
039: import com.jgoodies.animation.*;
040: import com.jgoodies.animation.animations.BasicTextAnimation;
041: import com.jgoodies.animation.animations.BasicTextAnimations;
042: import com.jgoodies.animation.components.BasicTextLabel;
043: import com.jgoodies.animation.tutorial.TutorialUtils;
044: import com.jgoodies.forms.builder.PanelBuilder;
045: import com.jgoodies.forms.layout.CellConstraints;
046: import com.jgoodies.forms.layout.FormLayout;
047:
048: /**
049: * Builds a page that consists of two <code>BasicTextLabel</code>s
050: * that render an intro animation.
051: *
052: * @author Karsten Lentzsch
053: * @version $Revision: 1.6 $
054: *
055: * @see Animation
056: * @see BasicTextLabel
057: */
058: public final class BasicTextLabelIntro {
059:
060: // UI Components
061: private BasicTextLabel label1;
062: private BasicTextLabel label2;
063:
064: /**
065: * Refers to the Action that starts the intro animation.
066: */
067: private Action animateAction;
068:
069: // Self Starter ***********************************************************
070:
071: public static void main(String[] args) {
072: try {
073: UIManager
074: .setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
075: } catch (Exception e) {
076: // Likely PlasticXP is not in the class path; ignore.
077: }
078: JFrame frame = new JFrame();
079: frame.setTitle("Animation Tutorial :: BasicTextLabel Intro");
080: frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
081: JComponent panel = new BasicTextLabelIntro().buildPanel();
082: frame.getContentPane().add(panel);
083: frame.pack();
084: TutorialUtils.locateOnOpticalScreenCenter(frame);
085: frame.setVisible(true);
086: }
087:
088: // Instance Creation ******************************************************
089:
090: public BasicTextLabelIntro() {
091: //duration = 4000;
092: initComponents();
093: }
094:
095: // Building *************************************************************
096:
097: /**
098: * Creates and configures the UI components.
099: */
100: private void initComponents() {
101: Font font = new Font("Tahoma", Font.BOLD, 18);
102: label1 = new BasicTextLabel(" ");
103: label1.setFont(font);
104: //label1.setBounds(0, 0, 350, 100);
105: label1.setOpaque(false);
106:
107: label2 = new BasicTextLabel(" ");
108: label2.setFont(font);
109: //label2.setBounds(0, 0, 350, 100);
110: label2.setOpaque(false);
111:
112: animateAction = new AnimateAction();
113: }
114:
115: /**
116: * Builds and returns a panel with the preview in the top
117: * and the tool panel in the bottom.
118: *
119: * @return the built panel
120: */
121: private JComponent buildPanel() {
122: FormLayout layout = new FormLayout("fill:pref:grow",
123: "fill:pref:grow, p, p");
124:
125: PanelBuilder builder = new PanelBuilder(layout);
126: CellConstraints cc = new CellConstraints();
127: builder.add(buildPreviewPanel(), cc.xy(1, 1));
128: builder.addSeparator("", cc.xy(1, 2));
129: builder.add(buildToolsPanel(), cc.xy(1, 3));
130: return builder.getPanel();
131: }
132:
133: /**
134: * Builds this intro panel with two overlayed labels in the center.
135: *
136: * @return the panel that contains the two overlayed labels
137: */
138: public JPanel buildPreviewPanel() {
139: FormLayout layout = new FormLayout("fill:200dlu:grow",
140: "fill:100dlu:grow");
141: JPanel panel = new JPanel(layout);
142: CellConstraints cc = new CellConstraints();
143: panel.setBackground(Color.WHITE);
144: panel.add(label1, cc.xy(1, 1));
145: panel.add(label2, cc.xy(1, 1));
146: return panel;
147: }
148:
149: public JComponent buildToolsPanel() {
150: FormLayout layout = new FormLayout("right:pref:grow", "pref");
151:
152: PanelBuilder builder = new PanelBuilder(layout);
153: builder.setDefaultDialogBorder();
154: CellConstraints cc = new CellConstraints();
155: builder.add(new JButton(animateAction), cc.xy(1, 1));
156: return builder.getPanel();
157: }
158:
159: // Animation Creation ***************************************************
160:
161: /**
162: * Creates and returns a composed animation for the intro.
163: *
164: * @return the composed animation
165: */
166: private Animation createAnimation() {
167: Animation welcome = BasicTextAnimation.defaultFade(label1,
168: 2500, "Welcome To", Color.DARK_GRAY);
169:
170: Animation theJGoodiesAnimation = BasicTextAnimation
171: .defaultFade(label1, 3000, "The JGoodies Animation",
172: Color.DARK_GRAY);
173:
174: Animation description = BasicTextAnimations
175: .defaultFade(
176: label1,
177: label2,
178: 2000,
179: -100,
180: "An open source framework|"
181: + "for time-based|real-time animations|in Java.",
182: Color.DARK_GRAY);
183:
184: Animation features = BasicTextAnimations.defaultFade(label1,
185: label2, 3000, 500, "Main Features:", Color.DARK_GRAY);
186:
187: Animation featureList = BasicTextAnimations.defaultFade(label1,
188: label2, 1750, 0,
189: "Seamless|flexible|and powerful integration|with Java.|"
190: + "small library size", Color.DARK_GRAY);
191:
192: Animation all = Animations.sequential(new Animation[] {
193: Animations.pause(1000), welcome,
194: Animations.pause(1000), theJGoodiesAnimation,
195: Animations.pause(1000), description,
196: Animations.pause(1000), features,
197: Animations.pause(1000), featureList,
198: Animations.pause(1500), });
199:
200: return all;
201: }
202:
203: // Animation Action *******************************************************
204:
205: private final class AnimateAction extends AbstractAction {
206:
207: private AnimateAction() {
208: super ("Animate");
209: }
210:
211: public void actionPerformed(ActionEvent e) {
212: Animation animation = createAnimation();
213: int fps = 30;
214: animation.addAnimationListener(new StartStopHandler());
215: new Animator(animation, fps).start();
216: }
217:
218: }
219:
220: /**
221: * Disables the actions at animation start and enables them
222: * when the animation stopped. Also restores the text label's text.
223: */
224: private final class StartStopHandler extends AnimationAdapter {
225:
226: public void animationStarted(AnimationEvent e) {
227: animateAction.setEnabled(false);
228: }
229:
230: public void animationStopped(AnimationEvent e) {
231: animateAction.setEnabled(true);
232: }
233: }
234:
235: }
|