KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ObjectTranslating.java
3  *
4  * Created on 17 October 2005, 16:48
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 moves them in various ways.
21  *
22  * @author Brandon Franklin
23  * @version $Date: 2006/11/25 09:31:50 $
24  */

25 public class ObjectTranslating 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>ObjectTranslating</CODE>.
32      */

33     public ObjectTranslating() {
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 Translating 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, 120, 80), 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 translate 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 TranslationTask(textObj, 100, 75, 4000));
91         chain.addTask(new TranslationTask(textObj, -40, -100, 2000));
92         chain.addTask(new TranslationTask(textObj, -60, 25, 3000));
93         vvDisplay.getTaskManager().addTask(chain);
94
95         vvDisplay.getTaskManager().addTask(new TranslationTask(rectangle1, 50, -50, 10000));
96         vvDisplay.getTaskManager().addTask(new TranslationTask(rectangle2, -15, 75, 5000));
97
98         chain = new TaskChain();
99         chain.addTask(new TranslationTask(ellipse, 0, -50, 2000));
100         chain.addTask(new TranslationTask(ellipse, -30, 75, 5000));
101         vvDisplay.getTaskManager().addTask(chain);
102     }
103
104     /**
105      * Instantiates a <CODE>ObjectTranslating</CODE> and executes it.
106      *
107      * @param args the command line arguments, ignored here
108      */

109     public static void main(final String JavaDoc[] args) {
110         Runnable JavaDoc example = new ObjectTranslating();
111         example.run();
112     }
113
114 }
115
Popular Tags