Source Code Cross Referenced for BlurredIconExample.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:        import java.beans.PropertyChangeEvent;
036:        import java.beans.PropertyChangeListener;
037:        import java.net.URL;
038:
039:        import javax.swing.*;
040:
041:        import com.jgoodies.animation.*;
042:        import com.jgoodies.animation.tutorial.TutorialUtils;
043:        import com.jgoodies.binding.adapter.BoundedRangeAdapter;
044:        import com.jgoodies.binding.beans.Model;
045:        import com.jgoodies.binding.beans.PropertyAdapter;
046:        import com.jgoodies.binding.value.ConverterFactory;
047:        import com.jgoodies.binding.value.ValueModel;
048:        import com.jgoodies.forms.builder.PanelBuilder;
049:        import com.jgoodies.forms.layout.CellConstraints;
050:        import com.jgoodies.forms.layout.FormLayout;
051:
052:        /**
053:         * Demonstrates the BlurredIcon.
054:         *
055:         * @author Karsten Lentzsch
056:         * @version $Revision: 1.6 $
057:         */
058:        public final class BlurredIconExample extends Model {
059:
060:            private static final String ICON_FILENAME = "com/jgoodies/animation/tutorial/component/JavaOne.jpg";
061:
062:            private static final long DURATION = 2000;
063:
064:            private BlurredIcon blurredIcon;
065:            private JLabel iconLabel;
066:            private JSlider timeSlider;
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 :: BlurredIcon");
080:                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
081:                JComponent panel = new BlurredIconExample().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 BlurredIconExample() {
091:                initComponents();
092:            }
093:
094:            // Component Creation and Initialization **********************************
095:
096:            /**
097:             * Creates the text label, sliders and animation Actions.
098:             * Binds sliders to bound properties of the text label. 
099:             */
100:            private void initComponents() {
101:                // Load the JavaOne logo.
102:                URL url = getClass().getClassLoader()
103:                        .getResource(ICON_FILENAME);
104:                ImageIcon javaOneLogo = new ImageIcon(url);
105:                // Setup a BlurredIcon with a JavaOne logo.
106:                blurredIcon = new BlurredIcon(javaOneLogo, DURATION, 100);
107:
108:                // Have a label that uses the blurred Icon
109:                iconLabel = new JLabel(blurredIcon);
110:
111:                // Create a slider for the label's time in interval [0, 5000]
112:                timeSlider = new JSlider();
113:                ValueModel timeAdapter = new PropertyAdapter(blurredIcon,
114:                        "time", true);
115:                timeSlider.setModel(new BoundedRangeAdapter(ConverterFactory
116:                        .createLongToIntegerConverter(timeAdapter), 0, 0,
117:                        (int) DURATION));
118:                timeAdapter
119:                        .addValueChangeListener(new PropertyChangeListener() {
120:
121:                            public void propertyChange(PropertyChangeEvent evt) {
122:                                iconLabel.repaint();
123:                            }
124:                        });
125:
126:                // Create an Action to animate the blur effect
127:                animateAction = new AnimateAction();
128:            }
129:
130:            // Building *************************************************************
131:
132:            /**
133:             * Builds and returns a panel with the preview in the top 
134:             * and the tool panel in the bottom.
135:             * 
136:             * @return the built panel
137:             */
138:            private JComponent buildPanel() {
139:                FormLayout layout = new FormLayout("fill:pref:grow",
140:                        "fill:pref:grow, p, p");
141:
142:                PanelBuilder builder = new PanelBuilder(layout);
143:                CellConstraints cc = new CellConstraints();
144:                builder.add(buildPreviewPanel(), cc.xy(1, 1));
145:                builder.addSeparator("", cc.xy(1, 2));
146:                builder.add(buildToolsPanel(), cc.xy(1, 3));
147:                return builder.getPanel();
148:            }
149:
150:            public JComponent buildPreviewPanel() {
151:                FormLayout layout = new FormLayout("fill:200dlu:grow",
152:                        "fill:150dlu:grow");
153:                JPanel panel = new JPanel(layout);
154:                panel.setBackground(Color.WHITE);
155:                panel.add(iconLabel, new CellConstraints());
156:                return panel;
157:            }
158:
159:            public JComponent buildToolsPanel() {
160:                FormLayout layout = new FormLayout(
161:                        "pref, 3dlu, 50dlu, 12dlu, 50dlu", "pref");
162:
163:                PanelBuilder builder = new PanelBuilder(layout);
164:                builder.setDefaultDialogBorder();
165:                CellConstraints cc = new CellConstraints();
166:                builder.addLabel("Time", cc.xy(1, 1));
167:                builder.add(timeSlider, cc.xy(3, 1));
168:                builder.add(new JButton(animateAction), cc.xy(5, 1));
169:                return builder.getPanel();
170:            }
171:
172:            // Animation **************************************************************
173:
174:            private Animation createAnimation() {
175:                Animation blurAnimation = new BlurAnimation(DURATION / 2);
176:                return Animations.sequential(Animations.reverse(blurAnimation),
177:                        blurAnimation);
178:            }
179:
180:            private final class BlurAnimation extends AbstractAnimation {
181:
182:                private BlurAnimation(long duration) {
183:                    super (duration, true);
184:                }
185:
186:                public void applyEffect(long time) {
187:                    blurredIcon.setTime(time * 2);
188:                    iconLabel.repaint();
189:                }
190:
191:            }
192:
193:            // Animation Action *******************************************************
194:
195:            private final class AnimateAction extends AbstractAction {
196:
197:                private AnimateAction() {
198:                    super ("Animate");
199:                }
200:
201:                public void actionPerformed(ActionEvent e) {
202:                    Animation animation = createAnimation();
203:                    int fps = 30;
204:                    animation.addAnimationListener(new StartStopHandler());
205:                    new Animator(animation, fps).start();
206:                }
207:
208:            }
209:
210:            /**
211:             * Disables the animate action at animation start and
212:             * enables it when the animation stopped.
213:             */
214:            private final class StartStopHandler extends AnimationAdapter {
215:
216:                public void animationStarted(AnimationEvent e) {
217:                    animateAction.setEnabled(false);
218:                }
219:
220:                public void animationStopped(AnimationEvent e) {
221:                    animateAction.setEnabled(true);
222:                }
223:            }
224:
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.