KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * HelloEmbedding.java
3  *
4  * Created on 2 August 2004, 01:29
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>), place objects on it, and embed objects
19  * into one another.
20  *
21  * @author Brandon Franklin
22  * @version $Date: 2006/11/25 09:35:06 $
23  */

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

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

39     public void run() {
40         JFrame frame = new JFrame("Vector Visuals Embedding Example");
41         frame.setSize(640, 480);
42         frame.getContentPane().setLayout(new BorderLayout());
43         frame.getContentPane().add(vvDisplay.getViewPane(), BorderLayout.CENTER);
44         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
45
46         frame.setVisible(true);
47
48         // Set up the panel itself
49
vvDisplay.getViewPane().setBackground(Color.DARK_GRAY);
50         vvDisplay.setWorldViewScale(1);
51
52         // Create a nice red rectangle
53
Brush rectLineBrush = new Brush(Color.WHITE, null, null);
54         Brush rectFillBrush = new Brush(Color.RED, null, null);
55         VisualObject rectangle = new VisualObject(new Rectangle2D.Double(0, 0, 115, 40), rectLineBrush, rectFillBrush);
56
57         // Create a text object reading "Hello, Embedding!"
58
Brush textBrush = new Brush(Color.YELLOW, null, null);
59         VisualTextObject textObj = new VisualTextObject("Hello, Embedding!", null, null, textBrush);
60
61         // Embed the text object into the rectangle object, so they'll move and
62
// scale together
63
rectangle.add(textObj);
64
65         // Set the location of the text inside the rectangle
66
AffineTransform transform = textObj.getTransform();
67         transform.translate(5, 25);
68         textObj.setTransform(transform);
69
70         // Move and rescale the rectangle
71
transform = rectangle.getTransform();
72         transform.scale(3.0, 3.0);
73         transform.translate(50, 45);
74         rectangle.setTransform(transform);
75
76         // Display the objects on the VVPanel
77
vvDisplay.addObject(rectangle);
78     }
79
80     /**
81      * Instantiates a <CODE>HelloEmbedding</CODE> and executes it.
82      *
83      * @param args the command line arguments, ignored here
84      */

85     public static void main(final String JavaDoc[] args) {
86         Runnable JavaDoc example = new HelloEmbedding();
87         example.run();
88     }
89
90 }
91
Popular Tags