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.event.ActionListener;
044: import javax.swing.*;
045:
046: /**
047: * This class animates two <code>AnimatedContainers</code> - the selected one is enlarging, the previously selected container is shrinking.
048: * The animation parameters are set here as static final fields.
049: * CURRENTLY WE DO NOT USE THIS CLASS.
050: */
051: public class Animator implements ActionListener {
052: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
053:
054: private static final int STEPS = 5;
055: private static final int DURATION = 100; //miliseconds
056:
057: //~ Instance fields ----------------------------------------------------------------------------------------------------------
058:
059: //containers that will be animated
060: AnimatedContainer cont1;
061:
062: //~ Instance fields ----------------------------------------------------------------------------------------------------------
063:
064: //containers that will be animated
065: AnimatedContainer cont2;
066:
067: //timer producing animation frames events
068: Timer timer;
069: private int stepsCounter;
070:
071: //~ Constructors -------------------------------------------------------------------------------------------------------------
072:
073: /** Creates a new instance of Animator */
074: public Animator(AnimatedContainer cont1, AnimatedContainer cont2) {
075: this .cont1 = cont1;
076: this .cont2 = cont2;
077:
078: timer = new Timer(DURATION / STEPS, null);
079: }
080:
081: //~ Methods ------------------------------------------------------------------------------------------------------------------
082:
083: public void actionPerformed(java.awt.event.ActionEvent e) {
084: performAnimationStep();
085: }
086:
087: public void startAnimation() {
088: //reset counter
089: stepsCounter = 0;
090:
091: //register itself to timer
092: timer.addActionListener(this );
093:
094: //start animation
095: timer.start();
096: }
097:
098: private void performAnimationStep() {
099: int percIncrement = (int) 100 / STEPS;
100:
101: stepsCounter++;
102:
103: if (stepsCounter == STEPS) {
104: cont1.setFinishState();
105:
106: if (cont2 != null) {
107: cont2.setFinishState();
108: }
109:
110: cont1.revalidate();
111:
112: if (cont2 != null) {
113: cont2.revalidate();
114: }
115:
116: //stop animation
117: timer.stop();
118: //unregister
119: timer.removeActionListener(this);
120: } else {
121: cont1.setState(stepsCounter * percIncrement);
122:
123: if (cont2 != null) {
124: cont2.setState(stepsCounter * percIncrement);
125: }
126:
127: cont1.revalidate();
128:
129: if (cont2 != null) {
130: cont2.revalidate();
131: }
132: }
133: }
134: }
|