Source Code Cross Referenced for AnimatedLabelExample.java in  » Swing-Library » jgoodies-animation » com » jgoodies » animation » tutorial » component » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jgoodies animation » com.jgoodies.animation.tutorial.component 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.component;
032:
033:        import java.awt.Color;
034:        import java.awt.event.ActionEvent;
035:
036:        import javax.swing.*;
037:
038:        import com.jgoodies.animation.components.AnimatedLabel;
039:        import com.jgoodies.animation.tutorial.TutorialUtils;
040:        import com.jgoodies.binding.adapter.BasicComponentFactory;
041:        import com.jgoodies.binding.beans.BeanAdapter;
042:        import com.jgoodies.binding.beans.Model;
043:        import com.jgoodies.forms.builder.ButtonBarBuilder;
044:        import com.jgoodies.forms.builder.PanelBuilder;
045:        import com.jgoodies.forms.layout.CellConstraints;
046:        import com.jgoodies.forms.layout.FormLayout;
047:
048:        /**
049:         * Demonstrates the features of the {@link AnimatedLabel}.
050:         * Consists of a preview panel that displays an AnimatedLabel and a 
051:         * tools panel to edit its duration, animated state and to change the text.
052:         *
053:         * @author Karsten Lentzsch
054:         * @version $Revision: 1.7 $
055:         */
056:
057:        public final class AnimatedLabelExample extends Model {
058:
059:            private static final Color AMAZON_ORANGE = new Color(255, 142, 12);
060:
061:            private static final String[] TEXTS = { "The AnimatedLabel",
062:                    "Uses an Animation", "That Blends Over", "Texts.",
063:                    "YOU CAN CONFIGURE", "THE DURATION", "AND ANIMATED STATE" };
064:
065:            /**
066:             * The current index in the above array of sample texts.
067:             */
068:            private int textIndex;
069:
070:            /**
071:             * Refers to the animated label that is demonstrated in this example.
072:             */
073:            private AnimatedLabel animatedLabel;
074:
075:            private JTextField durationField;
076:            private JComponent animatedBox;
077:            private Action nextTextAction;
078:
079:            // Self Starter ***********************************************************
080:
081:            public static void main(String[] args) {
082:                try {
083:                    UIManager
084:                            .setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
085:                } catch (Exception e) {
086:                    // Likely PlasticXP is not in the class path; ignore.
087:                }
088:                JFrame frame = new JFrame();
089:                frame.setTitle("Animation Tutorial :: AnimatedLabel");
090:                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
091:                JComponent panel = new AnimatedLabelExample().buildPanel();
092:                frame.getContentPane().add(panel);
093:                frame.pack();
094:                TutorialUtils.locateOnOpticalScreenCenter(frame);
095:                frame.setVisible(true);
096:            }
097:
098:            // Instance Creation ******************************************************
099:
100:            public AnimatedLabelExample() {
101:                initComponents();
102:            }
103:
104:            // Component Creation and Initialization **********************************
105:
106:            /**
107:             * Creates the animated label, duration text field, a check box
108:             * for the animated state and an Action to set the new text.
109:             */
110:            private void initComponents() {
111:                textIndex = 0;
112:                // Setup an AnimatedLabel with an Amazon.com organe and a font
113:                // 16 pt larger than the dialog font.
114:                animatedLabel = new AnimatedLabel(AMAZON_ORANGE, 16,
115:                        TEXTS[textIndex]);
116:
117:                // Create a bean adapter that vends property adapters.
118:                BeanAdapter beanAdapter = new BeanAdapter(animatedLabel, true);
119:
120:                // Create a text field bound to the label's blend over duration.
121:                durationField = BasicComponentFactory
122:                        .createIntegerField(beanAdapter
123:                                .getValueModel(AnimatedLabel.PROPERTYNAME_DURATION));
124:                durationField.setColumns(5);
125:                animatedBox = BasicComponentFactory.createCheckBox(beanAdapter
126:                        .getValueModel(AnimatedLabel.PROPERTYNAME_ANIMATED),
127:                        "animated");
128:
129:                // Create an Action to set the next text.
130:                nextTextAction = new AnimateAction();
131:            }
132:
133:            // Building *************************************************************
134:
135:            /**
136:             * Builds and returns a panel with the preview in the top 
137:             * and the tool panel in the bottom.
138:             * 
139:             * @return the built panel
140:             */
141:            private JComponent buildPanel() {
142:                FormLayout layout = new FormLayout("fill:pref:grow",
143:                        "fill:p:grow, p, p");
144:
145:                PanelBuilder builder = new PanelBuilder(layout);
146:                CellConstraints cc = new CellConstraints();
147:                builder.add(buildPreviewPanel(), cc.xy(1, 1));
148:                builder.addSeparator("", cc.xy(1, 2));
149:                builder.add(buildToolsPanel(), cc.xy(1, 3));
150:
151:                return builder.getPanel();
152:            }
153:
154:            public JComponent buildPreviewPanel() {
155:                FormLayout layout = new FormLayout(
156:                        "50dlu, left:200dlu:grow, 50dlu", "fill:100dlu:grow");
157:                JPanel panel = new JPanel(layout);
158:                panel.setBackground(Color.WHITE);
159:                panel.add(animatedLabel, new CellConstraints(2, 1));
160:                return panel;
161:            }
162:
163:            public JComponent buildToolsPanel() {
164:                FormLayout layout = new FormLayout(
165:                        "p, 3dlu, p, 6dlu, p, 24dlu:grow, p", "p");
166:
167:                PanelBuilder builder = new PanelBuilder(layout);
168:                builder.setDefaultDialogBorder();
169:                CellConstraints cc = new CellConstraints();
170:                builder.addLabel("Duration:", cc.xy(1, 1));
171:                builder.add(durationField, cc.xy(3, 1));
172:                builder.add(animatedBox, cc.xy(5, 1));
173:                builder.add(buildButtonBar(), cc.xy(7, 1));
174:                return builder.getPanel();
175:            }
176:
177:            private JComponent buildButtonBar() {
178:                ButtonBarBuilder builder = new ButtonBarBuilder();
179:                builder.addGridded(new JButton(nextTextAction));
180:                return builder.getPanel();
181:            }
182:
183:            // Animation Action *******************************************************
184:
185:            private final class AnimateAction extends AbstractAction {
186:
187:                private AnimateAction() {
188:                    super ("Next Text");
189:                }
190:
191:                public void actionPerformed(ActionEvent e) {
192:                    if (++textIndex == TEXTS.length)
193:                        textIndex = 0;
194:                    animatedLabel.setText(TEXTS[textIndex]);
195:                }
196:
197:            }
198:
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.