KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgrapht > experimental > touchgraph > SimpleTouchgraphApplet


1 /* ==========================================
2  * JGraphT : a free Java graph-theory library
3  * ==========================================
4  *
5  * Project Info: http://jgrapht.sourceforge.net/
6  * Project Creator: Barak Naveh (http://sourceforge.net/users/barak_naveh)
7  *
8  * (C) Copyright 2003-2006, by Barak Naveh and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this library; if not, write to the Free Software Foundation,
22  * Inc.,
23  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
24  */

25 /* -------------------
26  * SimpleTouchgraphApplet.java
27  * -------------------
28  * (C) Copyright 2006-2006, by Carl Anderson and Contributors.
29  *
30  * Original Author: Carl Anderson
31  * Contributor(s): -
32  *
33  * $Id: SimpleTouchgraphApplet.java 504 2006-07-03 02:37:26Z perfecthash $
34  *
35  * Changes
36  * -------
37  * 8-May-2006 : Initial revision (CA);
38  *
39  */

40 package org.jgrapht.experimental.touchgraph;
41
42 import java.applet.*;
43
44 import java.awt.*;
45
46 import javax.swing.*;
47
48 import org.jgrapht.*;
49 import org.jgrapht.graph.*;
50
51
52 /**
53  * SimpleTouchgraphApplet
54  *
55  * @author canderson
56  */

57 public class SimpleTouchgraphApplet
58     extends Applet
59 {
60
61     //~ Static fields/initializers --------------------------------------------
62

63     /**
64      */

65     private static final long serialVersionUID = 6213379835360007840L;
66
67     //~ Methods ---------------------------------------------------------------
68

69     /**
70      * create a graph: code taken from non-visible
71      * org._3pq.jgrapht.demo.createStringGraph()
72      */

73     public static Graph<String JavaDoc, DefaultEdge> createSamplegraph()
74     {
75         UndirectedGraph<String JavaDoc, DefaultEdge> g =
76             new SimpleGraph<String JavaDoc, DefaultEdge>(DefaultEdge.class);
77
78         String JavaDoc v1 = "v1";
79         String JavaDoc v2 = "v2";
80         String JavaDoc v3 = "v3";
81         String JavaDoc v4 = "v4";
82
83         // add the vertices
84
g.addVertex(v1);
85         g.addVertex(v2);
86         g.addVertex(v3);
87         g.addVertex(v4);
88
89         // add edges to create a circuit
90
g.addEdge(v1, v2);
91         g.addEdge(v2, v3);
92         g.addEdge(v3, v4);
93         g.addEdge(v4, v1);
94
95         return g;
96     }
97
98     /**
99      * initialize the applet
100      */

101     public void init()
102     {
103         Graph<String JavaDoc, DefaultEdge> g = createSamplegraph();
104         boolean selfReferencesAllowed = false;
105
106         setLayout(new BorderLayout());
107         setSize(800, 600);
108         add(
109             new TouchgraphPanel<String JavaDoc, DefaultEdge>(g, selfReferencesAllowed),
110             BorderLayout.CENTER);
111     }
112
113     public static void main(String JavaDoc [] args)
114     {
115         Graph<String JavaDoc, DefaultEdge> g = createSamplegraph();
116         boolean selfReferencesAllowed = false;
117
118         JFrame frame = new JFrame();
119         frame.getContentPane().add(
120             new TouchgraphPanel<String JavaDoc, DefaultEdge>(g, selfReferencesAllowed));
121         frame.setPreferredSize(new Dimension(800, 800));
122         frame.setTitle("JGraphT to Touchgraph Converter Demo");
123         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
124         frame.pack();
125         frame.setVisible(true);
126         try {
127             Thread.sleep(5000000);
128         } catch (InterruptedException JavaDoc ex) {
129         }
130     }
131 }
132
133 // End SimpleTouchgraphApplet.java
134
Popular Tags