KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtriver > open > vectorvisuals > example > meta > AnimatedConnectors


1 /*
2  * AnimatedConnectors.java
3  *
4  * Created on 23 May 2005, 13:46
5  */

6
7 package com.thoughtriver.open.vectorvisuals.example.meta;
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.meta.connector.*;
16 import com.thoughtriver.open.vectorvisuals.task.*;
17
18 /**
19  * This example illustrates the use of <CODE>AnimationTask</CODE> in
20  * combination with the <CODE>VisualConnectorObject</CODE>. It renders a
21  * simple military tank that drives in a circle around the view area while its
22  * turret moves back and forth. The tank has a couple of connectors pointing to
23  * specific parts of it, and the connectors continue to point at the tank no
24  * matter where it goes.
25  *
26  * @author Brandon Franklin
27  * @version $Date: 2006/11/25 09:23:20 $
28  */

29 public class AnimatedConnectors implements Runnable JavaDoc {
30
31     /** The <CODE>VVDisplay</CODE> used to display the test */
32     private VVDisplay vvDisplay = null;
33
34     /**
35      * Creates a new instance of <CODE>AnimatedConnectors</CODE>.
36      */

37     public AnimatedConnectors() {
38         vvDisplay = new VVDisplay(new VVPanel());
39     }
40
41     /**
42      * Starts the example.
43      */

44     public void run() {
45         JFrame frame = new JFrame("Vector Visuals Animated Connectors Example");
46         frame.setSize(640, 480);
47         frame.getContentPane().setLayout(new BorderLayout());
48         frame.getContentPane().add(vvDisplay.getViewPane(), BorderLayout.CENTER);
49         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
50
51         frame.setVisible(true);
52
53         // Set up the panel itself
54
vvDisplay.getViewPane().setBackground(Color.DARK_GRAY);
55         vvDisplay.setWorldViewTranslation(125, 0);
56         vvDisplay.setWorldViewScale(1);
57
58         VisualObject container = new VisualContainerObject();
59
60         AffineTransform transform = AffineTransform.getTranslateInstance(200, 200);
61         container.setTransform(transform);
62         vvDisplay.addObject(container);
63
64         ArmyTank tank = new ArmyTank();
65
66         // Center the tank
67
transform = AffineTransform.getTranslateInstance(125, 0);
68         tank.setTransform(transform);
69         container.add(tank);
70
71         // Animation
72
IndefiniteOscillationTask task = new IndefiniteOscillationTask(tank.getTurret(), 1);
73         task.setRate(1);
74         vvDisplay.getTaskManager().addTask(task);
75
76         // A couple of label boxes
77
Brush boxLineBrush = new Brush(Color.WHITE, null, null);
78         Brush boxFillBrush = new Brush(Color.BLUE, null, null);
79         Brush textLineBrush = null;
80         Brush textFillBrush = new Brush(Color.WHITE, null, null);
81         Font labelFont = new Font("SansSerif", Font.BOLD, 20);
82         VisualObject labelBox1 = new VisualObject(new RoundRectangle2D.Double(0, 0, 100, 35, 15, 15), boxLineBrush, boxFillBrush);
83         labelBox1.setLayer(2);
84         transform = AffineTransform.getTranslateInstance(50, 50);
85         labelBox1.setTransform(transform);
86         VisualTextObject label1 = new VisualTextObject("Tank", labelFont, textLineBrush, textFillBrush);
87         transform = AffineTransform.getTranslateInstance(25, 25);
88         label1.setTransform(transform);
89         labelBox1.add(label1);
90
91         VisualObject labelBox2 = new VisualObject(new RoundRectangle2D.Double(0, 0, 100, 35, 15, 15), boxLineBrush, boxFillBrush);
92         labelBox2.setLayer(2);
93         transform = AffineTransform.getTranslateInstance(200, 325);
94         labelBox2.setTransform(transform);
95         VisualTextObject label2 = new VisualTextObject("Turret", labelFont, textLineBrush, textFillBrush);
96         transform = AffineTransform.getTranslateInstance(20, 25);
97         label2.setTransform(transform);
98         labelBox2.add(label2);
99
100         vvDisplay.addObject(labelBox1);
101         vvDisplay.addObject(labelBox2);
102
103         // Connectors
104
EndpointConfiguration config1 = new EndpointConfiguration(null, labelBox1, true);
105         EndpointConfiguration config2 = new EndpointConfiguration(ArrowTipFactory.getAngularArrowTip(), tank, true);
106         VisualConnectorObject conn1 = new VisualConnectorObject(new Brush(Color.WHITE, null, null), config1, config2);
107         vvDisplay.addObject(conn1);
108
109         config1 = new EndpointConfiguration(null, labelBox2, true);
110         config2 = new EndpointConfiguration(ArrowTipFactory.getAngularArrowTip(), tank.getTurret(), false);
111         VisualConnectorObject conn2 = new VisualConnectorObject(new Brush(Color.WHITE, null, null), config1, config2);
112         vvDisplay.addObject(conn2);
113
114         // Animate the root container with an endless rotation
115
IndefiniteRotationTask task2 = new IndefiniteRotationTask(container);
116         task2.setRate(-0.5);
117         vvDisplay.getTaskManager().addTask(task2);
118     }
119
120     /**
121      * Instantiates a <CODE>AnimatedConnectors</CODE> and executes it.
122      *
123      * @param args the command line arguments, ignored here
124      */

125     public static void main(final String JavaDoc[] args) {
126         Runnable JavaDoc example = new AnimatedConnectors();
127         example.run();
128     }
129
130 }
131
Popular Tags