KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtriver > open > vectorvisuals > example > fundamental > Grouping


1 /*
2  * Grouping.java
3  *
4  * Created on 3 August 2004, 22:58
5  */

6
7 package com.thoughtriver.open.vectorvisuals.example.fundamental;
8
9 import java.awt.*;
10 import java.awt.geom.*;
11
12 import javax.swing.*;
13
14 import com.thoughtriver.open.vectorvisuals.*;
15
16 /**
17  * This small application illustrates how to create a Vector Visuals drawing
18  * area (a <CODE>VVDisplay</CODE>) and place objects in a group on it.
19  *
20  * @author Brandon Franklin
21  * @version $Date: 2006/11/25 09:35:06 $
22  */

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

31     public Grouping() {
32         vvDisplay = new VVDisplay(new VVPanel());
33     }
34
35     /**
36      * Starts the example.
37      */

38     public void run() {
39         JFrame frame = new JFrame("Vector Visuals Grouping Example");
40         frame.setSize(640, 480);
41         frame.getContentPane().setLayout(new BorderLayout());
42         frame.getContentPane().add(vvDisplay.getViewPane(), BorderLayout.CENTER);
43         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
44
45         frame.setVisible(true);
46
47         // Set up the panel itself
48
vvDisplay.getViewPane().setBackground(Color.DARK_GRAY);
49         vvDisplay.setWorldViewScale(1);
50
51         // Create a nice red rectangle
52
Brush rectLineBrush1 = new Brush(Color.WHITE, null, null);
53         Brush rectFillBrush1 = new Brush(Color.RED, null, null);
54         VisualObject rectangle1 = new VisualObject(new Rectangle2D.Double(0, 0, 115, 40), rectLineBrush1, rectFillBrush1);
55
56         // Create a nice yellow rectangle
57
Brush rectLineBrush2 = new Brush(Color.BLACK, null, null);
58         Brush rectFillBrush2 = new Brush(Color.YELLOW, null, null);
59         VisualObject rectangle2 = new VisualObject(new Rectangle2D.Double(0, 0, 40, 90), rectLineBrush2, rectFillBrush2);
60
61         // Create a nice blue rectangle
62
Brush rectLineBrush3 = new Brush(Color.YELLOW, null, null);
63         Brush rectFillBrush3 = new Brush(Color.BLUE, null, null);
64         VisualObject rectangle3 = new VisualObject(new Rectangle2D.Double(0, 0, 60, 60), rectLineBrush3, rectFillBrush3);
65
66         // Create a container object to group the rectangles
67
VisualObject group = new VisualContainerObject();
68         group.add(rectangle1);
69         group.add(rectangle2);
70         group.add(rectangle3);
71
72         // Set the location of the rectangles inside the group
73
AffineTransform transform = rectangle1.getTransform();
74         transform.translate(-120, 0);
75         rectangle1.setTransform(transform);
76
77         transform = rectangle2.getTransform();
78         transform.translate(0, 0);
79         rectangle2.setTransform(transform);
80
81         transform = rectangle3.getTransform();
82         transform.translate(50, 0);
83         rectangle3.setTransform(transform);
84
85         // Rotate the group
86
// NOTE: The order of operations matters here! Try rotating before
87
// translating.
88
transform = group.getTransform();
89         transform.translate(250, 200);
90         transform.rotate(0.5);
91         group.setTransform(transform);
92
93         // Display the objects on the VVPanel
94
vvDisplay.addObject(group);
95     }
96
97     /**
98      * Instantiates a <CODE>Grouping</CODE> and executes it.
99      *
100      * @param args the command line arguments, ignored here
101      */

102     public static void main(final String JavaDoc[] args) {
103         Runnable JavaDoc example = new Grouping();
104         example.run();
105     }
106
107 }
108
Popular Tags