KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * MoreConnectors.java
3  *
4  * Created on 23 May 2005, 11:20
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
17 /**
18  * This small application illustrates how to create a Vector Visuals drawing
19  * area (a <CODE>VVDisplay</CODE>) and connect objects using several <CODE>VisualConnectorObject</CODE>s.
20  *
21  * @author Brandon Franklin
22  * @version $Date: 2006/11/25 09:23:20 $
23  */

24 public class MoreConnectors 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>MoreConnectors</CODE>.
31      */

32     public MoreConnectors() {
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 Connectors 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.setWorldViewTranslation(160, 50);
51         vvDisplay.setWorldViewScale(1.5);
52
53         // Define the X position, Y position, height, width, and color of each
54
// connected object
55
double[] xPositions = new double[] {
56                 50, 50, 50, 250, 250, 250
57         };
58         double[] yPositions = new double[] {
59                 50, 125, 200, 125, 200, 275
60         };
61         double[] widths = new double[] {
62                 25, 25, 25, 25, 25, 25
63         };
64         double[] heights = new double[] {
65                 25, 25, 25, 25, 25, 25
66         };
67         Color[] colors = new Color[] {
68                 Color.RED,
69                 Color.BLUE,
70                 Color.GREEN,
71                 Color.RED,
72                 Color.BLUE,
73                 Color.GREEN
74         };
75
76         VisualObject[] objs = new VisualObject[xPositions.length];
77
78         // Create all the objects to connect
79
for (int i = 0; i < objs.length; i++) {
80             VisualObject newObj = new VisualObject(new RoundRectangle2D.Double(xPositions[i], yPositions[i], widths[i], heights[i], 5, 5), new Brush(colors[i], null, null), new Brush(colors[i].darker(), null, null));
81
82             vvDisplay.addObject(newObj);
83             objs[i] = newObj;
84         }
85
86         // Build the connectors
87
Font connectorFont = new Font("SansSerif", Font.PLAIN, 10);
88         Brush connectorTextBrush = new Brush(Color.YELLOW, null, null);
89
90         EndpointConfiguration config1 = new EndpointConfiguration(ArrowTipFactory.getBasicArrowTip(), objs[0], false);
91         EndpointConfiguration config2 = new EndpointConfiguration(ArrowTipFactory.getBasicArrowTip(), objs[3], false);
92         VisualConnectorObject conn1 = new VisualConnectorObject(new Brush(Color.WHITE, null, null), config1, config2);
93         conn1.setLabel("Center to Center", connectorFont, connectorTextBrush);
94         vvDisplay.addObject(conn1);
95
96         config1 = new EndpointConfiguration(ArrowTipFactory.getAngularArrowTip(), objs[1], true);
97         config2 = new EndpointConfiguration(ArrowTipFactory.getAngularArrowTip(), objs[4], true);
98         VisualConnectorObject conn2 = new VisualConnectorObject(new Brush(Color.WHITE, null, null), config1, config2);
99         conn2.setLabel("Edge to Edge", connectorFont, connectorTextBrush);
100         vvDisplay.addObject(conn2);
101
102         config1 = new EndpointConfiguration(ArrowTipFactory.getClosedArrowTip(), objs[2], false);
103         config2 = new EndpointConfiguration(ArrowTipFactory.getClosedArrowTip(), objs[5], true);
104         VisualConnectorObject conn3 = new VisualConnectorObject(new Brush(Color.WHITE, null, null), config1, config2);
105         conn3.setLabel("Center to Edge", connectorFont, connectorTextBrush);
106         vvDisplay.addObject(conn3);
107     }
108
109     /**
110      * Instantiates a <CODE>MoreConnectors</CODE> and executes it.
111      *
112      * @param args the command line arguments, ignored here
113      */

114     public static void main(final String JavaDoc[] args) {
115         Runnable JavaDoc example = new MoreConnectors();
116         example.run();
117     }
118
119 }
120
Popular Tags