KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtriver > open > vectorvisuals > example > animation > ObjectScaling


1 /*
2  * ObjectScaling.java
3  *
4  * Created on 17 October 2005, 13:25
5  */

6
7 package com.thoughtriver.open.vectorvisuals.example.animation;
8
9 import java.awt.*;
10 import java.awt.geom.*;
11
12 import javax.swing.*;
13
14 import com.thoughtriver.open.vectorvisuals.*;
15 import com.thoughtriver.open.vectorvisuals.task.*;
16
17 /**
18  * This example illustrates the use of <CODE>AnimationTask</CODE> that is
19  * included with the Vector Visuals framework. It creates a few simple objects,
20  * then shrinks and expands their scales in a smooth way.
21  *
22  * @author Brandon Franklin
23  * @version $Date: 2006/11/25 09:31:50 $
24  */

25 public class ObjectScaling implements Runnable JavaDoc {
26
27     /** The <CODE>VVDisplay</CODE> used to display the test */
28     private VVDisplay vvDisplay = null;
29
30     /**
31      * Creates a new instance of <CODE>ObjectScaling</CODE>.
32      */

33     public ObjectScaling() {
34         vvDisplay = new VVDisplay(new VVPanel());
35     }
36
37     /**
38      * Starts the example.
39      */

40     public void run() {
41         JFrame frame = new JFrame("Vector Visuals Object Scaling Example");
42         frame.setSize(640, 480);
43         frame.getContentPane().setLayout(new BorderLayout());
44         frame.getContentPane().add(vvDisplay.getViewPane(), BorderLayout.CENTER);
45         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
46
47         frame.setVisible(true);
48
49         // Set up the panel itself
50
vvDisplay.getViewPane().setBackground(Color.DARK_GRAY);
51         vvDisplay.setWorldViewTranslation(80, 20);
52         vvDisplay.setWorldViewScale(1);
53
54         // Create a nice red rectangle
55
Brush rectLineBrush1 = new Brush(Color.WHITE, null, null);
56         Brush rectFillBrush1 = new Brush(Color.RED, null, null);
57         VisualObject rectangle1 = new VisualObject(new Rectangle2D.Double(0, 0, 115, 40), rectLineBrush1, rectFillBrush1);
58         rectangle1.setTransform(AffineTransform.getTranslateInstance(120, 150));
59
60         // Create a nice yellow rectangle
61
Brush rectLineBrush2 = new Brush(Color.BLACK, null, null);
62         Brush rectFillBrush2 = new Brush(Color.YELLOW, null, null);
63         VisualObject rectangle2 = new VisualObject(new Rectangle2D.Double(0, 0, 40, 90), rectLineBrush2, rectFillBrush2);
64         rectangle2.setTransform(AffineTransform.getTranslateInstance(240, 75));
65
66         // Create a nice blue ellipse
67
Brush lineBrush3 = new Brush(Color.YELLOW, null, null);
68         Brush fillBrush3 = new Brush(Color.BLUE, null, null);
69         VisualObject ellipse = new VisualObject(new Ellipse2D.Double(0, 0, 60, 60), lineBrush3, fillBrush3);
70         ellipse.setTransform(AffineTransform.getTranslateInstance(210, 180));
71
72         // Create some descriptive text
73
Brush brush = new Brush(Color.YELLOW, null, null);
74         VisualTextObject textObj = new VisualTextObject("Vectors scale nicely", null, null, brush);
75
76         // Set the location and size of the objects
77
AffineTransform transform = textObj.getTransform();
78         transform.scale(2.0, 2.0);
79         transform.translate(15, 120);
80         textObj.setTransform(transform);
81
82         // Display the objects on the VVPanel
83
vvDisplay.addObject(rectangle1);
84         vvDisplay.addObject(rectangle2);
85         vvDisplay.addObject(ellipse);
86         vvDisplay.addObject(textObj);
87
88         // Activate the animation
89
TaskChain chain = new TaskChain();
90         chain.addTask(new ScalingTask(textObj, 0.1, 0.1, 4000));
91         chain.addTask(new ScalingTask(textObj, 1, 2, 3000));
92         chain.addTask(new ScalingTask(textObj, 3, 0.5, 1000));
93         chain.addTask(new ScalingTask(textObj, 2, 2, 2000));
94         vvDisplay.getTaskManager().addTask(chain);
95
96         vvDisplay.getTaskManager().addTask(new ScalingTask(rectangle1, 0.1, 0.1, 10000));
97         vvDisplay.getTaskManager().addTask(new ScalingTask(rectangle2, 3, 3, 5000));
98
99         chain = new TaskChain();
100         chain.addTask(new ScalingTask(ellipse, 3, 0.3, 2000));
101         chain.addTask(new ScalingTask(ellipse, 0.3, 3, 3000));
102         chain.addTask(new ScalingTask(ellipse, 0.75, 0.5, 2000));
103         ;
104         chain.addTask(new ScalingTask(ellipse, 3, 3, 3000));
105         ;
106         vvDisplay.getTaskManager().addTask(chain);
107     }
108
109     /**
110      * Instantiates a <CODE>ObjectScaling</CODE> and executes it.
111      *
112      * @param args the command line arguments, ignored here
113      */

114     public static void main(final String JavaDoc[] args) {
115         Runnable JavaDoc example = new ObjectScaling();
116         example.run();
117     }
118
119 }
120
Popular Tags