KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * DisplayScaling.java
3  *
4  * Created on 17 October 2005, 12:15
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, expands, and resets the scale of the view in a smooth way.
21  *
22  * @author Brandon Franklin
23  * @version $Date: 2006/11/25 09:31:50 $
24  */

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

33     public DisplayScaling() {
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 Display 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(120, 150, 115, 40), rectLineBrush1, rectFillBrush1);
58
59         // Create a nice yellow rectangle
60
Brush rectLineBrush2 = new Brush(Color.BLACK, null, null);
61         Brush rectFillBrush2 = new Brush(Color.YELLOW, null, null);
62         VisualObject rectangle2 = new VisualObject(new Rectangle2D.Double(240, 75, 40, 90), rectLineBrush2, rectFillBrush2);
63
64         // Create a nice blue rectangle
65
Brush rectLineBrush3 = new Brush(Color.YELLOW, null, null);
66         Brush rectFillBrush3 = new Brush(Color.BLUE, null, null);
67         VisualObject rectangle3 = new VisualObject(new Rectangle2D.Double(380, 250, 60, 60), rectLineBrush3, rectFillBrush3);
68
69         // Create some descriptive text
70
Brush brush = new Brush(Color.YELLOW, null, null);
71         VisualTextObject textObj = new VisualTextObject("Vectors scale nicely", null, null, brush);
72
73         // Set the location and size of the objects
74
AffineTransform transform = textObj.getTransform();
75         transform.scale(2.0, 2.0);
76         transform.translate(15, 120);
77         textObj.setTransform(transform);
78
79         // Display the objects on the VVPanel
80
vvDisplay.addObject(rectangle1);
81         vvDisplay.addObject(rectangle2);
82         vvDisplay.addObject(rectangle3);
83         vvDisplay.addObject(textObj);
84
85         // Activate the animation
86
TaskChain chain = new TaskChain();
87         chain.addTask(new DisplayScalingTask(vvDisplay, 0.1, 5000));
88         chain.addTask(new DisplayScalingTask(vvDisplay, 2.0, 2000));
89         chain.addTask(new DisplayScalingTask(vvDisplay, 1.0, 3000));
90         vvDisplay.getTaskManager().addTask(chain);
91     }
92
93     /**
94      * Instantiates a <CODE>DisplayScaling</CODE> and executes it.
95      *
96      * @param args the command line arguments, ignored here
97      */

98     public static void main(final String JavaDoc[] args) {
99         Runnable JavaDoc example = new DisplayScaling();
100         example.run();
101     }
102
103 }
104
Popular Tags