Source Code Cross Referenced for AnimatedContainer.java in  » IDE-Netbeans » cvsclient » org » netbeans » lib » profiler » ui » components » 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 » IDE Netbeans » cvsclient » org.netbeans.lib.profiler.ui.components 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         * The Original Software is NetBeans. The Initial Developer of the Original
026:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027:         * Microsystems, Inc. All Rights Reserved.
028:         *
029:         * If you wish your version of this file to be governed by only the CDDL
030:         * or only the GPL Version 2, indicate your decision by adding
031:         * "[Contributor] elects to include this software in this distribution
032:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
033:         * single choice of license, a recipient has the option to distribute
034:         * your version of this file under either the CDDL, the GPL Version 2 or
035:         * to extend the choice of license to its licensees as provided above.
036:         * However, if you add GPL Version 2 code and therefore, elected the GPL
037:         * Version 2 license, then the option applies only if the new code is
038:         * made subject to such option by the copyright holder.
039:         */
040:
041:        package org.netbeans.lib.profiler.ui.components;
042:
043:        import java.awt.*;
044:        import javax.swing.*;
045:
046:        /**
047:         * A container for two contents that are animated in traansition between them.
048:         *
049:         * @author Vlada Nemec
050:         */
051:        public class AnimatedContainer extends javax.swing.JPanel {
052:            //~ Static fields/initializers -----------------------------------------------------------------------------------------------
053:
054:            public static final int WIDTH = 10;
055:            public static final int HEIGHT = 20;
056:            private static final int BOTH = 30;
057:
058:            //~ Instance fields ----------------------------------------------------------------------------------------------------------
059:
060:            //custom layout manager used for placing content component
061:            private AnimationLayout layout = new AnimationLayout();
062:            private CustomTaskButtonBorder border;
063:
064:            //content of the container - limited to one component
065:            private JComponent content;
066:
067:            //target content for the animation
068:            private JComponent targetContent;
069:
070:            //temporary content used during animation
071:            private JComponent transContent;
072:            private int animatedDimension = BOTH;
073:            private int origHeight;
074:
075:            //original dimensions
076:            private int origWidth;
077:            private int targetHeight;
078:
079:            //new dimension for animation (if needed)
080:            private int targetWidth;
081:
082:            //~ Constructors -------------------------------------------------------------------------------------------------------------
083:
084:            /**
085:             * Creates a new instance of AnimatedContainer
086:             */
087:            public AnimatedContainer(Color backgroundColor) {
088:                setLayout(layout);
089:
090:                border = new CustomTaskButtonBorder(backgroundColor, super 
091:                        .getBackground());
092:                setBorder(border);
093:            }
094:
095:            //~ Methods ------------------------------------------------------------------------------------------------------------------
096:
097:            public void setAnimatedDimension(int dimension) {
098:                animatedDimension = dimension;
099:            }
100:
101:            /**
102:             * Setups animation parameters.
103:             */
104:            public void setAnimation(JComponent targetContent,
105:                    JComponent transContent) {
106:                //setup starting point dimension
107:                origWidth = content.getWidth();
108:                origHeight = content.getHeight();
109:
110:                //set contents
111:                if (targetContent == null) {
112:                    this .targetContent = content;
113:                } else if (transContent == null) {
114:                    this .transContent = content;
115:                } else {
116:                    this .targetContent = targetContent;
117:                    this .transContent = transContent;
118:
119:                    targetWidth = (int) targetContent.getPreferredSize()
120:                            .getWidth();
121:                    targetHeight = (int) targetContent.getPreferredSize()
122:                            .getHeight();
123:                }
124:            }
125:
126:            /**
127:             * Setups animation parameters. <code>transContent</code> is set to <code>content</code>
128:             */
129:            public void setAnimation(JComponent aTargetContent) {
130:                //setup starting point dimension
131:                origWidth = content.getWidth();
132:                origHeight = content.getHeight();
133:
134:                if (aTargetContent == null) {
135:                    targetContent = content;
136:                } else {
137:                    targetContent = aTargetContent;
138:
139:                    targetWidth = (int) targetContent.getPreferredSize()
140:                            .getWidth();
141:                    targetHeight = (int) targetContent.getPreferredSize()
142:                            .getHeight();
143:                }
144:            }
145:
146:            public void setAnimation(Dimension dimension) {
147:                //setup starting point dimension
148:                origWidth = content.getWidth();
149:                origHeight = content.getHeight();
150:
151:                targetContent = null;
152:                transContent = content;
153:
154:                targetWidth = (int) dimension.getWidth();
155:                targetHeight = (int) dimension.getHeight();
156:            }
157:
158:            public void setAnimation() {
159:                origWidth = content.getWidth();
160:                origHeight = content.getHeight();
161:
162:                transContent = content;
163:                targetContent = content;
164:            }
165:
166:            /**
167:             * Sets content component reference. This method does NOT place any component into container.
168:             */
169:            public void setContent(JComponent content) {
170:                this .content = content;
171:            }
172:
173:            public void setDefaultBorder() {
174:                border.setDefault();
175:                repaint();
176:            }
177:
178:            /**
179:             * Sets the state of the container to finish state  with target size and content
180:             */
181:            public void setFinishState() {
182:                //empty container
183:                removeAll();
184:
185:                //add target content
186:                if (targetContent != null) {
187:                    add(targetContent);
188:                    //resize to final size
189:                    setPreferredSize(new Dimension(targetWidth, targetHeight));
190:                    setMinimumSize(new Dimension(targetWidth, targetHeight));
191:                } else if (transContent != null) {
192:                    add(transContent);
193:                    //resize to final size
194:                    setPreferredSize(transContent.getPreferredSize());
195:                    setMinimumSize(transContent.getPreferredSize());
196:                }
197:
198:                //resize to final size
199:                setPreferredSize(content.getPreferredSize());
200:                setMinimumSize(content.getPreferredSize());
201:            }
202:
203:            public void setFocusedBorder() {
204:                border.setFocused();
205:                repaint();
206:            }
207:
208:            public void setSelectedBorder() {
209:                border.setSelected();
210:                repaint();
211:            }
212:
213:            /**
214:             * Sets the state of the container - this method provides the resizing of container for animation
215:             */
216:            public void setState(int percents) {
217:                int newWidth;
218:                int newHeight;
219:
220:                newWidth = targetWidth;
221:                newHeight = targetHeight;
222:
223:                origWidth = (int) getSize().getWidth();
224:                origHeight = (int) getSize().getHeight();
225:
226:                int deltaWidth = newWidth - origWidth;
227:                int deltaHeight = newHeight - origHeight;
228:
229:                double perc = (double) percents / 100.0;
230:
231:                Dimension d;
232:
233:                if (animatedDimension == WIDTH) {
234:                    d = new Dimension((int) (origWidth + (deltaWidth * perc)),
235:                            origHeight);
236:                } else if (animatedDimension == HEIGHT) {
237:                    d = new Dimension(origWidth,
238:                            (int) (origHeight + (deltaHeight * perc)));
239:                } else {
240:                    d = new Dimension((int) (origWidth + (deltaWidth * perc)),
241:                            (int) (origHeight + (deltaHeight * perc)));
242:                }
243:
244:                setPreferredSize(d);
245:                setMinimumSize(d);
246:            }
247:
248:            /**
249:             * Sets target content component reference. This method does NOT place any component into container.
250:             */
251:            public void setTargetContent(JComponent targetContent) {
252:                this .targetContent = targetContent;
253:            }
254:
255:            /**
256:             * Sets transient content component reference. This method does NOT place any component into container.
257:             */
258:            public void setTransContent(JComponent transContent) {
259:                this .transContent = transContent;
260:            }
261:
262:            /**
263:             * Overriden - we need to store reference to the content component
264:             */
265:            public Component add(Component component) {
266:                content = (JComponent) component;
267:
268:                return super .add(component);
269:            }
270:
271:            /**
272:             * locks the content size - while resizing the content component size and layout remains the same
273:             */
274:            public void lockContentResizing(boolean lock) {
275:                if ((lock) && (transContent != null)) {
276:                    layout.setLockedSize(transContent.getSize());
277:                } else {
278:                    layout.setLockedSize(null);
279:                }
280:            }
281:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.