KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * HelloClipping.java
3  *
4  * Created on 14 March 2006, 4:30 PM
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 in such a way that the embedded objects are clipped to the
20  * shape of the containing object.
21  *
22  * @author Brandon Franklin
23  * @version $Date: 2006/11/25 09:35:06 $
24  */

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

33     public HelloClipping() {
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 Clipping 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.setWorldViewScale(1);
52
53         // Create a nice red rectangle
54
Brush rectLineBrush = new Brush(Color.WHITE, null, null);
55         Brush rectFillBrush = new Brush(Color.RED, null, null);
56         VisualObject rectangle = new VisualObject(new Rectangle2D.Double(0, 0, 115, 40), rectLineBrush, rectFillBrush);
57
58         // Create a text object reading "Hello, Clipping!"
59
Brush textBrush = new Brush(Color.YELLOW, null, null);
60         VisualTextObject textObj = new VisualTextObject("Hello, Clipping!", null, null, textBrush);
61
62         // Embed the text object into the rectangle object, so they'll move and
63
// scale together
64
rectangle.add(textObj);
65
66         // Set the location of the text inside the rectangle
67
AffineTransform transform = textObj.getTransform();
68         transform.translate(-18, 25);
69         textObj.setTransform(transform);
70         textObj.setLayer(-1);
71
72         // Move and rescale the rectangle
73
transform = rectangle.getTransform();
74         transform.scale(3.0, 3.0);
75         transform.translate(50, 45);
76         rectangle.setTransform(transform);
77
78         // Display the objects on the VVPanel
79
vvDisplay.addObject(rectangle);
80     }
81
82     /**
83      * Instantiates a <CODE>HelloClipping</CODE> and executes it.
84      *
85      * @param args the command line arguments, ignored here
86      */

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